Skip to content

Commit

Permalink
fix: unified decode message (#228)
Browse files Browse the repository at this point in the history
Co-authored-by: nulnut <[email protected]>
  • Loading branch information
zakir-code and nulnut authored Feb 23, 2024
1 parent 69664a4 commit f49467a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion x/crosschain/keeper/relay_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (k Keeper) bridgeCallEvmHandler(
ctx.EventManager().EmitEvents(sdk.Events{sdk.NewEvent(types.EventTypeBridgeCallEvm, attrs...)})
}()

txResp, err := k.evmKeeper.CallEVM(ctx, sender, to, value.BigInt(), gasLimit, fxtypes.MustDecodeHex(message), true)
txResp, err := k.evmKeeper.CallEVM(ctx, sender, to, value.BigInt(), gasLimit, types.MustDecodeMessage(message), true)
if err != nil {
k.Logger(ctx).Error("bridge call evm error", "nonce", eventNonce, "error", err.Error())
callErr = err.Error()
Expand Down
11 changes: 11 additions & 0 deletions x/crosschain/types/bridge_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@ func PackERC20Asset(tokens [][]byte, amounts []*big.Int) ([]byte, error) {
}
return assetTypeDecode.Pack("ERC20", assetData)
}

func MustDecodeMessage(message string) []byte {
if len(message) == 0 {
return []byte{}
}
bz, err := hex.DecodeString(message)
if err != nil {
panic(err)
}
return bz
}
3 changes: 1 addition & 2 deletions x/crosschain/types/msg_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"

fxtypes "github.com/functionx/fx-core/v7/types"
)
Expand Down Expand Up @@ -215,7 +214,7 @@ func (b MsgValidate) MsgBridgeCallClaimValidate(m *MsgBridgeCallClaim) (err erro
return errortypes.ErrInvalidRequest.Wrap("invalid value")
}
if len(m.Message) > 0 {
if _, err := hexutil.Decode(m.Message); err != nil {
if _, err := hex.DecodeString(m.Message); err != nil {
return errortypes.ErrInvalidRequest.Wrap("invalid message")
}
}
Expand Down
3 changes: 1 addition & 2 deletions x/tron/types/msg_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common/hexutil"
tronaddress "github.com/fbsobreira/gotron-sdk/pkg/address"

crosschaintypes "github.com/functionx/fx-core/v7/x/crosschain/types"
Expand Down Expand Up @@ -170,7 +169,7 @@ func (b TronMsgValidate) MsgBridgeCallClaimValidate(m *crosschaintypes.MsgBridge
return errortypes.ErrInvalidRequest.Wrap("invalid value")
}
if len(m.Message) > 0 {
if _, err := hexutil.Decode(m.Message); err != nil {
if _, err := hex.DecodeString(m.Message); err != nil {
return errortypes.ErrInvalidRequest.Wrap("invalid message")
}
}
Expand Down

0 comments on commit f49467a

Please sign in to comment.