diff options
author | aaronbuchwald <[email protected]> | 2020-10-26 22:03:05 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-26 22:03:05 -0400 |
commit | 806d04e9aa4b6e22fc2a484ada6fecb0c9a348e3 (patch) | |
tree | 36822cea4b16638e6a246af209ccdf77b3eb2088 /eth/api_tracer.go | |
parent | 8a8ef56dd1a0f2cd28c6d4b3a579b16cdda6e2cf (diff) | |
parent | cccb47666b2bccce378a9a56824061ea3a9a95fa (diff) |
Merge pull request #43 from ava-labs/handle-block-number-requests
Handle block number requests
Diffstat (limited to 'eth/api_tracer.go')
-rw-r--r-- | eth/api_tracer.go | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/eth/api_tracer.go b/eth/api_tracer.go index c044dcc..23209de 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -105,26 +105,18 @@ func (api *PrivateDebugAPI) TraceChain(ctx context.Context, start, end rpc.Block // Fetch the block interval that we want to trace var from, to *types.Block - switch start { - case rpc.PendingBlockNumber: - from = api.eth.miner.PendingBlock() - case rpc.LatestBlockNumber: - from = api.eth.blockchain.CurrentBlock() - case rpc.AcceptedBlockNumber: + if start.IsAccepted() { from = api.eth.AcceptedBlock() - default: + } else { from = api.eth.blockchain.GetBlockByNumber(uint64(start)) } - switch end { - case rpc.PendingBlockNumber: - to = api.eth.miner.PendingBlock() - case rpc.LatestBlockNumber: - to = api.eth.blockchain.CurrentBlock() - case rpc.AcceptedBlockNumber: - from = api.eth.AcceptedBlock() - default: + + if end.IsAccepted() { + to = api.eth.AcceptedBlock() + } else { to = api.eth.blockchain.GetBlockByNumber(uint64(end)) } + // Trace the chain if we've found all our blocks if from == nil { return nil, fmt.Errorf("starting block #%d not found", start) @@ -360,16 +352,12 @@ func (api *PrivateDebugAPI) TraceBlockByNumber(ctx context.Context, number rpc.B // Fetch the block that we want to trace var block *types.Block - switch number { - case rpc.PendingBlockNumber: - block = api.eth.miner.PendingBlock() - case rpc.LatestBlockNumber: - block = api.eth.blockchain.CurrentBlock() - case rpc.AcceptedBlockNumber: + if number.IsAccepted() { block = api.eth.AcceptedBlock() - default: + } else { block = api.eth.blockchain.GetBlockByNumber(uint64(number)) } + // Trace the block if it was found if block == nil { return nil, fmt.Errorf("block #%d not found", number) |