Skip to content

Commit

Permalink
refactor: adapting transfer metadata bytes field to memo string (back…
Browse files Browse the repository at this point in the history
…port #2595) (#2596)

* refactor: adapting transfer metadata bytes field to memo string (#2595)

* adapting transfer metadata bytes field to memo string

* updating changelog

(cherry picked from commit 05685b3)

# Conflicts:
#	CHANGELOG.md
#	docs/ibc/proto-docs.md
#	go.mod
#	go.sum
#	modules/apps/29-fee/transfer_test.go
#	modules/apps/transfer/client/cli/tx.go
#	modules/apps/transfer/ibc_module.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

* updating docs

Co-authored-by: Damian Nolan <[email protected]>
  • Loading branch information
mergify[bot] and damiannolan authored Oct 26, 2022
1 parent 303d693 commit 70c5efa
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 120 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

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

### Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +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 |
| `memo` | [string](#string) | | optional memo |



Expand Down Expand Up @@ -761,7 +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 |
| `memo` | [string](#string) | | optional memo |



Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -119,7 +119,7 @@ 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)
msg.Memo = memo

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
Expand All @@ -128,7 +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.")
cmd.Flags().String(flagMemo, "", "Memo to be sent along with the packet.")
flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
msg.Memo)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +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")
msg.Memo = "memo"

tc.malleate()

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (k Keeper) SendTransfer(
receiver,
timeoutHeight,
timeoutTimestamp,
nil,
"",
)
return err
}
Expand All @@ -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
Expand Down Expand Up @@ -177,7 +177,7 @@ func (k Keeper) sendTransfer(
packetData := types.NewFungibleTokenPacketData(
fullDenomPath, token.Amount.String(), sender.String(), receiver,
)
packetData.Metadata = metadata
packetData.Memo = memo

packet := channeltypes.NewPacket(
packetData.GetBytes(),
Expand Down
16 changes: 8 additions & 8 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
trace types.DenomTrace
amount sdk.Int
receiver string
metadata []byte
memo string
)

testCases := []struct {
Expand All @@ -159,12 +159,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{}
Expand Down Expand Up @@ -206,7 +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
memo = "" // can be explicitly changed in malleate
amount = sdk.NewInt(100) // must be explicitly changed in malleate
seq := uint64(1)

Expand Down Expand Up @@ -234,14 +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
transferMsg.Memo = memo
_, 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
data.Memo = memo
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)
Expand Down
7 changes: 3 additions & 4 deletions modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package transfer

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"math"
Expand Down Expand Up @@ -355,7 +354,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.AttributeKeyMemo, data.Memo),
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
),
)
Expand Down Expand Up @@ -392,7 +391,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.AttributeKeyMemo, data.Memo),
sdk.NewAttribute(types.AttributeKeyAck, ack.String()),
),
)
Expand Down Expand Up @@ -439,7 +438,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)),
sdk.NewAttribute(types.AttributeKeyMemo, data.Memo),
),
)

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/spec/04_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type MsgTransfer struct {
Receiver string
TimeoutHeight ibcexported.Height
TimeoutTimestamp uint64
Metadata []byte
Memo string
}
```

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/spec/05_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ order: 5
| fungible_token_packet | denom | {denom} |
| fungible_token_packet | amount | {amount} |
| fungible_token_packet | success | {ackSuccess} |
| fungible_token_packet | metadata | {metadata} |
| fungible_token_packet | memo | {memo} |
| denomination_trace | trace_hash | {hex_hash} |

## OnAcknowledgePacket callback
Expand All @@ -33,7 +33,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 | memo | {memo} |
| fungible_token_packet | acknowledgement | {ack.String()} |
| fungible_token_packet | success | error | {ack.Response} |

Expand All @@ -45,4 +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} |
| fungible_token_packet | memo | {memo} |
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const (
AttributeKeyAck = "acknowledgement"
AttributeKeyAckError = "error"
AttributeKeyTraceHash = "trace_hash"
AttributeKeyMetadata = "metadata"
AttributeKeyMemo = "memo"
)
71 changes: 34 additions & 37 deletions modules/apps/transfer/types/packet.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 70c5efa

Please sign in to comment.