diff options
Diffstat (limited to 'internal/ethapi')
-rw-r--r-- | internal/ethapi/api.go | 13 | ||||
-rw-r--r-- | internal/ethapi/backend.go | 4 |
2 files changed, 9 insertions, 8 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 0e8e905aa..806005482 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -366,14 +366,15 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI { // BlockNumber returns the block number of the chain head. func (s *PublicBlockChainAPI) BlockNumber() *big.Int { - return s.b.HeaderByNumber(rpc.LatestBlockNumber).Number + header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available + return header.Number } // GetBalance returns the amount of wei for the given address in the state of the // given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta // block numbers are also allowed. func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*big.Int, error) { - state, _, err := s.b.StateAndHeaderByNumber(blockNr) + state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr) if state == nil || err != nil { return nil, err } @@ -458,7 +459,7 @@ func (s *PublicBlockChainAPI) GetUncleCountByBlockHash(ctx context.Context, bloc // GetCode returns the code stored at the given address in the state for the given block number. func (s *PublicBlockChainAPI) GetCode(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (string, error) { - state, _, err := s.b.StateAndHeaderByNumber(blockNr) + state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr) if state == nil || err != nil { return "", err } @@ -473,7 +474,7 @@ func (s *PublicBlockChainAPI) GetCode(ctx context.Context, address common.Addres // block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta block // numbers are also allowed. func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.Address, key string, blockNr rpc.BlockNumber) (string, error) { - state, _, err := s.b.StateAndHeaderByNumber(blockNr) + state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr) if state == nil || err != nil { return "0x", err } @@ -517,7 +518,7 @@ type CallArgs struct { func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr rpc.BlockNumber) (string, *big.Int, error) { defer func(start time.Time) { glog.V(logger.Debug).Infof("call took %v", time.Since(start)) }(time.Now()) - state, header, err := s.b.StateAndHeaderByNumber(blockNr) + state, header, err := s.b.StateAndHeaderByNumber(ctx, blockNr) if state == nil || err != nil { return "0x", common.Big0, err } @@ -859,7 +860,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx cont // GetTransactionCount returns the number of transactions the given address has sent for the given block number func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*rpc.HexNumber, error) { - state, _, err := s.b.StateAndHeaderByNumber(blockNr) + state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr) if state == nil || err != nil { return nil, err } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 0aa3da18d..ec5a84c5c 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -44,9 +44,9 @@ type Backend interface { AccountManager() *accounts.Manager // BlockChain API SetHead(number uint64) - HeaderByNumber(blockNr rpc.BlockNumber) *types.Header + HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) - StateAndHeaderByNumber(blockNr rpc.BlockNumber) (State, *types.Header, error) + StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (State, *types.Header, error) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) GetTd(blockHash common.Hash) *big.Int |