chain

package
v0.0.0-...-e4e12f0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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

type BlockReader interface {
	Read() ([]*ExtendedBlock, error)
}

BlockReader defines the interface to stream block activity.

type BlockSummary

type BlockSummary struct {
	Header    *block.Header
	Txs       []workshare.Bytes32
	Size      uint64
	Conflicts uint32
	SteadyNum uint32
}

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

func (c *Chain) Exclude(other *Chain) ([]workshare.Bytes32, error)

Exclude returns ids of blocks belongs to this chain, but not belongs to other.

The returned ids are in ascending order.

func (*Chain) FindBlockHeaderByTimestamp

func (c *Chain) FindBlockHeaderByTimestamp(ts uint64, flag int) (header *block.Header, err error)

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) GenesisID

func (c *Chain) GenesisID() workshare.Bytes32

GenesisID returns genesis id.

func (*Chain) GetBlock

func (c *Chain) GetBlock(num uint32) (*block.Block, error)

GetBlock returns block by given block number.

func (*Chain) GetBlockHeader

func (c *Chain) GetBlockHeader(num uint32) (*block.Header, error)

GetBlockHeader returns block header by given block number.

func (*Chain) GetBlockID

func (c *Chain) GetBlockID(num uint32) (workshare.Bytes32, error)

GetBlockID returns block id by given block number.

func (Chain) GetBlockSummary

func (c Chain) GetBlockSummary(num uint32) (*BlockSummary, error)

GetBlockSummary returns block summary by given block number.

func (*Chain) GetTransaction

func (c *Chain) GetTransaction(id workshare.Bytes32) (*tx.Transaction, *TxMeta, error)

GetTransaction returns tx along with meta by given tx id.

func (*Chain) GetTransactionMeta

func (c *Chain) GetTransactionMeta(id workshare.Bytes32) (*TxMeta, error)

GetTransactionMeta returns tx meta by given tx id.

func (*Chain) GetTransactionReceipt

func (c *Chain) GetTransactionReceipt(txID workshare.Bytes32) (*tx.Receipt, error)

GetTransactionReceipt returns tx receipt by given tx id.

func (*Chain) HasBlock

func (c *Chain) HasBlock(id workshare.Bytes32) (bool, error)

HasBlock check if the block with given id belongs to the chain.

func (*Chain) HeadID

func (c *Chain) HeadID() workshare.Bytes32

HeadID returns the head block id.

func (*Chain) IsNotFound

func (c *Chain) IsNotFound(err error) bool

IsNotFound returns if the given error means not found.

type ExtendedBlock

type ExtendedBlock struct {
	*block.Block
	Obsolete bool
}

ExtendedBlock extend block.Block with the obsolete flag.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository stores block headers, txs and receipts.

It's thread-safe.

func NewRepository

func NewRepository(db *muxdb.MuxDB, genesis *block.Block) (*Repository, error)

NewRepository create an instance of repository.

func (*Repository) AddBlock

func (r *Repository) AddBlock(newBlock *block.Block, receipts tx.Receipts, conflicts uint32) error

AddBlock add a new block with its receipts into repository.

func (*Repository) BestBlockSummary

func (r *Repository) BestBlockSummary() *BlockSummary

BestBlockSummary returns the summary of the best block, which is the newest block of canonical chain.

func (*Repository) ChainTag

func (r *Repository) ChainTag() byte

ChainTag returns chain tag, which is the last byte of genesis id.

func (*Repository) GenesisBlock

func (r *Repository) GenesisBlock() *block.Block

GenesisBlock returns genesis block.

func (*Repository) GetBlock

func (r *Repository) GetBlock(id workshare.Bytes32) (*block.Block, error)

GetBlock get block by id.

func (*Repository) GetBlockReceipts

func (r *Repository) GetBlockReceipts(id workshare.Bytes32) (tx.Receipts, error)

GetBlockReceipts get all tx receipts of the block for given block id.

func (*Repository) GetBlockSummary

func (r *Repository) GetBlockSummary(id workshare.Bytes32) (summary *BlockSummary, err error)

GetBlockSummary get block summary by block id.

func (*Repository) GetBlockTransactions

func (r *Repository) GetBlockTransactions(id workshare.Bytes32) (tx.Transactions, error)

GetBlockTransactions get all transactions of the block for given block id.

func (*Repository) GetMaxBlockNum

func (r *Repository) GetMaxBlockNum() (uint32, error)

GetMaxBlockNum returns the max committed block number.

func (*Repository) IsNotFound

func (r *Repository) IsNotFound(err error) bool

IsNotFound returns if the given error means not found.

func (*Repository) NewBestChain

func (r *Repository) NewBestChain() *Chain

NewBestChain create a chain with best block as head.

func (*Repository) NewBlockReader

func (r *Repository) NewBlockReader(position workshare.Bytes32) BlockReader

NewBlockReader create BlockReader instance.

func (*Repository) NewChain

func (r *Repository) NewChain(headID workshare.Bytes32) *Chain

NewChain create a chain with head block specified by headID.

func (*Repository) NewTicker

func (r *Repository) NewTicker() co.Waiter

NewTicker create a signal Waiter to receive event that the best block changed.

func (*Repository) ScanConflicts

func (r *Repository) ScanConflicts(blockNum uint32) (uint32, error)

ScanConflicts returns the count of saved blocks with the given blockNum.

func (*Repository) SetBestBlockID

func (r *Repository) SetBestBlockID(id workshare.Bytes32) (err error)

SetBestBlockID set the given block id as best block id.

func (*Repository) SetSteadyBlockID

func (r *Repository) SetSteadyBlockID(id workshare.Bytes32) error

SetSteadyBlockID set the given block id as the head block id of the steady chain.

func (*Repository) SteadyBlockID

func (r *Repository) SteadyBlockID() workshare.Bytes32

SteadyBlockID return the head block id of the steady chain.

type TxMeta

type TxMeta struct {
	// The block id this tx is involved.
	BlockID workshare.Bytes32

	// Index the position of the tx in block's txs.
	Index uint64 // rlp require uint64.

	Reverted bool
}

TxMeta contains tx location and reversal state.

Jump to

Keyboard shortcuts

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