Documentation ¶
Index ¶
- Constants
- func HeadersToBlocks(headers []*types.Header) []*types.Block
- func NewTestBodyChain(n int) ([]*types.Header, []*types.Block, [][]*types.Receipt)
- func NewTestHeaderChain(n int) []*types.Header
- func NewTestHeaderChainWithSeed(genesis *types.Header, n int, seed uint64) []*types.Header
- func NewTestHeaderFromChain(headers []*types.Header, n int) []*types.Header
- func NewTestHeaderFromChainWithSeed(headers []*types.Header, n int, seed uint64) []*types.Header
- type BlockResult
- type Blockchain
- func (b *Blockchain) CalculateGasLimit(number uint64) (uint64, error)
- func (b *Blockchain) Close() error
- func (b *Blockchain) ComputeGenesis() error
- func (b *Blockchain) Config() *chain.Params
- func (b *Blockchain) CurrentTD() *big.Int
- func (b *Blockchain) Empty() bool
- func (b *Blockchain) Genesis() types.Hash
- func (b *Blockchain) GetAvgGasPrice() *big.Int
- func (b *Blockchain) GetBlock(hash types.Hash, number uint64, full bool) (*types.Block, bool)
- func (b *Blockchain) GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool)
- func (b *Blockchain) GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool)
- func (b *Blockchain) GetBodyByHash(hash types.Hash) (*types.Body, bool)
- func (b *Blockchain) GetChainTD() (*big.Int, bool)
- func (b *Blockchain) GetConsensus() Verifier
- func (b *Blockchain) GetForks() ([]types.Hash, error)
- func (b *Blockchain) GetHashByNumber(blockNumber uint64) types.Hash
- func (b *Blockchain) GetHashHelper(header *types.Header) func(i uint64) (res types.Hash)
- func (b *Blockchain) GetHeader(hash types.Hash, number uint64) (*types.Header, bool)
- func (b *Blockchain) GetHeaderByHash(hash types.Hash) (*types.Header, bool)
- func (b *Blockchain) GetHeaderByNumber(n uint64) (*types.Header, bool)
- func (b *Blockchain) GetParent(header *types.Header) (*types.Header, bool)
- func (b *Blockchain) GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, error)
- func (b *Blockchain) GetTD(hash types.Hash) (*big.Int, bool)
- func (b *Blockchain) Header() *types.Header
- func (b *Blockchain) ReadTxLookup(hash types.Hash) (types.Hash, bool)
- func (b *Blockchain) SetConsensus(c Verifier)
- func (b *Blockchain) SubscribeEvents() Subscription
- func (b *Blockchain) UpdateGasPriceAvg(newValue *big.Int)
- func (b *Blockchain) WriteBlock(block *types.Block) error
- func (b *Blockchain) WriteHeaders(headers []*types.Header) error
- func (b *Blockchain) WriteHeadersWithBodies(headers []*types.Header) error
- type Event
- type EventType
- type Executor
- type MockSubscription
- type MockVerifier
- type Subscription
- type Verifier
Constants ¶
const (
BlockGasTargetDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations
)
Variables ¶
This section is empty.
Functions ¶
func NewTestBodyChain ¶
NewTestBodyChain creates a test blockchain with headers, body and receipts
func NewTestHeaderChain ¶
NewTestHeaderChain creates a chain of valid headers
func NewTestHeaderChainWithSeed ¶
NewTestHeaderChainWithSeed creates a new chain with a seed factor
func NewTestHeaderFromChain ¶
NewTestHeaderFromChain creates n new headers from an already existing chain
Types ¶
type BlockResult ¶ added in v0.3.0
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain is a blockchain reference
func NewBlockchain ¶
func NewBlockchain( logger hclog.Logger, dataDir string, config *chain.Chain, consensus Verifier, executor Executor, ) (*Blockchain, error)
NewBlockchain creates a new blockchain object
func NewTestBlockchain ¶
func NewTestBlockchain(t *testing.T, headers []*types.Header) *Blockchain
NewTestBlockchain creates a new dummy blockchain for testing
func TestBlockchain ¶
func TestBlockchain(t *testing.T, genesis *chain.Genesis) *Blockchain
func (*Blockchain) CalculateGasLimit ¶
func (b *Blockchain) CalculateGasLimit(number uint64) (uint64, error)
CalculateGasLimit returns the gas limit of the next block after parent
func (*Blockchain) ComputeGenesis ¶
func (b *Blockchain) ComputeGenesis() error
ComputeGenesis computes the genesis hash, and updates the blockchain reference
func (*Blockchain) Config ¶
func (b *Blockchain) Config() *chain.Params
Config returns the blockchain configuration
func (*Blockchain) CurrentTD ¶
func (b *Blockchain) CurrentTD() *big.Int
CurrentTD returns the current total difficulty (atomic)
func (*Blockchain) Empty ¶
func (b *Blockchain) Empty() bool
Empty checks if the blockchain is empty
func (*Blockchain) Genesis ¶
func (b *Blockchain) Genesis() types.Hash
Genesis returns the genesis block
func (*Blockchain) GetAvgGasPrice ¶
func (b *Blockchain) GetAvgGasPrice() *big.Int
GetAvgGasPrice returns the average gas price
func (*Blockchain) GetBlockByHash ¶
GetBlockByHash returns the block using the block hash
func (*Blockchain) GetBlockByNumber ¶
GetBlockByNumber returns the block using the block number
func (*Blockchain) GetBodyByHash ¶
GetBodyByHash returns the body by their hash
func (*Blockchain) GetChainTD ¶
func (b *Blockchain) GetChainTD() (*big.Int, bool)
GetChainTD returns the latest difficulty
func (*Blockchain) GetConsensus ¶
func (b *Blockchain) GetConsensus() Verifier
func (*Blockchain) GetForks ¶
func (b *Blockchain) GetForks() ([]types.Hash, error)
GetForks returns the forks
func (*Blockchain) GetHashByNumber ¶
func (b *Blockchain) GetHashByNumber(blockNumber uint64) types.Hash
GetHashByNumber returns the block hash using the block number
func (*Blockchain) GetHashHelper ¶
GetHashHelper is used by the EVM, so that the SC can get the hash of the header number
func (*Blockchain) GetHeaderByHash ¶
GetHeaderByHash returns the header by his hash
func (*Blockchain) GetHeaderByNumber ¶
func (b *Blockchain) GetHeaderByNumber(n uint64) (*types.Header, bool)
GetHeaderByNumber returns the header using the block number
func (*Blockchain) GetReceiptsByHash ¶
GetReceiptsByHash returns the receipts by their hash
func (*Blockchain) Header ¶
func (b *Blockchain) Header() *types.Header
Header returns the current header (atomic)
func (*Blockchain) ReadTxLookup ¶
ReadTxLookup returns the block hash using the transaction hash
func (*Blockchain) SetConsensus ¶
func (b *Blockchain) SetConsensus(c Verifier)
SetConsensus sets the consensus
func (*Blockchain) SubscribeEvents ¶
func (b *Blockchain) SubscribeEvents() Subscription
SubscribeEvents returns a blockchain event subscription
func (*Blockchain) UpdateGasPriceAvg ¶
func (b *Blockchain) UpdateGasPriceAvg(newValue *big.Int)
UpdateGasPriceAvg Updates the rolling average value of the gas price
func (*Blockchain) WriteBlock ¶
func (b *Blockchain) WriteBlock(block *types.Block) error
WriteBlock writes a single block
func (*Blockchain) WriteHeaders ¶
func (b *Blockchain) WriteHeaders(headers []*types.Header) error
WriteHeaders writes an array of headers
func (*Blockchain) WriteHeadersWithBodies ¶
func (b *Blockchain) WriteHeadersWithBodies(headers []*types.Header) error
WriteHeadersWithBodies writes a batch of headers
type Event ¶
type Event struct { // Old chain (removed headers) if there was a reorg OldChain []*types.Header // New part of the chain (or a fork) NewChain []*types.Header // Difficulty is the new difficulty created with this event Difficulty *big.Int // Type is the type of event Type EventType // Source is the source that generated the blocks for the event // right now it can be either the Sealer or the Syncer. TODO Source string }
Event is the blockchain event that gets passed to the listeners
func (*Event) AddNewHeader ¶
AddNewHeader appends a header to the event's NewChain array
func (*Event) AddOldHeader ¶
AddOldHeader appends a header to the event's OldChain array
func (*Event) SetDifficulty ¶
SetDifficulty sets the event difficulty
type MockSubscription ¶
type MockSubscription struct {
// contains filtered or unexported fields
}
func NewMockSubscription ¶
func NewMockSubscription() *MockSubscription
func (*MockSubscription) Close ¶
func (m *MockSubscription) Close()
func (*MockSubscription) GetEvent ¶
func (m *MockSubscription) GetEvent() *Event
func (*MockSubscription) GetEventCh ¶
func (m *MockSubscription) GetEventCh() chan *Event
func (*MockSubscription) Push ¶
func (m *MockSubscription) Push(e *Event)
type MockVerifier ¶
type MockVerifier struct { }
func (*MockVerifier) GetBlockCreator ¶
func (*MockVerifier) PreStateCommit ¶ added in v0.3.0
func (m *MockVerifier) PreStateCommit(header *types.Header, txn *state.Transition) error
func (*MockVerifier) VerifyHeader ¶
func (m *MockVerifier) VerifyHeader(parent, header *types.Header) error
type Subscription ¶
Subscription is the blockchain subscription interface