Skip to content

Commit fd9bbbf

Browse files
authored
refactor: use the built-in max to simplify the code (#775)
Signed-off-by: pennylees <[email protected]>
1 parent 444c44a commit fd9bbbf

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

indexer/indexer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,7 @@ func (i *Indexer) initialCatchup() error {
331331
currentTip := latestBlock.Number().Int64()
332332

333333
// Calculate starting height (tip - lookbackDepth)
334-
startHeight := currentTip - i.lookbackDepth
335-
if startHeight < 0 {
336-
startHeight = 0
337-
}
334+
startHeight := max(currentTip-i.lookbackDepth, 0)
338335

339336
log.Info().
340337
Int64("currentTip", currentTip).

util/util.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ func GetBlockRangeInPages(ctx context.Context, from, to, pageSize uint64, c *eth
9696
var allBlocks []*json.RawMessage
9797

9898
for i := from; i <= to; i += pageSize {
99-
end := i + pageSize - 1
100-
if end > to {
101-
end = to
102-
}
99+
end := min(i+pageSize-1, to)
103100

104101
blocks, err := GetBlockRange(ctx, i, end, c, onlyTxHashes)
105102
if err != nil {

0 commit comments

Comments
 (0)