mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
add BlockByNumber to simulated backend
This commit is contained in:
parent
e7dc0188ba
commit
47d1a8a321
1 changed files with 11 additions and 0 deletions
|
|
@ -46,6 +46,7 @@ import (
|
|||
var _ bind.ContractBackend = (*SimulatedBackend)(nil)
|
||||
|
||||
var errBlockNumberUnsupported = errors.New("SimulatedBackend cannot access blocks other than the latest block")
|
||||
var errBlockDoesNotExist = errors.New("block does not exist in blockchain")
|
||||
var errGasEstimationFailed = errors.New("gas required exceeds allowance or always failing transaction")
|
||||
|
||||
// SimulatedBackend implements bind.ContractBackend, simulating a blockchain in
|
||||
|
|
@ -170,6 +171,16 @@ func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.
|
|||
return transaction, blockNumber != 0, nil
|
||||
}
|
||||
|
||||
// BlockByNumber retrieves a block from the database by number, caching it
|
||||
// (associated with its hash) if found.
|
||||
func (b *SimulatedBackend) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
|
||||
block := b.blockchain.GetBlockByNumber(number.Uint64())
|
||||
if block == nil {
|
||||
return nil, errBlockDoesNotExist
|
||||
}
|
||||
return block, nil
|
||||
}
|
||||
|
||||
// HeaderByNumber returns a block header from the current canonical chain. If number is
|
||||
// nil, the latest known header is returned.
|
||||
func (b *SimulatedBackend) HeaderByNumber(ctx context.Context, block *big.Int) (*types.Header, error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue