Documentation ¶
Index ¶
- func GenerateChain(config *params.ChainConfig, parent *block.Block, engine consensus.Engine, ...) ([]*block.Block, []transaction.Receipts)
- type BlockGen
- func (b *BlockGen) AddTx(tx *transaction.Transaction)
- func (b *BlockGen) AddUncheckedReceipt(receipt *transaction.Receipt)
- func (b *BlockGen) Number() *big.Int
- func (b *BlockGen) OffsetTime(seconds int64)
- func (b *BlockGen) PrevBlock(index int) *block.Block
- func (b *BlockGen) SetCoinbase(addr types.Address)
- func (b *BlockGen) SetConsensusData(data []byte)
- func (b *BlockGen) TxNonce(addr types.Address) uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateChain ¶
func GenerateChain(config *params.ChainConfig, parent *block.Block, engine consensus.Engine, db database.IDatabase, n int, gen func(int, *BlockGen)) ([]*block.Block, []transaction.Receipts)
GenerateChain creates a chain of n blocks. The first block's parent will be the provided parent. db is used to store intermediate states and should contain the parent's state trie.
The generator function is called with a new block generator for every block. Any transactions.If gen is nil, the blocks will be empty and their coinbase will be the zero address.
Blocks created by GenerateChain do not contain valid proof of work values. Inserting them into BlockChain requires use of FakePow or a similar non-validating proof of work implementation.
Types ¶
type BlockGen ¶
type BlockGen struct {
// contains filtered or unexported fields
}
BlockGen creates blocks for testing. See GenerateChain for a detailed explanation.
func (*BlockGen) AddTx ¶
func (b *BlockGen) AddTx(tx *transaction.Transaction)
AddTx adds a transaction to the generated block. If no coinbase has been set, the block's coinbase is set to the zero address.
AddTx panics if the transaction cannot be executed. In addition to the protocol-imposed limitations , there are some further limitations on the content of transactions that can be added. Notably, contract code relying on the BLOCKHASH instruction will panic during execution.
func (*BlockGen) AddUncheckedReceipt ¶
func (b *BlockGen) AddUncheckedReceipt(receipt *transaction.Receipt)
AddUncheckedReceipt forcefully adds a receipts to the block without a backing transaction.
AddUncheckedReceipt will cause consensus failures when used during real chain processing. This is best used in conjunction with raw block insertion.
func (*BlockGen) OffsetTime ¶
OffsetTime modifies the time instance of a block, implicitly changing its associated difficulty. It's useful to test scenarios where forking is not tied to chain length directly.
func (*BlockGen) PrevBlock ¶
PrevBlock returns a previously generated block by number. It panics if num is greater or equal to the number of the block being generated. For index -1, PrevBlock returns the parent block given to GenerateChain.
func (*BlockGen) SetCoinbase ¶
SetCoinbase sets the coinbase of the generated block. It can be called at most once.
func (*BlockGen) SetConsensusData ¶
SetExtra sets the extra data field of the generated block.