Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add func convert token to coin ibc #6584

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/hashicorp/go-metrics"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -181,10 +180,11 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
}

// parse the transfer amount
transferAmount, ok := sdkmath.NewIntFromString(token.Amount)
if !ok {
return errorsmod.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount: %s", token.Amount)
coin, err := token.ConvertToCoin()
if err != nil {
return err
}
transferAmount := coin.Amount

// This is the prefix that would have been prefixed to the denomination
// on sender chain IF and only if the token originally came from the
Expand All @@ -199,8 +199,6 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
// remove prefix added by sender chain
token.Denom.Trace = token.Denom.Trace[1:]

coin := sdk.NewCoin(token.Denom.IBCDenom(), transferAmount)
Copy link
Contributor

@DimitrisJim DimitrisJim Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, we modify the trace here so the hashed denom ends up different (ditto if not Source), we would need to swap out the coins Denomination to have this working 😞 we should do manual conversion here and ooth use ToCoin in forwarding.go (which I think should be possible)

Can take care of fixing these!


if k.bankKeeper.BlockedAddr(receiver) {
return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver)
}
Expand Down Expand Up @@ -290,13 +288,11 @@ func (k Keeper) refundPacketTokens(ctx sdk.Context, packet channeltypes.Packet,
// NOTE: packet data type already checked in handler.go

for _, token := range data.Tokens {
transferAmount, ok := sdkmath.NewIntFromString(token.Amount)
if !ok {
return errorsmod.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", transferAmount)
coin, err := token.ConvertToCoin()
if err != nil {
return err
}

coin := sdk.NewCoin(token.Denom.IBCDenom(), transferAmount)

sender, err := sdk.AccAddressFromBech32(data.Sender)
if err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions modules/apps/transfer/types/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Tokens is a slice of Tokens
Expand All @@ -25,3 +26,13 @@ func (t Token) Validate() error {

return nil
}

func (t Token) ConvertToCoin() (sdk.Coin, error) {
transferAmount, ok := sdkmath.NewIntFromString(t.Amount)
if !ok {
return sdk.Coin{}, errorsmod.Wrapf(ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", transferAmount)
}

coin := sdk.NewCoin(t.Denom.IBCDenom(), transferAmount)
return coin, nil
}