diff --git a/docs/apps/transfer/events.md b/docs/apps/transfer/events.md index a538d07d068..2bf2fde16f7 100644 --- a/docs/apps/transfer/events.md +++ b/docs/apps/transfer/events.md @@ -23,6 +23,7 @@ order: 5 | fungible_token_packet | denom | {denom} | | fungible_token_packet | amount | {amount} | | fungible_token_packet | success | {ackSuccess} | +| fungible_token_packet | metadata | {metadata} | | denomination_trace | trace_hash | {hex_hash} | ## `OnAcknowledgePacket` callback @@ -34,6 +35,7 @@ order: 5 | fungible_token_packet | receiver | {receiver} | | fungible_token_packet | denom | {denom} | | fungible_token_packet | amount | {amount} | +| fungible_token_packet | metadata | {metadata} | | fungible_token_packet | acknowledgement | {ack.String()} | | fungible_token_packet | success | error | {ack.Response} | @@ -45,3 +47,4 @@ order: 5 | fungible_token_packet | refund_receiver | {receiver} | | fungible_token_packet | denom | {denom} | | fungible_token_packet | amount | {amount} | +| fungible_token_packet | metadata | {metadata} | diff --git a/docs/apps/transfer/messages.md b/docs/apps/transfer/messages.md index 7cb61402e04..8ed89ab8e07 100644 --- a/docs/apps/transfer/messages.md +++ b/docs/apps/transfer/messages.md @@ -17,6 +17,7 @@ type MsgTransfer struct { Receiver string TimeoutHeight ibcexported.Height TimeoutTimestamp uint64 + Metadata []byte } ``` diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 10602b62d66..b7d8471b7f4 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -2248,6 +2248,7 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf | `receiver` | [string](#string) | | the recipient address on the destination chain | | `timeout_height` | [ibc.core.client.v1.Height](#ibc.core.client.v1.Height) | | Timeout height relative to the current block height. The timeout is disabled when set to 0. | | `timeout_timestamp` | [uint64](#uint64) | | Timeout timestamp in absolute nanoseconds since unix epoch. The timeout is disabled when set to 0. | +| `metadata` | [bytes](#bytes) | | optional metadata | @@ -2262,7 +2263,7 @@ MsgTransferResponse defines the Msg/Transfer response type. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `sequence` | [uint64](#uint64) | | sequence number of the packet on the channel. | +| `sequence` | [uint64](#uint64) | | sequence number of the transfer packet sent | @@ -2309,6 +2310,7 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf | `amount` | [string](#string) | | the token amount to be transferred | | `sender` | [string](#string) | | the sender address | | `receiver` | [string](#string) | | the recipient address on the destination chain | +| `metadata` | [bytes](#bytes) | | optional metadata | diff --git a/go.mod b/go.mod index c93789b378b..ecb85848809 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/btcsuite/btcd v0.22.1 // indirect - github.com/cenkalti/backoff/v4 v4.1.3 // indirect + github.com/cenkalti/backoff/v4 v4.1.1 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect diff --git a/go.sum b/go.sum index 62728763fde..f7cd80631bc 100644 --- a/go.sum +++ b/go.sum @@ -180,9 +180,8 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= +github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= -github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= -github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= diff --git a/modules/apps/29-fee/transfer_test.go b/modules/apps/29-fee/transfer_test.go index 96c7582e3dc..30770f17078 100644 --- a/modules/apps/29-fee/transfer_test.go +++ b/modules/apps/29-fee/transfer_test.go @@ -30,7 +30,7 @@ func (suite *FeeTestSuite) TestFeeTransfer() { msgs := []sdk.Msg{ types.NewMsgPayPacketFee(fee, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, suite.chainA.SenderAccount.GetAddress().String(), nil), - transfertypes.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 100), 0), + transfertypes.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 100), 0, nil), } res, err := suite.chainA.SendMsgs(msgs...) suite.Require().NoError(err) // message committed diff --git a/modules/apps/transfer/client/cli/tx.go b/modules/apps/transfer/client/cli/tx.go index 0eafbf2da46..cec2de88e19 100644 --- a/modules/apps/transfer/client/cli/tx.go +++ b/modules/apps/transfer/client/cli/tx.go @@ -22,6 +22,7 @@ const ( flagPacketTimeoutHeight = "packet-timeout-height" flagPacketTimeoutTimestamp = "packet-timeout-timestamp" flagAbsoluteTimeouts = "absolute-timeouts" + flagMetadata = "metadata" ) // NewTransferTxCmd returns the command to create a NewMsgTransfer transaction @@ -76,6 +77,11 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), return err } + metadataStr, err := cmd.Flags().GetString(flagMetadata) + if err != nil { + return err + } + // if the timeouts are not absolute, retrieve latest block height and block timestamp // for the consensus state connected to the destination port/channel if !absoluteTimeouts { @@ -111,7 +117,7 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), } msg := types.NewMsgTransfer( - srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp, + srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp, []byte(metadataStr), ) return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, @@ -120,6 +126,7 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), cmd.Flags().String(flagPacketTimeoutHeight, types.DefaultRelativePacketTimeoutHeight, "Packet timeout block height. The timeout is disabled when set to 0-0.") cmd.Flags().Uint64(flagPacketTimeoutTimestamp, types.DefaultRelativePacketTimeoutTimestamp, "Packet timeout timestamp in nanoseconds from now. Default is 10 minutes. The timeout is disabled when set to 0.") cmd.Flags().Bool(flagAbsoluteTimeouts, false, "Timeout flags are used as absolute timeouts.") + cmd.Flags().String(flagMetadata, "", "Metadata to be sent along with the packet. The CLI accepts only strings here but you can construct a packet with arbitrary bytes via code.") flags.AddTxFlagsToCmd(cmd) return cmd diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index 5825b89b5bb..9eb794d88ab 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -1,6 +1,7 @@ package transfer import ( + "encoding/hex" "fmt" "math" "strings" @@ -194,6 +195,7 @@ func (im IBCModule) OnRecvPacket( sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), sdk.NewAttribute(types.AttributeKeyDenom, data.Denom), sdk.NewAttribute(types.AttributeKeyAmount, data.Amount), + sdk.NewAttribute(types.AttributeKeyMetadata, hex.EncodeToString(data.Metadata)), sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())), } @@ -240,6 +242,7 @@ func (im IBCModule) OnAcknowledgementPacket( sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), sdk.NewAttribute(types.AttributeKeyDenom, data.Denom), sdk.NewAttribute(types.AttributeKeyAmount, data.Amount), + sdk.NewAttribute(types.AttributeKeyMetadata, hex.EncodeToString(data.Metadata)), sdk.NewAttribute(types.AttributeKeyAck, ack.String()), ), ) @@ -286,6 +289,7 @@ func (im IBCModule) OnTimeoutPacket( sdk.NewAttribute(types.AttributeKeyRefundReceiver, data.Sender), sdk.NewAttribute(types.AttributeKeyRefundDenom, data.Denom), sdk.NewAttribute(types.AttributeKeyRefundAmount, data.Amount), + sdk.NewAttribute(types.AttributeKeyMetadata, hex.EncodeToString(data.Metadata)), ), ) diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 59103b36c4a..07d15cef561 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -146,7 +146,8 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack DenomFromTla(packet.Data.Denom), packet.Data.Amount, AddressFromString(packet.Data.Sender), - AddressFromString(packet.Data.Receiver)), + AddressFromString(packet.Data.Receiver), + nil), } } @@ -346,7 +347,8 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { sender, tc.packet.Data.Receiver, clienttypes.NewHeight(0, 110), - 0) + 0, + nil) } case "OnRecvPacket": err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, tc.packet.Data) diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 622ce2a404b..f9c83b8c10b 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -21,7 +21,7 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. sequence, err := k.sendTransfer( ctx, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, - ) + msg.Metadata) if err != nil { return nil, err } diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index fee7ba71b5d..4cbd63506a6 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -54,6 +54,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { path.EndpointA.ChannelID, coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, // only use timeout height + []byte("custom metadata"), ) tc.malleate() diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index a1a3a3aae97..5ff3d64ef4a 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -59,6 +59,7 @@ func (k Keeper) SendTransfer( receiver string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, + metadata []byte, ) error { _, err := k.sendTransfer( ctx, @@ -69,6 +70,7 @@ func (k Keeper) SendTransfer( receiver, timeoutHeight, timeoutTimestamp, + metadata, ) return err } @@ -83,6 +85,7 @@ func (k Keeper) sendTransfer( receiver string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, + metadata []byte, ) (uint64, error) { if !k.GetSendEnabled(ctx) { return 0, types.ErrSendDisabled @@ -163,7 +166,7 @@ func (k Keeper) sendTransfer( } packetData := types.NewFungibleTokenPacketData( - fullDenomPath, token.Amount.String(), sender.String(), receiver, + fullDenomPath, token.Amount.String(), sender.String(), receiver, metadata, ) sequence, err := k.ics4Wrapper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData.GetBytes()) diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index a18064a8ed5..af91612be39 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -18,10 +18,11 @@ import ( // chainA and coin that orignate on chainB func (suite *KeeperTestSuite) TestSendTransfer() { var ( - amount sdk.Coin - path *ibctesting.Path - sender sdk.AccAddress - err error + amount sdk.Coin + path *ibctesting.Path + sender sdk.AccAddress + err error + metadata []byte ) testCases := []struct { @@ -37,6 +38,14 @@ func (suite *KeeperTestSuite) TestSendTransfer() { amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) }, true, true, }, + { + "successful transfer from source chain with metadata", + func() { + suite.coordinator.CreateTransferChannels(path) + amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) + metadata = []byte("metadata") + }, true, true, + }, { "successful transfer with coin from counterparty chain", func() { @@ -45,6 +54,15 @@ func (suite *KeeperTestSuite) TestSendTransfer() { amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.DefaultBondDenom, sdk.NewInt(100)) }, false, true, }, + { + "successful transfer with coin from counterparty chain with metadata", + func() { + // send coin from chainA back to chainB + suite.coordinator.CreateTransferChannels(path) + amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.DefaultBondDenom, sdk.NewInt(100)) + metadata = []byte("metadata") + }, false, true, + }, { "source channel not found", func() { @@ -100,18 +118,19 @@ func (suite *KeeperTestSuite) TestSendTransfer() { path = NewTransferPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) sender = suite.chainA.SenderAccount.GetAddress() + metadata = []byte{} tc.malleate() if !tc.sendFromSource { // send coin from chainB to chainA coinFromBToA := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) - transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 110), 0) + transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 110), 0, nil) _, err = suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed // receive coin on chainA from chainB - fungibleTokenPacket := types.NewFungibleTokenPacketData(coinFromBToA.Denom, coinFromBToA.Amount.String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String()) + fungibleTokenPacket := types.NewFungibleTokenPacketData(coinFromBToA.Denom, coinFromBToA.Amount.String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), nil) packet := channeltypes.NewPacket(fungibleTokenPacket.GetBytes(), 1, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, clienttypes.NewHeight(0, 110), 0) // get proof of packet commitment from chainB @@ -128,6 +147,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount, sender, suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, + metadata, ) if tc.expPass { @@ -148,6 +168,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { trace types.DenomTrace amount math.Int receiver string + metadata []byte ) testCases := []struct { @@ -157,7 +178,13 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { expPass bool }{ {"success receive on source chain", func() {}, true, true}, + {"success receive on source chain with metadata", func() { + metadata = []byte("metadata") + }, true, true}, {"success receive with coin from another chain as source", func() {}, false, true}, + {"success receive with coin from another chain as source with metadata", func() { + metadata = []byte("metadata") + }, false, true}, {"empty coin", func() { trace = types.DenomTrace{} amount = sdk.ZeroInt() @@ -198,13 +225,14 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.coordinator.Setup(path) receiver = suite.chainB.SenderAccount.GetAddress().String() // must be explicitly changed in malleate + metadata = []byte{} // can be explicitly changed in malleate amount = sdk.NewInt(100) // must be explicitly changed in malleate seq := uint64(1) if tc.recvIsSource { // send coin from chainB to chainA, receive them, acknowledge them, and send back to chainB coinFromBToA := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) - transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 110), 0) + transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 110), 0, metadata) res, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -223,13 +251,13 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } // send coin from chainA to chainB - transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoin(trace.IBCDenom(), amount), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(0, 110), 0) + transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoin(trace.IBCDenom(), amount), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(0, 110), 0, metadata) _, err := suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed tc.malleate() - data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), receiver) + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), receiver, metadata) packet := channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(0, 100), 0) err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -302,7 +330,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { tc.malleate() - data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), nil) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(0, 100), 0) preCoin := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), trace.IBCDenom()) @@ -398,7 +426,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { tc.malleate() - data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), sender, suite.chainB.SenderAccount.GetAddress().String()) + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), sender, suite.chainB.SenderAccount.GetAddress().String(), nil) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(0, 100), 0) preCoin := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), trace.IBCDenom()) diff --git a/modules/apps/transfer/transfer_test.go b/modules/apps/transfer/transfer_test.go index 1b44ba0bc1a..ae13b3f79da 100644 --- a/modules/apps/transfer/transfer_test.go +++ b/modules/apps/transfer/transfer_test.go @@ -54,7 +54,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, amount) // send from chainA to chainB - msg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coinToSendToB, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0) + msg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coinToSendToB, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0, nil) res, err := suite.chainA.SendMsgs(msg) suite.Require().NoError(err) // message committed @@ -80,7 +80,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { suite.coordinator.Setup(pathBtoC) // send from chainB to chainC - msg = types.NewMsgTransfer(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, coinSentFromAToB, suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String(), timeoutHeight, 0) + msg = types.NewMsgTransfer(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, coinSentFromAToB, suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String(), timeoutHeight, 0, nil) res, err = suite.chainB.SendMsgs(msg) suite.Require().NoError(err) // message committed @@ -104,7 +104,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { suite.Require().Zero(balance.Amount.Int64()) // send from chainC back to chainB - msg = types.NewMsgTransfer(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, coinSentFromBToC, suite.chainC.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0) + msg = types.NewMsgTransfer(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, coinSentFromBToC, suite.chainC.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0, nil) res, err = suite.chainC.SendMsgs(msg) suite.Require().NoError(err) // message committed diff --git a/modules/apps/transfer/types/events.go b/modules/apps/transfer/types/events.go index a3ed5b413c7..5cc87f11797 100644 --- a/modules/apps/transfer/types/events.go +++ b/modules/apps/transfer/types/events.go @@ -18,4 +18,5 @@ const ( AttributeKeyAck = "acknowledgement" AttributeKeyAckError = "error" AttributeKeyTraceHash = "trace_hash" + AttributeKeyMetadata = "metadata" ) diff --git a/modules/apps/transfer/types/msgs.go b/modules/apps/transfer/types/msgs.go index f076ba979e7..4daa7a8c81a 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -22,6 +22,7 @@ func NewMsgTransfer( sourcePort, sourceChannel string, token sdk.Coin, sender, receiver string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, + metadata []byte, ) *MsgTransfer { return &MsgTransfer{ SourcePort: sourcePort, @@ -31,6 +32,7 @@ func NewMsgTransfer( Receiver: receiver, TimeoutHeight: timeoutHeight, TimeoutTimestamp: timeoutTimestamp, + Metadata: metadata, } } diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index cf690f35c17..ceff3576835 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -41,20 +41,20 @@ var ( // TestMsgTransferRoute tests Route for MsgTransfer func TestMsgTransferRoute(t *testing.T) { - msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0) + msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil) require.Equal(t, RouterKey, msg.Route()) } // TestMsgTransferType tests Type for MsgTransfer func TestMsgTransferType(t *testing.T) { - msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0) + msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil) require.Equal(t, "transfer", msg.Type()) } func TestMsgTransferGetSignBytes(t *testing.T) { - msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0) + msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil) expected := fmt.Sprintf(`{"type":"cosmos-sdk/MsgTransfer","value":{"receiver":"%s","sender":"%s","source_channel":"testchannel","source_port":"testportid","timeout_height":{"revision_height":"10"},"token":{"amount":"100","denom":"atom"}}}`, addr2, addr1) require.NotPanics(t, func() { res := msg.GetSignBytes() @@ -69,20 +69,20 @@ func TestMsgTransferValidation(t *testing.T) { msg *MsgTransfer expPass bool }{ - {"valid msg with base denom", NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), true}, - {"valid msg with trace hash", NewMsgTransfer(validPort, validChannel, ibcCoin, addr1, addr2, timeoutHeight, 0), true}, - {"invalid ibc denom", NewMsgTransfer(validPort, validChannel, invalidIBCCoin, addr1, addr2, timeoutHeight, 0), false}, - {"too short port id", NewMsgTransfer(invalidShortPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), false}, - {"too long port id", NewMsgTransfer(invalidLongPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), false}, - {"port id contains non-alpha", NewMsgTransfer(invalidPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), false}, - {"too short channel id", NewMsgTransfer(validPort, invalidShortChannel, coin, addr1, addr2, timeoutHeight, 0), false}, - {"too long channel id", NewMsgTransfer(validPort, invalidLongChannel, coin, addr1, addr2, timeoutHeight, 0), false}, - {"channel id contains non-alpha", NewMsgTransfer(validPort, invalidChannel, coin, addr1, addr2, timeoutHeight, 0), false}, - {"invalid denom", NewMsgTransfer(validPort, validChannel, invalidDenomCoin, addr1, addr2, timeoutHeight, 0), false}, - {"zero coin", NewMsgTransfer(validPort, validChannel, zeroCoin, addr1, addr2, timeoutHeight, 0), false}, - {"missing sender address", NewMsgTransfer(validPort, validChannel, coin, emptyAddr, addr2, timeoutHeight, 0), false}, - {"missing recipient address", NewMsgTransfer(validPort, validChannel, coin, addr1, "", timeoutHeight, 0), false}, - {"empty coin", NewMsgTransfer(validPort, validChannel, sdk.Coin{}, addr1, addr2, timeoutHeight, 0), false}, + {"valid msg with base denom", NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), true}, + {"valid msg with trace hash", NewMsgTransfer(validPort, validChannel, ibcCoin, addr1, addr2, timeoutHeight, 0, nil), true}, + {"invalid ibc denom", NewMsgTransfer(validPort, validChannel, invalidIBCCoin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"too short port id", NewMsgTransfer(invalidShortPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"too long port id", NewMsgTransfer(invalidLongPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"port id contains non-alpha", NewMsgTransfer(invalidPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"too short channel id", NewMsgTransfer(validPort, invalidShortChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"too long channel id", NewMsgTransfer(validPort, invalidLongChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"channel id contains non-alpha", NewMsgTransfer(validPort, invalidChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"invalid denom", NewMsgTransfer(validPort, validChannel, invalidDenomCoin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"zero coin", NewMsgTransfer(validPort, validChannel, zeroCoin, addr1, addr2, timeoutHeight, 0, nil), false}, + {"missing sender address", NewMsgTransfer(validPort, validChannel, coin, emptyAddr, addr2, timeoutHeight, 0, nil), false}, + {"missing recipient address", NewMsgTransfer(validPort, validChannel, coin, addr1, "", timeoutHeight, 0, nil), false}, + {"empty coin", NewMsgTransfer(validPort, validChannel, sdk.Coin{}, addr1, addr2, timeoutHeight, 0, nil), false}, } for i, tc := range testCases { @@ -99,7 +99,7 @@ func TestMsgTransferValidation(t *testing.T) { func TestMsgTransferGetSigners(t *testing.T) { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - msg := NewMsgTransfer(validPort, validChannel, coin, addr.String(), addr2, timeoutHeight, 0) + msg := NewMsgTransfer(validPort, validChannel, coin, addr.String(), addr2, timeoutHeight, 0, nil) res := msg.GetSigners() require.Equal(t, []sdk.AccAddress{addr}, res) diff --git a/modules/apps/transfer/types/packet.go b/modules/apps/transfer/types/packet.go index 6203cdbfa05..77b4accaa0e 100644 --- a/modules/apps/transfer/types/packet.go +++ b/modules/apps/transfer/types/packet.go @@ -25,12 +25,14 @@ var ( func NewFungibleTokenPacketData( denom string, amount string, sender, receiver string, + metadata []byte, ) FungibleTokenPacketData { return FungibleTokenPacketData{ Denom: denom, Amount: amount, Sender: sender, Receiver: receiver, + Metadata: metadata, } } diff --git a/modules/apps/transfer/types/packet.pb.go b/modules/apps/transfer/types/packet.pb.go index 688f51cbab2..b7f9d84fb4d 100644 --- a/modules/apps/transfer/types/packet.pb.go +++ b/modules/apps/transfer/types/packet.pb.go @@ -34,6 +34,8 @@ type FungibleTokenPacketData struct { Sender string `protobuf:"bytes,3,opt,name=sender,proto3" json:"sender,omitempty"` // the recipient address on the destination chain Receiver string `protobuf:"bytes,4,opt,name=receiver,proto3" json:"receiver,omitempty"` + // optional metadata + Metadata []byte `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"` } func (m *FungibleTokenPacketData) Reset() { *m = FungibleTokenPacketData{} } @@ -97,6 +99,13 @@ func (m *FungibleTokenPacketData) GetReceiver() string { return "" } +func (m *FungibleTokenPacketData) GetMetadata() []byte { + if m != nil { + return m.Metadata + } + return nil +} + func init() { proto.RegisterType((*FungibleTokenPacketData)(nil), "ibc.applications.transfer.v2.FungibleTokenPacketData") } @@ -106,23 +115,24 @@ func init() { } var fileDescriptor_653ca2ce9a5ca313 = []byte{ - // 242 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x8f, 0xbd, 0x4a, 0x04, 0x31, - 0x14, 0x46, 0x27, 0xfe, 0x2c, 0x9a, 0x72, 0x10, 0x1d, 0x44, 0x82, 0x58, 0x69, 0x61, 0x02, 0x2b, - 0x68, 0x2f, 0x62, 0xad, 0x62, 0x65, 0x97, 0x64, 0xae, 0x63, 0xd8, 0x49, 0x6e, 0x48, 0x32, 0x03, - 0xe2, 0x4b, 0xf8, 0x58, 0x96, 0x5b, 0x5a, 0xca, 0xcc, 0x8b, 0xc8, 0x66, 0x74, 0xd9, 0xf2, 0x9c, - 0xfb, 0xdd, 0xe2, 0xd0, 0x0b, 0xa3, 0xb4, 0x90, 0xde, 0xb7, 0x46, 0xcb, 0x64, 0xd0, 0x45, 0x91, - 0x82, 0x74, 0xf1, 0x15, 0x82, 0xe8, 0xe7, 0xc2, 0x4b, 0xbd, 0x80, 0xc4, 0x7d, 0xc0, 0x84, 0xe5, - 0x89, 0x51, 0x9a, 0x6f, 0x4e, 0xf9, 0xff, 0x94, 0xf7, 0xf3, 0xb3, 0x0f, 0x7a, 0x74, 0xdf, 0xb9, - 0xc6, 0xa8, 0x16, 0x9e, 0x71, 0x01, 0xee, 0x21, 0xbf, 0xde, 0xc9, 0x24, 0xcb, 0x03, 0xba, 0x5b, - 0x83, 0x43, 0x5b, 0x91, 0x53, 0x72, 0xbe, 0xff, 0x34, 0x41, 0x79, 0x48, 0x67, 0xd2, 0x62, 0xe7, - 0x52, 0xb5, 0x95, 0xf5, 0x1f, 0xad, 0x7c, 0x04, 0x57, 0x43, 0xa8, 0xb6, 0x27, 0x3f, 0x51, 0x79, - 0x4c, 0xf7, 0x02, 0x68, 0x30, 0x3d, 0x84, 0x6a, 0x27, 0x5f, 0xd6, 0x7c, 0xfb, 0xf8, 0x35, 0x30, - 0xb2, 0x1c, 0x18, 0xf9, 0x19, 0x18, 0xf9, 0x1c, 0x59, 0xb1, 0x1c, 0x59, 0xf1, 0x3d, 0xb2, 0xe2, - 0xe5, 0xa6, 0x31, 0xe9, 0xad, 0x53, 0x5c, 0xa3, 0x15, 0x1a, 0xa3, 0xc5, 0x28, 0x8c, 0xd2, 0x97, - 0x0d, 0x8a, 0xfe, 0x5a, 0x58, 0xac, 0xbb, 0x16, 0xe2, 0xaa, 0x7f, 0xa3, 0x3b, 0xbd, 0x7b, 0x88, - 0x6a, 0x96, 0xa3, 0xaf, 0x7e, 0x03, 0x00, 0x00, 0xff, 0xff, 0x22, 0x23, 0xa1, 0x28, 0x21, 0x01, - 0x00, 0x00, + // 259 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x4a, 0xc4, 0x40, + 0x10, 0x86, 0xb3, 0xea, 0x1d, 0x1a, 0xac, 0x82, 0x68, 0x10, 0x59, 0x0e, 0xab, 0xb3, 0x30, 0x0b, + 0x27, 0x68, 0x2f, 0x62, 0xad, 0x87, 0x95, 0xdd, 0xee, 0x66, 0x8c, 0xcb, 0x65, 0x77, 0xc2, 0xee, + 0x24, 0xe0, 0x5b, 0xd8, 0xf9, 0x4a, 0x96, 0x57, 0x5a, 0x4a, 0xf2, 0x22, 0x92, 0xc4, 0x3b, 0xae, + 0xfc, 0xbe, 0xf9, 0xa7, 0xf9, 0xe2, 0x2b, 0xa3, 0xb4, 0x90, 0x55, 0x55, 0x1a, 0x2d, 0xc9, 0xa0, + 0x0b, 0x82, 0xbc, 0x74, 0xe1, 0x0d, 0xbc, 0x68, 0x16, 0xa2, 0x92, 0x7a, 0x05, 0x94, 0x55, 0x1e, + 0x09, 0x93, 0x0b, 0xa3, 0x74, 0xb6, 0x3b, 0xcd, 0x36, 0xd3, 0xac, 0x59, 0x5c, 0x7e, 0xb1, 0xf8, + 0xec, 0xb1, 0x76, 0x85, 0x51, 0x25, 0xbc, 0xe0, 0x0a, 0xdc, 0xd3, 0xf0, 0xfb, 0x20, 0x49, 0x26, + 0x27, 0xf1, 0x24, 0x07, 0x87, 0x36, 0x65, 0x33, 0x36, 0x3f, 0x5a, 0x8e, 0x90, 0x9c, 0xc6, 0x53, + 0x69, 0xb1, 0x76, 0x94, 0xee, 0x0d, 0xfa, 0x9f, 0x7a, 0x1f, 0xc0, 0xe5, 0xe0, 0xd3, 0xfd, 0xd1, + 0x8f, 0x94, 0x9c, 0xc7, 0x87, 0x1e, 0x34, 0x98, 0x06, 0x7c, 0x7a, 0x30, 0x5c, 0xb6, 0xdc, 0xdf, + 0x2c, 0x90, 0xcc, 0x25, 0xc9, 0x74, 0x32, 0x63, 0xf3, 0xe3, 0xe5, 0x96, 0xef, 0x9f, 0xbf, 0x5b, + 0xce, 0xd6, 0x2d, 0x67, 0xbf, 0x2d, 0x67, 0x9f, 0x1d, 0x8f, 0xd6, 0x1d, 0x8f, 0x7e, 0x3a, 0x1e, + 0xbd, 0xde, 0x15, 0x86, 0xde, 0x6b, 0x95, 0x69, 0xb4, 0x42, 0x63, 0xb0, 0x18, 0x84, 0x51, 0xfa, + 0xba, 0x40, 0xd1, 0xdc, 0x0a, 0x8b, 0x79, 0x5d, 0x42, 0xe8, 0xe3, 0xec, 0x44, 0xa1, 0x8f, 0x0a, + 0x82, 0x9a, 0x0e, 0x45, 0x6e, 0xfe, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe2, 0x6b, 0x46, 0x44, 0x3e, + 0x01, 0x00, 0x00, } func (m *FungibleTokenPacketData) Marshal() (dAtA []byte, err error) { @@ -145,6 +155,13 @@ func (m *FungibleTokenPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l + if len(m.Metadata) > 0 { + i -= len(m.Metadata) + copy(dAtA[i:], m.Metadata) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Metadata))) + i-- + dAtA[i] = 0x2a + } if len(m.Receiver) > 0 { i -= len(m.Receiver) copy(dAtA[i:], m.Receiver) @@ -209,6 +226,10 @@ func (m *FungibleTokenPacketData) Size() (n int) { if l > 0 { n += 1 + l + sovPacket(uint64(l)) } + l = len(m.Metadata) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } return n } @@ -375,6 +396,40 @@ func (m *FungibleTokenPacketData) Unmarshal(dAtA []byte) error { } m.Receiver = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Metadata = append(m.Metadata[:0], dAtA[iNdEx:postIndex]...) + if m.Metadata == nil { + m.Metadata = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPacket(dAtA[iNdEx:]) diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index e5d21d648d2..a2f8cfc6e00 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -20,15 +20,16 @@ func TestFungibleTokenPacketDataValidateBasic(t *testing.T) { packetData FungibleTokenPacketData expPass bool }{ - {"valid packet", NewFungibleTokenPacketData(denom, amount, addr1, addr2), true}, - {"valid packet with large amount", NewFungibleTokenPacketData(denom, largeAmount, addr1, addr2), true}, - {"invalid denom", NewFungibleTokenPacketData("", amount, addr1, addr2), false}, - {"invalid empty amount", NewFungibleTokenPacketData(denom, "", addr1, addr2), false}, - {"invalid zero amount", NewFungibleTokenPacketData(denom, "0", addr1, addr2), false}, - {"invalid negative amount", NewFungibleTokenPacketData(denom, "-1", addr1, addr2), false}, - {"invalid large amount", NewFungibleTokenPacketData(denom, invalidLargeAmount, addr1, addr2), false}, - {"missing sender address", NewFungibleTokenPacketData(denom, amount, emptyAddr, addr2), false}, - {"missing recipient address", NewFungibleTokenPacketData(denom, amount, addr1, emptyAddr), false}, + {"valid packet", NewFungibleTokenPacketData(denom, amount, addr1, addr2, nil), true}, + {"valid packet with metadata", NewFungibleTokenPacketData(denom, amount, addr1, addr2, []byte("metadata")), true}, + {"valid packet with large amount", NewFungibleTokenPacketData(denom, largeAmount, addr1, addr2, nil), true}, + {"invalid denom", NewFungibleTokenPacketData("", amount, addr1, addr2, nil), false}, + {"invalid empty amount", NewFungibleTokenPacketData(denom, "", addr1, addr2, nil), false}, + {"invalid zero amount", NewFungibleTokenPacketData(denom, "0", addr1, addr2, nil), false}, + {"invalid negative amount", NewFungibleTokenPacketData(denom, "-1", addr1, addr2, nil), false}, + {"invalid large amount", NewFungibleTokenPacketData(denom, invalidLargeAmount, addr1, addr2, nil), false}, + {"missing sender address", NewFungibleTokenPacketData(denom, amount, emptyAddr, addr2, nil), false}, + {"missing recipient address", NewFungibleTokenPacketData(denom, amount, addr1, emptyAddr, nil), false}, } for i, tc := range testCases { diff --git a/modules/apps/transfer/types/tx.pb.go b/modules/apps/transfer/types/tx.pb.go index 4a9cf75545e..0cb52f069ed 100644 --- a/modules/apps/transfer/types/tx.pb.go +++ b/modules/apps/transfer/types/tx.pb.go @@ -50,6 +50,8 @@ type MsgTransfer struct { // Timeout timestamp in absolute nanoseconds since unix epoch. // The timeout is disabled when set to 0. TimeoutTimestamp uint64 `protobuf:"varint,7,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty" yaml:"timeout_timestamp"` + // optional metadata + Metadata []byte `protobuf:"bytes,8,opt,name=metadata,proto3" json:"metadata,omitempty"` } func (m *MsgTransfer) Reset() { *m = MsgTransfer{} } @@ -87,7 +89,7 @@ var xxx_messageInfo_MsgTransfer proto.InternalMessageInfo // MsgTransferResponse defines the Msg/Transfer response type. type MsgTransferResponse struct { - // sequence number of the packet on the channel. + // sequence number of the transfer packet sent Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` } @@ -141,39 +143,40 @@ func init() { } var fileDescriptor_7401ed9bed2f8e09 = []byte{ - // 506 bytes of a gzipped FileDescriptorProto + // 521 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x6d, 0x92, 0x86, 0x70, 0x51, 0x2b, 0x30, 0x50, 0xb9, 0x51, 0xb1, 0x23, 0x4b, 0x48, - 0x61, 0xe0, 0x4e, 0x2e, 0x82, 0x4a, 0x9d, 0x50, 0xba, 0xc0, 0x50, 0x09, 0xac, 0x4e, 0x2c, 0xc5, - 0xbe, 0x3e, 0x9c, 0x13, 0xf1, 0x3d, 0xe3, 0xbb, 0x58, 0xf4, 0x1b, 0x30, 0xf2, 0x11, 0x3a, 0xf3, - 0x49, 0x3a, 0x76, 0x64, 0x8a, 0x50, 0xb2, 0x30, 0xe7, 0x13, 0xa0, 0xb3, 0x9d, 0x90, 0x2c, 0x88, - 0x29, 0xf7, 0xde, 0xfb, 0xbd, 0xfc, 0xfd, 0xbf, 0xf7, 0x8e, 0x3c, 0x15, 0x09, 0x67, 0x71, 0x9e, - 0x4f, 0x04, 0x8f, 0xb5, 0x40, 0xa9, 0x98, 0x2e, 0x62, 0xa9, 0x3e, 0x41, 0xc1, 0xca, 0x90, 0xe9, - 0xaf, 0x34, 0x2f, 0x50, 0xa3, 0x73, 0x28, 0x12, 0x4e, 0x37, 0x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, 0x7d, 0x95, 0x83, 0x4a, 0x3a, 0xd5, 0xaa, 0xbe, 0xf8, 0x13, 0x00, 0x00, - 0xff, 0xff, 0xca, 0x82, 0x70, 0x0f, 0x48, 0x03, 0x00, 0x00, + 0x14, 0xc7, 0x6d, 0x92, 0x86, 0x70, 0xa1, 0x15, 0x18, 0xa8, 0xdc, 0xa8, 0xd8, 0x91, 0x25, 0xa4, + 0x30, 0x70, 0x27, 0x17, 0x41, 0xa5, 0x4e, 0x28, 0x5d, 0x60, 0xa8, 0x04, 0x56, 0x27, 0x96, 0x72, + 0xbe, 0x3c, 0x9c, 0x13, 0xf1, 0x9d, 0xf1, 0x5d, 0x2c, 0xfa, 0x0d, 0x18, 0xf9, 0x08, 0xfd, 0x34, + 0xa8, 0x63, 0x47, 0xa6, 0x08, 0x25, 0x0b, 0x73, 0x3e, 0x01, 0x3a, 0xdb, 0x09, 0xce, 0x82, 0x3a, + 0xe5, 0xfe, 0xef, 0xfd, 0x5e, 0xfe, 0x7e, 0xf7, 0xde, 0xa1, 0x67, 0x3c, 0x66, 0x84, 0x66, 0xd9, + 0x94, 0x33, 0xaa, 0xb9, 0x14, 0x8a, 0xe8, 0x9c, 0x0a, 0xf5, 0x19, 0x72, 0x52, 0x84, 0x44, 0x7f, + 0xc3, 0x59, 0x2e, 0xb5, 0x74, 0x0e, 0x79, 0xcc, 0x70, 0x13, 0xc3, 0x6b, 0x0c, 0x17, 0x61, 0xff, + 0x71, 0x22, 0x13, 0x59, 0x82, 0xc4, 0x9c, 0xaa, 0x9a, 0xbe, 0xc7, 0xa4, 0x4a, 0xa5, 0x22, 0x31, + 0x55, 0x40, 0x8a, 0x30, 0x06, 0x4d, 0x43, 0xc2, 0x24, 0x17, 0x75, 0xde, 0x37, 0xd6, 0x4c, 0xe6, + 0x40, 0xd8, 0x94, 0x83, 0xd0, 0xc6, 0xb0, 0x3a, 0x55, 0x40, 0xf0, 0xb3, 0x85, 0x7a, 0x67, 0x2a, + 0x39, 0xaf, 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x0e, 0x57, 0x73, 0xdf, 0xdd, 0xfe, 0x93, 0x0d, + 0x12, 0x44, 0x0f, 0xea, 0xd8, 0xf9, 0x3a, 0x64, 0x1a, 0x49, 0x41, 0xd3, 0x31, 0xd5, 0xd4, 0xed, + 0x0e, 0xec, 0xe1, 0xfd, 0x68, 0xa3, 0x4f, 0xba, 0xdf, 0xaf, 0x7c, 0xeb, 0xcf, 0x95, 0x6f, 0x05, + 0x21, 0x7a, 0xd4, 0x98, 0x63, 0x04, 0x2a, 0x93, 0x42, 0x81, 0x29, 0x56, 0xf0, 0x75, 0x06, 0x82, + 0x41, 0x39, 0xcc, 0x76, 0xb4, 0xd1, 0x47, 0x12, 0xb5, 0xce, 0x54, 0xe2, 0x4c, 0x50, 0x77, 0x33, + 0xfe, 0xe7, 0xf8, 0x7f, 0x4b, 0x88, 0x1b, 0x0e, 0xfd, 0xf0, 0xd6, 0xe8, 0xfa, 0x63, 0x46, 0x1f, + 0xae, 0x17, 0x9e, 0x7d, 0xb3, 0xf0, 0xec, 0xdf, 0x0b, 0xcf, 0xfe, 0xb1, 0xf4, 0xac, 0x9b, 0xa5, + 0x67, 0xfd, 0x5a, 0x7a, 0xd6, 0xc7, 0xe3, 0x84, 0xeb, 0xc9, 0x2c, 0xc6, 0x4c, 0xa6, 0xa4, 0x5e, + 0x69, 0x1e, 0xb3, 0x17, 0x89, 0x24, 0xc5, 0x6b, 0x92, 0xca, 0xf1, 0x6c, 0x0a, 0xca, 0x3c, 0xa1, + 0xc6, 0xd3, 0xd1, 0x97, 0x19, 0xa8, 0xb8, 0x53, 0xae, 0xf1, 0xcb, 0xbf, 0x01, 0x00, 0x00, 0xff, + 0xff, 0xc0, 0x4c, 0xff, 0xf5, 0x64, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -278,6 +281,13 @@ func (m *MsgTransfer) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Metadata) > 0 { + i -= len(m.Metadata) + copy(dAtA[i:], m.Metadata) + i = encodeVarintTx(dAtA, i, uint64(len(m.Metadata))) + i-- + dAtA[i] = 0x42 + } if m.TimeoutTimestamp != 0 { i = encodeVarintTx(dAtA, i, uint64(m.TimeoutTimestamp)) i-- @@ -402,6 +412,10 @@ func (m *MsgTransfer) Size() (n int) { if m.TimeoutTimestamp != 0 { n += 1 + sovTx(uint64(m.TimeoutTimestamp)) } + l = len(m.Metadata) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -665,6 +679,40 @@ func (m *MsgTransfer) Unmarshal(dAtA []byte) error { break } } + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Metadata = append(m.Metadata[:0], dAtA[iNdEx:postIndex]...) + if m.Metadata == nil { + m.Metadata = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto index e35795f832e..31de5e7e82d 100644 --- a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto @@ -38,7 +38,7 @@ message MsgSendTx { string owner = 1; string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""]; ibc.applications.interchain_accounts.v1.InterchainAccountPacketData packet_data = 3 - [(gogoproto.moretags) = "yaml:\"packet_data\"", (gogoproto.nullable) = false]; + [(gogoproto.moretags) = "yaml:\"packet_data\"", (gogoproto.nullable) = false]; // Relative timeout timestamp provided will be added to the current block time during transaction execution. // The timeout timestamp must be non-zero. uint64 relative_timeout = 4 [(gogoproto.moretags) = "yaml:\"relative_timeout\""]; diff --git a/proto/ibc/applications/transfer/v1/tx.proto b/proto/ibc/applications/transfer/v1/tx.proto index d0bd3e98246..43c6ec9a6ce 100644 --- a/proto/ibc/applications/transfer/v1/tx.proto +++ b/proto/ibc/applications/transfer/v1/tx.proto @@ -38,6 +38,8 @@ message MsgTransfer { // Timeout timestamp in absolute nanoseconds since unix epoch. // The timeout is disabled when set to 0. uint64 timeout_timestamp = 7 [(gogoproto.moretags) = "yaml:\"timeout_timestamp\""]; + // optional metadata + bytes metadata = 8; } // MsgTransferResponse defines the Msg/Transfer response type. diff --git a/proto/ibc/applications/transfer/v2/packet.proto b/proto/ibc/applications/transfer/v2/packet.proto index 684afcfe3de..0844a557300 100644 --- a/proto/ibc/applications/transfer/v2/packet.proto +++ b/proto/ibc/applications/transfer/v2/packet.proto @@ -16,4 +16,6 @@ message FungibleTokenPacketData { string sender = 3; // the recipient address on the destination chain string receiver = 4; + // optional metadata + bytes metadata = 5; }