sebak: boscoin.io/sebak/lib/block Index | Files

package block

import "boscoin.io/sebak/lib/block"

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

Package Files

account.go block.go genesis.go header.go operation.go test.go transaction.go transaction_pool.go

Variables

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

func DeleteTransactionPool Uses

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

func ExistsBlock Uses

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

func ExistsBlockAccount Uses

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

func ExistsBlockByHeight Uses

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

func ExistsBlockOperation Uses

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

func ExistsBlockTransaction Uses

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

func ExistsTransactionPool Uses

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

func GetBlockAccountAddressesByCreated Uses

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

func GetBlockAccountCreatedKey Uses

func GetBlockAccountCreatedKey(created string) string

func GetBlockAccountKey Uses

func GetBlockAccountKey(address string) string

func GetBlockAccountSequenceIDByAddress Uses

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

func GetBlockAccountSequenceIDByAddressKey Uses

func GetBlockAccountSequenceIDByAddressKey(address string) string

func GetBlockAccountSequenceIDByAddressKeyPrefix Uses

func GetBlockAccountSequenceIDByAddressKeyPrefix(address string) string

func GetBlockAccountSequenceIDKey Uses

func GetBlockAccountSequenceIDKey(address string, sequenceID uint64) string

func GetBlockAccountsByCreated Uses

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

func GetBlockHeadersByConfirmed Uses

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

func GetBlockKeyPrefixHeight Uses

func GetBlockKeyPrefixHeight(height uint64) string

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

func GetBlockOperationCreateFrozenKey Uses

func GetBlockOperationCreateFrozenKey(hash string, height uint64) string

func GetBlockOperationsByBlockHeight Uses

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

func GetBlockOperationsByFrozen Uses

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

Find all operations which created frozen account.

func GetBlockOperationsByLinked Uses

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 Uses

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

func GetBlockOperationsByPeersAndType Uses

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

func GetBlockOperationsBySource Uses

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

func GetBlockOperationsBySourceAndType Uses

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

func GetBlockOperationsByTarget Uses

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

func GetBlockOperationsByTargetAndType Uses

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

func GetBlockOperationsByTx Uses

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

func GetBlockTransactionKey Uses

func GetBlockTransactionKey(hash string) string

func GetBlockTransactionKeyPrefixAccount Uses

func GetBlockTransactionKeyPrefixAccount(accountAddress string) string

func GetBlockTransactionKeyPrefixBlock Uses

func GetBlockTransactionKeyPrefixBlock(hash string) string

func GetBlockTransactionKeyPrefixConfirmed Uses

func GetBlockTransactionKeyPrefixConfirmed(confirmed string) string

func GetBlockTransactionKeyPrefixSource Uses

func GetBlockTransactionKeyPrefixSource(source string) string

func GetBlockTransactionsByAccount Uses

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

func GetBlockTransactionsByBlock Uses

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

func GetBlockTransactionsByConfirmed Uses

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

func GetBlockTransactionsBySource Uses

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

func GetBlocksByConfirmed Uses

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

func GetTransactionPoolKey Uses

func GetTransactionPoolKey(hash string) string

func InitTestBlockchain Uses

func InitTestBlockchain() *storage.LevelDBBackend

Like `MakeTestBlockchain`, but also create a storage

func LoadBlockAccountsInsideIterator Uses

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

func LoadBlockHeadersInsideIterator Uses

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

func LoadBlockOperationsInsideIterator Uses

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

func LoadBlockTransactionsInsideIterator Uses

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

func LoadBlocksInsideIterator Uses

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

func MakeTestBlockchain Uses

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 Uses

func NewBlockOperationKey(opHash, txHash string) string

func WalkBlocks Uses

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

type Block Uses

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 Uses

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

func GetBlockByHeight Uses

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

func GetGenesis Uses

func GetGenesis(st *storage.LevelDBBackend) Block

Returns: Genesis block

func GetLatestBlock Uses

func GetLatestBlock(st *storage.LevelDBBackend) Block

func MakeGenesisBlock Uses

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 Uses

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 Uses

func TestMakeNewBlock(transactions []string) Block

func TestMakeNewBlockWithPrevBlock Uses

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

func (Block) IsEmpty Uses

func (bck Block) IsEmpty() bool

func (*Block) MustSave Uses

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

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

func (Block) NewBlockKeyConfirmed Uses

func (b Block) NewBlockKeyConfirmed() string

func (Block) NextBlock Uses

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

