Skip to content

Commit

Permalink
fix(evm-precompile): use bank.MsgServer Send in precompile IFunToken.…
Browse files Browse the repository at this point in the history
…bankMsgSend
  • Loading branch information
Unique-Divine committed Jan 10, 2025
1 parent f7a7007 commit 710f160
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions x/evm/precompile/funtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
gethabi "github.com/ethereum/go-ethereum/accounts/abi"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -701,9 +703,6 @@ func (p precompileFunToken) bankMsgSend(
if err != nil {
return nil, ErrInvalidArgs(err)
}
if amount.Sign() != 1 {
return nil, fmt.Errorf("msgSend amount must be positive")
}

// parse toStr (bech32 or hex)
toEthAddr, e := parseToAddr(toStr)
Expand All @@ -715,8 +714,16 @@ func (p precompileFunToken) bankMsgSend(

// do the bank send
coin := sdk.NewCoins(sdk.NewCoin(denom, math.NewIntFromBigInt(amount)))
if err := p.evmKeeper.Bank.SendCoins(
ctx, fromBech32, toBech32, coin,
bankMsg := &bank.MsgSend{
FromAddress: fromBech32.String(),
ToAddress: toBech32.String(),
Amount: coin,
}
if err := bankMsg.ValidateBasic(); err != nil {
return nil, err
}
if _, err := bankkeeper.NewMsgServerImpl(p.evmKeeper.Bank).Send(
sdk.WrapSDKContext(ctx), bankMsg,
); err != nil {
return nil, fmt.Errorf("bankMsgSend: %w", err)
}
Expand Down

0 comments on commit 710f160

Please sign in to comment.