@@ -2,101 +2,15 @@ package bridge
22
33import (
44 "context"
5- "encoding/json"
6- "errors"
75 "fmt"
86
97 "github.com/0xPolygon/polygon-cli/bindings/ulxly"
10- ulxlycommon "github.com/0xPolygon/polygon-cli/cmd/ulxly/common"
11- smcerror "github.com/0xPolygon/polygon-cli/errors"
12- "github.com/ethereum/go-ethereum"
13- "github.com/ethereum/go-ethereum/accounts/abi/bind"
148 "github.com/ethereum/go-ethereum/common"
159 "github.com/ethereum/go-ethereum/core/types"
1610 "github.com/ethereum/go-ethereum/ethclient"
1711 "github.com/rs/zerolog/log"
1812)
1913
20- // logAndReturnJSONError logs and returns a JSON-RPC error with additional context.
21- func logAndReturnJSONError (ctx context.Context , client * ethclient.Client , tx * types.Transaction , opts * bind.TransactOpts , err error ) error {
22- var callErr error
23- if tx != nil {
24- // in case the error came down to gas estimation, we can sometimes get more information by doing a call
25- _ , callErr = client .CallContract (ctx , ethereum.CallMsg {
26- From : opts .From ,
27- To : tx .To (),
28- Gas : tx .Gas (),
29- GasPrice : tx .GasPrice (),
30- GasFeeCap : tx .GasFeeCap (),
31- GasTipCap : tx .GasTipCap (),
32- Value : tx .Value (),
33- Data : tx .Data (),
34- AccessList : tx .AccessList (),
35- BlobGasFeeCap : tx .BlobGasFeeCap (),
36- BlobHashes : tx .BlobHashes (),
37- }, nil )
38-
39- if ulxlycommon .InputArgs .DryRun {
40- castCmd := "cast call"
41- castCmd += fmt .Sprintf (" --rpc-url %s" , ulxlycommon .InputArgs .RPCURL )
42- castCmd += fmt .Sprintf (" --from %s" , opts .From .String ())
43- castCmd += fmt .Sprintf (" --gas-limit %d" , tx .Gas ())
44- if tx .Type () == types .LegacyTxType {
45- castCmd += fmt .Sprintf (" --gas-price %s" , tx .GasPrice ().String ())
46- } else {
47- castCmd += fmt .Sprintf (" --gas-price %s" , tx .GasFeeCap ().String ())
48- castCmd += fmt .Sprintf (" --priority-gas-price %s" , tx .GasTipCap ().String ())
49- }
50- castCmd += fmt .Sprintf (" --value %s" , tx .Value ().String ())
51- castCmd += fmt .Sprintf (" %s" , tx .To ().String ())
52- castCmd += fmt .Sprintf (" %s" , common .Bytes2Hex (tx .Data ()))
53- log .Info ().Str ("cmd" , castCmd ).Msg ("use this command to replicate the call" )
54- }
55- }
56-
57- if err == nil {
58- return nil
59- }
60-
61- var jsonError ulxlycommon.JSONError
62- jsonErrorBytes , jsErr := json .Marshal (err )
63- if jsErr != nil {
64- log .Error ().Err (err ).Msg ("Unable to interact with the bridge contract" )
65- return err
66- }
67-
68- jsErr = json .Unmarshal (jsonErrorBytes , & jsonError )
69- if jsErr != nil {
70- log .Error ().Err (err ).Msg ("Unable to interact with the bridge contract" )
71- return err
72- }
73-
74- reason , decodeErr := smcerror .DecodeSmcErrorCode (jsonError .Data )
75- if decodeErr != nil {
76- log .Error ().Err (err ).Msg ("unable to decode smart contract error" )
77- return err
78- }
79- errLog := log .Error ().
80- Err (err ).
81- Str ("message" , jsonError .Message ).
82- Int ("code" , jsonError .Code ).
83- Interface ("data" , jsonError .Data ).
84- Str ("reason" , reason )
85-
86- if callErr != nil {
87- errLog = errLog .Err (callErr )
88- }
89-
90- customErr := errors .New (err .Error () + ": " + reason )
91- if errCode , isValid := jsonError .Data .(string ); isValid && errCode == "0x646cf558" {
92- // I don't want to bother with the additional error logging for previously claimed deposits
93- return customErr
94- }
95-
96- errLog .Msg ("Unable to interact with bridge contract" )
97- return customErr
98- }
99-
10014// parseDepositCountFromTransaction extracts the deposit count from a bridge transaction receipt.
10115func parseDepositCountFromTransaction (ctx context.Context , client * ethclient.Client , txHash common.Hash , bridgeContract * ulxly.Ulxly ) (uint32 , error ) {
10216 receipt , err := client .TransactionReceipt (ctx , txHash )
0 commit comments