func (Block) PreviousBlock Uses

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

func (*Block) Save Uses

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

func (Block) String Uses

func (bck Block) String() string

type BlockAccount Uses

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 Uses

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

func NewBlockAccount Uses

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

func NewBlockAccountLinked Uses

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

func TestMakeBlockAccount Uses

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

func (*BlockAccount) Deposit Uses

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 Uses

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

func (*BlockAccount) IncreaseSequenceID Uses

func (b *BlockAccount) IncreaseSequenceID()

func (*BlockAccount) IsFrozen Uses

func (b *BlockAccount) IsFrozen() bool

func (*BlockAccount) MustSave Uses

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

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

func (*BlockAccount) Save Uses

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

func (*BlockAccount) String Uses

func (b *BlockAccount) String() string

func (*BlockAccount) Withdraw Uses

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 Uses

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 Uses

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

func (*BlockAccountSequenceID) Save Uses

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

func (*BlockAccountSequenceID) String Uses

func (b *BlockAccountSequenceID) String() string

type BlockOperation Uses

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 Uses

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

func GetBlockOperationByIndex Uses

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 Uses

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

func TestMakeNewBlockOperation Uses

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

func (*BlockOperation) MustSave Uses

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

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

func (BlockOperation) NewBlockOperationBlockHeightKey Uses

func (bo BlockOperation) NewBlockOperationBlockHeightKey() string

func (BlockOperation) NewBlockOperationFrozenLinkedKey Uses

func (bo BlockOperation) NewBlockOperationFrozenLinkedKey(hash string) string

func (BlockOperation) NewBlockOperationPeersAndTypeKey Uses

func (bo BlockOperation) NewBlockOperationPeersAndTypeKey(addr string) string

func (BlockOperation) NewBlockOperationPeersKey Uses

func (bo BlockOperation) NewBlockOperationPeersKey(addr string) string

func (BlockOperation) NewBlockOperationSourceAndTypeKey Uses

func (bo BlockOperation) NewBlockOperationSourceAndTypeKey() string

func (BlockOperation) NewBlockOperationSourceKey Uses

func (bo BlockOperation) NewBlockOperationSourceKey() string

func (BlockOperation) NewBlockOperationTargetAndTypeKey Uses

func (bo BlockOperation) NewBlockOperationTargetAndTypeKey(target string) string

func (BlockOperation) NewBlockOperationTargetKey Uses

func (bo BlockOperation) NewBlockOperationTargetKey(target string) string

func (BlockOperation) NewBlockOperationTxHashKey Uses

func (bo BlockOperation) NewBlockOperationTxHashKey() string

func (*BlockOperation) Save Uses

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

type BlockTransaction Uses

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 Uses

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

func NewBlockTransactionFromTransaction Uses

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

func (*BlockTransaction) GetOperationIndex Uses

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 Uses

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

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

func (BlockTransaction) NewBlockTransactionKeyByAccount Uses

func (bt BlockTransaction) NewBlockTransactionKeyByAccount(accountAddress string) string

func (BlockTransaction) NewBlockTransactionKeyByBlock Uses

func (bt BlockTransaction) NewBlockTransactionKeyByBlock(hash string) string

func (BlockTransaction) NewBlockTransactionKeyConfirmed Uses

func (bt BlockTransaction) NewBlockTransactionKeyConfirmed() string

func (BlockTransaction) NewBlockTransactionKeySource Uses

func (bt BlockTransaction) NewBlockTransactionKeySource() string

func (*BlockTransaction) Save Uses

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

func (*BlockTransaction) SaveBlockOperation Uses

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

func (*BlockTransaction) SaveBlockOperations Uses

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

func (BlockTransaction) String Uses

func (bt BlockTransaction) String() string

func (BlockTransaction) Transaction Uses

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 Uses

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

func GetBlockHeaderByHeight Uses

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

func NewBlockHeader Uses

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

func (Header) Serialize Uses

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

func (Header) String Uses

func (h Header) String() string

type TransactionPool Uses

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 Uses

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

func NewTransactionPool Uses

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

func SaveTransactionPool Uses

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

func (TransactionPool) Save Uses

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

func (TransactionPool) Serialize Uses

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

func (TransactionPool) String Uses

func (tp TransactionPool) String() string

func (TransactionPool) Transaction Uses

func (tp TransactionPool) Transaction() transaction.Transaction

Package block imports 11 packages (graph) and is imported by 22 packages. Updated 2019-03-27. Refresh now. Tools for package owners.