allow for nil block number to get most recent block

This commit is contained in:
Ilan Gitter 2018-10-04 17:38:30 -04:00 committed by Josh Giles
parent e6f04b6feb
commit 2e8ecf3dc0

View file

@ -188,6 +188,9 @@ func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.
// BlockByNumber retrieves a block from the database by number, caching it // BlockByNumber retrieves a block from the database by number, caching it
// (associated with its hash) if found. // (associated with its hash) if found.
func (b *SimulatedBackend) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { func (b *SimulatedBackend) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
if number == nil {
return b.blockchain.CurrentBlock(), nil
}
block := b.blockchain.GetBlockByNumber(number.Uint64()) block := b.blockchain.GetBlockByNumber(number.Uint64())
if block == nil { if block == nil {
return nil, errBlockDoesNotExist return nil, errBlockDoesNotExist