From b44a78404fb3e49f8e937b49a5faa9ced4b89c1f Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 26 Oct 2022 15:19:26 +0200 Subject: [PATCH] refactor: adapting transfer metadata bytes field to memo string (#2595) * adapting transfer metadata bytes field to memo string * updating changelog (cherry picked from commit 05685b3f1bb4241ec04c4768dbb7152273f83a96) # Conflicts: # CHANGELOG.md # go.mod # go.sum # modules/apps/29-fee/transfer_test.go # modules/apps/transfer/client/cli/tx.go # modules/apps/transfer/keeper/mbt_relay_test.go # modules/apps/transfer/keeper/msg_server_test.go # modules/apps/transfer/keeper/relay.go # modules/apps/transfer/keeper/relay_test.go # modules/apps/transfer/transfer_test.go # modules/apps/transfer/types/msgs.go # modules/apps/transfer/types/msgs_test.go # modules/apps/transfer/types/packet.go # modules/apps/transfer/types/packet.pb.go # modules/apps/transfer/types/packet_test.go # modules/apps/transfer/types/tx.pb.go --- CHANGELOG.md | 6 ++ docs/ibc/proto-docs.md | 4 +- go.mod | 4 + go.sum | 5 ++ modules/apps/29-fee/transfer_test.go | 4 + modules/apps/transfer/client/cli/tx.go | 10 ++- modules/apps/transfer/ibc_module.go | 7 +- .../apps/transfer/keeper/mbt_relay_test.go | 14 +++ modules/apps/transfer/keeper/msg_server.go | 2 +- .../apps/transfer/keeper/msg_server_test.go | 11 +++ modules/apps/transfer/keeper/relay.go | 6 +- modules/apps/transfer/keeper/relay_test.go | 87 +++++++++++++++++-- modules/apps/transfer/transfer_test.go | 12 +++ modules/apps/transfer/types/events.go | 2 +- modules/apps/transfer/types/msgs.go | 8 ++ modules/apps/transfer/types/msgs_test.go | 29 +++++++ modules/apps/transfer/types/packet.go | 8 ++ modules/apps/transfer/types/packet.pb.go | 56 ++++++++---- modules/apps/transfer/types/packet_test.go | 13 +++ modules/apps/transfer/types/tx.pb.go | 67 ++++++++++---- proto/ibc/applications/transfer/v1/tx.proto | 4 +- .../ibc/applications/transfer/v2/packet.proto | 4 +- 22 files changed, 306 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73bc03f0756..1737cb8bd47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +<<<<<<< HEAD * (apps/transfer) [\#2305](https://github.com/cosmos/ibc-go/pull/2305) Added optional metadata field to `FungibleTokenPacketData` and `MsgTransfer`. +======= +* (apps/27-interchain-accounts) [\#2147](https://github.com/cosmos/ibc-go/pull/2147) Adding a `SubmitTx` gRPC endpoint for the ICS27 Controller module which allows owners of interchain accounts to submit transactions. This replaces the previously existing need for authentication modules to implement this standard functionality. +* (testing/simapp) [\#2190](https://github.com/cosmos/ibc-go/pull/2190) Adding the new `x/group` cosmos-sdk module to simapp. +* (apps/transfer) [\#2595](https://github.com/cosmos/ibc-go/pull/2595) Adding optional memo field to `FungibleTokenPacketData` and `MsgTransfer`. +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) ### Bug Fixes diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 3a4a7885361..c7f1b1e9652 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -2146,7 +2146,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 | +| `memo` | [string](#string) | | optional memo | @@ -2208,7 +2208,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 | +| `memo` | [string](#string) | | optional memo | diff --git a/go.mod b/go.mod index c26dfd0ace9..5df71b9e0d5 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,10 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/btcsuite/btcd v0.22.1 // indirect +<<<<<<< HEAD +======= + github.com/cenkalti/backoff/v4 v4.1.1 // indirect +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/coinbase/rosetta-sdk-go v0.7.0 // indirect diff --git a/go.sum b/go.sum index 910a1741860..f1b27b5bc14 100644 --- a/go.sum +++ b/go.sum @@ -130,6 +130,11 @@ github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46f 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= +<<<<<<< HEAD +======= +github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ= +github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) 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 12a7a556e66..b14be7b64f5 100644 --- a/modules/apps/29-fee/transfer_test.go +++ b/modules/apps/29-fee/transfer_test.go @@ -30,7 +30,11 @@ func (suite *FeeTestSuite) TestFeeTransfer() { msgs := []sdk.Msg{ types.NewMsgPayPacketFee(fee, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, suite.chainA.SenderAccount.GetAddress().String(), nil), +<<<<<<< HEAD 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(1, 100), 0, ""), +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } 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 1290139a48c..6046dab299b 100644 --- a/modules/apps/transfer/client/cli/tx.go +++ b/modules/apps/transfer/client/cli/tx.go @@ -22,7 +22,7 @@ const ( flagPacketTimeoutHeight = "packet-timeout-height" flagPacketTimeoutTimestamp = "packet-timeout-timestamp" flagAbsoluteTimeouts = "absolute-timeouts" - flagMetadata = "metadata" + flagMemo = "memo" ) // NewTransferTxCmd returns the command to create a NewMsgTransfer transaction @@ -77,7 +77,7 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), return err } - metadataStr, err := cmd.Flags().GetString(flagMetadata) + memo, err := cmd.Flags().GetString(flagMemo) if err != nil { return err } @@ -117,7 +117,11 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`), } msg := types.NewMsgTransfer( +<<<<<<< HEAD srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp, +======= + srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp, memo, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) ) msg.Metadata = []byte(metadataStr) @@ -128,7 +132,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.") + cmd.Flags().String(flagMemo, "", "Memo to be sent along with the packet.") flags.AddTxFlagsToCmd(cmd) return cmd diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index 8d989e8de37..6ecd7f1a6b4 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -1,7 +1,6 @@ package transfer import ( - "encoding/hex" "fmt" "math" "strings" @@ -195,7 +194,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.AttributeKeyMemo, data.Memo), sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())), } @@ -242,7 +241,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.AttributeKeyMemo, data.Memo), sdk.NewAttribute(types.AttributeKeyAck, ack.String()), ), ) @@ -289,7 +288,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)), + sdk.NewAttribute(types.AttributeKeyMemo, data.Memo), ), ) diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index 16aa831b37d..9cac653b410 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -145,7 +145,12 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack DenomFromTla(packet.Data.Denom), packet.Data.Amount, AddressFromString(packet.Data.Sender), +<<<<<<< HEAD AddressFromString(packet.Data.Receiver)), +======= + AddressFromString(packet.Data.Receiver), + ""), +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } } @@ -344,8 +349,17 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { sdk.NewCoin(denom, amount), sender, tc.packet.Data.Receiver, +<<<<<<< HEAD clienttypes.NewHeight(0, 110), 0) +======= + suite.chainA.GetTimeoutHeight(), 0, // only use timeout height + "", + ) + + _, err = suite.chainB.GetSimApp().TransferKeeper.Transfer(sdk.WrapSDKContext(suite.chainB.GetContext()), msg) + +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } 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 7b3cb71c517..279200346f9 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) + msg.Memo) 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 103a51b2790..45f6473415e 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -48,6 +48,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { path := NewTransferPath(suite.chainA, suite.chainB) suite.coordinator.Setup(path) +<<<<<<< HEAD coin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) msg = types.NewMsgTransfer( path.EndpointA.ChannelConfig.PortID, @@ -56,6 +57,16 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { suite.chainB.GetTimeoutHeight(), 0, // only use timeout height ) msg.Metadata = []byte("custom metadata") +======= + coin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) + msg = types.NewMsgTransfer( + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), + suite.chainB.GetTimeoutHeight(), 0, // only use timeout height + "memo", + ) +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) tc.malleate() diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 000a3e91f9a..f588c180fa5 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -84,7 +84,7 @@ func (k Keeper) sendTransfer( receiver string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, - metadata []byte, + memo string, ) (uint64, error) { if !k.GetSendEnabled(ctx) { return 0, types.ErrSendDisabled @@ -175,6 +175,7 @@ func (k Keeper) sendTransfer( } packetData := types.NewFungibleTokenPacketData( +<<<<<<< HEAD fullDenomPath, token.Amount.String(), sender.String(), receiver, ) packetData.Metadata = metadata @@ -188,6 +189,9 @@ func (k Keeper) sendTransfer( destinationChannel, timeoutHeight, timeoutTimestamp, +======= + fullDenomPath, token.Amount.String(), sender.String(), receiver, memo, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) ) if err := k.ics4Wrapper.SendPacket(ctx, channelCap, packet); err != nil { diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index c4b67754c38..98026ed2745 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -17,10 +17,18 @@ import ( // chainA and coin that orignate on chainB func (suite *KeeperTestSuite) TestSendTransfer() { var ( +<<<<<<< HEAD amount sdk.Coin path *ibctesting.Path sender sdk.AccAddress err error +======= + coin sdk.Coin + path *ibctesting.Path + sender sdk.AccAddress + timeoutHeight clienttypes.Height + memo string +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) ) testCases := []struct { @@ -30,19 +38,43 @@ func (suite *KeeperTestSuite) TestSendTransfer() { expPass bool }{ { +<<<<<<< HEAD "successful transfer from source chain", +======= + "successful transfer with native token", + func() {}, true, + }, + { + "successful transfer from source chain with memo", + func() { + memo = "memo" + }, true, + }, + { + "successful transfer with IBC token", + +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) func() { suite.coordinator.CreateTransferChannels(path) amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) }, true, true, }, { +<<<<<<< HEAD "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, +======= + "successful transfer with IBC token and memo", + func() { + // send IBC token back to chainB + coin = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coin.Denom, coin.Amount) + memo = "memo" + }, true, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) }, { "source channel not found", @@ -114,8 +146,18 @@ func (suite *KeeperTestSuite) TestSendTransfer() { path = NewTransferPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) sender = suite.chainA.SenderAccount.GetAddress() +<<<<<<< HEAD tc.malleate() +======= + memo = "" + timeoutHeight = suite.chainB.GetTimeoutHeight() + + // create IBC token on chainA + transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coin, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainA.GetTimeoutHeight(), 0, "") + result, err := suite.chainB.SendMsgs(transferMsg) + suite.Require().NoError(err) // message committed +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) if !tc.sendFromSource { // send coin from chainB to chainA @@ -134,10 +176,20 @@ func (suite *KeeperTestSuite) TestSendTransfer() { packetKey := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) proof, proofHeight := path.EndpointB.QueryProof(packetKey) +<<<<<<< HEAD recvMsg := channeltypes.NewMsgRecvPacket(packet, proof, proofHeight, suite.chainA.SenderAccount.GetAddress().String()) _, err = suite.chainA.SendMsgs(recvMsg) suite.Require().NoError(err) // message committed } +======= + msg := types.NewMsgTransfer( + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + coin, sender.String(), suite.chainB.SenderAccount.GetAddress().String(), + timeoutHeight, 0, // only use timeout height + memo, + ) +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount, @@ -162,7 +214,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { trace types.DenomTrace amount sdk.Int receiver string - metadata []byte + memo string ) testCases := []struct { @@ -172,12 +224,12 @@ 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") + {"success receive on source chain with memo", func() { + memo = "memo" }, 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") + {"success receive with coin from another chain as source with memo", func() { + memo = "memo" }, false, true}, {"empty coin", func() { trace = types.DenomTrace{} @@ -219,14 +271,18 @@ 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 + memo = "" // 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)) +<<<<<<< HEAD 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(1, 110), 0, memo) +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) res, err := suite.chainB.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed @@ -245,16 +301,25 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { } // send coin from chainA to chainB +<<<<<<< HEAD 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 +======= + transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoin(trace.IBCDenom(), amount), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, memo) +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) _, err := suite.chainA.SendMsgs(transferMsg) suite.Require().NoError(err) // message committed tc.malleate() +<<<<<<< HEAD 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) +======= + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), receiver, memo) + packet := channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -326,8 +391,13 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { tc.malleate() +<<<<<<< HEAD data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) 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) +======= + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "") + packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) preCoin := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), trace.IBCDenom()) @@ -422,8 +492,13 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { tc.malleate() +<<<<<<< HEAD data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), sender, suite.chainB.SenderAccount.GetAddress().String()) 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) +======= + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), sender, suite.chainB.SenderAccount.GetAddress().String(), "") + packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) 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 d1089f0ee82..d8cb1ff5348 100644 --- a/modules/apps/transfer/transfer_test.go +++ b/modules/apps/transfer/transfer_test.go @@ -54,7 +54,11 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, amount) // send from chainA to chainB +<<<<<<< HEAD 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, "") +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) res, err := suite.chainA.SendMsgs(msg) suite.Require().NoError(err) // message committed @@ -80,7 +84,11 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { suite.coordinator.Setup(pathBtoC) // send from chainB to chainC +<<<<<<< HEAD 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, "") +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) res, err = suite.chainB.SendMsgs(msg) suite.Require().NoError(err) // message committed @@ -104,7 +112,11 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { suite.Require().Zero(balance.Amount.Int64()) // send from chainC back to chainB +<<<<<<< HEAD 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, "") +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) 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 5cc87f11797..89964a8a9a4 100644 --- a/modules/apps/transfer/types/events.go +++ b/modules/apps/transfer/types/events.go @@ -18,5 +18,5 @@ const ( AttributeKeyAck = "acknowledgement" AttributeKeyAckError = "error" AttributeKeyTraceHash = "trace_hash" - AttributeKeyMetadata = "metadata" + AttributeKeyMemo = "memo" ) diff --git a/modules/apps/transfer/types/msgs.go b/modules/apps/transfer/types/msgs.go index 5df624d43d0..ef537c8eac8 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -22,6 +22,10 @@ func NewMsgTransfer( sourcePort, sourceChannel string, token sdk.Coin, sender, receiver string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, +<<<<<<< HEAD +======= + memo string, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) ) *MsgTransfer { return &MsgTransfer{ SourcePort: sourcePort, @@ -31,6 +35,10 @@ func NewMsgTransfer( Receiver: receiver, TimeoutHeight: timeoutHeight, TimeoutTimestamp: timeoutTimestamp, +<<<<<<< HEAD +======= + Memo: memo, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } } diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 929de3a4d6f..3c61f988ece 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -41,7 +41,11 @@ var ( // TestMsgTransferRoute tests Route for MsgTransfer func TestMsgTransferRoute(t *testing.T) { +<<<<<<< HEAD msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0) +======= + msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, "") +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) require.Equal(t, RouterKey, msg.Route()) } @@ -54,7 +58,11 @@ func TestMsgTransferType(t *testing.T) { } func TestMsgTransferGetSignBytes(t *testing.T) { +<<<<<<< HEAD msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0) +======= + msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, "") +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) 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,6 +77,7 @@ func TestMsgTransferValidation(t *testing.T) { msg *MsgTransfer expPass bool }{ +<<<<<<< HEAD {"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}, @@ -83,6 +92,22 @@ func TestMsgTransferValidation(t *testing.T) { {"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, ""), 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}, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } for i, tc := range testCases { @@ -99,7 +124,11 @@ func TestMsgTransferValidation(t *testing.T) { func TestMsgTransferGetSigners(t *testing.T) { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) +<<<<<<< HEAD msg := NewMsgTransfer(validPort, validChannel, coin, addr.String(), addr2, timeoutHeight, 0) +======= + msg := NewMsgTransfer(validPort, validChannel, coin, addr.String(), addr2, timeoutHeight, 0, "") +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) 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 a7384c47486..74427499550 100644 --- a/modules/apps/transfer/types/packet.go +++ b/modules/apps/transfer/types/packet.go @@ -25,12 +25,20 @@ var ( func NewFungibleTokenPacketData( denom string, amount string, sender, receiver string, +<<<<<<< HEAD +======= + memo string, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) ) FungibleTokenPacketData { return FungibleTokenPacketData{ Denom: denom, Amount: amount, Sender: sender, Receiver: receiver, +<<<<<<< HEAD +======= + Memo: memo, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } } diff --git a/modules/apps/transfer/types/packet.pb.go b/modules/apps/transfer/types/packet.pb.go index 38a721a3466..560a1b5c960 100644 --- a/modules/apps/transfer/types/packet.pb.go +++ b/modules/apps/transfer/types/packet.pb.go @@ -34,8 +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"` + // optional memo + Memo string `protobuf:"bytes,5,opt,name=memo,proto3" json:"memo,omitempty"` } func (m *FungibleTokenPacketData) Reset() { *m = FungibleTokenPacketData{} } @@ -99,11 +99,11 @@ func (m *FungibleTokenPacketData) GetReceiver() string { return "" } -func (m *FungibleTokenPacketData) GetMetadata() []byte { +func (m *FungibleTokenPacketData) GetMemo() string { if m != nil { - return m.Metadata + return m.Memo } - return nil + return "" } func init() { @@ -115,6 +115,7 @@ func init() { } var fileDescriptor_653ca2ce9a5ca313 = []byte{ +<<<<<<< HEAD // 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, @@ -133,6 +134,25 @@ var fileDescriptor_653ca2ce9a5ca313 = []byte{ 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, 0x9d, 0x43, 0xd7, 0x9e, 0x3e, 0x01, 0x00, 0x00, +======= + // 254 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x4a, 0x34, 0x31, + 0x14, 0x46, 0x27, 0xff, 0xbf, 0xbb, 0x68, 0xca, 0x20, 0x3a, 0x88, 0x04, 0xb1, 0xd2, 0xc2, 0x09, + 0xac, 0xa0, 0xbd, 0x88, 0xb5, 0x8a, 0x95, 0x5d, 0x92, 0xb9, 0x8e, 0x61, 0x27, 0xb9, 0x21, 0xc9, + 0x0c, 0xf8, 0x14, 0xfa, 0x58, 0x96, 0x5b, 0x5a, 0xca, 0xcc, 0x8b, 0xc8, 0x66, 0x54, 0xb6, 0xcb, + 0x39, 0xf9, 0x6e, 0x73, 0xe8, 0x99, 0x51, 0x5a, 0x48, 0xef, 0x5b, 0xa3, 0x65, 0x32, 0xe8, 0xa2, + 0x48, 0x41, 0xba, 0xf8, 0x0c, 0x41, 0xf4, 0x4b, 0xe1, 0xa5, 0x5e, 0x41, 0xaa, 0x7c, 0xc0, 0x84, + 0xec, 0xc8, 0x28, 0x5d, 0x6d, 0x4f, 0xab, 0xdf, 0x69, 0xd5, 0x2f, 0x4f, 0xde, 0x08, 0x3d, 0xb8, + 0xed, 0x5c, 0x63, 0x54, 0x0b, 0x8f, 0xb8, 0x02, 0x77, 0x97, 0x6f, 0x6f, 0x64, 0x92, 0x6c, 0x8f, + 0xce, 0x6b, 0x70, 0x68, 0x4b, 0x72, 0x4c, 0x4e, 0x77, 0x1f, 0x26, 0x60, 0xfb, 0x74, 0x21, 0x2d, + 0x76, 0x2e, 0x95, 0xff, 0xb2, 0xfe, 0xa1, 0x8d, 0x8f, 0xe0, 0x6a, 0x08, 0xe5, 0xff, 0xc9, 0x4f, + 0xc4, 0x0e, 0xe9, 0x4e, 0x00, 0x0d, 0xa6, 0x87, 0x50, 0xce, 0xf2, 0xcf, 0x1f, 0x33, 0x46, 0x67, + 0x16, 0x2c, 0x96, 0xf3, 0xec, 0xf3, 0xfb, 0xfa, 0xfe, 0x63, 0xe0, 0x64, 0x3d, 0x70, 0xf2, 0x35, + 0x70, 0xf2, 0x3e, 0xf2, 0x62, 0x3d, 0xf2, 0xe2, 0x73, 0xe4, 0xc5, 0xd3, 0x55, 0x63, 0xd2, 0x4b, + 0xa7, 0x2a, 0x8d, 0x56, 0x68, 0x8c, 0x16, 0xa3, 0x30, 0x4a, 0x9f, 0x37, 0x28, 0xfa, 0x4b, 0x61, + 0xb1, 0xee, 0x5a, 0x88, 0x9b, 0x28, 0x5b, 0x31, 0xd2, 0xab, 0x87, 0xa8, 0x16, 0xb9, 0xc4, 0xc5, + 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2d, 0xee, 0xa2, 0x5e, 0x36, 0x01, 0x00, 0x00, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } func (m *FungibleTokenPacketData) Marshal() (dAtA []byte, err error) { @@ -155,10 +175,10 @@ 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))) + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Memo))) i-- dAtA[i] = 0x2a } @@ -226,7 +246,7 @@ func (m *FungibleTokenPacketData) Size() (n int) { if l > 0 { n += 1 + l + sovPacket(uint64(l)) } - l = len(m.Metadata) + l = len(m.Memo) if l > 0 { n += 1 + l + sovPacket(uint64(l)) } @@ -398,9 +418,9 @@ func (m *FungibleTokenPacketData) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPacket @@ -410,25 +430,23 @@ func (m *FungibleTokenPacketData) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPacket } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen 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{} - } + m.Memo = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index e5d21d648d2..9ddfaf3c9de 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -20,6 +20,7 @@ func TestFungibleTokenPacketDataValidateBasic(t *testing.T) { packetData FungibleTokenPacketData expPass bool }{ +<<<<<<< HEAD {"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}, @@ -29,6 +30,18 @@ func TestFungibleTokenPacketDataValidateBasic(t *testing.T) { {"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, ""), true}, + {"valid packet with memo", NewFungibleTokenPacketData(denom, amount, addr1, addr2, "memo"), 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}, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } for i, tc := range testCases { diff --git a/modules/apps/transfer/types/tx.pb.go b/modules/apps/transfer/types/tx.pb.go index d7b11f8eea1..dc823b72f35 100644 --- a/modules/apps/transfer/types/tx.pb.go +++ b/modules/apps/transfer/types/tx.pb.go @@ -50,8 +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"` + // optional memo + Memo string `protobuf:"bytes,8,opt,name=memo,proto3" json:"memo,omitempty"` } func (m *MsgTransfer) Reset() { *m = MsgTransfer{} } @@ -143,6 +143,7 @@ func init() { } var fileDescriptor_7401ed9bed2f8e09 = []byte{ +<<<<<<< HEAD // 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, 0xa1, 0x15, 0x18, 0xa8, 0xdc, 0xa8, 0xd8, 0x91, 0x25, 0xa4, @@ -177,6 +178,42 @@ var fileDescriptor_7401ed9bed2f8e09 = []byte{ 0x69, 0x1e, 0xb3, 0x17, 0x89, 0x24, 0xc5, 0x2b, 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, 0xbf, 0x64, 0x6e, 0x2f, 0x64, 0x03, 0x00, 0x00, +======= + // 516 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0xb5, 0x49, 0x1a, 0xc2, 0x46, 0xad, 0x60, 0x81, 0xca, 0x8d, 0x8a, 0x1d, 0x59, 0x42, 0x0a, + 0x07, 0x76, 0xe5, 0x22, 0xa8, 0xd4, 0x13, 0x4a, 0x2f, 0x70, 0xa8, 0x04, 0x56, 0x4f, 0x5c, 0x8a, + 0xbd, 0x1d, 0x9c, 0x15, 0xb1, 0xc7, 0x78, 0x37, 0x16, 0xfd, 0x03, 0x8e, 0x7c, 0x42, 0xbf, 0x84, + 0x73, 0x8f, 0x3d, 0x72, 0x8a, 0x50, 0x72, 0xe1, 0x9c, 0x2f, 0x40, 0x6b, 0x3b, 0x21, 0xb9, 0x20, + 0x4e, 0x9e, 0x99, 0xf7, 0xc6, 0x6f, 0xdf, 0xce, 0x2c, 0x79, 0x2a, 0x63, 0xc1, 0xa3, 0x3c, 0x9f, + 0x48, 0x11, 0x69, 0x89, 0x99, 0xe2, 0xba, 0x88, 0x32, 0xf5, 0x09, 0x0a, 0x5e, 0x06, 0x5c, 0x7f, + 0x65, 0x79, 0x81, 0x1a, 0xe9, 0xa1, 0x8c, 0x05, 0xdb, 0xa4, 0xb1, 0x15, 0x8d, 0x95, 0x41, 0xff, + 0x51, 0x82, 0x09, 0x56, 0x44, 0x6e, 0xa2, 0xba, 0xa7, 0xef, 0x0a, 0x54, 0x29, 0x2a, 0x1e, 0x47, + 0x0a, 0x78, 0x19, 0xc4, 0xa0, 0xa3, 0x80, 0x0b, 0x94, 0x59, 0x83, 0x7b, 0x46, 0x5a, 0x60, 0x01, + 0x5c, 0x4c, 0x24, 0x64, 0xda, 0x08, 0xd6, 0x51, 0x4d, 0xf0, 0x7f, 0xb4, 0x48, 0xef, 0x4c, 0x25, + 0xe7, 0x8d, 0x12, 0x3d, 0x26, 0x3d, 0x85, 0xd3, 0x42, 0xc0, 0x45, 0x8e, 0x85, 0x76, 0xec, 0x81, + 0x3d, 0xbc, 0x37, 0xda, 0x5f, 0xce, 0x3c, 0x7a, 0x15, 0xa5, 0x93, 0x13, 0x7f, 0x03, 0xf4, 0x43, + 0x52, 0x67, 0xef, 0xb0, 0xd0, 0xf4, 0x35, 0xd9, 0x6b, 0x30, 0x31, 0x8e, 0xb2, 0x0c, 0x26, 0xce, + 0x9d, 0xaa, 0xf7, 0x60, 0x39, 0xf3, 0x1e, 0x6f, 0xf5, 0x36, 0xb8, 0x1f, 0xee, 0xd6, 0x85, 0xd3, + 0x3a, 0xa7, 0x2f, 0xc9, 0x8e, 0xc6, 0xcf, 0x90, 0x39, 0xad, 0x81, 0x3d, 0xec, 0x1d, 0x1d, 0xb0, + 0xda, 0x1b, 0x33, 0xde, 0x58, 0xe3, 0x8d, 0x9d, 0xa2, 0xcc, 0x46, 0xed, 0x9b, 0x99, 0x67, 0x85, + 0x35, 0x9b, 0xee, 0x93, 0x8e, 0x82, 0xec, 0x12, 0x0a, 0xa7, 0x6d, 0x04, 0xc3, 0x26, 0xa3, 0x7d, + 0xd2, 0x2d, 0x40, 0x80, 0x2c, 0xa1, 0x70, 0x76, 0x2a, 0x64, 0x9d, 0xd3, 0x8f, 0x64, 0x4f, 0xcb, + 0x14, 0x70, 0xaa, 0x2f, 0xc6, 0x20, 0x93, 0xb1, 0x76, 0x3a, 0x95, 0x66, 0x9f, 0x99, 0x19, 0x98, + 0xfb, 0x62, 0xcd, 0x2d, 0x95, 0x01, 0x7b, 0x53, 0x31, 0x46, 0x4f, 0x8c, 0xe8, 0x5f, 0x33, 0xdb, + 0xfd, 0x7e, 0xb8, 0xdb, 0x14, 0x6a, 0x36, 0x7d, 0x4b, 0x1e, 0xac, 0x18, 0xe6, 0xab, 0x74, 0x94, + 0xe6, 0xce, 0xdd, 0x81, 0x3d, 0x6c, 0x8f, 0x0e, 0x97, 0x33, 0xcf, 0xd9, 0xfe, 0xc9, 0x9a, 0xe2, + 0x87, 0xf7, 0x9b, 0xda, 0xf9, 0xaa, 0x44, 0x29, 0x69, 0xa7, 0x90, 0xa2, 0xd3, 0xad, 0x4c, 0x54, + 0xf1, 0x49, 0xf7, 0xdb, 0xb5, 0x67, 0xfd, 0xbe, 0xf6, 0x2c, 0x3f, 0x20, 0x0f, 0x37, 0xe6, 0x17, + 0x82, 0xca, 0x31, 0x53, 0x60, 0xdc, 0x2b, 0xf8, 0x32, 0x85, 0x4c, 0x40, 0x35, 0xc4, 0x76, 0xb8, + 0xce, 0x8f, 0x90, 0xb4, 0xce, 0x54, 0x42, 0xc7, 0xa4, 0xbb, 0x1e, 0xfb, 0x33, 0xf6, 0xaf, 0xe5, + 0x63, 0x1b, 0x0a, 0xfd, 0xe0, 0xbf, 0xa9, 0xab, 0xc3, 0x8c, 0xde, 0xdf, 0xcc, 0x5d, 0xfb, 0x76, + 0xee, 0xda, 0xbf, 0xe6, 0xae, 0xfd, 0x7d, 0xe1, 0x5a, 0xb7, 0x0b, 0xd7, 0xfa, 0xb9, 0x70, 0xad, + 0x0f, 0xc7, 0x89, 0xd4, 0xe3, 0x69, 0xcc, 0x04, 0xa6, 0xbc, 0x59, 0x65, 0x19, 0x8b, 0xe7, 0x09, + 0xf2, 0xf2, 0x15, 0x4f, 0xf1, 0x72, 0x3a, 0x01, 0x65, 0x9e, 0xce, 0xc6, 0x93, 0xd1, 0x57, 0x39, + 0xa8, 0xb8, 0x53, 0xad, 0xef, 0x8b, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xc1, 0x2a, 0x32, 0x96, + 0x5c, 0x03, 0x00, 0x00, +>>>>>>> 05685b3 (refactor: adapting transfer metadata bytes field to memo string (#2595)) } // Reference imports to suppress errors if they are not otherwise used. @@ -281,10 +318,10 @@ 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))) + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintTx(dAtA, i, uint64(len(m.Memo))) i-- dAtA[i] = 0x42 } @@ -412,7 +449,7 @@ func (m *MsgTransfer) Size() (n int) { if m.TimeoutTimestamp != 0 { n += 1 + sovTx(uint64(m.TimeoutTimestamp)) } - l = len(m.Metadata) + l = len(m.Memo) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -681,9 +718,9 @@ func (m *MsgTransfer) Unmarshal(dAtA []byte) error { } case 8: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -693,25 +730,23 @@ func (m *MsgTransfer) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen 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{} - } + m.Memo = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/proto/ibc/applications/transfer/v1/tx.proto b/proto/ibc/applications/transfer/v1/tx.proto index e098820e72d..44e068d6967 100644 --- a/proto/ibc/applications/transfer/v1/tx.proto +++ b/proto/ibc/applications/transfer/v1/tx.proto @@ -38,8 +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; + // optional memo + string memo = 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 74b3d685f32..129815ebc0b 100644 --- a/proto/ibc/applications/transfer/v2/packet.proto +++ b/proto/ibc/applications/transfer/v2/packet.proto @@ -16,6 +16,6 @@ message FungibleTokenPacketData { string sender = 3; // the recipient address on the destination chain string receiver = 4; - // optional metadata - bytes metadata = 5; + // optional memo + string memo = 5; }