Skip to content

Commit dd5305f

Browse files
committed
fixup! contracts: release candidate 5: 0d9061f229da73edae890e6fdd1fbf753028df6d
1 parent 0543708 commit dd5305f

File tree

4 files changed

+268
-306
lines changed

4 files changed

+268
-306
lines changed

receipt_fetcher.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sequence
22

33
import (
44
"context"
5+
"fmt"
56
"time"
67

78
"github.com/0xsequence/ethkit"
@@ -53,7 +54,7 @@ done:
5354
case V2IsTxExecutedEvent(log, metaTxnHash):
5455
result.Status = MetaTxnExecuted
5556
break done
56-
case V3IsCallSuccessEvent(log, metaTxnHash):
57+
case V3IsCallSucceededEvent(log, metaTxnHash):
5758
result.Status = MetaTxnExecuted
5859
break done
5960
case V1IsTxFailedEvent(log, metaTxnHash):
@@ -66,11 +67,13 @@ done:
6667
break done
6768
case V3IsCallFailedEvent(log, metaTxnHash):
6869
result.Status = MetaTxnFailed
69-
_, _, result.Reason, _ = V3DecodeCallFailedEvent(log)
70+
_, _, reason, _ := V3DecodeCallFailedEvent(log)
71+
result.Reason = fmt.Sprint(reason)
7072
break done
7173
case V3IsCallAbortedEvent(log, metaTxnHash):
7274
result.Status = MetaTxnFailed
73-
_, _, result.Reason, _ = V3DecodeCallAbortedEvent(log)
75+
_, _, reason, _ := V3DecodeCallAbortedEvent(log)
76+
result.Reason = fmt.Sprint(reason)
7477
break done
7578
}
7679
}
@@ -90,7 +93,7 @@ func FilterMetaTransactionID(metaTxnID ethkit.Hash) ethreceipts.FilterQuery {
9093
fallthrough
9194
case V2IsTxFailedEvent(log, metaTxnID):
9295
fallthrough
93-
case V3IsCallSuccessEvent(log, metaTxnID):
96+
case V3IsCallSucceededEvent(log, metaTxnID):
9497
fallthrough
9598
case V3IsCallFailedEvent(log, metaTxnID):
9699
fallthrough

receipts.go

Lines changed: 251 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/0xsequence/ethkit/go-ethereum/common"
1414
"github.com/0xsequence/ethkit/go-ethereum/common/hexutil"
1515
"github.com/0xsequence/ethkit/go-ethereum/core/types"
16+
"github.com/0xsequence/go-sequence/contracts"
1617
"github.com/0xsequence/go-sequence/core"
1718
)
1819

@@ -171,11 +172,11 @@ func V2IsTxExecutedEvent(log *types.Log, hash common.Hash) bool {
171172
bytes.Equal(log.Topics[1][:], hash[:])
172173
}
173174

