Skip to content

Commit 51dd4ea

Browse files
committed
receipts: MaxFilterBlockRange
1 parent 51bc4a8 commit 51dd4ea

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

receipts/fetch.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,33 @@ import (
1212
sequence "github.com/0xsequence/go-sequence"
1313
)
1414

15+
const MaxFilterBlockRange = 10000
16+
1517
// FetchReceipts looks up the transaction that emitted Call* events for the given
1618
// digest and returns all decoded Sequence receipts along with the native receipt.
1719
func FetchReceipts(ctx context.Context, opHash common.Hash, provider *ethrpc.Provider, fromBlock, toBlock *big.Int) (Receipts, *types.Receipt, error) {
1820
if provider == nil {
1921
return Receipts{}, nil, fmt.Errorf("no provider")
2022
}
2123

24+
fromBlock_ := fromBlock
25+
if fromBlock_ == nil {
26+
fromBlock_ = new(big.Int)
27+
}
28+
29+
toBlock_ := toBlock
30+
if toBlock_ == nil {
31+
latest, err := provider.BlockNumber(ctx)
32+
if err != nil {
33+
return Receipts{}, nil, fmt.Errorf("unable to get latest block: %w", err)
34+
}
35+
toBlock_ = new(big.Int).SetUint64(latest)
36+
}
37+
38+
if new(big.Int).Sub(toBlock_, fromBlock_).Cmp(big.NewInt(MaxFilterBlockRange)) > 0 {
39+
return Receipts{}, nil, fmt.Errorf("block range %v to %v exceeds %v, reduce block range", fromBlock_, toBlock_, MaxFilterBlockRange)
40+
}
41+
2242
query := ethereum.FilterQuery{
2343
FromBlock: fromBlock,
2444
ToBlock: toBlock,

0 commit comments

Comments
 (0)