From 9f8d192991c4f68fa14c91366722bbca601da117 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Fri, 14 Oct 2016 05:51:29 +0200 Subject: les: light client protocol and API --- eth/api_backend.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'eth/api_backend.go') diff --git a/eth/api_backend.go b/eth/api_backend.go index 42b84bf9b..639f186c1 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -44,17 +44,17 @@ func (b *EthApiBackend) SetHead(number uint64) { b.eth.blockchain.SetHead(number) } -func (b *EthApiBackend) HeaderByNumber(blockNr rpc.BlockNumber) *types.Header { +func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) { // Pending block is only known by the miner if blockNr == rpc.PendingBlockNumber { block, _ := b.eth.miner.Pending() - return block.Header() + return block.Header(), nil } // Otherwise resolve and return the block if blockNr == rpc.LatestBlockNumber { - return b.eth.blockchain.CurrentBlock().Header() + return b.eth.blockchain.CurrentBlock().Header(), nil } - return b.eth.blockchain.GetHeaderByNumber(uint64(blockNr)) + return b.eth.blockchain.GetHeaderByNumber(uint64(blockNr)), nil } func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) { @@ -70,16 +70,16 @@ func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb return b.eth.blockchain.GetBlockByNumber(uint64(blockNr)), nil } -func (b *EthApiBackend) StateAndHeaderByNumber(blockNr rpc.BlockNumber) (ethapi.State, *types.Header, error) { +func (b *EthApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (ethapi.State, *types.Header, error) { // Pending state is only known by the miner if blockNr == rpc.PendingBlockNumber { block, state := b.eth.miner.Pending() return EthApiState{state}, block.Header(), nil } // Otherwise resolve the block number and return its state - header := b.HeaderByNumber(blockNr) - if header == nil { - return nil, nil, nil + header, err := b.HeaderByNumber(ctx, blockNr) + if header == nil || err != nil { + return nil, nil, err } stateDb, err := b.eth.BlockChain().StateAt(header.Root) return EthApiState{stateDb}, header, err -- cgit