174-
func V3IsCallSuccessEvent(log *types.Log, hash common.Hash) bool {
175+
func V3IsCallSucceededEvent(log *types.Log, hash common.Hash) bool {
175176
if len(log.Topics) != 1 || log.Topics[0] != V3CallSucceeded {
176177
return false
177178
}
178-
transaction, _, err := V3DecodeCallSuccessEvent(log)
179+
transaction, _, err := V3DecodeCallSucceededEvent(log)
179180
if err != nil {
180181
return false
181182
}
@@ -215,54 +216,260 @@ func V3IsCallSkippedEvent(log *types.Log, hash common.Hash) bool {
215216
return transaction == hash
216217
}
217218

218-
func V3DecodeCallSuccessEvent(log *types.Log) (common.Hash, *big.Int, error) {
219-
var transaction common.Hash
220-
var index *big.Int
221-
err := ethcoder.ABIUnpackArgumentsByRef([]string{"bytes32", "uint256"}, log.Data, []any{&transaction, &index})
222-
if err != nil {
223-
return common.Hash{}, nil, err
219+
func V3DecodeCallSucceededEvent(log *types.Log) (common.Hash, *big.Int, error) {
220+
event := contracts.V3.WalletStage1Module.ABI.Events["CallSucceeded"]
221+
222+
if len(log.Topics) == 0 || log.Topics[0] != event.ID {
223+
return common.Hash{}, nil, fmt.Errorf("not CallSucceeded")
224+
}
225+
226+
switch len(log.Topics) {
227+
case 1:
228+
args, err := event.Inputs.Unpack(log.Data)
229+
if err != nil {
230+
return common.Hash{}, nil, fmt.Errorf("unable to decode CallSucceeded: %w", err)
231+
}
232+
if len(args) != 2 {
233+
return common.Hash{}, nil, fmt.Errorf("%v CallSucceeded arguments, expected two", len(args))
234+
}
235+
236+
digest, ok := args[0].([common.HashLength]byte)
237+
if !ok {
238+
return common.Hash{}, nil, fmt.Errorf("CallSucceeded digest is %T, expected common.Hash", args[0])
239+
}
240+
241+
index, ok := args[1].(*big.Int)
242+
if !ok {
243+
return common.Hash{}, nil, fmt.Errorf("CallSucceeded index is %T, expected *big.Int", args[1])
244+
}
245+
246+
return digest, index, nil
247+
248+
case 2:
249+
args, err := event.Inputs.NonIndexed().Unpack(log.Data)
250+
if err != nil {
251+
return common.Hash{}, nil, fmt.Errorf("unable to decode CallSucceeded: %w", err)
252+
}
253+
if len(args) != 1 {
254+
return common.Hash{}, nil, fmt.Errorf("%v non-indexed CallSucceeded arguments, expected one", len(args))
255+
}
256+
257+
digest := log.Topics[1]
258+
259+
index, ok := args[0].(*big.Int)
260+
if !ok {
261+
return common.Hash{}, nil, fmt.Errorf("CallSucceeded index is %T, expected *big.Int", args[0])
262+
}
263+
264+
return digest, index, nil
265+
266+
default:
267+
return common.Hash{}, nil, fmt.Errorf("%v topics, expected one or two", len(log.Topics))
224268
}
225-
return transaction, index, nil
226269
}
227270

228-
func V3DecodeCallFailedEvent(log *types.Log) (common.Hash, *big.Int, string, error) {
229-
var transaction common.Hash
230-
var index *big.Int
231-
var result []byte
232-
err := ethcoder.ABIUnpackArgumentsByRef([]string{"bytes32", "uint256", "bytes"}, log.Data, []any{&transaction, &index, &result})
233-
if err != nil {
234-
return common.Hash{}, nil, "", fmt.Errorf("unable to decode CallFailed event: %w", err)
271+
func V3DecodeCallFailedEvent(log *types.Log) (common.Hash, *big.Int, error, error) {
272+
event := contracts.V3.WalletStage1Module.ABI.Events["CallFailed"]
273+
274+
if len(log.Topics) == 0 || log.Topics[0] != event.ID {
275+
return common.Hash{}, nil, nil, fmt.Errorf("not CallFailed")
235276
}
236-
revert, err := abi.UnpackRevert(result)
237-
if err != nil {
238-
return transaction, index, hexutil.Encode(result), nil
277+
278+
switch len(log.Topics) {
279+
case 1:
280+
args, err := event.Inputs.Unpack(log.Data)
281+
if err != nil {
282+
return common.Hash{}, nil, nil, fmt.Errorf("unable to decode CallFailed: %w", err)
283+
}
284+
if len(args) != 3 {
285+
return common.Hash{}, nil, nil, fmt.Errorf("%v CallFailed arguments, expected three", len(args))
286+
}
287+
288+
digest, ok := args[0].([common.HashLength]byte)
289+
if !ok {
290+
return common.Hash{}, nil, nil, fmt.Errorf("CallFailed digest is %T, expected common.Hash", args[0])
291+
}
292+
293+
index, ok := args[1].(*big.Int)
294+
if !ok {
295+
return common.Hash{}, nil, nil, fmt.Errorf("CallFailed index is %T, expected *big.Int", args[1])
296+
}
297+
298+
reason, ok := args[2].([]byte)
299+
if !ok {
300+
return common.Hash{}, nil, nil, fmt.Errorf("CallFailed reason is %T, expected []byte", args[2])
301+
}
302+
303+
var reason_ error
304+
if reason__, err := abi.UnpackRevert(reason); err == nil {
305+
reason_ = fmt.Errorf("%v", reason__)
306+
} else {
307+
reason_ = fmt.Errorf("%v", hexutil.Encode(reason))
308+
}
309+
310+
return digest, index, reason_, nil
311+
312+
case 2:
313+
args, err := event.Inputs.NonIndexed().Unpack(log.Data)
314+
if err != nil {
315+
return common.Hash{}, nil, nil, fmt.Errorf("unable to decode CallFailed: %w", err)
316+
}
317+
if len(args) != 2 {
318+
return common.Hash{}, nil, nil, fmt.Errorf("%v non-indexed CallFailed arguments, expected two", len(args))
319+
}
320+
321+
digest := log.Topics[1]
322+
323+
index, ok := args[0].(*big.Int)
324+
if !ok {
325+
return common.Hash{}, nil, nil, fmt.Errorf("CallFailed index is %T, expected *big.Int", args[0])
326+
}
327+
328+
reason, ok := args[1].([]byte)
329+
if !ok {
330+
return common.Hash{}, nil, nil, fmt.Errorf("CallFailed reason is %T, expected []byte", args[1])
331+
}
332+
333+
var reason_ error
334+
if reason__, err := abi.UnpackRevert(reason); err == nil {
335+
reason_ = fmt.Errorf("%v", reason__)
336+
} else {
337+
reason_ = fmt.Errorf("%v", hexutil.Encode(reason))
338+
}
339+
340+
return digest, index, reason_, nil
341+
342+
default:
343+
return common.Hash{}, nil, nil, fmt.Errorf("%v topics, expected one or two", len(log.Topics))
239344
}
240-
return transaction, index, revert, nil
241345
}
242346

243-
func V3DecodeCallAbortedEvent(log *types.Log) (common.Hash, *big.Int, string, error) {
244-
var transaction common.Hash
245-
var index *big.Int
246-
var result []byte
247-
err := ethcoder.ABIUnpackArgumentsByRef([]string{"bytes32", "uint256", "bytes"}, log.Data, []any{&transaction, &index, &result})
248-
if err != nil {
249-
return common.Hash{}, nil, "", fmt.Errorf("unable to decode CallAborted event: %w", err)
347+
func V3DecodeCallAbortedEvent(log *types.Log) (common.Hash, *big.Int, error, error) {
348+
event := contracts.V3.WalletStage1Module.ABI.Events["CallAborted"]
349+
350+
if len(log.Topics) == 0 || log.Topics[0] != event.ID {
351+
return common.Hash{}, nil, nil, fmt.Errorf("not CallAborted")
250352
}
251-
revert, err := abi.UnpackRevert(result)
252-
if err != nil {
253-
return transaction, index, hexutil.Encode(result), nil
353+
354+
switch len(log.Topics) {
355+
case 1:
356+
args, err := event.Inputs.Unpack(log.Data)
357+
if err != nil {
358+
return common.Hash{}, nil, nil, fmt.Errorf("unable to decode CallAborted: %w", err)
359+
}
360+
if len(args) != 3 {
361+
return common.Hash{}, nil, nil, fmt.Errorf("%v CallAborted arguments, expected three", len(args))
362+
}
363+
364+
digest, ok := args[0].([common.HashLength]byte)
365+
if !ok {
366+
return common.Hash{}, nil, nil, fmt.Errorf("CallAborted digest is %T, expected common.Hash", args[0])
367+
}
368+
369+
index, ok := args[1].(*big.Int)
370+
if !ok {
371+
return common.Hash{}, nil, nil, fmt.Errorf("CallAborted index is %T, expected *big.Int", args[1])
372+
}
373+
374+
reason, ok := args[2].([]byte)
375+
if !ok {
376+
return common.Hash{}, nil, nil, fmt.Errorf("CallAborted reason is %T, expected []byte", args[2])
377+
}
378+
379+
var reason_ error
380+
if reason__, err := abi.UnpackRevert(reason); err == nil {
381+
reason_ = fmt.Errorf("%v", reason__)
382+
} else {
383+
reason_ = fmt.Errorf("%v", hexutil.Encode(reason))
384+
}
385+
386+
return digest, index, reason_, nil
387+
388+
case 2:
389+
args, err := event.Inputs.NonIndexed().Unpack(log.Data)
390+
if err != nil {
391+
return common.Hash{}, nil, nil, fmt.Errorf("unable to decode CallAborted: %w", err)
392+
}
393+
if len(args) != 2 {
394+
return common.Hash{}, nil, nil, fmt.Errorf("%v non-indexed CallAborted arguments, expected two", len(args))
395+
}
396+
397+
digest := log.Topics[1]
398+
399+
index, ok := args[0].(*big.Int)
400+
if !ok {
401+
return common.Hash{}, nil, nil, fmt.Errorf("CallAborted index is %T, expected *big.Int", args[0])
402+
}
403+
404+
reason, ok := args[1].([]byte)
405+
if !ok {
406+
return common.Hash{}, nil, nil, fmt.Errorf("CallAborted reason is %T, expected []byte", args[1])
407+
}
408+
409+
var reason_ error
410+
if reason__, err := abi.UnpackRevert(reason); err == nil {
411+
reason_ = fmt.Errorf("%v", reason__)
412+
} else {
413+
reason_ = fmt.Errorf("%v", hexutil.Encode(reason))
414+
}
415+
416+
return digest, index, reason_, nil
417+
418+
default:
419+
return common.Hash{}, nil, nil, fmt.Errorf("%v topics, expected one or two", len(log.Topics))
254420
}
255-
return transaction, index, revert, nil
256421
}
257422

258423
func V3DecodeCallSkippedEvent(log *types.Log) (common.Hash, *big.Int, error) {
259-
var transaction common.Hash
260-
var index *big.Int
261-
err := ethcoder.ABIUnpackArgumentsByRef([]string{"bytes32", "uint256"}, log.Data, []any{&transaction, &index})
262-
if err != nil {
263-
return common.Hash{}, nil, err
424+
event := contracts.V3.WalletStage1Module.ABI.Events["CallSkipped"]
425+
426+
if len(log.Topics) == 0 || log.Topics[0] != event.ID {
427+
return common.Hash{}, nil, fmt.Errorf("not CallSkipped")
428+
}
429+
430+
switch len(log.Topics) {
431+
case 1:
432+
args, err := event.Inputs.Unpack(log.Data)
433+
if err != nil {
434+
return common.Hash{}, nil, fmt.Errorf("unable to decode CallSkipped: %w", err)
435+
}
436+
if len(args) != 2 {
437+
return common.Hash{}, nil, fmt.Errorf("%v CallSkipped arguments, expected two", len(args))
438+
}
439+
440+
digest, ok := args[0].([common.HashLength]byte)
441+
if !ok {
442+
return common.Hash{}, nil, fmt.Errorf("CallSkipped digest is %T, expected common.Hash", args[0])
443+
}
444+
445+
index, ok := args[1].(*big.Int)
446+
if !ok {
447+
return common.Hash{}, nil, fmt.Errorf("CallSkipped index is %T, expected *big.Int", args[1])
448+
}
449+
450+
return digest, index, nil
451+
452+
case 2:
453+
args, err := event.Inputs.NonIndexed().Unpack(log.Data)
454+
if err != nil {
455+
return common.Hash{}, nil, fmt.Errorf("unable to decode CallSkipped: %w", err)
456+
}
457+
if len(args) != 1 {
458+
return common.Hash{}, nil, fmt.Errorf("%v non-indexed CallSkipped arguments, expected one", len(args))
459+
}
460+
461+
digest := log.Topics[1]
462+
463+
index, ok := args[0].(*big.Int)
464+
if !ok {
465+
return common.Hash{}, nil, fmt.Errorf("CallSkipped index is %T, expected *big.Int", args[0])
466+
}
467+
468+
return digest, index, nil
469+
470+
default:
471+
return common.Hash{}, nil, fmt.Errorf("%v topics, expected one or two", len(log.Topics))
264472
}
265-
return transaction, index, nil
266473
}
267474

268475
func V2IsTxFailedEvent(log *types.Log, hash common.Hash) bool {
@@ -380,7 +587,7 @@ func decodeReceipt(logs []*types.Log, transactions Transactions, nonce *big.Int,
380587
log, logs = logs[0], logs[1:]
381588

382589
isTxExecuted := V1IsTxExecutedEvent(log, hash) || V2IsTxExecutedEvent(log, hash)
383-
if V3IsCallSuccessEvent(log, digest.Hash) {
590+
if V3IsCallSucceededEvent(log, digest.Hash) {
384591
isTxExecuted = true
385592
receipt.MetaTxnID = MetaTxnID(digest.Hash.String()[2:])
386593
}
@@ -395,13 +602,17 @@ func decodeReceipt(logs []*types.Log, transactions Transactions, nonce *big.Int,
395602
failedHash, failedReason, _, err = V2DecodeTxFailedEvent(log)
396603
}
397604
if err != nil {
398-
failedHash, _, failedReason, err = V3DecodeCallFailedEvent(log)
605+
var reason error
606+
failedHash, _, reason, err = V3DecodeCallFailedEvent(log)
607+
failedReason = fmt.Sprint(reason)
399608
if err == nil {
400609
receipt.MetaTxnID = MetaTxnID(digest.Hash.String()[2:])
401610
}
402611
}
403612
if err != nil {
404-
failedHash, _, failedReason, err = V3DecodeCallAbortedEvent(log)
613+
var reason error
614+
failedHash, _, reason, err = V3DecodeCallAbortedEvent(log)
615+
failedReason = fmt.Sprint(reason)
405616
if err == nil {
406617
receipt.MetaTxnID = MetaTxnID(digest.Hash.String()[2:])
407618
}

0 commit comments

Comments
 (0)