@@ -12,12 +12,15 @@ import (
1212 sequence "github.com/0xsequence/go-sequence"
1313)
1414
15- const MaxFilterBlockRange = 10_000
15+ const MaxFilterBlockRange = 7500
1616
17- // FetchReceipts looks up the transaction that emitted Call* events for the given
18- // digest and returns all decoded Sequence receipts along with the native receipt.
17+ // FetchMetaTransactionReceiptByETHGetLogs looks up the transaction that emitted Call*
18+ // events for the given digest and returns all decoded Sequence receipts along with
19+ // the native receipt.
1920//
20- // The `opHash` is also known as the "MetaTxnID"
21+ // The `opHash` is also known as the "MetaTxnID" but please make sure
22+ // it has the "0x" prefix when passing as a common.Hash, even though
23+ // sometimes we represent a MetaTxnID without the 0x prefix as a string.
2124//
2225// NOTE: toBlock can also be nil, in which case the latest block is used.
2326//
@@ -27,9 +30,9 @@ const MaxFilterBlockRange = 10_000
2730// receipt directly. However, this is not to be confused with where a "Call" inside
2831// of the native transaction fails, but the native transaction itself succeeds which
2932// is more common and works fine.
30- func FetchReceipts (ctx context.Context , opHash common.Hash , provider * ethrpc.Provider , fromBlock , toBlock * big.Int ) (Receipts , * types.Receipt , error ) {
33+ func FetchMetaTransactionReceiptByETHGetLogs (ctx context.Context , opHash common.Hash , provider ethrpc.Interface , fromBlock , toBlock * big.Int ) (Receipts , * types.Receipt , error ) {
3134 if provider == nil {
32- return Receipts {}, nil , fmt .Errorf ("no provider" )
35+ return Receipts {}, nil , fmt .Errorf ("receipts: no provider" )
3336 }
3437
3538 fromBlock_ := fromBlock
@@ -54,25 +57,22 @@ func FetchReceipts(ctx context.Context, opHash common.Hash, provider *ethrpc.Pro
5457 FromBlock : fromBlock ,
5558 ToBlock : toBlock ,
5659 Topics : [][]common.Hash {
57- {sequence .V3CallSucceeded , sequence .V3CallFailed , sequence .V3CallAborted , sequence .V3CallSkipped },
60+ {sequence .V3CallSucceeded , sequence .V3CallFailed }, // , sequence.V3CallAborted, sequence.V3CallSkipped},
5861 {opHash },
5962 },
6063 }
6164
65+ // TODO: what if there is a node failure here, we should retry a few times
66+ // and also check the type of error from the node to see how we should behave/handle.
6267 logs , err := provider .FilterLogs (ctx , query )
6368 if err != nil {
6469 return Receipts {}, nil , fmt .Errorf ("unable to filter logs: %w" , err )
6570 }
6671 if len (logs ) == 0 {
67- // Fallback for legacy events where the digest is not indexed.
68- query .Topics = [][]common.Hash {{sequence .V3CallSucceeded , sequence .V3CallFailed , sequence .V3CallAborted , sequence .V3CallSkipped }}
69- logs , err = provider .FilterLogs (ctx , query )
70- if err != nil {
71- return Receipts {}, nil , fmt .Errorf ("unable to filter logs without digest topic: %w" , err )
72- }
72+ return Receipts {}, nil , ethereum .NotFound
7373 }
7474
75- log , err := findDigestLog (logs , opHash )
75+ log , err := findV3CallsDigestLog (logs , opHash )
7676 if err != nil {
7777 return Receipts {}, nil , err
7878 }
@@ -91,33 +91,27 @@ func FetchReceipts(ctx context.Context, opHash common.Hash, provider *ethrpc.Pro
9191 if receipts == nil {
9292 return Receipts {}, receipt , fmt .Errorf ("decoded receipts do not include digest %v" , opHash )
9393 }
94-
9594 return * receipts , receipt , nil
9695}
9796
98- func findDigestLog (logs []types.Log , digest common.Hash ) (* types.Log , error ) {
97+ func findV3CallsDigestLog (logs []types.Log , digest common.Hash ) (* types.Log , error ) {
9998 var selected * types.Log
100-
10199 for i := range logs {
102100 log := & logs [i ]
103-
104- if ! matchesDigest (log , digest ) {
101+ if ! matchesV3CallsDigest (log , digest ) {
105102 continue
106103 }
107-
108104 if selected == nil || isNewerLog (log , selected ) {
109105 selected = log
110106 }
111107 }
112-
113108 if selected == nil {
114109 return nil , fmt .Errorf ("no Call* events found for digest %v" , digest )
115110 }
116-
117111 return selected , nil
118112}
119113
120- func matchesDigest (log * types.Log , digest common.Hash ) bool {
114+ func matchesV3CallsDigest (log * types.Log , digest common.Hash ) bool {
121115 if hash , _ , err := sequence .V3DecodeCallSucceededEvent (log ); err == nil && hash == digest {
122116 return true
123117 }
0 commit comments