cli

package
v0.0.0-...-10b9c98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLI

type CLI struct {
	GCfg       config.GlobalConfigData
	AllBlocks  []*block.BlockType
	BlockIndex index.BlockIndex
}

func NewCLI

func NewCLI(c config.GlobalConfigData) *CLI

NewCLI returns a new command line config.

func (*CLI) AppendBlock

func (cc *CLI) AppendBlock(bk *block.BlockType)

AppendBlock appends a new block to the set of blocks in the blockchain. The block mining reward will be added as the last transaction in the block. Mining will be performed to seal the block. The block will be written out to the file system and the index of blocks is updated. Verification occures that the block has produced a unique hash. (Hash Collisions are possible but very rare - It would be simple to add a fix so that if you get a collision it fixes it. This has not been done).

func (*CLI) AppendTxToBlock

func (cc *CLI) AppendTxToBlock(bk *block.BlockType, tx *transactions.TransactionType)

AppendTxToBlock takes a transaction and appends it to the set of transactions in the block. TxOffset values for transaction outputs have to be set. The BlockNo is also set to the current blocks. If the list of addresses, cc.BLockIndex.FindValue.AddrIndex is nil then the map is allocated.

func (*CLI) BuildBlockFileName

func (cc *CLI) BuildBlockFileName(hashStr string) (fnBlockPath string)

BuildBlockFileName takes a hashStr that is the name of the JSON file withouth the path and `.json` and combines to make a full file name.

func (*CLI) BuildIndexFileName

func (cc *CLI) BuildIndexFileName() (fnIndexPath string)

BuildIndexFileName returns the name of the index.json file with the correct path from the configuration.

func (*CLI) CreateGenesis

func (cc *CLI) CreateGenesis(args []string)

CreateGenesis creates and writes out the genesis block and the initial index.json files. Theis is the ""genesis"" of the blockchain.

func (*CLI) GetNonZeroForAccount

func (cc *CLI) GetNonZeroForAccount(acct addr.AddressType) (rv []*transactions.TxOutputType)

GetNonZeroForAccount returns a slice of tranactions that have a positive (Non-Zero) balance. This is the set of output tranactions that will need to be turned into input tranactions to make a funds transfer occure.

func (*CLI) GetTotalValueForAccount

func (cc *CLI) GetTotalValueForAccount(acct addr.AddressType) (sum int)

GetTotalValueForAccount walks the index finding all the non-zero tranactions for an account and adds up the total value for the account.

func (*CLI) ListAccounts

func (cc *CLI) ListAccounts(args []string)

ListAccounts will walk through the index and find all the accounts, construct a non-dup list the accounts and print it out.

Improvement - this could be split into a library function to get the accoutns and then just print.

func (*CLI) ListAccountsJSON

func (cc *CLI) ListAccountsJSON() string

ListAccounts will walk through the index and find all the accounts, construct a non-dup list the accounts and print it out.

Improvement - this could be split into a library function to get the accoutns and then just print.

func (*CLI) NewEmptyBlock

func (cc *CLI) NewEmptyBlock() (bk *block.BlockType)

func (*CLI) ReadGlobalConfig

func (cc *CLI) ReadGlobalConfig()

ReadGlobalConfig reads in the index and all of the blocks.

func (*CLI) ReadGlobalData

func (cc *CLI) ReadGlobalData(args []string)

ReadGlobalData is an intialization function to read the locally stored set of blocks and index from ./data.

func (*CLI) SendFundsJSON

func (cc *CLI) SendFundsJSON(fromStr, toStr, amountStr, addrStr, signature, msg, memo string) (jsonData string)

SendFundsJSON will process command argumetns and walk through the transaction process of sending funds once. This is essentially the transaction process - but driven from the command line.

func (*CLI) SendFundsTransaction

func (cc *CLI) SendFundsTransaction(
	from addr.AddressType,
	sig lib.SignatureType,
	message string,
	to addr.AddressType,
	amount int,
	memo string,
) (
	tx *transactions.TransactionType,
	err error,
)

SendFundsTransaction is the core chunk of moving funds from one account to another.

This is your homework. Finish out this function and test.

func (*CLI) ShowBalance

func (cc *CLI) ShowBalance(args []string)

ShowBalance will use the index to find an account, then walk through all the unused outputs (the balance) and add that up. Then it will print out the balance for that account.

func (*CLI) ShowBalanceJSON

func (cc *CLI) ShowBalanceJSON(acctStr string) string

ShowBalanceJSON will use the index to find an account, then walk through all the unused outputs (the balance) and add that up. Then it will convert this to a JSON responce and return it.

func (*CLI) TestReadBlock

func (cc *CLI) TestReadBlock(args []string)

TestReadBlock Test code for command line.

func (*CLI) TestSendFunds

func (cc *CLI) TestSendFunds(args []string)

TestSendFunds will process command argumetns and walk through the transaction process of sending funds once. This is essentially the transaction process - but driven from the command line.

func (*CLI) TestWriteBlock

func (cc *CLI) TestWriteBlock(args []string)

TestWriteBlock Test code for command line.

func (*CLI) Usage

func (cc *CLI) Usage()

func (*CLI) ValidateSignature

func (cc *CLI) ValidateSignature(addrStr, signature, msg string) (isValid bool, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL