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 /rpc | |
parent | 8a8ef56dd1a0f2cd28c6d4b3a579b16cdda6e2cf (diff) | |
parent | cccb47666b2bccce378a9a56824061ea3a9a95fa (diff) |
Merge pull request #43 from ava-labs/handle-block-number-requests
Handle block number requests
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/types.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/rpc/types.go b/rpc/types.go index 99e29fc..4e62a53 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -92,7 +92,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error { *bn = EarliestBlockNumber return nil case "latest": - *bn = AcceptedBlockNumber + *bn = LatestBlockNumber return nil case "pending": *bn = PendingBlockNumber @@ -117,6 +117,11 @@ func (bn BlockNumber) Int64() int64 { return (int64)(bn) } +// IsAccepted returns true if this blockNumber should be treated as a request for the last accepted block +func (bn BlockNumber) IsAccepted() bool { + return bn < EarliestBlockNumber && bn >= AcceptedBlockNumber +} + type BlockNumberOrHash struct { BlockNumber *BlockNumber `json:"blockNumber,omitempty"` BlockHash *common.Hash `json:"blockHash,omitempty"` @@ -147,7 +152,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { bnh.BlockNumber = &bn return nil case "latest": - bn := AcceptedBlockNumber + bn := LatestBlockNumber bnh.BlockNumber = &bn return nil case "pending": |