block

package
v0.0.0-...-8aa4d74 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Defines primitives used to build and interact with both the genesis and common budget blocks / accounts, which are special blocks in the BOScoin blockchain

Index

Constants

This section is empty.

Variables

View Source
var (
	GenesisKP *keypair.Full
	CommonKP  *keypair.Full
)
View Source
var GetBlockTransactions = GetBlockTransactionsByConfirmed

Functions

func DeleteTransactionPool

func DeleteTransactionPool(st *storage.LevelDBBackend, hash string) error

func ExistsBlock

func ExistsBlock(st *storage.LevelDBBackend, hash string) (exists bool, err error)

func ExistsBlockAccount

func ExistsBlockAccount(st *storage.LevelDBBackend, address string) (exists bool, err error)

func ExistsBlockByHeight

func ExistsBlockByHeight(st *storage.LevelDBBackend, height uint64) (exists bool, err error)

func ExistsBlockOperation

func ExistsBlockOperation(st *storage.LevelDBBackend, hash string) (bool, error)

func ExistsBlockTransaction

func ExistsBlockTransaction(st *storage.LevelDBBackend, hash string) (bool, error)

func ExistsTransactionPool

func ExistsTransactionPool(st *storage.LevelDBBackend, hash string) (bool, error)

func GetBlockAccountAddressesByCreated

func GetBlockAccountAddressesByCreated(st *storage.LevelDBBackend, options storage.ListOptions) (func() (string, bool, []byte), func())

func GetBlockAccountCreatedKey

func GetBlockAccountCreatedKey(created string) string

func GetBlockAccountKey

func GetBlockAccountKey(address string) string

func GetBlockAccountSequenceIDByAddress

func GetBlockAccountSequenceIDByAddress(st *storage.LevelDBBackend, address string, options storage.ListOptions) (func() (BlockAccountSequenceID, bool, []byte), func())

func GetBlockAccountSequenceIDByAddressKey

func GetBlockAccountSequenceIDByAddressKey(address string) string

func GetBlockAccountSequenceIDByAddressKeyPrefix

func GetBlockAccountSequenceIDByAddressKeyPrefix(address string) string

func GetBlockAccountSequenceIDKey

func GetBlockAccountSequenceIDKey(address string, sequenceID uint64) string

func GetBlockAccountsByCreated

func GetBlockAccountsByCreated(st *storage.LevelDBBackend, options storage.ListOptions) (func() (*BlockAccount, bool, []byte), func())

func GetBlockHeadersByConfirmed

func GetBlockHeadersByConfirmed(st *storage.LevelDBBackend, options storage.ListOptions) (
	func() (Header, bool, []byte),
	func(),
)

func GetBlockKeyPrefixHeight

func GetBlockKeyPrefixHeight(height uint64) string

GetBlockKeyPrefixHeight returns index key by height. It is used to make cursor as height.

func GetBlockOperationCreateFrozenKey

func GetBlockOperationCreateFrozenKey(hash string, height uint64) string

func GetBlockOperationsByBlockHeight

