-
Notifications
You must be signed in to change notification settings - Fork 673
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
MsgTransfer For Eureka #7957
MsgTransfer For Eureka #7957
Changes from 5 commits
ac136ca
83d35d6
e1f325a
635a2a2
556dded
3e12678
3e64c07
6750736
b7138c5
80947c0
fea0633
80a7547
2a10a5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"github.com/cosmos/ibc-go/v9/modules/apps/transfer/internal/telemetry" | ||
"github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" | ||
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" | ||
channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" | ||
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" | ||
) | ||
|
||
|
@@ -29,14 +30,19 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. | |
return nil, err | ||
} | ||
|
||
channel, found := k.channelKeeper.GetChannel(ctx, msg.SourcePort, msg.SourceChannel) | ||
if !found { | ||
return nil, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", msg.SourcePort, msg.SourceChannel) | ||
} | ||
|
||
appVersion, found := k.ics4Wrapper.GetAppVersion(ctx, msg.SourcePort, msg.SourceChannel) | ||
if !found { | ||
return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "application version not found for source port: %s and source channel: %s", msg.SourcePort, msg.SourceChannel) | ||
// if a eurela counterparty exists with source channel, then use IBC V2 protocol | ||
// otherwise use IBC V1 protocol | ||
var ( | ||
channel channeltypes.Channel | ||
isIBCV2 bool | ||
) | ||
_, isIBCV2 = k.clientKeeperV2.GetClientCounterparty(ctx, msg.SourceChannel) | ||
if !isIBCV2 { | ||
var found bool | ||
channel, found = k.channelKeeper.GetChannel(ctx, msg.SourcePort, msg.SourceChannel) | ||
if !found { | ||
return nil, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", msg.SourcePort, msg.SourceChannel) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i could choose to not have clientKeeperV2 in transfer keeper and just send the channelID from the msg directly to chanKeeperV2 and have it error if counterparty doesn't exist. But then we get a counterparty not found error over the channel not found error |
||
} | ||
} | ||
|
||
coin := msg.Token | ||
|
@@ -54,27 +60,62 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. | |
return nil, err | ||
} | ||
|
||
if err := k.SendTransfer(ctx, msg.SourcePort, msg.SourceChannel, token, sender); err != nil { | ||
return nil, err | ||
} | ||
packetData := types.NewFungibleTokenPacketData(token.Denom.Path(), token.Amount, sender.String(), msg.Receiver, msg.Memo) | ||
|
||
packetDataBytes, err := createPacketDataBytesFromVersion( | ||
appVersion, sender.String(), msg.Receiver, msg.Memo, token, | ||
) | ||
if err != nil { | ||
return nil, err | ||
if err := packetData.ValidateBasic(); err != nil { | ||
return nil, errorsmod.Wrapf(err, "failed to validate %s packet data", types.V1) | ||
} | ||
|
||
sequence, err := k.ics4Wrapper.SendPacket(ctx, msg.SourcePort, msg.SourceChannel, msg.TimeoutHeight, msg.TimeoutTimestamp, packetDataBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var sequence uint64 | ||
if isIBCV2 { | ||
encoding := msg.Encoding | ||
if encoding == "" { | ||
encoding = types.EncodingJSON | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default to JSON since that is expected ics20-v1 behaviour |
||
} | ||
|
||
data, err := types.MarshalPacketData(packetData, types.V1, encoding) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
payload := channeltypesv2.NewPayload( | ||
types.PortID, types.PortID, | ||
types.V1, encoding, data, | ||
) | ||
msg := channeltypesv2.NewMsgSendPacket( | ||
msg.SourceChannel, msg.TimeoutTimestamp, | ||
sender.String(), payload, | ||
) | ||
|
||
res, err := k.channelKeeperV2.SendPacket(ctx, msg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SendPacket will call transfer module's |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sequence = res.Sequence | ||
} else { | ||
|
||
events.EmitTransferEvent(ctx, sender.String(), msg.Receiver, token, msg.Memo) | ||
AdityaSripal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err := k.SendTransfer(ctx, msg.SourcePort, msg.SourceChannel, token, sender); err != nil { | ||
return nil, err | ||
} | ||
|
||
packetDataBytes, err := createPacketDataBytesFromVersion( | ||
types.V1, sender.String(), msg.Receiver, msg.Memo, token, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
destinationPort := channel.Counterparty.PortId | ||
destinationChannel := channel.Counterparty.ChannelId | ||
telemetry.ReportTransfer(msg.SourcePort, msg.SourceChannel, destinationPort, destinationChannel, token) | ||
sequence, err = k.ics4Wrapper.SendPacket(ctx, msg.SourcePort, msg.SourceChannel, msg.TimeoutHeight, msg.TimeoutTimestamp, packetDataBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
events.EmitTransferEvent(ctx, sender.String(), msg.Receiver, token, msg.Memo) | ||
destinationPort := channel.Counterparty.PortId | ||
destinationChannel := channel.Counterparty.ChannelId | ||
telemetry.ReportTransfer(msg.SourcePort, msg.SourceChannel, destinationPort, destinationChannel, token) | ||
} | ||
|
||
k.Logger(ctx).Info("IBC fungible token transfer", "token", coin, "sender", msg.Sender, "receiver", msg.Receiver) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could remove this if desired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have less stuff to put in here, but what would that mean for the code?