-
Notifications
You must be signed in to change notification settings - Fork 662
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 4 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 |
---|---|---|
|
@@ -10,7 +10,9 @@ import ( | |
"github.com/cosmos/ibc-go/v9/modules/apps/transfer/internal/events" | ||
"github.com/cosmos/ibc-go/v9/modules/apps/transfer/internal/telemetry" | ||
"github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" | ||
clienttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/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 +31,22 @@ 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 | ||
counterparty clienttypesv2.CounterpartyInfo | ||
isIBCV2 bool | ||
destinationPort string | ||
destinationChannel string | ||
) | ||
counterparty, 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) | ||
} | ||
} | ||
|
||
coin := msg.Token | ||
|
@@ -54,26 +64,56 @@ 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 { | ||
data, err := types.MarshalPacketData(packetData, types.V1, msg.Encoding) | ||
if err != nil { | ||
return nil, err | ||
} | ||
payload := channeltypesv2.NewPayload( | ||
types.PortID, types.PortID, | ||
types.V1, msg.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 | ||
destinationPort = types.PortID | ||
destinationChannel = counterparty.ClientId | ||
} else { | ||
|
||
if err := k.SendTransfer(ctx, msg.SourcePort, msg.SourceChannel, token, sender); err != nil { | ||
return nil, err | ||
} | ||
|
||
events.EmitTransferEvent(ctx, sender.String(), msg.Receiver, token, msg.Memo) | ||
AdityaSripal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
packetDataBytes, err := createPacketDataBytesFromVersion( | ||
types.V1, sender.String(), msg.Receiver, msg.Memo, token, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
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 | ||
} | ||
|
||
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) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ import ( | |
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
|
||
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" | ||
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" | ||
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" | ||
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" | ||
channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" | ||
) | ||
|
||
// AccountKeeper defines the contract required for account APIs. | ||
|
@@ -41,9 +42,14 @@ type ChannelKeeper interface { | |
HasChannel(ctx context.Context, portID, channelID string) bool | ||
} | ||
|
||
// ChannelKeeperV2 defines the expected IBC channelV2 keeper | ||
type ChannelKeeperV2 interface { | ||
SendPacket(ctx context.Context, msg *channeltypesv2.MsgSendPacket) (*channeltypesv2.MsgSendPacketResponse, error) | ||
} | ||
|
||
// ClientKeeper defines the expected IBC client keeper | ||
type ClientKeeper interface { | ||
GetClientConsensusState(ctx sdk.Context, clientID string) (connection ibcexported.ConsensusState, found bool) | ||
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. nonsensical method not used |
||
type ClientKeeperV2 interface { | ||
GetClientCounterparty(ctx sdk.Context, clientID string) (counterparty clienttypes.CounterpartyInfo, found bool) | ||
} | ||
|
||
// ConnectionKeeper defines the expected IBC connection keeper | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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?