func GetBlockOperationsByBlockHeight(st *storage.LevelDBBackend, height uint64, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockOperationsByFrozen

func GetBlockOperationsByFrozen(st *storage.LevelDBBackend, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

Find all operations which created frozen account.

func GetBlockOperationsByLinked

func GetBlockOperationsByLinked(st *storage.LevelDBBackend, hash string, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

Find all operations which created frozen account and have the link of a general account's address.

func GetBlockOperationsByPeers

func GetBlockOperationsByPeers(st *storage.LevelDBBackend, addr string, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockOperationsByPeersAndType

func GetBlockOperationsByPeersAndType(st *storage.LevelDBBackend, addr string, ty operation.OperationType, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockOperationsBySource

func GetBlockOperationsBySource(st *storage.LevelDBBackend, source string, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockOperationsBySourceAndType

func GetBlockOperationsBySourceAndType(st *storage.LevelDBBackend, source string, ty operation.OperationType, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockOperationsByTarget

func GetBlockOperationsByTarget(st *storage.LevelDBBackend, target string, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockOperationsByTargetAndType

func GetBlockOperationsByTargetAndType(st *storage.LevelDBBackend, target string, ty operation.OperationType, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockOperationsByTx

func GetBlockOperationsByTx(st *storage.LevelDBBackend, txHash string, options storage.ListOptions) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func GetBlockTransactionKey

func GetBlockTransactionKey(hash string) string

func GetBlockTransactionKeyPrefixAccount

func GetBlockTransactionKeyPrefixAccount(accountAddress string) string

func GetBlockTransactionKeyPrefixBlock

func GetBlockTransactionKeyPrefixBlock(hash string) string

func GetBlockTransactionKeyPrefixConfirmed

func GetBlockTransactionKeyPrefixConfirmed(confirmed string) string

func GetBlockTransactionKeyPrefixSource

func GetBlockTransactionKeyPrefixSource(source string) string

func GetBlockTransactionsByAccount

func GetBlockTransactionsByAccount(st *storage.LevelDBBackend, accountAddress string, options storage.ListOptions) (
	func() (BlockTransaction, bool, []byte),
	func(),
)

func GetBlockTransactionsByBlock

func GetBlockTransactionsByBlock(st *storage.LevelDBBackend, hash string, options storage.ListOptions) (
	func() (BlockTransaction, bool, []byte),
	func(),
)

func GetBlockTransactionsByConfirmed

func GetBlockTransactionsByConfirmed(st *storage.LevelDBBackend, options storage.ListOptions) (
	func() (BlockTransaction, bool, []byte),
	func(),
)

func GetBlockTransactionsBySource

func GetBlockTransactionsBySource(st *storage.LevelDBBackend, source string, options storage.ListOptions) (
	func() (BlockTransaction, bool, []byte),
	func(),
)

func GetBlocksByConfirmed

func GetBlocksByConfirmed(st *storage.LevelDBBackend, options storage.ListOptions) (
	func() (Block, bool, []byte),
	func(),
)

func GetTransactionPoolKey

func GetTransactionPoolKey(hash string) string

func InitTestBlockchain

func InitTestBlockchain() *storage.LevelDBBackend

Like `MakeTestBlockchain`, but also create a storage

func LoadBlockAccountsInsideIterator

func LoadBlockAccountsInsideIterator(
	st *storage.LevelDBBackend,
	iterFunc func() (storage.IterItem, bool),
	closeFunc func(),
) (
	func() (*BlockAccount, bool, []byte),
	func(),
)

func LoadBlockHeadersInsideIterator

func LoadBlockHeadersInsideIterator(
	st *storage.LevelDBBackend,
	iterFunc func() (storage.IterItem, bool),
	closeFunc func(),
) (
	func() (Header, bool, []byte),
	func(),
)

func LoadBlockOperationsInsideIterator

func LoadBlockOperationsInsideIterator(
	st *storage.LevelDBBackend,
	iterFunc func() (storage.IterItem, bool),
	closeFunc func(),
) (
	func() (BlockOperation, bool, []byte),
	func(),
)

func LoadBlockTransactionsInsideIterator

func LoadBlockTransactionsInsideIterator(
	st *storage.LevelDBBackend,
	iterFunc func() (storage.IterItem, bool),
	closeFunc func(),
) (
	func() (BlockTransaction, bool, []byte),
	func(),
)

func LoadBlocksInsideIterator

func LoadBlocksInsideIterator(
	st *storage.LevelDBBackend,
	iterFunc func() (storage.IterItem, bool),
	closeFunc func(),
) (
	func() (Block, bool, []byte),
	func(),
)

func MakeTestBlockchain

func MakeTestBlockchain(st *storage.LevelDBBackend)

Make a default-initialized test blockchain

Write to the provided storage the genesis and common account, as well as the genesis block. This provide a simple, workable chain to use within tests.

If anything goes wrong, `panic`

Params:

st = Storage to write the blockchain to

func NewBlockOperationKey

func NewBlockOperationKey(opHash, txHash string) string

func WalkBlocks

func WalkBlocks(st *storage.LevelDBBackend, option *storage.WalkOption, walkFunc func(*Block, []byte) (bool, error)) error

Types

type Block

type Block struct {
	Header
	Transactions        []string `json:"transactions"`         /* []Transaction.GetHash() */
	ProposerTransaction string   `json:"proposer_transaction"` /* ProposerTransaction */

	Hash      string `json:"hash"`
	Proposer  string `json:"proposer"` /* Node.Address() */
	Round     uint64 `json:"round"`
	Confirmed string `json:"confirmed" rlp:"-"`
}

func GetBlock

func GetBlock(st *storage.LevelDBBackend, hash string) (bt Block, err error)

func GetBlockByHeight

func GetBlockByHeight(st *storage.LevelDBBackend, height uint64) (bt Block, err error)

func GetGenesis

func GetGenesis(st *storage.LevelDBBackend) Block

Returns: Genesis block

func GetLatestBlock

func GetLatestBlock(st *storage.LevelDBBackend) Block

func MakeGenesisBlock

func MakeGenesisBlock(st *storage.LevelDBBackend, genesisAccount BlockAccount, commonAccount BlockAccount, networkID []byte) (blk *Block, err error)

MakeGenesisBlock makes genesis block.

This special block has different part from the other Block * `Block.Proposer` is empty * `Block.Transaction` is empty * `Block.ProposedTime` is `common.GenesisBlockConfirmedTime` * has only one `Transaction`

This Transaction is different from other normal Transaction; * signed by `keypair.Master(string(networkID))` * must have only two `Operation`, `CreateAccount` * The first `Operation` is for genesis account

  • `CreateAccount.Amount` is same with balance of genesis account
  • `CreateAccount.Target` is genesis account

* The next `Operation` is for common account

  • `CreateAccount.Amount` is 0
  • `CreateAccount.Target` is common account

* `Transaction.B.Fee` is 0

func NewBlock

func NewBlock(proposer string, basis voting.Basis, ptx string, transactions []string, proposedTime string) *Block

NewBlock creates new block; `ptx` represents the `ProposerTransaction.GetHash()`.

func TestMakeNewBlock

func TestMakeNewBlock(transactions []string) Block

func TestMakeNewBlockWithPrevBlock

func TestMakeNewBlockWithPrevBlock(prevBlock Block, txs []string) Block

func (Block) IsEmpty

func (bck Block) IsEmpty() bool

func (*Block) MustSave

func (b *Block) MustSave(st *storage.LevelDBBackend)

/ Version of `Block.Save` that panics on error, usable only in tests

func (Block) NewBlockKeyConfirmed

func (b Block) NewBlockKeyConfirmed() string

func (Block) NextBlock

func (b Block) NextBlock(st *storage.LevelDBBackend) (Block, error)

func (Block) PreviousBlock

func (b Block) PreviousBlock(st *storage.LevelDBBackend) (blk Block, err error)

func (*Block) Save

func (b *Block) Save(st *storage.LevelDBBackend) (err error)

func (Block) String

func (bck Block) String() string

type BlockAccount

type BlockAccount struct {
	Address    string        `json:"address"`
	Balance    common.Amount `json:"balance"`
	SequenceID uint64        `json:"sequence_id"`
	// An address, or "" if the account isn't frozen
	Linked   string      `json:"linked"`
	CodeHash []byte      `json:"code_hash"`
	RootHash common.Hash `json:"root_hash"`
}

func GetBlockAccount

func GetBlockAccount(st *storage.LevelDBBackend, address string) (b *BlockAccount, err error)

func NewBlockAccount

func NewBlockAccount(address string, balance common.Amount) *BlockAccount

func NewBlockAccountLinked

func NewBlockAccountLinked(address string, balance common.Amount, linked string) *BlockAccount

func TestMakeBlockAccount

func TestMakeBlockAccount(kps ...*keypair.Full) *BlockAccount

func (*BlockAccount) Deposit

func (b *BlockAccount) Deposit(fund common.Amount) error

Add fund to an account

If the amount would make the account overflow over the full supply of coin, an `error` is returned.

func (*BlockAccount) GetBalance

func (b *BlockAccount) GetBalance() common.Amount

func (*BlockAccount) IncreaseSequenceID

func (b *BlockAccount) IncreaseSequenceID()

func (*BlockAccount) IsFrozen

func (b *BlockAccount) IsFrozen() bool

func (*BlockAccount) MustSave

func (b *BlockAccount) MustSave(st *storage.LevelDBBackend)

/ Version of `BlockAccount.Save` that panics on error, usable only in tests

func (*BlockAccount) Save

func (b *BlockAccount) Save(st *storage.LevelDBBackend) (err error)

func (*BlockAccount) String

func (b *BlockAccount) String() string

func (*BlockAccount) Withdraw

func (b *BlockAccount) Withdraw(fund common.Amount) error

Remove fund from an account

If the amount would make the account go negative, an `error` is returned.

type BlockAccountSequenceID

type BlockAccountSequenceID struct {
	SequenceID uint64
	Address    string
	Balance    common.Amount
}

BlockAccountSequenceID is the one-and-one model of account and sequenceID in block. the storage should support,

  • find by `Address`:
  • key: "`Address`-`SequenceID`": value: `ID` of BlockAccountSequenceID
  • get list by created order:

models

  • 'address' and 'sequenceID'
  • 'bac-<BlockAccountSequenceID.Address>-<BlockAccountSequenceID.SequenceID>': `BlockAccountSequenceID`

func GetBlockAccountSequenceID

func GetBlockAccountSequenceID(st *storage.LevelDBBackend, address string, sequenceID uint64) (b BlockAccountSequenceID, err error)

func (*BlockAccountSequenceID) Save

func (*BlockAccountSequenceID) String

func (b *BlockAccountSequenceID) String() string

type BlockOperation

type BlockOperation struct {
	Hash string `json:"hash"`

	OpHash string `json:"op_hash"`
	TxHash string `json:"tx_hash"`

	Type   operation.OperationType `json:"type"`
	Source string                  `json:"source"`
	Target string                  `json:"target"`
	Body   []byte                  `json:"body"`
	Height uint64                  `json:"block_height"`
	// contains filtered or unexported fields
}

func GetBlockOperation

func GetBlockOperation(st *storage.LevelDBBackend, hash string) (bo BlockOperation, err error)

func GetBlockOperationByIndex

func GetBlockOperationByIndex(st *storage.LevelDBBackend, txHash string, opIndex int) (BlockOperation, error)

Looks up the operation referenced by `txHash`, then get the operation's hash from it

func NewBlockOperationFromOperation

func NewBlockOperationFromOperation(op operation.Operation, tx transaction.Transaction, blockHeight uint64) (BlockOperation, error)

func TestMakeNewBlockOperation

func TestMakeNewBlockOperation(networkID []byte, n int) (bos []BlockOperation)

func (*BlockOperation) MustSave

func (b *BlockOperation) MustSave(st *storage.LevelDBBackend)

/ Version of `BlockTransaction.Save` that panics on error, usable only in tests

func (BlockOperation) NewBlockOperationBlockHeightKey

func (bo BlockOperation) NewBlockOperationBlockHeightKey() string

func (BlockOperation) NewBlockOperationFrozenLinkedKey

func (bo BlockOperation) NewBlockOperationFrozenLinkedKey(hash string) string

func (BlockOperation) NewBlockOperationPeersAndTypeKey

func (bo BlockOperation) NewBlockOperationPeersAndTypeKey(addr string) string

func (BlockOperation) NewBlockOperationPeersKey

func (bo BlockOperation) NewBlockOperationPeersKey(addr string) string

func (BlockOperation) NewBlockOperationSourceAndTypeKey

func (bo BlockOperation) NewBlockOperationSourceAndTypeKey() string

func (BlockOperation) NewBlockOperationSourceKey

func (bo BlockOperation) NewBlockOperationSourceKey() string

func (BlockOperation) NewBlockOperationTargetAndTypeKey

func (bo BlockOperation) NewBlockOperationTargetAndTypeKey(target string) string

func (BlockOperation) NewBlockOperationTargetKey

func (bo BlockOperation) NewBlockOperationTargetKey(target string) string

func (BlockOperation) NewBlockOperationTxHashKey

func (bo BlockOperation) NewBlockOperationTxHashKey() string

func (*BlockOperation) Save

func (bo *BlockOperation) Save(st *storage.LevelDBBackend) (err error)

type BlockTransaction

type BlockTransaction struct {
	Hash  string `json:"hash"`
	Block string `json:"block"`

	SequenceID uint64        `json:"sequence_id"`
	Signature  string        `json:"signature"`
	Source     string        `json:"source"`
	Fee        common.Amount `json:"fee"`
	Operations []string      `json:"operations"`
	Amount     common.Amount `json:"amount"`

	Confirmed string `json:"confirmed"`
	Created   string `json:"created"`
	Message   []byte `json:"message"`
	// contains filtered or unexported fields
}

func GetBlockTransaction

func GetBlockTransaction(st *storage.LevelDBBackend, hash string) (bt BlockTransaction, err error)

func NewBlockTransactionFromTransaction

func NewBlockTransactionFromTransaction(blockHash string, blockHeight uint64, confirmed string, tx transaction.Transaction) BlockTransaction

func (*BlockTransaction) GetOperationIndex

func (bt *BlockTransaction) GetOperationIndex(opHash string) (opIndex int, err error)

TODO: This function is no longer required when Index for operation is applied

func (*BlockTransaction) MustSave

func (b *BlockTransaction) MustSave(st *storage.LevelDBBackend)

/ Version of `BlockTransaction.Save` that panics on error, usable only in tests

func (BlockTransaction) NewBlockTransactionKeyByAccount

func (bt BlockTransaction) NewBlockTransactionKeyByAccount(accountAddress string) string

func (BlockTransaction) NewBlockTransactionKeyByBlock

func (bt BlockTransaction) NewBlockTransactionKeyByBlock(hash string) string

func (BlockTransaction) NewBlockTransactionKeyConfirmed

func (bt BlockTransaction) NewBlockTransactionKeyConfirmed() string

func (BlockTransaction) NewBlockTransactionKeySource

func (bt BlockTransaction) NewBlockTransactionKeySource() string

func (*BlockTransaction) Save

func (bt *BlockTransaction) Save(st *storage.LevelDBBackend) (err error)

func (*BlockTransaction) SaveBlockOperation

func (bt *BlockTransaction) SaveBlockOperation(st *storage.LevelDBBackend, op operation.Operation) (err error)

func (*BlockTransaction) SaveBlockOperations

func (bt *BlockTransaction) SaveBlockOperations(st *storage.LevelDBBackend) (err error)

func (BlockTransaction) String

func (bt BlockTransaction) String() string

func (BlockTransaction) Transaction

func (bt BlockTransaction) Transaction() transaction.Transaction
type Header struct {
	// TODO rename `Header` to `BlockHeader`
	Version          uint32 `json:"version"`
	PrevBlockHash    string `json:"prev_block_hash"`   // TODO Uint256 type
	TransactionsRoot string `json:"transactions_root"` // Merkle root of Txs // TODO Uint256 type
	ProposedTime     string `json:"proposed_time"`
	Height           uint64 `json:"height"`
	TotalTxs         uint64 `json:"total-txs"`
	TotalOps         uint64 `json:"total-ops"`
}

func GetBlockHeader

func GetBlockHeader(st *storage.LevelDBBackend, hash string) (bt Header, err error)

func GetBlockHeaderByHeight

func GetBlockHeaderByHeight(st *storage.LevelDBBackend, height uint64) (bt Header, err error)

func NewBlockHeader

func NewBlockHeader(basis voting.Basis, txRoot string, proposedTime string) *Header

func (Header) Serialize

func (h Header) Serialize() (encoded []byte, err error)

func (Header) String

func (h Header) String() string

type TransactionPool

type TransactionPool struct {
	Hash    string `json:"hash"`
	Message []byte `json:"message"`
	// contains filtered or unexported fields
}

TransactionPool is not `transaction.Pool`; this contains the all the valid transactions. The unconfirmed transactions of `TransactionPool` can be removed, but confirmed transactions must be here.

NOTE The sync process must store the confirmed transactions.

func GetTransactionPool

func GetTransactionPool(st *storage.LevelDBBackend, hash string) (tp TransactionPool, err error)

func NewTransactionPool

func NewTransactionPool(tx transaction.Transaction) (tp TransactionPool, err error)

func SaveTransactionPool

func SaveTransactionPool(st *storage.LevelDBBackend, tx transaction.Transaction) (tp TransactionPool, err error)

func (TransactionPool) Save

func (tp TransactionPool) Save(st *storage.LevelDBBackend) (err error)

func (TransactionPool) Serialize

func (tp TransactionPool) Serialize() ([]byte, error)

func (TransactionPool) String

func (tp TransactionPool) String() string

func (TransactionPool) Transaction

func (tp TransactionPool) Transaction() transaction.Transaction

Jump to

Keyboard shortcuts

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