Skip to content

Commit

Permalink
refactor: rename target coins to coins
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored and github-actions[bot] committed Mar 5, 2024
1 parent 96ae7cf commit ebdfacb
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions x/crosschain/keeper/bridge_call_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func (k Keeper) bridgeCallERC20Handler(
if err != nil {
return errorsmod.Wrap(types.ErrInvalid, "asset erc20")
}
targetCoins, err := k.bridgeCallTransferToSender(ctx, sender, tokens, amounts)
coins, err := k.bridgeCallTransferToSender(ctx, sender, tokens, amounts)
if err != nil {
return err
}

switch dstChainID {
case types.FxcoreChainID:
if err = k.bridgeCallTransferToReceiver(ctx, sender, receiver, targetCoins); err != nil {
if err = k.bridgeCallTransferToReceiver(ctx, sender, receiver, coins); err != nil {
return err
}
var toAddrPtr *common.Address
Expand All @@ -52,22 +52,6 @@ func (k Keeper) bridgeCallERC20Handler(
return nil
}

func (k Keeper) bridgeCallTransferToReceiver(ctx sdk.Context, sender sdk.AccAddress, receiver []byte, targetCoins sdk.Coins) error {
for _, coin := range targetCoins {
if coin.Denom == fxtypes.DefaultDenom {
continue
}
if _, err := k.erc20Keeper.ConvertCoin(sdk.WrapSDKContext(ctx), &erc20types.MsgConvertCoin{
Coin: coin,
Receiver: common.BytesToAddress(receiver).String(),
Sender: sender.String(),
}); err != nil {
return err
}
}
return nil
}

func (k Keeper) bridgeCallTransferToSender(ctx sdk.Context, receiver sdk.AccAddress, tokens [][]byte, amounts []*big.Int) (sdk.Coins, error) {
tokens, amounts = types.MergeDuplicationERC20(tokens, amounts)

Expand Down Expand Up @@ -111,13 +95,23 @@ func (k Keeper) bridgeCallTransferToSender(ctx sdk.Context, receiver sdk.AccAddr
return targetCoins, nil
}

func (k Keeper) bridgeCallEvmHandler(
ctx sdk.Context,
sender common.Address,
to *common.Address,
message string, value sdkmath.Int,
gasLimit, eventNonce uint64,
) {
func (k Keeper) bridgeCallTransferToReceiver(ctx sdk.Context, sender sdk.AccAddress, receiver []byte, coins sdk.Coins) error {
for _, coin := range coins {
if coin.Denom == fxtypes.DefaultDenom {
continue
}
if _, err := k.erc20Keeper.ConvertCoin(sdk.WrapSDKContext(ctx), &erc20types.MsgConvertCoin{
Coin: coin,
Receiver: common.BytesToAddress(receiver).String(),
Sender: sender.String(),
}); err != nil {
return err
}
}
return nil
}

func (k Keeper) bridgeCallEvmHandler(ctx sdk.Context, sender common.Address, to *common.Address, message string, value sdkmath.Int, gasLimit, eventNonce uint64) {
callErr, callResult := "", false
defer func() {
attrs := []sdk.Attribute{sdk.NewAttribute(types.AttributeKeyEvmCallResult, strconv.FormatBool(callResult))}
Expand Down

0 comments on commit ebdfacb

Please sign in to comment.