aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-10-14 11:51:29 +0800
committerFelix Lange <fjl@twurst.com>2016-11-09 09:12:53 +0800
commit9f8d192991c4f68fa14c91366722bbca601da117 (patch)
tree5c1e089673d3f0208cd4a8208623bb95f29622c9 /internal
parent760fd65487614b7a61443cd9371015925795f40f (diff)
downloaddexon-9f8d192991c4f68fa14c91366722bbca601da117.tar
dexon-9f8d192991c4f68fa14c91366722bbca601da117.tar.gz
dexon-9f8d192991c4f68fa14c91366722bbca601da117.tar.bz2
dexon-9f8d192991c4f68fa14c91366722bbca601da117.tar.lz
dexon-9f8d192991c4f68fa14c91366722bbca601da117.tar.xz
dexon-9f8d192991c4f68fa14c91366722bbca601da117.tar.zst
dexon-9f8d192991c4f68fa14c91366722bbca601da117.zip
les: light client protocol and API
Diffstat (limited to 'internal')
-rw-r--r--internal/ethapi/api.go13
-rw-r--r--internal/ethapi/backend.go4
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