Skip to content

Commit bb0c88f

Browse files
mergify[bot]damiannolan
authored andcommitted
refactor: adapting transfer metadata bytes field to memo string (backport cosmos#2595) (cosmos#2598)
* refactor: adapting transfer metadata bytes field to memo string (cosmos#2595) * adapting transfer metadata bytes field to memo string * updating changelog (cherry picked from commit 05685b3) # 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 * resolving conflicts Co-authored-by: Damian Nolan <[email protected]>
1 parent 202b967 commit bb0c88f

File tree

13 files changed

+110
-116
lines changed

13 files changed

+110
-116
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4848

4949
### Features
5050

51-
* (apps/transfer) [\#2305](https://github.com/cosmos/ibc-go/pull/2305) Added optional metadata field to `FungibleTokenPacketData` and `MsgTransfer`.
51+
* (apps/transfer) [\#2595](https://github.com/cosmos/ibc-go/pull/2595) Adding optional memo field to `FungibleTokenPacketData` and `MsgTransfer`.
5252

5353
### Bug Fixes
5454

docs/ibc/proto-docs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf
21462146
| `receiver` | [string](#string) | | the recipient address on the destination chain |
21472147
| `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. |
21482148
| `timeout_timestamp` | [uint64](#uint64) | | Timeout timestamp in absolute nanoseconds since unix epoch. The timeout is disabled when set to 0. |
2149-
| `metadata` | [bytes](#bytes) | | optional metadata |
2149+
| `memo` | [string](#string) | | optional memo |
21502150

21512151

21522152

@@ -2208,7 +2208,7 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf
22082208
| `amount` | [string](#string) | | the token amount to be transferred |
22092209
| `sender` | [string](#string) | | the sender address |
22102210
| `receiver` | [string](#string) | | the recipient address on the destination chain |
2211-
| `metadata` | [bytes](#bytes) | | optional metadata |
2211+
| `memo` | [string](#string) | | optional memo |
22122212

22132213

22142214

modules/apps/transfer/client/cli/tx.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
flagPacketTimeoutHeight = "packet-timeout-height"
2323
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
2424
flagAbsoluteTimeouts = "absolute-timeouts"
25-
flagMetadata = "metadata"
25+
flagMemo = "memo"
2626
)
2727

2828
// 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.`),
7777
return err
7878
}
7979

80-
metadataStr, err := cmd.Flags().GetString(flagMetadata)
80+
memo, err := cmd.Flags().GetString(flagMemo)
8181
if err != nil {
8282
return err
8383
}
@@ -119,7 +119,7 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`),
119119
msg := types.NewMsgTransfer(
120120
srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp,
121121
)
122-
msg.Metadata = []byte(metadataStr)
122+
msg.Memo = memo
123123

124124
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
125125
},
@@ -128,7 +128,7 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`),
128128
cmd.Flags().String(flagPacketTimeoutHeight, types.DefaultRelativePacketTimeoutHeight, "Packet timeout block height. The timeout is disabled when set to 0-0.")
129129
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.")
130130
cmd.Flags().Bool(flagAbsoluteTimeouts, false, "Timeout flags are used as absolute timeouts.")
131-
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.")
131+
cmd.Flags().String(flagMemo, "", "Memo to be sent along with the packet.")
132132
flags.AddTxFlagsToCmd(cmd)
133133

134134
return cmd

modules/apps/transfer/ibc_module.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package transfer
22

33
import (
4-
"encoding/hex"
54
"fmt"
65
"math"
76
"strings"
@@ -195,7 +194,7 @@ func (im IBCModule) OnRecvPacket(
195194
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
196195
sdk.NewAttribute(types.AttributeKeyDenom, data.Denom),
197196
sdk.NewAttribute(types.AttributeKeyAmount, data.Amount),
198-
sdk.NewAttribute(types.AttributeKeyMetadata, hex.EncodeToString(data.Metadata)),
197+
sdk.NewAttribute(types.AttributeKeyMemo, data.Memo),
199198
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
200199
}
201200

@@ -242,7 +241,7 @@ func (im IBCModule) OnAcknowledgementPacket(
242241
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
243242
sdk.NewAttribute(types.AttributeKeyDenom, data.Denom),
244243
sdk.NewAttribute(types.AttributeKeyAmount, data.Amount),
245-
sdk.NewAttribute(types.AttributeKeyMetadata, hex.EncodeToString(data.Metadata)),
244+
sdk.NewAttribute(types.AttributeKeyMemo, data.Memo),
246245
sdk.NewAttribute(types.AttributeKeyAck, ack.String()),
247246
),
248247
)
@@ -289,7 +288,7 @@ func (im IBCModule) OnTimeoutPacket(
289288
sdk.NewAttribute(types.AttributeKeyRefundReceiver, data.Sender),
290289
sdk.NewAttribute(types.AttributeKeyRefundDenom, data.Denom),
291290
sdk.NewAttribute(types.AttributeKeyRefundAmount, data.Amount),
292-
sdk.NewAttribute(types.AttributeKeyMetadata, hex.EncodeToString(data.Metadata)),
291+
sdk.NewAttribute(types.AttributeKeyMemo, data.Memo),
293292
),
294293
)
295294

modules/apps/transfer/keeper/msg_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
2121

2222
sequence, err := k.sendTransfer(
2323
ctx, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp,
24-
msg.Metadata)
24+
msg.Memo)
2525
if err != nil {
2626
return nil, err
2727
}

