Documentation ¶
Index ¶
- Constants
- type BlockReader
- type BlockSummary
- type Chain
- func (c *Chain) Exclude(other *Chain) ([]thor.Bytes32, error)
- func (c *Chain) FindBlockHeaderByTimestamp(ts uint64, flag int) (header *block.Header, err error)
- func (c *Chain) GetBlock(num uint32) (*block.Block, error)
- func (c *Chain) GetBlockHeader(num uint32) (*block.Header, error)
- func (c *Chain) GetBlockID(num uint32) (thor.Bytes32, error)
- func (c *Chain) GetTransaction(id thor.Bytes32) (*tx.Transaction, *TxMeta, error)
- func (c *Chain) GetTransactionMeta(id thor.Bytes32) (*TxMeta, error)
- func (c *Chain) GetTransactionReceipt(txID thor.Bytes32) (*tx.Receipt, error)
- func (c *Chain) HasBlock(id thor.Bytes32) (bool, error)
- func (c *Chain) HeadID() thor.Bytes32
- func (c *Chain) IsNotFound(err error) bool
- type ExtendedBlock
- type Repository
- func (r *Repository) AddBlock(newBlock *block.Block, receipts tx.Receipts) error
- func (r *Repository) BestBlock() *block.Block
- func (r *Repository) ChainTag() byte
- func (r *Repository) GenesisBlock() *block.Block
- func (r *Repository) GetBlock(id thor.Bytes32) (*block.Block, error)
- func (r *Repository) GetBlockReceipts(id thor.Bytes32) (tx.Receipts, error)
- func (r *Repository) GetBlockSummary(id thor.Bytes32) (summary *BlockSummary, err error)
- func (r *Repository) GetBlockTransactions(id thor.Bytes32) (tx.Transactions, error)
- func (r *Repository) IsNotFound(err error) bool
- func (r *Repository) NewBestChain() *Chain
- func (r *Repository) NewBlockReader(position thor.Bytes32) BlockReader
- func (r *Repository) NewChain(headID thor.Bytes32) *Chain
- func (r *Repository) NewTicker() co.Waiter
- func (r *Repository) SetBestBlockID(id thor.Bytes32) (err error)
- type TxMeta
Constants ¶
const ( // IndexTrieName is the name of index trie. // The index tire is used to store mappings from block number to block id, and tx id to tx meta. IndexTrieName = "i" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockReader ¶ added in v1.0.2
type BlockReader interface {
Read() ([]*ExtendedBlock, error)
}
BlockReader defines the interface to stream block activity.
type BlockSummary ¶ added in v1.3.0
type BlockSummary struct { Header *block.Header IndexRoot thor.Bytes32 Txs []thor.Bytes32 Size uint64 }
BlockSummary presents block summary.
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain presents the linked block chain, with the range from genesis to given head block.
It provides reliable methods to access block by number, tx by id, etc...
func (*Chain) Exclude ¶ added in v1.3.0
Exclude returns ids of blocks belongs to this chain, but not belongs to other.
The returned ids are in ascending order.
func (*Chain) FindBlockHeaderByTimestamp ¶ added in v1.3.0
FindBlockHeaderByTimestamp find the block whose timestamp matches the given timestamp.
When flag == 0, exact match is performed (may return error not found) flag > 0, matches the lowest block whose timestamp >= ts flag < 0, matches the highest block whose timestamp <= ts.
func (*Chain) GetBlockHeader ¶
GetBlockHeader returns block header by given block number.
func (*Chain) GetBlockID ¶ added in v1.3.0
GetBlockID returns block id by given block number.
func (*Chain) GetTransaction ¶
GetTransaction returns tx along with meta by given tx id.
func (*Chain) GetTransactionMeta ¶
GetTransactionMeta returns tx meta by given tx id.
func (*Chain) GetTransactionReceipt ¶
GetTransactionReceipt returns tx receipt by given tx id.
func (*Chain) HasBlock ¶ added in v1.3.0
HasBlock check if the block with given id belongs to the chain.
func (*Chain) IsNotFound ¶
IsNotFound returns if the given error means not found.
type ExtendedBlock ¶ added in v1.3.0
ExtendedBlock extend block.Block with the obsolete flag.
type Repository ¶ added in v1.3.0
type Repository struct {
// contains filtered or unexported fields
}
Repository stores block headers, txs and receipts.
It's thread-safe.
func NewRepository ¶ added in v1.3.0
NewRepository create an instance of repository.
func (*Repository) AddBlock ¶ added in v1.3.0
AddBlock add a new block with its receipts into repository.
func (*Repository) BestBlock ¶ added in v1.3.0
func (r *Repository) BestBlock() *block.Block
BestBlock returns the best block, which is the newest block of canonical chain.
func (*Repository) ChainTag ¶ added in v1.3.0
func (r *Repository) ChainTag() byte
ChainTag returns chain tag, which is the last byte of genesis id.
func (*Repository) GenesisBlock ¶ added in v1.3.0
func (r *Repository) GenesisBlock() *block.Block
GenesisBlock returns genesis block.
func (*Repository) GetBlockReceipts ¶ added in v1.3.0
GetBlockReceipts get all tx receipts of the block for given block id.
func (*Repository) GetBlockSummary ¶ added in v1.3.0
func (r *Repository) GetBlockSummary(id thor.Bytes32) (summary *BlockSummary, err error)
GetBlockSummary get block summary by block id.
func (*Repository) GetBlockTransactions ¶ added in v1.3.0
func (r *Repository) GetBlockTransactions(id thor.Bytes32) (tx.Transactions, error)
GetBlockTransactions get all transactions of the block for given block id.
func (*Repository) IsNotFound ¶ added in v1.3.0
func (r *Repository) IsNotFound(err error) bool
IsNotFound returns if the given error means not found.
func (*Repository) NewBestChain ¶ added in v1.3.0
func (r *Repository) NewBestChain() *Chain
NewBestChain create a chain with best block as head.
func (*Repository) NewBlockReader ¶ added in v1.3.0
func (r *Repository) NewBlockReader(position thor.Bytes32) BlockReader
NewBlockReader create BlockReader instance.
func (*Repository) NewChain ¶ added in v1.3.0
func (r *Repository) NewChain(headID thor.Bytes32) *Chain
NewChain create a chain with head block specified by headID.
func (*Repository) NewTicker ¶ added in v1.3.0
func (r *Repository) NewTicker() co.Waiter
NewTicker create a signal Waiter to receive event that the best block changed.
func (*Repository) SetBestBlockID ¶ added in v1.3.0
func (r *Repository) SetBestBlockID(id thor.Bytes32) (err error)
SetBestBlockID set the given block id as best block id.