@@ -30,6 +30,7 @@ import (
3030 ethclient "github.com/ethereum/go-ethereum/ethclient"
3131 ethrpc "github.com/ethereum/go-ethereum/rpc"
3232
33+ smcerror "github.com/0xPolygon/polygon-cli/errors"
3334 "github.com/0xPolygon/polygon-cli/bindings/tokens"
3435 "github.com/0xPolygon/polygon-cli/bindings/ulxly"
3536 "github.com/0xPolygon/polygon-cli/bindings/ulxly/polygonrollupmanager"
@@ -545,12 +546,12 @@ type JsonError struct {
545546 Data interface {} `json:"data"`
546547}
547548
548- func logAndReturnJsonError (cmd * cobra. Command , client * ethclient.Client , tx * types.Transaction , opts * bind.TransactOpts , err error ) error {
549+ func logAndReturnJsonError (ctx context. Context , client * ethclient.Client , tx * types.Transaction , opts * bind.TransactOpts , err error ) error {
549550
550551 var callErr error
551552 if tx != nil {
552553 // in case the error came down to gas estimation, we can sometimes get more information by doing a call
553- _ , callErr = client .CallContract (cmd . Context () , ethereum.CallMsg {
554+ _ , callErr = client .CallContract (ctx , ethereum.CallMsg {
554555 From : opts .From ,
555556 To : tx .To (),
556557 Gas : tx .Gas (),
@@ -599,24 +600,30 @@ func logAndReturnJsonError(cmd *cobra.Command, client *ethclient.Client, tx *typ
599600 return err
600601 }
601602
603+ reason , decodeErr := smcerror .DecodeInterfaceSmcErrorCode (jsonError .Data )
604+ if decodeErr != nil {
605+ log .Error ().Err (err ).Msg ("unable to decode smart contract error" )
606+ return err
607+ }
602608 errLog := log .Error ().
603609 Err (err ).
604610 Str ("message" , jsonError .Message ).
605611 Int ("code" , jsonError .Code ).
606- Interface ("data" , jsonError .Data )
612+ Interface ("data" , jsonError .Data ).
613+ Str ("reason" , reason )
607614
608615 if callErr != nil {
609616 errLog = errLog .Err (callErr )
610617 }
611618
619+ customErr := errors .New (err .Error ()+ ": " + reason )
612620 if errCode , isValid := jsonError .Data .(string ); isValid && errCode == "0x646cf558" {
613621 // I don't want to bother with the additional error logging for previously claimed deposits
614- return err
622+ return customErr
615623 }
616624
617625 errLog .Msg ("Unable to interact with bridge contract" )
618-
619- return err
626+ return customErr
620627}
621628
622629// Function to parse deposit count from bridge transaction logs
@@ -725,7 +732,7 @@ func bridgeAsset(cmd *cobra.Command) error {
725732
726733 // Approve the bridge contract to spend the tokens on behalf of the user
727734 approveTxn , iErr := tokenContract .Approve (auth , bridgeAddress , value )
728- if iErr = logAndReturnJsonError (cmd , client , approveTxn , auth , iErr ); iErr != nil {
735+ if iErr = logAndReturnJsonError (cmd . Context () , client , approveTxn , auth , iErr ); iErr != nil {
729736 return iErr
730737 }
731738 log .Info ().Msg ("approveTxn: " + approveTxn .Hash ().String ())
@@ -736,7 +743,7 @@ func bridgeAsset(cmd *cobra.Command) error {
736743 }
737744
738745 bridgeTxn , err := bridgeV2 .BridgeAsset (auth , destinationNetwork , toAddress , value , tokenAddress , isForced , callData )
739- if err = logAndReturnJsonError (cmd , client , bridgeTxn , auth , err ); err != nil {
746+ if err = logAndReturnJsonError (cmd . Context () , client , bridgeTxn , auth , err ); err != nil {
740747 log .Info ().Err (err ).Str ("calldata" , callDataString ).Msg ("Bridge transaction failed" )
741748 return err
742749 }
@@ -790,7 +797,7 @@ func bridgeMessage(cmd *cobra.Command) error {
790797 }
791798
792799 bridgeTxn , err := bridgeV2 .BridgeMessage (auth , destinationNetwork , toAddress , isForced , callData )
793- if err = logAndReturnJsonError (cmd , client , bridgeTxn , auth , err ); err != nil {
800+ if err = logAndReturnJsonError (cmd . Context () , client , bridgeTxn , auth , err ); err != nil {
794801 log .Info ().Err (err ).Str ("calldata" , callDataString ).Msg ("Bridge transaction failed" )
795802 return err
796803 }
@@ -847,7 +854,7 @@ func bridgeWETHMessage(cmd *cobra.Command) error {
847854 callData := common .Hex2Bytes (strings .TrimPrefix (callDataString , "0x" ))
848855
849856 bridgeTxn , err := bridgeV2 .BridgeMessageWETH (auth , destinationNetwork , toAddress , value , isForced , callData )
850- if err = logAndReturnJsonError (cmd , client , bridgeTxn , auth , err ); err != nil {
857+ if err = logAndReturnJsonError (cmd . Context () , client , bridgeTxn , auth , err ); err != nil {
851858 log .Info ().Err (err ).Str ("calldata" , callDataString ).Msg ("Bridge transaction failed" )
852859 return err
853860 }
@@ -911,7 +918,7 @@ func claimAsset(cmd *cobra.Command) error {
911918 merkleProofArray , rollupMerkleProofArray , mainExitRoot , rollupExitRoot := getMerkleProofsExitRoots (bridgeServiceProofEndpoint )
912919
913920 claimTxn , err := bridgeV2 .ClaimAsset (auth , merkleProofArray , rollupMerkleProofArray , globalIndex , [32 ]byte (mainExitRoot ), [32 ]byte (rollupExitRoot ), claimOriginalNetwork , originAddress , claimDestNetwork , toAddress , amount , metadata )
914- if err = logAndReturnJsonError (cmd , client , claimTxn , auth , err ); err != nil {
921+ if err = logAndReturnJsonError (cmd . Context () , client , claimTxn , auth , err ); err != nil {
915922 return err
916923 }
917924 log .Info ().Msg ("claimTxn: " + claimTxn .Hash ().String ())
@@ -964,7 +971,7 @@ func claimMessage(cmd *cobra.Command) error {
964971 merkleProofArray , rollupMerkleProofArray , mainExitRoot , rollupExitRoot := getMerkleProofsExitRoots (bridgeServiceProofEndpoint )
965972
966973 claimTxn , err := bridgeV2 .ClaimMessage (auth , merkleProofArray , rollupMerkleProofArray , globalIndex , [32 ]byte (mainExitRoot ), [32 ]byte (rollupExitRoot ), claimOriginalNetwork , originAddress , claimDestNetwork , toAddress , amount , metadata )
967- if err = logAndReturnJsonError (cmd , client , claimTxn , auth , err ); err != nil {
974+ if err = logAndReturnJsonError (cmd . Context () , client , claimTxn , auth , err ); err != nil {
968975 return err
969976 }
970977 log .Info ().Msg ("claimTxn: " + claimTxn .Hash ().String ())
@@ -1252,7 +1259,7 @@ func claimSingleDeposit(cmd *cobra.Command, client *ethclient.Client, bridgeCont
12521259 claimTx , err = bridgeContract .ClaimMessage (opts , merkleProofArray , rollupMerkleProofArray , globalIndex , [32 ]byte (mainExitRoot ), [32 ]byte (rollupExitRoot ), deposit .OrigNet , originAddress , deposit .DestNet , toAddress , amount , metadata )
12531260 }
12541261
1255- if err = logAndReturnJsonError (cmd , client , claimTx , opts , err ); err != nil {
1262+ if err = logAndReturnJsonError (cmd . Context () , client , claimTx , opts , err ); err != nil {
12561263 log .Warn ().
12571264 Uint32 ("DepositCnt" , deposit .DepositCnt ).
12581265 Uint32 ("OrigNet" , deposit .OrigNet ).
@@ -1875,7 +1882,7 @@ func getDeposit(bridgeServiceDepositsEndpoint string) (globalIndex *big.Int, ori
18751882 return nil , common .HexToAddress ("0x0" ), nil , nil , 0 , 0 , 0 , ErrNotReadyForClaim
18761883 } else if bridgeDeposit .Deposit .ClaimTxHash != "" {
18771884 log .Info ().Str ("claimTxHash" , bridgeDeposit .Deposit .ClaimTxHash ).Msg ("The claim transaction has already been claimed" )
1878- return nil , common .HexToAddress ("0x0" ), nil , nil , 0 , 0 , 0 , ErrDepositAlreadyClaimed
1885+ // return nil, common.HexToAddress("0x0"), nil, nil, 0, 0, 0, ErrDepositAlreadyClaimed
18791886 }
18801887 originAddress = common .HexToAddress (bridgeDeposit .Deposit .OrigAddr )
18811888 globalIndex .SetString (bridgeDeposit .Deposit .GlobalIndex , 10 )
@@ -2429,7 +2436,7 @@ or if it's actually an intermediate hash.`,
24292436 inputUlxlyArgs .gasLimit = ulxlyBridgeAndClaimCmd .PersistentFlags ().Uint64 (ArgGasLimit , 0 , "force a gas limit when sending a transaction" )
24302437 inputUlxlyArgs .chainID = ulxlyBridgeAndClaimCmd .PersistentFlags ().String (ArgChainID , "" , "set the chain id to be used in the transaction" )
24312438 inputUlxlyArgs .privateKey = ulxlyBridgeAndClaimCmd .PersistentFlags ().String (ArgPrivateKey , "" , "the hex encoded private key to be used when sending the tx" )
2432- inputUlxlyArgs .destAddress = ulxlyBridgeAndClaimCmd .PersistentFlags ().String (ArgDestAddress , "" , "the address where the bridge will be sent to" )
2439+ inputUlxlyArgs .destAddress = ulxlyBridgeAndClaimCmd .Flags ().String (ArgDestAddress , "" , "the address where the bridge will be sent to" )
24332440 inputUlxlyArgs .timeout = ulxlyBridgeAndClaimCmd .PersistentFlags ().Uint64 (ArgTimeout , 60 , "the amount of time to wait while trying to confirm a transaction receipt" )
24342441 inputUlxlyArgs .gasPrice = ulxlyBridgeAndClaimCmd .PersistentFlags ().String (ArgGasPrice , "" , "the gas price to be used" )
24352442 inputUlxlyArgs .dryRun = ulxlyBridgeAndClaimCmd .PersistentFlags ().Bool (ArgDryRun , false , "do all of the transaction steps but do not send the transaction" )
0 commit comments