modules/apps/transfer/keeper/msg_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() {
5555
coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(),
5656
suite.chainB.GetTimeoutHeight(), 0, // only use timeout height
5757
)
58-
msg.Metadata = []byte("custom metadata")
58+
msg.Memo = "memo"
5959

6060
tc.malleate()
6161

modules/apps/transfer/keeper/relay.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (k Keeper) SendTransfer(
6969
receiver,
7070
timeoutHeight,
7171
timeoutTimestamp,
72-
nil,
72+
"",
7373
)
7474
return err
7575
}
@@ -84,7 +84,7 @@ func (k Keeper) sendTransfer(
8484
receiver string,
8585
timeoutHeight clienttypes.Height,
8686
timeoutTimestamp uint64,
87-
metadata []byte,
87+
memo string,
8888
) (uint64, error) {
8989
if !k.GetSendEnabled(ctx) {
9090
return 0, types.ErrSendDisabled
@@ -177,7 +177,7 @@ func (k Keeper) sendTransfer(
177177
packetData := types.NewFungibleTokenPacketData(
178178
fullDenomPath, token.Amount.String(), sender.String(), receiver,
179179
)
180-
packetData.Metadata = metadata
180+
packetData.Memo = memo
181181

182182
packet := channeltypes.NewPacket(
183183
packetData.GetBytes(),

modules/apps/transfer/keeper/relay_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
162162
trace types.DenomTrace
163163
amount sdk.Int
164164
receiver string
165-
metadata []byte
165+
memo string
166166
)
167167

168168
testCases := []struct {
@@ -172,12 +172,12 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
172172
expPass bool
173173
}{
174174
{"success receive on source chain", func() {}, true, true},
175-
{"success receive on source chain with metadata", func() {
176-
metadata = []byte("metadata")
175+
{"success receive on source chain with memo", func() {
176+
memo = "memo"
177177
}, true, true},
178178
{"success receive with coin from another chain as source", func() {}, false, true},
179-
{"success receive with coin from another chain as source with metadata", func() {
180-
metadata = []byte("metadata")
179+
{"success receive with coin from another chain as source with memo", func() {
180+
memo = "memo"
181181
}, false, true},
182182
{"empty coin", func() {
183183
trace = types.DenomTrace{}
@@ -219,7 +219,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
219219
suite.coordinator.Setup(path)
220220
receiver = suite.chainB.SenderAccount.GetAddress().String() // must be explicitly changed in malleate
221221

222-
metadata = []byte{} // can be explicitly changed in malleate
222+
memo = "" // can be explicitly changed in malleate
223223
amount = sdk.NewInt(100) // must be explicitly changed in malleate
224224
seq := uint64(1)
225225

@@ -246,14 +246,14 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
246246

247247
// send coin from chainA to chainB
248248
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)
249-
transferMsg.Metadata = metadata
249+
transferMsg.Memo = memo
250250
_, err := suite.chainA.SendMsgs(transferMsg)
251251
suite.Require().NoError(err) // message committed
252252

253253
tc.malleate()
254254

255255
data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), receiver)
256-
data.Metadata = metadata
256+
data.Memo = memo
257257
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)
258258

259259
err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data)

modules/apps/transfer/types/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ const (
1818
AttributeKeyAck = "acknowledgement"
1919
AttributeKeyAckError = "error"
2020
AttributeKeyTraceHash = "trace_hash"
21-
AttributeKeyMetadata = "metadata"
21+
AttributeKeyMemo = "memo"
2222
)

modules/apps/transfer/types/packet.pb.go

Lines changed: 34 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)