diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 5aaf1fd55f4..881a5e4bc07 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -699,6 +699,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 nanoseconds) relative to the current block timestamp. The timeout is disabled when set to 0. | +| `metadata` | [bytes](#bytes) | | optional metadata | @@ -760,6 +761,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 f4ebcf04b4d..fe4df203c6a 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,6 @@ require ( google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 - gopkg.in/yaml.v2 v2.4.0 // indirect ) require ( @@ -119,6 +118,7 @@ require ( golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/ini.v1 v1.66.6 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect ) diff --git a/modules/apps/transfer/client/cli/tx.go b/modules/apps/transfer/client/cli/tx.go index 74ff6ae802b..85c012da865 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 { @@ -113,6 +119,8 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), msg := types.NewMsgTransfer( srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp, ) + msg.Metadata = []byte(metadataStr) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } @@ -120,6 +128,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. 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/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 84c4c6d59ce..77c83a2f3e5 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -20,7 +20,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 f884413aa96..e09d326aa84 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -55,6 +55,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0, // only use timeout height ) + msg.Metadata = []byte("custom metadata") tc.malleate() diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 3716d7cccb3..96527af63dc 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -69,6 +69,7 @@ func (k Keeper) SendTransfer( receiver, timeoutHeight, timeoutTimestamp, + nil, ) return err } @@ -83,6 +84,7 @@ func (k Keeper) sendTransfer( receiver string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, + metadata []byte, ) (uint64, error) { if !k.GetSendEnabled(ctx) { return 0, types.ErrSendDisabled @@ -175,6 +177,7 @@ func (k Keeper) sendTransfer( packetData := types.NewFungibleTokenPacketData( fullDenomPath, token.Amount.String(), sender.String(), receiver, ) + packetData.Metadata = metadata packet := channeltypes.NewPacket( packetData.GetBytes(), diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 5a2806b1e8b..1bac750a713 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -34,13 +34,15 @@ func (suite *KeeperTestSuite) TestSendTransfer() { suite.coordinator.CreateTransferChannels(path) amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) }, true, true}, - {"successful transfer with coin from counterparty chain", + { + "successful transfer with coin from counterparty chain", 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)) }, false, true}, - {"source channel not found", + { + "source channel not found", func() { // channel references wrong ID suite.coordinator.CreateTransferChannels(path) @@ -59,16 +61,14 @@ func (suite *KeeperTestSuite) TestSendTransfer() { ) suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) - }, true, false, - }, + }, true, false}, { "transfer failed - sender account is blocked", func() { suite.coordinator.CreateTransferChannels(path) amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) sender = suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(types.ModuleName) - }, true, false, - }, + }, true, false}, // createOutgoingPacket tests // - source chain {"send coin failed", @@ -149,6 +149,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { trace types.DenomTrace amount sdk.Int receiver string + metadata []byte ) testCases := []struct { @@ -158,7 +159,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() @@ -199,6 +206,7 @@ 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) @@ -226,12 +234,14 @@ 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.Metadata = 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.Metadata = 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) diff --git a/modules/apps/transfer/module.go b/modules/apps/transfer/module.go index 68123135f9a..4cf8bb65db4 100644 --- a/modules/apps/transfer/module.go +++ b/modules/apps/transfer/module.go @@ -2,6 +2,7 @@ package transfer import ( "context" + "encoding/hex" "encoding/json" "fmt" "math" @@ -354,6 +355,7 @@ func (am AppModule) 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())), ), ) @@ -390,6 +392,7 @@ func (am AppModule) 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()), ), ) @@ -436,6 +439,7 @@ func (am AppModule) 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/spec/04_messages.md b/modules/apps/transfer/spec/04_messages.md index 611e2423da7..b3808054353 100644 --- a/modules/apps/transfer/spec/04_messages.md +++ b/modules/apps/transfer/spec/04_messages.md @@ -17,6 +17,7 @@ type MsgTransfer struct { Receiver string TimeoutHeight ibcexported.Height TimeoutTimestamp uint64 + Metadata []byte } ``` diff --git a/modules/apps/transfer/spec/05_events.md b/modules/apps/transfer/spec/05_events.md index 51b49da4602..46343198bc6 100644 --- a/modules/apps/transfer/spec/05_events.md +++ b/modules/apps/transfer/spec/05_events.md @@ -22,6 +22,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 @@ -32,6 +33,8 @@ 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} | ## OnTimeoutPacket callback @@ -42,3 +45,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/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 12cc8ab1574..169ffe9ca36 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -15,6 +15,7 @@ const ( ) // NewMsgTransfer creates a new MsgTransfer instance +// //nolint:interfacer func NewMsgTransfer( sourcePort, sourceChannel string, diff --git a/modules/apps/transfer/types/packet.pb.go b/modules/apps/transfer/types/packet.pb.go index f3b3f59825e..8ff01154f9c 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,22 +115,24 @@ func init() { } var fileDescriptor_653ca2ce9a5ca313 = []byte{ - // 240 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x8f, 0xbf, 0x4a, 0xc5, 0x30, - 0x14, 0x87, 0x1b, 0xff, 0x5c, 0x34, 0x63, 0x11, 0x2d, 0x22, 0x41, 0x9c, 0x74, 0x30, 0x81, 0xeb, - 0xe0, 0x2e, 0xe2, 0xac, 0xe2, 0xe4, 0x96, 0xa4, 0xc7, 0x1a, 0x6e, 0x93, 0x13, 0x92, 0xb4, 0x20, - 0xbe, 0x84, 0x8f, 0xe5, 0x78, 0x47, 0x47, 0x69, 0x5f, 0x44, 0x9a, 0xaa, 0xdc, 0xf1, 0xfb, 0xce, - 0xef, 0x0c, 0x1f, 0xbd, 0x30, 0x4a, 0x0b, 0xe9, 0x7d, 0x6b, 0xb4, 0x4c, 0x06, 0x5d, 0x14, 0x29, - 0x48, 0x17, 0x5f, 0x20, 0x88, 0x7e, 0x29, 0xbc, 0xd4, 0x2b, 0x48, 0xdc, 0x07, 0x4c, 0x58, 0x9e, - 0x18, 0xa5, 0xf9, 0xe6, 0x94, 0xff, 0x4d, 0x79, 0xbf, 0x3c, 0x7b, 0xa7, 0x47, 0x77, 0x9d, 0x6b, - 0x8c, 0x6a, 0xe1, 0x09, 0x57, 0xe0, 0xee, 0xf3, 0xeb, 0xad, 0x4c, 0xb2, 0x3c, 0xa0, 0xbb, 0x35, - 0x38, 0xb4, 0x15, 0x39, 0x25, 0xe7, 0xfb, 0x8f, 0x33, 0x94, 0x87, 0x74, 0x21, 0x2d, 0x76, 0x2e, - 0x55, 0x5b, 0x59, 0xff, 0xd2, 0xe4, 0x23, 0xb8, 0x1a, 0x42, 0xb5, 0x3d, 0xfb, 0x99, 0xca, 0x63, - 0xba, 0x17, 0x40, 0x83, 0xe9, 0x21, 0x54, 0x3b, 0xf9, 0xf2, 0xcf, 0x37, 0x0f, 0x9f, 0x03, 0x23, - 0xeb, 0x81, 0x91, 0xef, 0x81, 0x91, 0x8f, 0x91, 0x15, 0xeb, 0x91, 0x15, 0x5f, 0x23, 0x2b, 0x9e, - 0xaf, 0x1b, 0x93, 0x5e, 0x3b, 0xc5, 0x35, 0x5a, 0xa1, 0x31, 0x5a, 0x8c, 0xc2, 0x28, 0x7d, 0xd9, - 0xe0, 0x94, 0x67, 0xb1, 0xee, 0x5a, 0x88, 0x53, 0xff, 0x46, 0x77, 0x7a, 0xf3, 0x10, 0xd5, 0x22, - 0x47, 0x5f, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0x9d, 0x75, 0xf2, 0x46, 0x21, 0x01, 0x00, 0x00, + // 258 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0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, 0x57, 0x5b, 0xbe, 0x7b, 0xfa, 0x6a, + 0x39, 0xdb, 0xb4, 0x9c, 0xfd, 0xb4, 0x9c, 0x7d, 0x74, 0x7c, 0xb2, 0xe9, 0xf8, 0xe4, 0xbb, 0xe3, + 0x93, 0x97, 0xdb, 0xd2, 0xd0, 0x5b, 0xad, 0x72, 0x8d, 0x56, 0x68, 0x8c, 0x16, 0xa3, 0x30, 0x4a, + 0x5f, 0x97, 0xd8, 0xff, 0x6e, 0xb1, 0xa8, 0x2b, 0x88, 0xbd, 0x9c, 0x1d, 0x29, 0xf4, 0xee, 0x21, + 0xaa, 0xd9, 0x60, 0xe4, 0xe6, 0x37, 0x00, 0x00, 0xff, 0xff, 0x5d, 0x3d, 0x15, 0x2a, 0x3e, 0x01, + 0x00, 0x00, } func (m *FungibleTokenPacketData) Marshal() (dAtA []byte, err error) { @@ -144,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) @@ -208,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 } @@ -374,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/tx.pb.go b/modules/apps/transfer/types/tx.pb.go index ba9f0397b36..b2cacf0fab6 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 nanoseconds) relative to the current block timestamp. // 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{} } @@ -141,39 +143,40 @@ func init() { } var fileDescriptor_7401ed9bed2f8e09 = []byte{ - // 508 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0x6e, 0xd3, 0x4c, - 0x10, 0xc7, 0xed, 0x2f, 0x69, 0xbe, 0xb0, 0x51, 0x2b, 0x30, 0x50, 0xb9, 0x51, 0xb1, 0x23, 0x4b, - 0x48, 0xe1, 0xc0, 0xae, 0x1c, 0x84, 0x2a, 0xf5, 0x84, 0xd2, 0x0b, 0x1c, 0x2a, 0x81, 0xd5, 0x13, - 0x97, 0x62, 0x6f, 0x07, 0x67, 0x45, 0xbc, 0x63, 0xbc, 0x1b, 0x8b, 0xbe, 0x01, 0x47, 0x1e, 0xa1, - 0x67, 0x9e, 0xa4, 0xc7, 0x1e, 0x39, 0x45, 0x28, 0xb9, 0x70, 0xce, 0x13, 0xa0, 0xb5, 0x9d, 0x90, - 0x5c, 0x10, 0xa7, 0xec, 0xcc, 0xfc, 0x26, 0x7f, 0xff, 0x77, 0x66, 0xc9, 0x53, 0x91, 0x70, 0x16, - 0xe7, 0xf9, 0x54, 0xf0, 0x58, 0x0b, 0x94, 0x8a, 0xe9, 0x22, 0x96, 0xea, 0x23, 0x14, 0xac, 0x0c, - 0x99, 0xfe, 0x42, 0xf3, 0x02, 0x35, 0x3a, 0xc7, 0x22, 0xe1, 0x74, 0x1b, 0xa3, 0x6b, 0x8c, 0x96, - 0x61, 0xff, 0x51, 0x8a, 0x29, 0x56, 0x20, 0x33, 0xa7, 0xba, 0xa7, 0xef, 0x71, 0x54, 0x19, 0x2a, - 0x96, 0xc4, 0x0a, 0x58, 0x19, 0x26, 0xa0, 0xe3, 0x90, 0x71, 0x14, 0xb2, 0xa9, 0xfb, 0x46, 0x9a, - 0x63, 0x01, 0x8c, 0x4f, 0x05, 0x48, 0x6d, 0x04, 0xeb, 0x53, 0x0d, 0x04, 0xdf, 0x5b, 0xa4, 0x77, - 0xae, 0xd2, 0x8b, 0x46, 0xc9, 0x39, 0x21, 0x3d, 0x85, 0xb3, 0x82, 0xc3, 0x65, 0x8e, 0x85, 0x76, - 0xed, 0x81, 0x3d, 0xbc, 0x37, 0x3e, 0x5c, 0xcd, 0x7d, 0xe7, 0x3a, 0xce, 0xa6, 0xa7, 0xc1, 0x56, - 0x31, 0x88, 0x48, 0x1d, 0xbd, 0xc5, 0x42, 0x3b, 0xaf, 0xc8, 0x41, 0x53, 0xe3, 0x93, 0x58, 0x4a, - 0x98, 0xba, 0xff, 0x55, 0xbd, 0x47, 0xab, 0xb9, 0xff, 0x78, 0xa7, 0xb7, 0xa9, 0x07, 0xd1, 0x7e, - 0x9d, 0x38, 0xab, 0x63, 0xe7, 0x25, 0xd9, 0xd3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 0x9f, 0xd1, 0xf5, - 0xc7, 0x8c, 0xdf, 0xdd, 0x2e, 0x3c, 0xfb, 0x6e, 0xe1, 0xd9, 0x3f, 0x17, 0x9e, 0xfd, 0x6d, 0xe9, - 0x59, 0x77, 0x4b, 0xcf, 0xfa, 0xb1, 0xf4, 0xac, 0xf7, 0x27, 0xa9, 0xd0, 0x93, 0x59, 0x42, 0x39, - 0x66, 0xac, 0x59, 0x5b, 0x91, 0xf0, 0xe7, 0x29, 0xb2, 0x72, 0xc4, 0x32, 0xbc, 0x9a, 0x4d, 0x41, - 0x99, 0x67, 0xb2, 0xf5, 0x3c, 0xf4, 0x75, 0x0e, 0x2a, 0xe9, 0x54, 0xab, 0xfa, 0xe2, 0x77, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x75, 0xd4, 0x23, 0x61, 0x48, 0x03, 0x00, 0x00, + // 520 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, 0xa1, 0x15, 0x18, 0xa8, 0xdc, 0xa8, 0xd8, 0x91, 0x25, 0xa4, + 0x30, 0x70, 0x27, 0x07, 0xa1, 0x4a, 0x9d, 0x50, 0xba, 0xc0, 0x50, 0x09, 0xac, 0x4e, 0x2c, 0xe5, + 0x7c, 0x79, 0x38, 0x27, 0xe2, 0x3b, 0xe3, 0xbb, 0x58, 0xf4, 0x1b, 0x30, 0xf2, 0x11, 0xfa, 0x69, + 0x50, 0xc7, 0x8e, 0x4c, 0x11, 0x4a, 0x16, 0xe6, 0x7c, 0x02, 0x74, 0xb6, 0x13, 0x9c, 0x05, 0x31, + 0xe5, 0xfe, 0xef, 0xfd, 0x5e, 0xfe, 0x7e, 0xf7, 0xde, 0xa1, 0x67, 0x3c, 0x66, 0x84, 0x66, 0xd9, + 0x8c, 0x33, 0xaa, 0xb9,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ca, + 0xb3, 0x7e, 0xae, 0x3c, 0xeb, 0xc3, 0x49, 0xc2, 0xf5, 0x74, 0x1e, 0x63, 0x26, 0x53, 0x52, 0xaf, + 0x34, 0x8f, 0xd9, 0x8b, 0x44, 0x92, 0x62, 0x44, 0x52, 0x39, 0x99, 0xcf, 0x40, 0x99, 0x27, 0xd4, + 0x78, 0x3a, 0xfa, 0x2a, 0x03, 0x15, 0x77, 0xca, 0x35, 0x7e, 0xf9, 0x27, 0x00, 0x00, 0xff, 0xff, + 0x7f, 0x1a, 0xac, 0x9b, 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/transfer/v1/tx.proto b/proto/ibc/applications/transfer/v1/tx.proto index d571d276a6c..d7396fa4bd5 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 nanoseconds) relative to the current block timestamp. // 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 593392a9005..953f67128a2 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; }