Skip to content

Commit c95ea08

Browse files
committed
Improve readability of resolveBlockNumber helper function
1 parent 237faaa commit c95ea08

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

api/utils.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,24 @@ func resolveBlockNumber(
6666
// FinalizedBlockNumber = BlockNumber(-3)
6767
// LatestBlockNumber = BlockNumber(-2)
6868
// PendingBlockNumber = BlockNumber(-1)
69-
//
70-
// EVM on Flow does not have these concepts, but the latest block is the closest fit
71-
height := uint64(blockNumber)
72-
var err error
73-
if blockNumber == rpc.EarliestBlockNumber {
74-
height = 0
75-
} else if blockNumber <= rpc.PendingBlockNumber {
76-
height, err = blocksDB.LatestEVMHeight()
69+
switch blockNumber {
70+
case rpc.EarliestBlockNumber:
71+
// the earliest block is the genesis block, which has a block number of `0`
72+
return 0, nil
73+
case rpc.SafeBlockNumber,
74+
rpc.FinalizedBlockNumber,
75+
rpc.LatestBlockNumber,
76+
rpc.PendingBlockNumber:
77+
// EVM on Flow does not have these concepts,
78+
// but the latest block is the closest fit
79+
height, err := blocksDB.LatestEVMHeight()
7780
if err != nil {
7881
return 0, err
7982
}
83+
return height, nil
8084
}
8185

82-
return height, nil
86+
return uint64(blockNumber), nil
8387
}
8488

8589
// decodeHash parses a hex-encoded 32-byte hash. The input may optionally

0 commit comments

Comments
 (0)