aboutsummaryrefslogtreecommitdiff
path: root/eth/api_backend.go
diff options
context:
space:
mode:
authoraaronbuchwald <[email protected]>2020-10-26 22:03:05 -0400
committerGitHub <[email protected]>2020-10-26 22:03:05 -0400
commit806d04e9aa4b6e22fc2a484ada6fecb0c9a348e3 (patch)
tree36822cea4b16638e6a246af209ccdf77b3eb2088 /eth/api_backend.go
parent8a8ef56dd1a0f2cd28c6d4b3a579b16cdda6e2cf (diff)
parentcccb47666b2bccce378a9a56824061ea3a9a95fa (diff)
Merge pull request #43 from ava-labs/handle-block-number-requests
Handle block number requests
Diffstat (limited to 'eth/api_backend.go')
-rw-r--r--eth/api_backend.go37
1 files changed, 8 insertions, 29 deletions
diff --git a/eth/api_backend.go b/eth/api_backend.go
index 6c5ebd8..f1b5f74 100644
--- a/eth/api_backend.go
+++ b/eth/api_backend.go
@@ -65,20 +65,12 @@ func (b *EthAPIBackend) SetHead(number uint64) {
}
func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {
- // Pending block is only known by the miner in
- // Ethereum, but Coreth does not have the same notion.
- // So we treat requests for the pending block identically
- // to the latest accepted block instead
- if number == rpc.PendingBlockNumber {
- return b.eth.AcceptedBlock().Header(), nil
- }
- // Otherwise resolve and return the block
- if number == rpc.LatestBlockNumber {
- return b.eth.blockchain.CurrentBlock().Header(), nil
- }
- if number == rpc.AcceptedBlockNumber {
+ // Treat requests for the pending, latest, or accepted block
+ // identically.
+ if number.IsAccepted() {
return b.eth.AcceptedBlock().Header(), nil
}
+
return b.eth.blockchain.GetHeaderByNumber(uint64(number)), nil
}
@@ -104,20 +96,12 @@ func (b *EthAPIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*ty
}
func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) {
- // Pending block is only known by the miner in
- // Ethereum, but Coreth does not have the same notion.
- // So we treat requests for the pending block identically
- // to the latest accepted block instead
- if number == rpc.PendingBlockNumber {
- return b.eth.AcceptedBlock(), nil
- }
- // Otherwise resolve and return the block
- if number == rpc.LatestBlockNumber {
- return b.eth.blockchain.CurrentBlock(), nil
- }
- if number == rpc.AcceptedBlockNumber {
+ // Treat requests for the pending, latest, or accepted block
+ // identically.
+ if number.IsAccepted() {
return b.eth.AcceptedBlock(), nil
}
+
return b.eth.blockchain.GetBlockByNumber(uint64(number)), nil
}
@@ -147,11 +131,6 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
}
func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
- // Note: Ethereum typically first checks if the request is for
- // the pending block (by rpc.PendingBlockNumber), but Coreth
- // does not have the same notion of the miner having a pending
- // block, so this is skipped here
-
// Request the block by its number and retrieve its state
header, err := b.HeaderByNumber(ctx, number)
if err != nil {