From 589cdd43e15ca803f57740e0c54d3576428b0c45 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Mon, 1 Jul 2024 13:33:43 +0300 Subject: [PATCH] chore: remove Trace type from protos, replace with Hop (#6728) * chore: remove Trace type from protos, replace with Hop * nit: remove trace file and move functionality to denom. --- e2e/tests/transfer/forwarding_test.go | 4 +- e2e/tests/wasm/grandpa_test.go | 2 +- modules/apps/callbacks/replay_test.go | 4 +- modules/apps/callbacks/transfer_test.go | 2 +- modules/apps/transfer/ibc_module_test.go | 6 +- modules/apps/transfer/internal/packet_test.go | 14 +- modules/apps/transfer/keeper/genesis_test.go | 16 +- .../apps/transfer/keeper/grpc_query_test.go | 28 +- .../apps/transfer/keeper/migrations_test.go | 20 +- modules/apps/transfer/keeper/msg_server.go | 6 +- .../apps/transfer/keeper/msg_server_test.go | 4 +- modules/apps/transfer/keeper/relay.go | 2 +- .../transfer/keeper/relay_forwarding_test.go | 30 +- modules/apps/transfer/keeper/relay_test.go | 32 +-- .../apps/transfer/simulation/decoder_test.go | 2 +- modules/apps/transfer/transfer_test.go | 4 +- modules/apps/transfer/types/denom.go | 101 ++++++- modules/apps/transfer/types/denom_test.go | 144 +++++++--- modules/apps/transfer/types/forwarding.go | 10 +- modules/apps/transfer/types/packet_test.go | 56 ++-- modules/apps/transfer/types/token.pb.go | 269 ++---------------- modules/apps/transfer/types/token_test.go | 52 ++-- modules/apps/transfer/types/trace.go | 127 --------- modules/apps/transfer/types/trace_test.go | 74 ----- modules/apps/transfer/types/transfer.pb.go | 49 ++-- .../applications/transfer/v1/transfer.proto | 5 +- .../ibc/applications/transfer/v2/token.proto | 12 +- 27 files changed, 403 insertions(+), 672 deletions(-) delete mode 100644 modules/apps/transfer/types/trace.go delete mode 100644 modules/apps/transfer/types/trace_test.go diff --git a/e2e/tests/transfer/forwarding_test.go b/e2e/tests/transfer/forwarding_test.go index d038a134d73..23a8dde01b1 100644 --- a/e2e/tests/transfer/forwarding_test.go +++ b/e2e/tests/transfer/forwarding_test.go @@ -80,8 +80,8 @@ func (s *TransferForwardingTestSuite) TestForwarding_WithLastChainBeingICS20v1_S t.Run("packets are relayed from A to B to C", func(t *testing.T) { chainCDenom := transfertypes.NewDenom(chainADenom, - transfertypes.NewTrace(channelBtoC.Counterparty.PortID, channelBtoC.Counterparty.ChannelID), - transfertypes.NewTrace(channelAtoB.Counterparty.PortID, channelAtoB.Counterparty.ChannelID), + transfertypes.NewHop(channelBtoC.Counterparty.PortID, channelBtoC.Counterparty.ChannelID), + transfertypes.NewHop(channelAtoB.Counterparty.PortID, channelAtoB.Counterparty.ChannelID), ) s.AssertPacketRelayed(ctx, chainA, channelAtoB.PortID, channelAtoB.ChannelID, 1) diff --git a/e2e/tests/wasm/grandpa_test.go b/e2e/tests/wasm/grandpa_test.go index 8543fb5d4cb..a0eade9cb1e 100644 --- a/e2e/tests/wasm/grandpa_test.go +++ b/e2e/tests/wasm/grandpa_test.go @@ -256,7 +256,7 @@ func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() { s.Require().True(cosmosUserStakeBal.Equal(finalStakeBal)) // Verify cosmos user's final "unit" balance - denom := transfertypes.NewDenom("UNIT", transfertypes.NewTrace("transfer", "channel-0")) + denom := transfertypes.NewDenom("UNIT", transfertypes.NewHop("transfer", "channel-0")) cosmosUserUnitBal, err := cosmosChain.GetBalance(ctx, cosmosUser.FormattedAddress(), denom.IBCDenom()) s.Require().NoError(err) s.Require().True(cosmosUserUnitBal.Equal(amountUnits)) diff --git a/modules/apps/callbacks/replay_test.go b/modules/apps/callbacks/replay_test.go index 4c619346597..3a31b1a0af5 100644 --- a/modules/apps/callbacks/replay_test.go +++ b/modules/apps/callbacks/replay_test.go @@ -286,7 +286,7 @@ func (s *CallbacksTestSuite) TestTransferRecvPacketReplayProtection() { } // save initial balance of receiver - denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID)) + denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID)) initialBalance := GetSimApp(s.chainB).BankKeeper.GetBalance(s.chainB.GetContext(), s.chainB.SenderAccount.GetAddress(), denom.IBCDenom()) // execute the transfer @@ -319,7 +319,7 @@ func (s *CallbacksTestSuite) ExecuteFailedTransfer(memo string) { // record the balance of the escrow address before the transfer escrowBalance := GetSimApp(s.chainA).BankKeeper.GetBalance(s.chainA.GetContext(), escrowAddress, sdk.DefaultBondDenom) // record the balance of the receiving address before the transfer - denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID)) + denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID)) receiverBalance := GetSimApp(s.chainB).BankKeeper.GetBalance(s.chainB.GetContext(), s.chainB.SenderAccount.GetAddress(), denom.IBCDenom()) amount := ibctesting.TestCoin diff --git a/modules/apps/callbacks/transfer_test.go b/modules/apps/callbacks/transfer_test.go index c1e935e204d..dead34dbd71 100644 --- a/modules/apps/callbacks/transfer_test.go +++ b/modules/apps/callbacks/transfer_test.go @@ -182,7 +182,7 @@ func (s *CallbacksTestSuite) ExecuteTransfer(memo string) { // record the balance of the escrow address before the transfer escrowBalance := GetSimApp(s.chainA).BankKeeper.GetBalance(s.chainA.GetContext(), escrowAddress, sdk.DefaultBondDenom) // record the balance of the receiving address before the transfer - denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID)) + denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID)) receiverBalance := GetSimApp(s.chainB).BankKeeper.GetBalance(s.chainB.GetContext(), s.chainB.SenderAccount.GetAddress(), denom.IBCDenom()) amount := ibctesting.TestCoin diff --git a/modules/apps/transfer/ibc_module_test.go b/modules/apps/transfer/ibc_module_test.go index 4cc72c970b7..20b3c3866e9 100644 --- a/modules/apps/transfer/ibc_module_test.go +++ b/modules/apps/transfer/ibc_module_test.go @@ -810,7 +810,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { initialPacketData = types.FungibleTokenPacketDataV2{ Tokens: []types.Token{ { - Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0")), + Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: ibctesting.TestCoin.Amount.String(), }, }, @@ -850,7 +850,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { initialPacketData = types.FungibleTokenPacketDataV2{ Tokens: []types.Token{ { - Denom: types.NewDenom(ibctesting.TestCoin.Denom, []types.Trace{{}}...), + Denom: types.NewDenom(ibctesting.TestCoin.Denom, []types.Hop{{}}...), Amount: ibctesting.TestCoin.Amount.String(), }, }, @@ -861,7 +861,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() { data = initialPacketData.(types.FungibleTokenPacketDataV2).GetBytes() }, - errors.New("invalid token denom: invalid trace: invalid portID: identifier cannot be blank: invalid identifier"), + errors.New("invalid token denom: invalid trace: invalid hop source port ID : identifier cannot be blank: invalid identifier"), }, { "failure: invalid packet data", diff --git a/modules/apps/transfer/internal/packet_test.go b/modules/apps/transfer/internal/packet_test.go index ab56c593111..30202ed8218 100644 --- a/modules/apps/transfer/internal/packet_test.go +++ b/modules/apps/transfer/internal/packet_test.go @@ -34,7 +34,7 @@ func TestUnmarshalPacketData(t *testing.T) { packetData := types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0")), + Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, }, "sender", "receiver", "", emptyForwardingPacketData) @@ -91,7 +91,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0")), + Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")), Amount: "1000", }, }, sender, receiver, "", emptyForwardingPacketData), @@ -115,7 +115,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("atom/withslash", types.NewTrace("transfer", "channel-0")), + Denom: types.NewDenom("atom/withslash", types.NewHop("transfer", "channel-0")), Amount: "1000", }, }, sender, receiver, "", emptyForwardingPacketData), @@ -127,7 +127,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("atom/", types.NewTrace("transfer", "channel-0")), + Denom: types.NewDenom("atom/", types.NewHop("transfer", "channel-0")), Amount: "1000", }, }, sender, receiver, "", emptyForwardingPacketData), @@ -139,7 +139,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("atom/pool", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: "1000", }, }, sender, receiver, "", emptyForwardingPacketData), @@ -151,7 +151,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer-custom", "channel-2")), + Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")), Amount: "1000", }, }, sender, receiver, "", emptyForwardingPacketData), @@ -163,7 +163,7 @@ func TestPacketV1ToPacketV2(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("atom/pool", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer-custom", "channel-2")), + Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")), Amount: "1000", }, }, sender, receiver, "", emptyForwardingPacketData), diff --git a/modules/apps/transfer/keeper/genesis_test.go b/modules/apps/transfer/keeper/genesis_test.go index 253c3c6e56d..566e408d3d5 100644 --- a/modules/apps/transfer/keeper/genesis_test.go +++ b/modules/apps/transfer/keeper/genesis_test.go @@ -11,22 +11,22 @@ import ( ) func (suite *KeeperTestSuite) TestGenesis() { - getTrace := func(index uint) types.Trace { - return types.NewTrace("transfer", fmt.Sprintf("channelToChain%d", index)) + getHop := func(index uint) types.Hop { + return types.NewHop("transfer", fmt.Sprintf("channelToChain%d", index)) } var ( denoms types.Denoms escrows sdk.Coins traceAndEscrowAmounts = []struct { - trace []types.Trace + trace []types.Hop escrow string }{ - {[]types.Trace{getTrace(0)}, "10"}, - {[]types.Trace{getTrace(1), getTrace(0)}, "100000"}, - {[]types.Trace{getTrace(2), getTrace(1), getTrace(0)}, "10000000000"}, - {[]types.Trace{getTrace(3), getTrace(2), getTrace(1), getTrace(0)}, "1000000000000000"}, - {[]types.Trace{getTrace(4), getTrace(3), getTrace(2), getTrace(1), getTrace(0)}, "100000000000000000000"}, + {[]types.Hop{getHop(0)}, "10"}, + {[]types.Hop{getHop(1), getHop(0)}, "100000"}, + {[]types.Hop{getHop(2), getHop(1), getHop(0)}, "10000000000"}, + {[]types.Hop{getHop(3), getHop(2), getHop(1), getHop(0)}, "1000000000000000"}, + {[]types.Hop{getHop(4), getHop(3), getHop(2), getHop(1), getHop(0)}, "100000000000000000000"}, } ) diff --git a/modules/apps/transfer/keeper/grpc_query_test.go b/modules/apps/transfer/keeper/grpc_query_test.go index 9c52cc9ed69..e396315d664 100644 --- a/modules/apps/transfer/keeper/grpc_query_test.go +++ b/modules/apps/transfer/keeper/grpc_query_test.go @@ -27,9 +27,9 @@ func (suite *KeeperTestSuite) TestQueryDenom() { "success: correct ibc denom", func() { expDenom = types.NewDenom( - "uatom", //nolint:goconst - types.NewTrace("transfer", "channelToA"), //nolint:goconst - types.NewTrace("transfer", "channelToB"), //nolint:goconst + "uatom", //nolint:goconst + types.NewHop("transfer", "channelToA"), //nolint:goconst + types.NewHop("transfer", "channelToB"), //nolint:goconst ) suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), expDenom) @@ -43,9 +43,9 @@ func (suite *KeeperTestSuite) TestQueryDenom() { "success: correct hex hash", func() { expDenom = types.NewDenom( - "uatom", //nolint:goconst - types.NewTrace("transfer", "channelToA"), //nolint:goconst - types.NewTrace("transfer", "channelToB"), //nolint:goconst + "uatom", //nolint:goconst + types.NewHop("transfer", "channelToA"), //nolint:goconst + types.NewHop("transfer", "channelToB"), //nolint:goconst ) suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), expDenom) @@ -68,9 +68,9 @@ func (suite *KeeperTestSuite) TestQueryDenom() { "failure: not found denom trace", func() { expDenom = types.NewDenom( - "uatom", //nolint:goconst - types.NewTrace("transfer", "channelToA"), //nolint:goconst - types.NewTrace("transfer", "channelToB"), //nolint:goconst + "uatom", //nolint:goconst + types.NewHop("transfer", "channelToA"), //nolint:goconst + types.NewHop("transfer", "channelToB"), //nolint:goconst ) req = &types.QueryDenomRequest{ @@ -124,8 +124,8 @@ func (suite *KeeperTestSuite) TestQueryDenoms() { "success", func() { expDenoms = append(expDenoms, types.NewDenom("uatom")) - expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewTrace("transfer", "channelToB"))) - expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewTrace("transfer", "channelToA"), types.NewTrace("transfer", "channelToB"))) + expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewHop("transfer", "channelToB"))) + expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewHop("transfer", "channelToA"), types.NewHop("transfer", "channelToB"))) for _, trace := range expDenoms { suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), trace) @@ -171,7 +171,7 @@ func (suite *KeeperTestSuite) TestQueryParams() { } func (suite *KeeperTestSuite) TestQueryDenomHash() { - reqDenom := types.NewDenom("uatom", types.NewTrace("transfer", "channelToA"), types.NewTrace("transfer", "channelToB")) + reqDenom := types.NewDenom("uatom", types.NewHop("transfer", "channelToA"), types.NewHop("transfer", "channelToB")) var ( req *types.QueryDenomHashRequest @@ -333,7 +333,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { { "valid ibc denom with escrow amount > 2^63", func() { - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace("transfer", "channel-0")) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop("transfer", "channel-0")) suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), denom) expEscrowAmount, ok := sdkmath.NewIntFromString("100000000000000000000") @@ -349,7 +349,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { { "valid ibc denom treated as native denom", func() { - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace("transfer", "channel-0")) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop("transfer", "channel-0")) req = &types.QueryTotalEscrowForDenomRequest{ Denom: denom.IBCDenom(), diff --git a/modules/apps/transfer/keeper/migrations_test.go b/modules/apps/transfer/keeper/migrations_test.go index 24fd65bfef6..c749b1e9b35 100644 --- a/modules/apps/transfer/keeper/migrations_test.go +++ b/modules/apps/transfer/keeper/migrations_test.go @@ -78,7 +78,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() { }) }, transfertypes.Denoms{ - transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-49")), + transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-49")), }, }, { @@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() { }) }, transfertypes.Denoms{ - transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-49"), transfertypes.NewTrace("transfer", "channel-32"), transfertypes.NewTrace("transfer", "channel-2")), + transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-49"), transfertypes.NewHop("transfer", "channel-32"), transfertypes.NewHop("transfer", "channel-2")), }, }, { @@ -119,10 +119,10 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() { }) }, transfertypes.Denoms{ - transfertypes.NewDenom("apple", transfertypes.NewTrace("transfer", "channel-0")), - transfertypes.NewDenom("cucumber", transfertypes.NewTrace("transfer", "channel-102"), transfertypes.NewTrace("transfer", "channel-0")), - transfertypes.NewDenom("pineapple", transfertypes.NewTrace("transfer", "channel-0")), - transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-49")), + transfertypes.NewDenom("apple", transfertypes.NewHop("transfer", "channel-0")), + transfertypes.NewDenom("cucumber", transfertypes.NewHop("transfer", "channel-102"), transfertypes.NewHop("transfer", "channel-0")), + transfertypes.NewDenom("pineapple", transfertypes.NewHop("transfer", "channel-0")), + transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-49")), }, }, @@ -136,7 +136,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() { }) }, transfertypes.Denoms{ - transfertypes.NewDenom("gamm/pool/1", transfertypes.NewTrace("transfer", "channel-0")), + transfertypes.NewDenom("gamm/pool/1", transfertypes.NewHop("transfer", "channel-0")), }, }, { @@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() { }) }, transfertypes.Denoms{ - transfertypes.NewDenom("erc/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", transfertypes.NewTrace("transfer", "channel-149")), + transfertypes.NewDenom("erc/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", transfertypes.NewHop("transfer", "channel-149")), }, }, { @@ -162,7 +162,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() { }) }, transfertypes.Denoms{ - transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-0"), transfertypes.NewTrace("customport", "channel-7")), + transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-0"), transfertypes.NewHop("customport", "channel-7")), }, }, } @@ -272,7 +272,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() { "success: valid ibc denom escrowed in one channel", func() { escrowAddress := transfertypes.GetEscrowAddress(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - voucherDenom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + voucherDenom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) coin := sdk.NewCoin(voucherDenom.IBCDenom(), sdkmath.NewInt(100)) denom = voucherDenom.IBCDenom() diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index b8712975df4..46e97ba1901 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -80,11 +80,9 @@ func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgT if token.Denom.IsNative() { return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "cannot unwind a native token") } - var unwindHops []types.Hop + // remove the first hop in denom as it is the current port/channel on this chain - for _, trace := range token.Denom.Trace[1:] { - unwindHops = append(unwindHops, types.NewHop(trace.PortId, trace.ChannelId)) //nolint: gosimple - } + unwindHops := token.Denom.Trace[1:] // Update message fields. msg.SourcePort, msg.SourceChannel = token.Denom.Trace[0].PortId, token.Denom.Trace[0].ChannelId diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 83449069878..8bfcd8dffc7 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -252,7 +252,7 @@ func (suite *KeeperTestSuite) TestUpdateParams() { func (suite *KeeperTestSuite) TestUnwindHops() { var msg *types.MsgTransfer var path *ibctesting.Path - denom := types.NewDenom(ibctesting.TestCoin.Denom, types.NewTrace(ibctesting.MockPort, "channel-0"), types.NewTrace(ibctesting.MockPort, "channel-1")) + denom := types.NewDenom(ibctesting.TestCoin.Denom, types.NewHop(ibctesting.MockPort, "channel-0"), types.NewHop(ibctesting.MockPort, "channel-1")) coins := sdk.NewCoins(sdk.NewCoin(denom.IBCDenom(), ibctesting.TestCoin.Amount)) testCases := []struct { name string @@ -275,7 +275,7 @@ func (suite *KeeperTestSuite) TestUnwindHops() { { "success: multiple unwind hops", func() { - denom.Trace = append(denom.Trace, types.NewTrace(ibctesting.MockPort, "channel-2"), types.NewTrace(ibctesting.MockPort, "channel-3")) + denom.Trace = append(denom.Trace, types.NewHop(ibctesting.MockPort, "channel-2"), types.NewHop(ibctesting.MockPort, "channel-3")) coins = sdk.NewCoins(sdk.NewCoin(denom.IBCDenom(), ibctesting.TestCoin.Amount)) suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), denom) msg.Tokens = coins diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index cb7992c5ae1..01784755c88 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -233,7 +233,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // sender chain is the source, mint vouchers // since SendPacket did not prefix the denomination, we must add the destination port and channel to the trace - trace := []types.Trace{types.NewTrace(packet.DestinationPort, packet.DestinationChannel)} + trace := []types.Hop{types.NewHop(packet.DestinationPort, packet.DestinationChannel)} token.Denom.Trace = append(trace, token.Denom.Trace...) if !k.HasDenom(ctx, token.Denom.Hash()) { diff --git a/modules/apps/transfer/keeper/relay_forwarding_test.go b/modules/apps/transfer/keeper/relay_forwarding_test.go index 05f18aadee5..e70d390b554 100644 --- a/modules/apps/transfer/keeper/relay_forwarding_test.go +++ b/modules/apps/transfer/keeper/relay_forwarding_test.go @@ -102,7 +102,7 @@ func (suite *KeeperTestSuite) TestStoredForwardedPacketAndEscrowAfterFirstHop() suite.assertAmountOnChain(suite.chainA, escrow, amount, sdk.DefaultBondDenom) // denom path: transfer/channel-0 - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) suite.assertAmountOnChain(suite.chainB, escrow, amount, denom.IBCDenom()) } @@ -165,7 +165,7 @@ func (suite *KeeperTestSuite) TestSuccessfulForward() { suite.assertAmountOnChain(suite.chainA, escrow, amount, sdk.DefaultBondDenom) // denom path: transfer/channel-0 - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) suite.assertAmountOnChain(suite.chainB, escrow, amount, denom.IBCDenom()) packetFromBtoC, err := ibctesting.ParsePacketFromEvents(result.Events) @@ -188,7 +188,7 @@ func (suite *KeeperTestSuite) TestSuccessfulForward() { // transfer/channel-0/transfer/channel-0/denom // Check that the final receiver has received the expected tokens. - denomABC := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID), types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denomABC := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID), types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) // Check that the final receiver has received the expected tokens. suite.assertAmountOnChain(suite.chainC, balance, amount, denomABC.IBCDenom()) @@ -287,7 +287,7 @@ func (suite *KeeperTestSuite) TestSuccessfulForwardWithMemo() { suite.assertAmountOnChain(suite.chainA, escrow, amount, sdk.DefaultBondDenom) // denom path: transfer/channel-0 - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) suite.assertAmountOnChain(suite.chainB, escrow, amount, denom.IBCDenom()) packetFromBtoC, err := ibctesting.ParsePacketFromEvents(result.Events) @@ -328,7 +328,7 @@ func (suite *KeeperTestSuite) TestSuccessfulForwardWithMemo() { // transfer/channel-0/transfer/channel-0/denom // Check that the final receiver has received the expected tokens. - denomABC := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID), types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denomABC := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID), types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) // Check that the final receiver has received the expected tokens. suite.assertAmountOnChain(suite.chainC, balance, amount, denomABC.IBCDenom()) @@ -465,8 +465,8 @@ func (suite *KeeperTestSuite) TestSuccessfulUnwind() { // set sender and escrow accounts with the right balances to set up an initial state // that should have been the same as sending token from A -> B -> C denomA := types.NewDenom(sdk.DefaultBondDenom) - denomAB := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) - denomABC := types.NewDenom(sdk.DefaultBondDenom, append([]types.Trace{types.NewTrace(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)}, denomAB.Trace...)...) + denomAB := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denomABC := types.NewDenom(sdk.DefaultBondDenom, append([]types.Hop{types.NewHop(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)}, denomAB.Trace...)...) coinOnA := sdk.NewCoin(denomA.IBCDenom(), amount) err := suite.chainA.GetSimApp().BankKeeper.MintCoins(suite.chainA.GetContext(), types.ModuleName, sdk.NewCoins(coinOnA)) @@ -638,7 +638,7 @@ func (suite *KeeperTestSuite) TestAcknowledgementFailureWithMiddleChainAsNativeT suite.Require().Equal(amount, escrowBalancBtoC.Amount) // Check that receiver has the expected tokens - denomOnC := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)) + denomOnC := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)) coinOnC := sdk.NewCoin(denomOnC.IBCDenom(), amount) balanceOnC := suite.chainC.GetSimApp().BankKeeper.GetBalance(suite.chainC.GetContext(), setupReceiver.GetAddress(), coinOnC.GetDenom()) suite.Require().Equal(amount, balanceOnC.Amount) @@ -818,7 +818,7 @@ func (suite *KeeperTestSuite) TestAcknowledgementFailureWithMiddleChainAsNotBein suite.Require().NotNil(result) // Check that Escrow B has amount - denomOnB := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID)) + denomOnB := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID)) suite.assertAmountOnChain(suite.chainB, escrow, amount, denomOnB.IBCDenom()) forwardedPacket, found := suite.chainB.GetSimApp().TransferKeeper.GetForwardedPacket(suite.chainB.GetContext(), pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID, packetFromCtoB.Sequence) @@ -894,8 +894,8 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketForwarding() { receiver := suite.chainC.SenderAccounts[0].SenderAccount denomA := types.NewDenom(coin.Denom) - denomAB := types.NewDenom(coin.Denom, types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) - denomABC := types.NewDenom(coin.Denom, append([]types.Trace{types.NewTrace(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)}, denomAB.Trace...)...) + denomAB := types.NewDenom(coin.Denom, types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denomABC := types.NewDenom(coin.Denom, append([]types.Hop{types.NewHop(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)}, denomAB.Trace...)...) originalABalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), sender.GetAddress(), coin.Denom) @@ -950,7 +950,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketForwarding() { data := types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathAtoB.EndpointA.ChannelConfig.PortID, pathAtoB.EndpointA.ChannelID)), + Denom: types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathAtoB.EndpointA.ChannelConfig.PortID, pathAtoB.EndpointA.ChannelID)), Amount: "100", }, }, @@ -1079,7 +1079,7 @@ func (suite *KeeperTestSuite) TestForwardingWithMoreThanOneHop() { suite.assertAmountOnChain(suite.chainA, escrow, coinOnA.Amount, coinOnA.Denom) // Check that Escrow B has amount - denomTrace := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) + denomTrace := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID)) suite.assertAmountOnChain(suite.chainB, escrow, coinOnA.Amount, denomTrace.IBCDenom()) // Receive on C the packet sent from B, verify amount. @@ -1098,7 +1098,7 @@ func (suite *KeeperTestSuite) TestForwardingWithMoreThanOneHop() { suite.Require().NotNil(result) // Check that Escrow C has amount - denomTraceABC := types.NewDenom(denomTrace.Base, append([]types.Trace{types.NewTrace(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)}, denomTrace.Trace...)...) + denomTraceABC := types.NewDenom(denomTrace.Base, append([]types.Hop{types.NewHop(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID)}, denomTrace.Trace...)...) suite.assertAmountOnChain(suite.chainC, escrow, coinOnA.Amount, denomTraceABC.IBCDenom()) // Finally, receive on D and verify that D has the desired amount. @@ -1116,7 +1116,7 @@ func (suite *KeeperTestSuite) TestForwardingWithMoreThanOneHop() { suite.Require().NoError(err) suite.Require().NotNil(result) - denomTraceABCD := types.NewDenom(denomTraceABC.Base, append([]types.Trace{types.NewTrace(pathCtoD.EndpointB.ChannelConfig.PortID, pathCtoD.EndpointB.ChannelID)}, denomTraceABC.Trace...)...) + denomTraceABCD := types.NewDenom(denomTraceABC.Base, append([]types.Hop{types.NewHop(pathCtoD.EndpointB.ChannelConfig.PortID, pathCtoD.EndpointB.ChannelID)}, denomTraceABC.Trace...)...) suite.assertAmountOnChain(suite.chainD, balance, coinOnA.Amount, denomTraceABCD.IBCDenom()) // Propagate the ack back from D to A. diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 4b3c23b6d28..6366454f967 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -64,7 +64,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { "successful transfer of IBC token", func() { // send IBC token back to chainB - denom := types.NewDenom(coin.Denom, types.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + denom := types.NewDenom(coin.Denom, types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) coin = sdk.NewCoin(denom.IBCDenom(), coin.Amount) }, nil, @@ -108,7 +108,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { "successful transfer of IBC token with memo", func() { // send IBC token back to chainB - denom := types.NewDenom(coin.Denom, types.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + denom := types.NewDenom(coin.Denom, types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) coin = sdk.NewCoin(denom.IBCDenom(), coin.Amount) memo = "memo" }, @@ -139,7 +139,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { { "failure: denom trace not found", func() { - denom := types.NewDenom("randomdenom", types.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + denom := types.NewDenom("randomdenom", types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) coin = sdk.NewCoin(denom.IBCDenom(), coin.Amount) }, types.ErrDenomNotFound, @@ -147,7 +147,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { { "failure: bank send from module account failed, insufficient balance", func() { - denom := types.NewDenom(coin.Denom, types.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + denom := types.NewDenom(coin.Denom, types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) coin = sdk.NewCoin(denom.IBCDenom(), coin.Amount.Add(sdkmath.NewInt(1))) }, sdkerrors.ErrInsufficientFunds, @@ -305,7 +305,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT suite.Require().NoError(err) // execute - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID)) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID)) coin = sdk.NewCoin(denom.IBCDenom(), sdkmath.NewInt(100)) msg := types.NewMsgTransfer( path2.EndpointB.ChannelConfig.PortID, @@ -403,7 +403,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() { expEscrowAmount = sdkmath.ZeroInt() // total amount in escrow of voucher denom on receiving chain // denom trace of tokens received on chain B and the associated expected metadata - denomOnB := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) + denomOnB := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) expDenomMetadataOnB := banktypes.Metadata{ Description: fmt.Sprintf("IBC token from %s", denomOnB.Path()), DenomUnits: []*banktypes.DenomUnit{ @@ -430,7 +430,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() { data := types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(sdk.DefaultBondDenom, []types.Trace{}...), + Denom: types.NewDenom(sdk.DefaultBondDenom, []types.Hop{}...), Amount: amount.String(), }, }, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo, emptyForwardingPacketData) @@ -568,7 +568,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() { seq++ // NOTE: trace must be explicitly changed in malleate to test invalid cases - denom = types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + denom = types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) // send coin back from chainA to chainB coin = sdk.NewCoin(denom.IBCDenom(), amount) @@ -652,8 +652,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT // denom path: {transfer/channel-1/transfer/channel-0} denom := types.NewDenom( sdk.DefaultBondDenom, - types.NewTrace(path2.EndpointA.ChannelConfig.PortID, path2.EndpointA.ChannelID), - types.NewTrace(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID), + types.NewHop(path2.EndpointA.ChannelConfig.PortID, path2.EndpointA.ChannelID), + types.NewHop(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID), ) data := types.NewFungibleTokenPacketDataV2( @@ -677,7 +677,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT // denom path: transfer/channel-0 denom = types.NewDenom( sdk.DefaultBondDenom, - types.NewTrace(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID), + types.NewHop(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID), ) escrowAddress := types.GetEscrowAddress(path2.EndpointB.ChannelConfig.PortID, path2.EndpointB.ChannelID) @@ -728,7 +728,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { "success ack: no-op", successAck, func() { - denom = types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) + denom = types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) }, nil, }, @@ -752,7 +752,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { failedAck, func() { escrow := types.GetEscrowAddress(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - denom = types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + denom = types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) coin := sdk.NewCoin(denom.IBCDenom(), amount) suite.Require().NoError(banktestutil.FundAccount(suite.chainA.GetContext(), suite.chainA.GetSimApp().BankKeeper, escrow, sdk.NewCoins(coin))) @@ -865,7 +865,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacketSetsTotalEscrowAmountFo // fund escrow account for transfer and channel-1 on chain B // denom path: transfer/channel-0 - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID)) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID)) escrowAddress := types.GetEscrowAddress(path2.EndpointB.ChannelConfig.PortID, path2.EndpointB.ChannelID) coin := sdk.NewCoin(denom.IBCDenom(), amount) @@ -951,7 +951,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { "successful timeout: sender is not source of coin", func() { escrow := types.GetEscrowAddress(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - denom = types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + denom = types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) coinAmount, ok := sdkmath.NewIntFromString(amount) suite.Require().True(ok) coin := sdk.NewCoin(denom.IBCDenom(), coinAmount) @@ -1095,7 +1095,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketSetsTotalEscrowAmountForSourceI path2.Setup() // fund escrow account for transfer and channel-1 on chain B - denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID)) + denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop(path1.EndpointB.ChannelConfig.PortID, path1.EndpointB.ChannelID)) escrowAddress := types.GetEscrowAddress(path2.EndpointB.ChannelConfig.PortID, path2.EndpointB.ChannelID) coin := sdk.NewCoin(denom.IBCDenom(), amount) diff --git a/modules/apps/transfer/simulation/decoder_test.go b/modules/apps/transfer/simulation/decoder_test.go index bf93622e49d..19cbcd6ddca 100644 --- a/modules/apps/transfer/simulation/decoder_test.go +++ b/modules/apps/transfer/simulation/decoder_test.go @@ -14,7 +14,7 @@ import ( func TestDecodeStore(t *testing.T) { dec := simulation.NewDecodeStore() - denom := types.NewDenom("uatom", types.NewTrace("transfer", "channelToA")) + denom := types.NewDenom("uatom", types.NewHop("transfer", "channelToA")) kvPairs := kv.Pairs{ Pairs: []kv.Pair{ diff --git a/modules/apps/transfer/transfer_test.go b/modules/apps/transfer/transfer_test.go index b3198fc8cc1..b334d39ba7b 100644 --- a/modules/apps/transfer/transfer_test.go +++ b/modules/apps/transfer/transfer_test.go @@ -61,7 +61,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { // pathAToB.EndpointB = endpoint on chainB pathAToB := ibctesting.NewTransferPath(suite.chainA, suite.chainB) pathAToB.Setup() - traceAToB := types.NewTrace(pathAToB.EndpointB.ChannelConfig.PortID, pathAToB.EndpointB.ChannelID) + traceAToB := types.NewHop(pathAToB.EndpointB.ChannelConfig.PortID, pathAToB.EndpointB.ChannelID) originalBalances := sdk.NewCoins() for _, denom := range tc.sourceDenomsToTransfer { @@ -117,7 +117,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { // pathBToC.EndpointB = endpoint on chainC pathBToC := ibctesting.NewTransferPath(suite.chainB, suite.chainC) pathBToC.Setup() - traceBToC := types.NewTrace(pathBToC.EndpointB.ChannelConfig.PortID, pathBToC.EndpointB.ChannelID) + traceBToC := types.NewHop(pathBToC.EndpointB.ChannelConfig.PortID, pathBToC.EndpointB.ChannelID) // send from chainB to chainC msg = types.NewMsgTransfer(pathBToC.EndpointA.ChannelConfig.PortID, pathBToC.EndpointA.ChannelID, coinsSentFromAToB, suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String(), timeoutHeight, 0, "", types.Forwarding{}) diff --git a/modules/apps/transfer/types/denom.go b/modules/apps/transfer/types/denom.go index c8fce741b6e..6af937d3525 100644 --- a/modules/apps/transfer/types/denom.go +++ b/modules/apps/transfer/types/denom.go @@ -2,20 +2,26 @@ package types import ( "crypto/sha256" + "encoding/hex" "fmt" "sort" "strings" errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + cmtbytes "github.com/cometbft/cometbft/libs/bytes" + cmttypes "github.com/cometbft/cometbft/types" + + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ) -// NewDenom creates a new Denom instance given the base denomination and a variable number of traces. -func NewDenom(base string, traces ...Trace) Denom { +// NewDenom creates a new Denom instance given the base denomination and a variable number of hops. +func NewDenom(base string, trace ...Hop) Denom { return Denom{ Base: base, - Trace: traces, + Trace: trace, } } @@ -27,8 +33,8 @@ func (d Denom) Validate() error { return errorsmod.Wrap(ErrInvalidDenomForTransfer, "base denomination cannot be blank") } - for _, trace := range d.Trace { - if err := trace.Validate(); err != nil { + for _, hop := range d.Trace { + if err := hop.Validate(); err != nil { return errorsmod.Wrap(err, "invalid trace") } } @@ -133,3 +139,88 @@ func (d Denoms) Sort() Denoms { sort.Sort(d) return d } + +// ExtractDenomFromPath returns the denom from the full path. +// Used to support v1 denoms. +func ExtractDenomFromPath(fullPath string) Denom { + denomSplit := strings.Split(fullPath, "/") + + if denomSplit[0] == fullPath { + return Denom{ + Base: fullPath, + } + } + + var ( + trace []Hop + baseDenomSlice []string + ) + + length := len(denomSplit) + for i := 0; i < length; i += 2 { + // The IBC specification does not guarantee the expected format of the + // destination port or destination channel identifier. A short term solution + // to determine base denomination is to expect the channel identifier to be the + // one ibc-go specifies. A longer term solution is to separate the path and base + // denomination in the ICS20 packet. If an intermediate hop prefixes the full denom + // with a channel identifier format different from our own, the base denomination + // will be incorrectly parsed, but the token will continue to be treated correctly + // as an IBC denomination. The hash used to store the token internally on our chain + // will be the same value as the base denomination being correctly parsed. + if i < length-1 && length > 2 && channeltypes.IsValidChannelID(denomSplit[i+1]) { + trace = append(trace, NewHop(denomSplit[i], denomSplit[i+1])) + } else { + baseDenomSlice = denomSplit[i:] + break + } + } + + base := strings.Join(baseDenomSlice, "/") + + return Denom{ + Base: base, + Trace: trace, + } +} + +// validateIBCDenom validates that the given denomination is either: +// +// - A valid base denomination (eg: 'uatom' or 'gamm/pool/1' as in https://github.com/cosmos/ibc-go/issues/894) +// - A valid fungible token representation (i.e 'ibc/{hash}') per ADR 001 https://github.com/cosmos/ibc-go/blob/main/docs/architecture/adr-001-coin-source-tracing.md +func validateIBCDenom(denom string) error { + if err := sdk.ValidateDenom(denom); err != nil { + return err + } + + denomSplit := strings.SplitN(denom, "/", 2) + + switch { + case denom == DenomPrefix: + return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) + + case len(denomSplit) == 2 && denomSplit[0] == DenomPrefix: + if strings.TrimSpace(denomSplit[1]) == "" { + return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) + } + + if _, err := ParseHexHash(denomSplit[1]); err != nil { + return errorsmod.Wrapf(err, "invalid denom trace hash %s", denomSplit[1]) + } + } + + return nil +} + +// ParseHexHash parses a hex hash in string format to bytes and validates its correctness. +func ParseHexHash(hexHash string) (cmtbytes.HexBytes, error) { + hash, err := hex.DecodeString(hexHash) + if err != nil { + return nil, err + } + + if err := cmttypes.ValidateHash(hash); err != nil { + return nil, err + } + + return hash, nil +} diff --git a/modules/apps/transfer/types/denom_test.go b/modules/apps/transfer/types/denom_test.go index 86c7d9b686a..da78b773b49 100644 --- a/modules/apps/transfer/types/denom_test.go +++ b/modules/apps/transfer/types/denom_test.go @@ -2,6 +2,9 @@ package types_test import ( "fmt" + "testing" + + "github.com/stretchr/testify/require" "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ) @@ -19,20 +22,20 @@ func (suite *TypesTestSuite) TestDenomsValidate() { }, { "valid multiple trace info", - types.Denoms{types.NewDenom("uatom", types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer", "channel-2"))}, + types.Denoms{types.NewDenom("uatom", types.NewHop("transfer", "channel-1"), types.NewHop("transfer", "channel-2"))}, nil, }, { "valid multiple trace info", types.Denoms{ - types.NewDenom("uatom", types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer", "channel-2")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer", "channel-2")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-1"), types.NewHop("transfer", "channel-2")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-1"), types.NewHop("transfer", "channel-2")), }, fmt.Errorf("duplicated denomination with hash"), }, { "empty base denom with trace", - types.Denoms{types.NewDenom("", types.NewTrace("transfer", "channel-1"))}, + types.Denoms{types.NewDenom("", types.NewHop("transfer", "channel-1"))}, fmt.Errorf("base denomination cannot be blank"), }, } @@ -73,22 +76,22 @@ func (suite *TypesTestSuite) TestPath() { }, { "1 hop denom", - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), "transfer/channel-0/uatom", }, { "2 hop denom", - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), "transfer/channel-0/transfer/channel-52/uatom", }, { "3 hop denom", - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52"), types.NewHop("transfer", "channel-52")), "transfer/channel-0/transfer/channel-52/transfer/channel-52/uatom", }, { "4 hop denom with base denom slashes", - types.NewDenom("other-denom/", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52"), types.NewTrace("transfer", "channel-52"), types.NewTrace("transfer", "channel-49")), + types.NewDenom("other-denom/", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52"), types.NewHop("transfer", "channel-52"), types.NewHop("transfer", "channel-49")), "transfer/channel-0/transfer/channel-52/transfer/channel-52/transfer/channel-49/other-denom/", }, } @@ -115,49 +118,49 @@ func (suite *TypesTestSuite) TestSort() { { "different base denom and same traces", types.Denoms{ - types.NewDenom("uosmo", types.NewTrace("transfer", "channel-0")), - types.NewDenom("gamm", types.NewTrace("transfer", "channel-0")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), + types.NewDenom("uosmo", types.NewHop("transfer", "channel-0")), + types.NewDenom("gamm", types.NewHop("transfer", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), }, types.Denoms{ - types.NewDenom("gamm", types.NewTrace("transfer", "channel-0")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), - types.NewDenom("uosmo", types.NewTrace("transfer", "channel-0")), + types.NewDenom("gamm", types.NewHop("transfer", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), + types.NewDenom("uosmo", types.NewHop("transfer", "channel-0")), }, }, { "same base denom and different traces", types.Denoms{ - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), - types.NewDenom("uatom", types.NewTrace("mountain", "channel-0")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52"), types.NewTrace("transfer", "channel-52")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), + types.NewDenom("uatom", types.NewHop("mountain", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52"), types.NewHop("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), types.NewDenom("uatom"), }, types.Denoms{ types.NewDenom("uatom"), - types.NewDenom("uatom", types.NewTrace("mountain", "channel-0")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("mountain", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52"), types.NewHop("transfer", "channel-52")), }, }, { "different base denoms and different traces", types.Denoms{ - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), - types.NewDenom("gamm", types.NewTrace("pool", "channel-0")), - types.NewDenom("gamm", types.NewTrace("pool", "channel-0"), types.NewTrace("transfer", "channel-52")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), + types.NewDenom("gamm", types.NewHop("pool", "channel-0")), + types.NewDenom("gamm", types.NewHop("pool", "channel-0"), types.NewHop("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52"), types.NewHop("transfer", "channel-52")), types.NewDenom("utia"), - types.NewDenom("gamm", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("gamm", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), }, types.Denoms{ - types.NewDenom("gamm", types.NewTrace("pool", "channel-0")), - types.NewDenom("gamm", types.NewTrace("pool", "channel-0"), types.NewTrace("transfer", "channel-52")), - types.NewDenom("gamm", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("gamm", types.NewHop("pool", "channel-0")), + types.NewDenom("gamm", types.NewHop("pool", "channel-0"), types.NewHop("transfer", "channel-52")), + types.NewDenom("gamm", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52"), types.NewHop("transfer", "channel-52")), types.NewDenom("utia"), }, }, @@ -180,7 +183,7 @@ func (suite *TypesTestSuite) TestDenomChainSource() { }{ { "sender chain is source: empty trace", - types.NewDenom("uatom", []types.Trace{}...), + types.NewDenom("uatom", []types.Hop{}...), "transfer", "channel-0", false, @@ -194,21 +197,21 @@ func (suite *TypesTestSuite) TestDenomChainSource() { }, { "sender chain is source: single trace", - types.NewDenom("ubtc", types.NewTrace("transfer", "channel-1")), + types.NewDenom("ubtc", types.NewHop("transfer", "channel-1")), "transfer", "channel-0", false, }, { "sender chain is source: swapped portID and channelID", - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), "channel-0", "transfer", false, }, { "sender chain is source: multi-trace", - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), "transfer", "channel-1", false, @@ -217,7 +220,7 @@ func (suite *TypesTestSuite) TestDenomChainSource() { "receiver chain is source: single trace", types.NewDenom( "factory/stars16da2uus9zrsy83h23ur42v3lglg5rmyrpqnju4/dust", - types.NewTrace("transfer", "channel-0"), + types.NewHop("transfer", "channel-0"), ), "transfer", "channel-0", @@ -225,7 +228,7 @@ func (suite *TypesTestSuite) TestDenomChainSource() { }, { "receiver chain is source: multi-trace", - types.NewDenom("uatom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-52")), + types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), "transfer", "channel-0", true, @@ -239,3 +242,68 @@ func (suite *TypesTestSuite) TestDenomChainSource() { }) } } + +func TestValidateIBCDenom(t *testing.T) { + testCases := []struct { + name string + denom string + expError bool + }{ + {"denom with trace hash", "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false}, + {"base denom", "uatom", false}, + {"base denom ending with '/'", "uatom/", false}, + {"base denom with single '/'s", "gamm/pool/1", false}, + {"base denom with double '/'s", "gamm//pool//1", false}, + {"non-ibc prefix with hash", "notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false}, + {"empty denom", "", true}, + {"denom 'ibc'", "ibc", true}, + {"denom 'ibc/'", "ibc/", true}, + {"invalid hash", "ibc/!@#$!@#", true}, + } + + for _, tc := range testCases { + tc := tc + + err := types.ValidateIBCDenom(tc.denom) + if tc.expError { + require.Error(t, err, tc.name) + continue + } + require.NoError(t, err, tc.name) + } +} + +func TestExtractDenomFromPath(t *testing.T) { + testCases := []struct { + name string + fullPath string + expDenom types.Denom + }{ + {"empty denom", "", types.Denom{}}, + {"base denom no slashes", "atom", types.NewDenom("atom")}, + {"base denom with trailing slash", "atom/", types.NewDenom("atom/")}, + {"base denom multiple trailing slash", "foo///bar//baz/atom/", types.NewDenom("foo///bar//baz/atom/")}, + {"ibc denom one hop", "transfer/channel-0/atom", types.NewDenom("atom", types.NewHop("transfer", "channel-0"))}, + {"ibc denom one hop trailing slash", "transfer/channel-0/atom/", types.NewDenom("atom/", types.NewHop("transfer", "channel-0"))}, + {"ibc denom one hop multiple slashes", "transfer/channel-0//at/om/", types.NewDenom("/at/om/", types.NewHop("transfer", "channel-0"))}, + {"ibc denom two hops", "transfer/channel-0/transfer/channel-60/atom", types.NewDenom("atom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-60"))}, + {"ibc denom two hops trailing slash", "transfer/channel-0/transfer/channel-60/atom/", types.NewDenom("atom/", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-60"))}, + {"empty prefix", "/uatom", types.NewDenom("/uatom")}, + {"empty identifiers", "//uatom", types.NewDenom("//uatom")}, + {"base denom with single '/'", "erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", types.NewDenom("erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA")}, + {"trace info and base denom with single '/'", "transfer/channel-1/erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", types.NewDenom("erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", types.NewHop("transfer", "channel-1"))}, + {"single trace identifier", "transfer/", types.NewDenom("transfer/")}, + {"trace info with custom port", "customtransfer/channel-1/uatom", types.NewDenom("uatom", types.NewHop("customtransfer", "channel-1"))}, + {"invalid path (1)", "channel-1/transfer/uatom", types.NewDenom("channel-1/transfer/uatom")}, + {"invalid path (2)", "transfer/channel-1", types.NewDenom("transfer/channel-1")}, + {"invalid path (3)", "transfer/channel-1/transfer/channel-2", types.NewDenom("", types.NewHop("transfer", "channel-1"), types.NewHop("transfer", "channel-2"))}, + {"invalid path (4)", "transfer/channelToA/uatom", types.NewDenom("transfer/channelToA/uatom")}, + } + + for _, tc := range testCases { + tc := tc + + denom := types.ExtractDenomFromPath(tc.fullPath) + require.Equal(t, tc.expDenom, denom, tc.name) + } +} diff --git a/modules/apps/transfer/types/forwarding.go b/modules/apps/transfer/types/forwarding.go index 9db76e10ad3..2e21c35a4e1 100644 --- a/modules/apps/transfer/types/forwarding.go +++ b/modules/apps/transfer/types/forwarding.go @@ -1,6 +1,8 @@ package types import ( + "fmt" + errorsmod "cosmossdk.io/errors" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" @@ -61,12 +63,18 @@ func (h Hop) Validate() error { return errorsmod.Wrapf(err, "invalid hop source port ID %s", h.PortId) } if err := host.ChannelIdentifierValidator(h.ChannelId); err != nil { - return errorsmod.Wrapf(err, "invalid source channel ID %s", h.ChannelId) + return errorsmod.Wrapf(err, "invalid hop source channel ID %s", h.ChannelId) } return nil } +// String returns the Hop in the format: +// / +func (h Hop) String() string { + return fmt.Sprintf("%s/%s", h.PortId, h.ChannelId) +} + // validateHops performs a basic validation of the hops. // It checks that the number of hops does not exceed the maximum allowed and that each hop is valid. // It will not return any errors if hops is empty. diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index ad348cfe450..286d7f6e4a5 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -177,7 +177,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -193,7 +193,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -209,7 +209,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: largeAmount, }, }, @@ -225,7 +225,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -241,7 +241,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -257,7 +257,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom("", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom("", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -273,7 +273,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: "", }, }, @@ -300,7 +300,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: "0", }, }, @@ -316,7 +316,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: "-100", }, }, @@ -332,7 +332,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: invalidLargeAmount, }, }, @@ -348,7 +348,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -364,7 +364,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -380,7 +380,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: largeAmount, }, }, @@ -396,7 +396,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -412,7 +412,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -431,7 +431,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -450,7 +450,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -466,7 +466,7 @@ func TestFungibleTokenPacketDataV2ValidateBasic(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -504,7 +504,7 @@ func TestGetPacketSender(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -520,7 +520,7 @@ func TestGetPacketSender(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -551,7 +551,7 @@ func TestPacketDataProvider(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -570,7 +570,7 @@ func TestPacketDataProvider(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -589,7 +589,7 @@ func TestPacketDataProvider(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -605,7 +605,7 @@ func TestPacketDataProvider(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -621,7 +621,7 @@ func TestPacketDataProvider(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -637,7 +637,7 @@ func TestPacketDataProvider(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -669,7 +669,7 @@ func TestFungibleTokenPacketDataOmitEmpty(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, @@ -685,7 +685,7 @@ func TestFungibleTokenPacketDataOmitEmpty(t *testing.T) { types.NewFungibleTokenPacketDataV2( []types.Token{ { - Denom: types.NewDenom(denom, types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")), + Denom: types.NewDenom(denom, types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")), Amount: amount, }, }, diff --git a/modules/apps/transfer/types/token.pb.go b/modules/apps/transfer/types/token.pb.go index 82789c743c3..12cdaf22660 100644 --- a/modules/apps/transfer/types/token.pb.go +++ b/modules/apps/transfer/types/token.pb.go @@ -83,7 +83,7 @@ type Denom struct { // the base token denomination Base string `protobuf:"bytes,1,opt,name=base,proto3" json:"base,omitempty"` // the trace of the token - Trace []Trace `protobuf:"bytes,3,rep,name=trace,proto3" json:"trace"` + Trace []Hop `protobuf:"bytes,3,rep,name=trace,proto3" json:"trace"` } func (m *Denom) Reset() { *m = Denom{} } @@ -126,71 +126,16 @@ func (m *Denom) GetBase() string { return "" } -func (m *Denom) GetTrace() []Trace { +func (m *Denom) GetTrace() []Hop { if m != nil { return m.Trace } return nil } -// Trace represents the portID and channelID the token arrived through. -// When a token is sent to a new chain, the portID and channelID of the -// destination chain are added to a token's trace. -type Trace struct { - PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` - ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` -} - -func (m *Trace) Reset() { *m = Trace{} } -func (*Trace) ProtoMessage() {} -func (*Trace) Descriptor() ([]byte, []int) { - return fileDescriptor_732b93aa1330663e, []int{2} -} -func (m *Trace) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Trace) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Trace.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Trace) XXX_Merge(src proto.Message) { - xxx_messageInfo_Trace.Merge(m, src) -} -func (m *Trace) XXX_Size() int { - return m.Size() -} -func (m *Trace) XXX_DiscardUnknown() { - xxx_messageInfo_Trace.DiscardUnknown(m) -} - -var xxx_messageInfo_Trace proto.InternalMessageInfo - -func (m *Trace) GetPortId() string { - if m != nil { - return m.PortId - } - return "" -} - -func (m *Trace) GetChannelId() string { - if m != nil { - return m.ChannelId - } - return "" -} - func init() { proto.RegisterType((*Token)(nil), "ibc.applications.transfer.v2.Token") proto.RegisterType((*Denom)(nil), "ibc.applications.transfer.v2.Denom") - proto.RegisterType((*Trace)(nil), "ibc.applications.transfer.v2.Trace") } func init() { @@ -198,27 +143,25 @@ func init() { } var fileDescriptor_732b93aa1330663e = []byte{ - // 319 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xb1, 0x4b, 0x3b, 0x31, - 0x14, 0xc7, 0xef, 0x7e, 0xed, 0xf5, 0x47, 0xe3, 0x16, 0x44, 0x8b, 0x68, 0x5a, 0xea, 0xd2, 0xc5, - 0x04, 0xea, 0xa0, 0xb8, 0x08, 0x45, 0x87, 0x8e, 0x96, 0x4e, 0x22, 0x68, 0x92, 0x8b, 0xd7, 0x60, - 0x2f, 0xef, 0xb8, 0xa4, 0x05, 0xff, 0x0b, 0x47, 0x47, 0xff, 0x9c, 0x8e, 0x1d, 0x9d, 0x44, 0xda, - 0x7f, 0x44, 0x92, 0x5e, 0xa1, 0x93, 0x6e, 0xef, 0xbd, 0xfb, 0x7c, 0xdf, 0xe7, 0xc8, 0x43, 0x3d, - 0x2d, 0x24, 0xe3, 0x45, 0x31, 0xd5, 0x92, 0x3b, 0x0d, 0xc6, 0x32, 0x57, 0x72, 0x63, 0x9f, 0x55, - 0xc9, 0xe6, 0x7d, 0xe6, 0xe0, 0x45, 0x19, 0x5a, 0x94, 0xe0, 0x00, 0x1f, 0x6b, 0x21, 0xe9, 0x2e, - 0x49, 0xb7, 0x24, 0x9d, 0xf7, 0x8f, 0xf6, 0x33, 0xc8, 0x20, 0x80, 0xcc, 0x57, 0x9b, 0x4c, 0xf7, - 0x09, 0x25, 0x63, 0xbf, 0x02, 0x5f, 0xa3, 0x24, 0x55, 0x06, 0xf2, 0x56, 0xdc, 0x89, 0x7b, 0x7b, - 0xfd, 0x53, 0xfa, 0xdb, 0x32, 0x7a, 0xe3, 0xd1, 0x41, 0x7d, 0xf1, 0xd5, 0x8e, 0x46, 0x9b, 0x1c, - 0x3e, 0x40, 0x0d, 0x9e, 0xc3, 0xcc, 0xb8, 0xd6, 0xbf, 0x4e, 0xdc, 0x6b, 0x8e, 0xaa, 0xae, 0xfb, - 0x80, 0x92, 0x40, 0x63, 0x8c, 0xea, 0x82, 0x5b, 0x15, 0x04, 0xcd, 0x51, 0xa8, 0xbd, 0xd5, 0x95, - 0x5c, 0xaa, 0x56, 0xad, 0x53, 0xfb, 0xdb, 0x3a, 0xf6, 0xe8, 0xd6, 0x1a, 0x72, 0xdd, 0x5b, 0x94, - 0x84, 0x29, 0x3e, 0x44, 0xff, 0x0b, 0x28, 0xdd, 0xa3, 0x4e, 0x2b, 0x41, 0xc3, 0xb7, 0xc3, 0x14, - 0x9f, 0x20, 0x24, 0x27, 0xdc, 0x18, 0x35, 0xf5, 0xdf, 0x36, 0xff, 0xd6, 0xac, 0x26, 0xc3, 0xf4, - 0xaa, 0xfe, 0xfe, 0xd1, 0x8e, 0x06, 0x77, 0x8b, 0x15, 0x89, 0x97, 0x2b, 0x12, 0x7f, 0xaf, 0x48, - 0xfc, 0xb6, 0x26, 0xd1, 0x72, 0x4d, 0xa2, 0xcf, 0x35, 0x89, 0xee, 0x2f, 0x32, 0xed, 0x26, 0x33, - 0x41, 0x25, 0xe4, 0x4c, 0x82, 0xcd, 0xc1, 0x32, 0x2d, 0xe4, 0x59, 0x06, 0x6c, 0x7e, 0xc9, 0x72, - 0x48, 0x67, 0x53, 0x65, 0xfd, 0x79, 0x76, 0xce, 0xe2, 0x5e, 0x0b, 0x65, 0x45, 0x23, 0x3c, 0xf0, - 0xf9, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xba, 0x9e, 0xff, 0x7f, 0xc0, 0x01, 0x00, 0x00, + // 285 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0x41, 0x4b, 0xc3, 0x30, + 0x18, 0x86, 0x1b, 0xb7, 0x0e, 0x96, 0xdd, 0x82, 0xc8, 0x18, 0x12, 0xe7, 0xbc, 0x14, 0xc4, 0x84, + 0xd5, 0x83, 0x5e, 0x44, 0x18, 0x1e, 0xbc, 0x3a, 0x3c, 0xed, 0x64, 0x92, 0xc5, 0x1a, 0x5c, 0xfb, + 0x95, 0x26, 0x1b, 0xf8, 0x2f, 0xfc, 0x59, 0x3b, 0xee, 0xe8, 0x49, 0xa4, 0xfd, 0x23, 0xd2, 0xd4, + 0xc9, 0x4e, 0xbd, 0xbd, 0x09, 0xcf, 0xf7, 0x3e, 0xf0, 0xe2, 0xc8, 0x48, 0xc5, 0x45, 0x9e, 0xaf, + 0x8c, 0x12, 0xce, 0x40, 0x66, 0xb9, 0x2b, 0x44, 0x66, 0x5f, 0x75, 0xc1, 0x37, 0x31, 0x77, 0xf0, + 0xae, 0x33, 0x96, 0x17, 0xe0, 0x80, 0x9c, 0x1a, 0xa9, 0xd8, 0x21, 0xc9, 0xf6, 0x24, 0xdb, 0xc4, + 0xa3, 0xcb, 0x96, 0x9e, 0xe9, 0x7f, 0x6e, 0xaa, 0x46, 0xc7, 0x09, 0x24, 0xe0, 0x23, 0xaf, 0x53, + 0xf3, 0x3b, 0x79, 0xc1, 0xe1, 0x73, 0xed, 0x23, 0xf7, 0x38, 0x5c, 0xea, 0x0c, 0xd2, 0x21, 0x1a, + 0xa3, 0x68, 0x10, 0x5f, 0xb0, 0x36, 0x33, 0x7b, 0xa8, 0xd1, 0x59, 0x77, 0xfb, 0x7d, 0x16, 0xcc, + 0x9b, 0x3b, 0x72, 0x82, 0x7b, 0x22, 0x85, 0x75, 0xe6, 0x86, 0x47, 0x63, 0x14, 0xf5, 0xe7, 0x7f, + 0xaf, 0xc9, 0x02, 0x87, 0x9e, 0x26, 0x04, 0x77, 0xa5, 0xb0, 0xda, 0x0b, 0xfa, 0x73, 0x9f, 0xc9, + 0x1d, 0x0e, 0x5d, 0x21, 0x94, 0x1e, 0x76, 0xc6, 0x9d, 0x68, 0x10, 0x9f, 0xb7, 0x59, 0xa7, 0xec, + 0x11, 0xf2, 0xbd, 0xd3, 0x5f, 0xcd, 0x9e, 0xb6, 0x25, 0x45, 0xbb, 0x92, 0xa2, 0x9f, 0x92, 0xa2, + 0xcf, 0x8a, 0x06, 0xbb, 0x8a, 0x06, 0x5f, 0x15, 0x0d, 0x16, 0x37, 0x89, 0x71, 0x6f, 0x6b, 0xc9, + 0x14, 0xa4, 0x5c, 0x81, 0x4d, 0xc1, 0x72, 0x23, 0xd5, 0x55, 0x02, 0x7c, 0x73, 0xcb, 0x53, 0x58, + 0xae, 0x57, 0xda, 0xd6, 0xd3, 0x1d, 0x4c, 0xe6, 0x3e, 0x72, 0x6d, 0x65, 0xcf, 0xef, 0x72, 0xfd, + 0x1b, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x46, 0xaa, 0xef, 0xa4, 0x01, 0x00, 0x00, } func (m *Token) Marshal() (dAtA []byte, err error) { @@ -305,43 +248,6 @@ func (m *Denom) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *Trace) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Trace) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Trace) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ChannelId) > 0 { - i -= len(m.ChannelId) - copy(dAtA[i:], m.ChannelId) - i = encodeVarintToken(dAtA, i, uint64(len(m.ChannelId))) - i-- - dAtA[i] = 0x12 - } - if len(m.PortId) > 0 { - i -= len(m.PortId) - copy(dAtA[i:], m.PortId) - i = encodeVarintToken(dAtA, i, uint64(len(m.PortId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func encodeVarintToken(dAtA []byte, offset int, v uint64) int { offset -= sovToken(v) base := offset @@ -387,23 +293,6 @@ func (m *Denom) Size() (n int) { return n } -func (m *Trace) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.PortId) - if l > 0 { - n += 1 + l + sovToken(uint64(l)) - } - l = len(m.ChannelId) - if l > 0 { - n += 1 + l + sovToken(uint64(l)) - } - return n -} - func sovToken(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -615,7 +504,7 @@ func (m *Denom) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Trace = append(m.Trace, Trace{}) + m.Trace = append(m.Trace, Hop{}) if err := m.Trace[len(m.Trace)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -641,120 +530,6 @@ func (m *Denom) Unmarshal(dAtA []byte) error { } return nil } -func (m *Trace) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowToken - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Trace: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Trace: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowToken - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthToken - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthToken - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PortId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowToken - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthToken - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthToken - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChannelId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipToken(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthToken - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipToken(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/modules/apps/transfer/types/token_test.go b/modules/apps/transfer/types/token_test.go index 3c9a2f550d6..f349765822b 100644 --- a/modules/apps/transfer/types/token_test.go +++ b/modules/apps/transfer/types/token_test.go @@ -27,9 +27,9 @@ func TestValidate(t *testing.T) { Token{ Denom: Denom{ Base: "atom", - Trace: []Trace{ - NewTrace("transfer", "channel-0"), - NewTrace("transfer", "channel-1"), + Trace: []Hop{ + NewHop("transfer", "channel-0"), + NewHop("transfer", "channel-1"), }, }, Amount: amount, @@ -41,8 +41,8 @@ func TestValidate(t *testing.T) { Token{ Denom: Denom{ Base: "uatom", - Trace: []Trace{ - NewTrace("transfer", "channel-1"), + Trace: []Hop{ + NewHop("transfer", "channel-1"), }, }, Amount: amount, @@ -54,10 +54,10 @@ func TestValidate(t *testing.T) { Token{ Denom: Denom{ Base: "uatom", - Trace: []Trace{ - NewTrace("transfer", "channel-0"), - NewTrace("transfer", "channel-1"), - NewTrace("transfer-custom", "channel-2"), + Trace: []Hop{ + NewHop("transfer", "channel-0"), + NewHop("transfer", "channel-1"), + NewHop("transfer-custom", "channel-2"), }, }, Amount: amount, @@ -77,9 +77,9 @@ func TestValidate(t *testing.T) { Token{ Denom: Denom{ Base: "atom", - Trace: []Trace{ - NewTrace("transfer", "channel-0"), - NewTrace("transfer", "channel-1"), + Trace: []Hop{ + NewHop("transfer", "channel-0"), + NewHop("transfer", "channel-1"), }, }, Amount: "value", @@ -91,9 +91,9 @@ func TestValidate(t *testing.T) { Token{ Denom: Denom{ Base: "atom", - Trace: []Trace{ - NewTrace("transfer", "channel-0"), - NewTrace("transfer", "channel-1"), + Trace: []Hop{ + NewHop("transfer", "channel-0"), + NewHop("transfer", "channel-1"), }, }, Amount: "0", @@ -105,9 +105,9 @@ func TestValidate(t *testing.T) { Token{ Denom: Denom{ Base: "atom", - Trace: []Trace{ - NewTrace("transfer", "channel-0"), - NewTrace("transfer", "channel-1"), + Trace: []Hop{ + NewHop("transfer", "channel-0"), + NewHop("transfer", "channel-1"), }, }, Amount: "-1", @@ -119,25 +119,25 @@ func TestValidate(t *testing.T) { Token{ Denom: Denom{ Base: "uatom", - Trace: []Trace{ - NewTrace("transfer", "channel-1"), - NewTrace("randomport", ""), + Trace: []Hop{ + NewHop("transfer", "channel-1"), + NewHop("randomport", ""), }, }, Amount: amount, }, - fmt.Errorf("invalid token denom: invalid trace: invalid channelID: identifier cannot be blank: invalid identifier"), + fmt.Errorf("invalid token denom: invalid trace: invalid hop source channel ID : identifier cannot be blank: invalid identifier"), }, { "failure: empty identifier in trace", Token{ Denom: Denom{ Base: "uatom", - Trace: []Trace{{}}, + Trace: []Hop{{}}, }, Amount: amount, }, - fmt.Errorf("invalid token denom: invalid trace: invalid portID: identifier cannot be blank: invalid identifier"), + fmt.Errorf("invalid token denom: invalid trace: invalid hop source port ID : identifier cannot be blank: invalid identifier"), }, } @@ -166,7 +166,7 @@ func TestToCoin(t *testing.T) { Token{ Denom: Denom{ Base: denom, - Trace: []Trace{}, + Trace: []Hop{}, }, Amount: amount, }, @@ -178,7 +178,7 @@ func TestToCoin(t *testing.T) { Token{ Denom: Denom{ Base: denom, - Trace: []Trace{}, + Trace: []Hop{}, }, Amount: "value", }, diff --git a/modules/apps/transfer/types/trace.go b/modules/apps/transfer/types/trace.go deleted file mode 100644 index 44e1cd95d41..00000000000 --- a/modules/apps/transfer/types/trace.go +++ /dev/null @@ -1,127 +0,0 @@ -package types - -import ( - "encoding/hex" - "fmt" - "strings" - - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - - cmtbytes "github.com/cometbft/cometbft/libs/bytes" - cmttypes "github.com/cometbft/cometbft/types" - - channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v8/modules/core/24-host" -) - -// NewTrace returns a Trace type -func NewTrace(portID, channelID string) Trace { - return Trace{ - PortId: portID, - ChannelId: channelID, - } -} - -// Validate does basic validation of the trace portID and channelID. -func (t Trace) Validate() error { - if err := host.PortIdentifierValidator(t.PortId); err != nil { - return errorsmod.Wrapf(err, "invalid portID") - } - if err := host.ChannelIdentifierValidator(t.ChannelId); err != nil { - return errorsmod.Wrapf(err, "invalid channelID") - } - return nil -} - -// String returns the Trace in the format: -// / -func (t Trace) String() string { - return fmt.Sprintf("%s/%s", t.PortId, t.ChannelId) -} - -// ExtractDenomFromPath returns the denom from the full path. -// Used to support v1 denoms. -func ExtractDenomFromPath(fullPath string) Denom { - denomSplit := strings.Split(fullPath, "/") - - if denomSplit[0] == fullPath { - return Denom{ - Base: fullPath, - } - } - - var ( - trace []Trace - baseDenomSlice []string - ) - - length := len(denomSplit) - for i := 0; i < length; i += 2 { - // The IBC specification does not guarantee the expected format of the - // destination port or destination channel identifier. A short term solution - // to determine base denomination is to expect the channel identifier to be the - // one ibc-go specifies. A longer term solution is to separate the path and base - // denomination in the ICS20 packet. If an intermediate hop prefixes the full denom - // with a channel identifier format different from our own, the base denomination - // will be incorrectly parsed, but the token will continue to be treated correctly - // as an IBC denomination. The hash used to store the token internally on our chain - // will be the same value as the base denomination being correctly parsed. - if i < length-1 && length > 2 && channeltypes.IsValidChannelID(denomSplit[i+1]) { - trace = append(trace, NewTrace(denomSplit[i], denomSplit[i+1])) - } else { - baseDenomSlice = denomSplit[i:] - break - } - } - - base := strings.Join(baseDenomSlice, "/") - - return Denom{ - Base: base, - Trace: trace, - } -} - -// validateIBCDenom validates that the given denomination is either: -// -// - A valid base denomination (eg: 'uatom' or 'gamm/pool/1' as in https://github.com/cosmos/ibc-go/issues/894) -// - A valid fungible token representation (i.e 'ibc/{hash}') per ADR 001 https://github.com/cosmos/ibc-go/blob/main/docs/architecture/adr-001-coin-source-tracing.md -func validateIBCDenom(denom string) error { - if err := sdk.ValidateDenom(denom); err != nil { - return err - } - - denomSplit := strings.SplitN(denom, "/", 2) - - switch { - case denom == DenomPrefix: - return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) - - case len(denomSplit) == 2 && denomSplit[0] == DenomPrefix: - if strings.TrimSpace(denomSplit[1]) == "" { - return errorsmod.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom) - } - - if _, err := ParseHexHash(denomSplit[1]); err != nil { - return errorsmod.Wrapf(err, "invalid denom trace hash %s", denomSplit[1]) - } - } - - return nil -} - -// ParseHexHash parses a hex hash in string format to bytes and validates its correctness. -func ParseHexHash(hexHash string) (cmtbytes.HexBytes, error) { - hash, err := hex.DecodeString(hexHash) - if err != nil { - return nil, err - } - - if err := cmttypes.ValidateHash(hash); err != nil { - return nil, err - } - - return hash, nil -} diff --git a/modules/apps/transfer/types/trace_test.go b/modules/apps/transfer/types/trace_test.go deleted file mode 100644 index 453fc4e0a55..00000000000 --- a/modules/apps/transfer/types/trace_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package types_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" -) - -func TestValidateIBCDenom(t *testing.T) { - testCases := []struct { - name string - denom string - expError bool - }{ - {"denom with trace hash", "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false}, - {"base denom", "uatom", false}, - {"base denom ending with '/'", "uatom/", false}, - {"base denom with single '/'s", "gamm/pool/1", false}, - {"base denom with double '/'s", "gamm//pool//1", false}, - {"non-ibc prefix with hash", "notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false}, - {"empty denom", "", true}, - {"denom 'ibc'", "ibc", true}, - {"denom 'ibc/'", "ibc/", true}, - {"invalid hash", "ibc/!@#$!@#", true}, - } - - for _, tc := range testCases { - tc := tc - - err := types.ValidateIBCDenom(tc.denom) - if tc.expError { - require.Error(t, err, tc.name) - continue - } - require.NoError(t, err, tc.name) - } -} - -func TestExtractDenomFromPath(t *testing.T) { - testCases := []struct { - name string - fullPath string - expDenom types.Denom - }{ - {"empty denom", "", types.Denom{}}, - {"base denom no slashes", "atom", types.NewDenom("atom")}, - {"base denom with trailing slash", "atom/", types.NewDenom("atom/")}, - {"base denom multiple trailing slash", "foo///bar//baz/atom/", types.NewDenom("foo///bar//baz/atom/")}, - {"ibc denom one hop", "transfer/channel-0/atom", types.NewDenom("atom", types.NewTrace("transfer", "channel-0"))}, - {"ibc denom one hop trailing slash", "transfer/channel-0/atom/", types.NewDenom("atom/", types.NewTrace("transfer", "channel-0"))}, - {"ibc denom one hop multiple slashes", "transfer/channel-0//at/om/", types.NewDenom("/at/om/", types.NewTrace("transfer", "channel-0"))}, - {"ibc denom two hops", "transfer/channel-0/transfer/channel-60/atom", types.NewDenom("atom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-60"))}, - {"ibc denom two hops trailing slash", "transfer/channel-0/transfer/channel-60/atom/", types.NewDenom("atom/", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-60"))}, - {"empty prefix", "/uatom", types.NewDenom("/uatom")}, - {"empty identifiers", "//uatom", types.NewDenom("//uatom")}, - {"base denom with single '/'", "erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", types.NewDenom("erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA")}, - {"trace info and base denom with single '/'", "transfer/channel-1/erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", types.NewDenom("erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", types.NewTrace("transfer", "channel-1"))}, - {"single trace identifier", "transfer/", types.NewDenom("transfer/")}, - {"trace info with custom port", "customtransfer/channel-1/uatom", types.NewDenom("uatom", types.NewTrace("customtransfer", "channel-1"))}, - {"invalid path (1)", "channel-1/transfer/uatom", types.NewDenom("channel-1/transfer/uatom")}, - {"invalid path (2)", "transfer/channel-1", types.NewDenom("transfer/channel-1")}, - {"invalid path (3)", "transfer/channel-1/transfer/channel-2", types.NewDenom("", types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer", "channel-2"))}, - {"invalid path (4)", "transfer/channelToA/uatom", types.NewDenom("transfer/channelToA/uatom")}, - } - - for _, tc := range testCases { - tc := tc - - denom := types.ExtractDenomFromPath(tc.fullPath) - require.Equal(t, tc.expDenom, denom, tc.name) - } -} diff --git a/modules/apps/transfer/types/transfer.pb.go b/modules/apps/transfer/types/transfer.pb.go index f2825d90088..f4b982d6c09 100644 --- a/modules/apps/transfer/types/transfer.pb.go +++ b/modules/apps/transfer/types/transfer.pb.go @@ -147,9 +147,8 @@ type Hop struct { ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` } -func (m *Hop) Reset() { *m = Hop{} } -func (m *Hop) String() string { return proto.CompactTextString(m) } -func (*Hop) ProtoMessage() {} +func (m *Hop) Reset() { *m = Hop{} } +func (*Hop) ProtoMessage() {} func (*Hop) Descriptor() ([]byte, []int) { return fileDescriptor_5041673e96e97901, []int{2} } @@ -205,28 +204,28 @@ func init() { } var fileDescriptor_5041673e96e97901 = []byte{ - // 323 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0x41, 0x4b, 0xc3, 0x30, - 0x14, 0xc7, 0xdb, 0x6d, 0x54, 0x97, 0x89, 0x42, 0x10, 0x1d, 0xa2, 0x75, 0xdb, 0xc5, 0x81, 0xd8, - 0x30, 0x3d, 0x28, 0x88, 0x97, 0x81, 0xb2, 0xdd, 0x74, 0x78, 0xf2, 0x32, 0xd2, 0x34, 0x76, 0x81, - 0x36, 0x2f, 0x24, 0x59, 0x87, 0xdf, 0xc2, 0x8f, 0xb5, 0xe3, 0x8e, 0x9e, 0x44, 0xb6, 0x2f, 0x22, - 0xed, 0xea, 0xd8, 0xc9, 0xdb, 0x7b, 0xbf, 0xf7, 0x7b, 0x8f, 0x90, 0x3f, 0xba, 0x14, 0x21, 0x23, - 0x54, 0xa9, 0x44, 0x30, 0x6a, 0x05, 0x48, 0x43, 0xac, 0xa6, 0xd2, 0xbc, 0x73, 0x4d, 0xb2, 0xde, - 0xa6, 0x0e, 0x94, 0x06, 0x0b, 0xf8, 0x54, 0x84, 0x2c, 0xd8, 0x96, 0x83, 0x8d, 0x90, 0xf5, 0x4e, - 0x0e, 0x63, 0x88, 0xa1, 0x10, 0x49, 0x5e, 0xad, 0x77, 0x3a, 0xaf, 0xc8, 0x7b, 0xa6, 0x9a, 0xa6, - 0x06, 0xb7, 0xd1, 0x9e, 0xe1, 0x32, 0x1a, 0x73, 0x49, 0xc3, 0x84, 0x47, 0x4d, 0xb7, 0xe5, 0x76, - 0x77, 0x47, 0x8d, 0x9c, 0x3d, 0xae, 0x11, 0xbe, 0x40, 0x07, 0x9a, 0x33, 0x2e, 0x32, 0xbe, 0xb1, - 0x2a, 0x85, 0xb5, 0x5f, 0xe2, 0x52, 0xec, 0x50, 0x84, 0x9e, 0x40, 0xcf, 0xa8, 0x8e, 0x84, 0x8c, - 0xf1, 0x11, 0xf2, 0xa6, 0x72, 0x26, 0xe4, 0xdf, 0xcd, 0xb2, 0xc3, 0xf7, 0xa8, 0x36, 0x01, 0x65, - 0x9a, 0x95, 0x56, 0xb5, 0xdb, 0xb8, 0x6e, 0x07, 0xff, 0x3d, 0x3f, 0x18, 0x80, 0xea, 0xd7, 0xe6, - 0xdf, 0xe7, 0xce, 0xa8, 0x58, 0xea, 0x3c, 0xa0, 0xea, 0x00, 0x14, 0x3e, 0x46, 0x3b, 0x0a, 0xb4, - 0x1d, 0x8b, 0xf5, 0xf1, 0xfa, 0xc8, 0xcb, 0xdb, 0x61, 0x84, 0xcf, 0x10, 0x62, 0x13, 0x2a, 0x25, - 0x4f, 0xf2, 0x59, 0xa5, 0x98, 0xd5, 0x4b, 0x32, 0x8c, 0xfa, 0x2f, 0xf3, 0xa5, 0xef, 0x2e, 0x96, - 0xbe, 0xfb, 0xb3, 0xf4, 0xdd, 0xcf, 0x95, 0xef, 0x2c, 0x56, 0xbe, 0xf3, 0xb5, 0xf2, 0x9d, 0xb7, - 0xdb, 0x58, 0xd8, 0xc9, 0x34, 0x0c, 0x18, 0xa4, 0x84, 0x81, 0x49, 0xc1, 0x10, 0x11, 0xb2, 0xab, - 0x18, 0x48, 0x76, 0x47, 0x52, 0x88, 0xa6, 0x09, 0x37, 0x79, 0x24, 0x5b, 0x51, 0xd8, 0x0f, 0xc5, - 0x4d, 0xe8, 0x15, 0x3f, 0x7a, 0xf3, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x94, 0x05, 0x3d, 0x15, 0xb4, - 0x01, 0x00, 0x00, + // 332 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xcf, 0x4a, 0xc3, 0x40, + 0x10, 0x87, 0x93, 0xb6, 0x44, 0xbb, 0x15, 0x85, 0x45, 0xb4, 0x88, 0xa6, 0x7f, 0x2e, 0x16, 0xc4, + 0x2c, 0xd5, 0x83, 0xa2, 0xb7, 0x8a, 0xd2, 0xde, 0xb4, 0x78, 0xf2, 0x52, 0x36, 0x9b, 0x35, 0x5d, + 0x48, 0x76, 0x96, 0xdd, 0x34, 0xc5, 0xb7, 0xf0, 0xe8, 0xd1, 0xc7, 0xe9, 0xb1, 0x47, 0x4f, 0x22, + 0xed, 0x8b, 0x48, 0xd2, 0x58, 0x7a, 0xf2, 0x36, 0xf3, 0xcd, 0x37, 0xc3, 0xb2, 0x3f, 0x74, 0x26, + 0x7c, 0x46, 0xa8, 0x52, 0x91, 0x60, 0x34, 0x11, 0x20, 0x0d, 0x49, 0x34, 0x95, 0xe6, 0x95, 0x6b, + 0x92, 0x76, 0xd7, 0xb5, 0xa7, 0x34, 0x24, 0x80, 0x8f, 0x85, 0xcf, 0xbc, 0x4d, 0xd9, 0x5b, 0x0b, + 0x69, 0xf7, 0x68, 0x3f, 0x84, 0x10, 0x72, 0x91, 0x64, 0xd5, 0x6a, 0xa7, 0xfd, 0x8c, 0x9c, 0x47, + 0xaa, 0x69, 0x6c, 0x70, 0x0b, 0xed, 0x18, 0x2e, 0x83, 0x11, 0x97, 0xd4, 0x8f, 0x78, 0x50, 0xb7, + 0x9b, 0x76, 0x67, 0x7b, 0x58, 0xcb, 0xd8, 0xfd, 0x0a, 0xe1, 0x53, 0xb4, 0xa7, 0x39, 0xe3, 0x22, + 0xe5, 0x6b, 0xab, 0x94, 0x5b, 0xbb, 0x05, 0x2e, 0xc4, 0x36, 0x45, 0xe8, 0x01, 0xf4, 0x94, 0xea, + 0x40, 0xc8, 0x10, 0x1f, 0x20, 0x67, 0x22, 0xa7, 0x42, 0xfe, 0xdd, 0x2c, 0x3a, 0x7c, 0x8b, 0x2a, + 0x63, 0x50, 0xa6, 0x5e, 0x6a, 0x96, 0x3b, 0xb5, 0x8b, 0x96, 0xf7, 0xdf, 0xf3, 0xbd, 0x3e, 0xa8, + 0x5e, 0x65, 0xf6, 0xdd, 0xb0, 0x86, 0xf9, 0x52, 0xfb, 0x0e, 0x95, 0xfb, 0xa0, 0xf0, 0x21, 0xda, + 0x52, 0xa0, 0x93, 0x91, 0x58, 0x1d, 0xaf, 0x0e, 0x9d, 0xac, 0x1d, 0x04, 0xf8, 0x04, 0x21, 0x36, + 0xa6, 0x52, 0xf2, 0x28, 0x9b, 0x95, 0xf2, 0x59, 0xb5, 0x20, 0x83, 0xe0, 0xa6, 0xf2, 0xf1, 0xd9, + 0xb0, 0x7a, 0x4f, 0xb3, 0x85, 0x6b, 0xcf, 0x17, 0xae, 0xfd, 0xb3, 0x70, 0xed, 0xf7, 0xa5, 0x6b, + 0xcd, 0x97, 0xae, 0xf5, 0xb5, 0x74, 0xad, 0x97, 0xab, 0x50, 0x24, 0xe3, 0x89, 0xef, 0x31, 0x88, + 0x09, 0x03, 0x13, 0x83, 0x21, 0xc2, 0x67, 0xe7, 0x21, 0x90, 0xf4, 0x9a, 0xc4, 0x10, 0x4c, 0x22, + 0x6e, 0xb2, 0x60, 0x36, 0x02, 0x49, 0xde, 0x14, 0x37, 0xbe, 0x93, 0xff, 0xeb, 0xe5, 0x6f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x47, 0xd5, 0x1b, 0x06, 0xba, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { diff --git a/proto/ibc/applications/transfer/v1/transfer.proto b/proto/ibc/applications/transfer/v1/transfer.proto index 2c0b942e554..65b443709e2 100644 --- a/proto/ibc/applications/transfer/v1/transfer.proto +++ b/proto/ibc/applications/transfer/v1/transfer.proto @@ -32,6 +32,7 @@ message Forwarding { // Hop defines a port ID, channel ID pair specifying where tokens must be forwarded // next in a multihop transfer. message Hop { - string port_id = 1; - string channel_id = 2; + option (gogoproto.goproto_stringer) = false; + string port_id = 1; + string channel_id = 2; } diff --git a/proto/ibc/applications/transfer/v2/token.proto b/proto/ibc/applications/transfer/v2/token.proto index 3ab833fa7fc..00ebe111adf 100644 --- a/proto/ibc/applications/transfer/v2/token.proto +++ b/proto/ibc/applications/transfer/v2/token.proto @@ -4,6 +4,7 @@ package ibc.applications.transfer.v2; option go_package = "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"; +import "ibc/applications/transfer/v1/transfer.proto"; import "gogoproto/gogo.proto"; // Token defines a struct which represents a token to be transferred. @@ -19,14 +20,5 @@ message Denom { // the base token denomination string base = 1; // the trace of the token - repeated Trace trace = 3 [(gogoproto.nullable) = false]; -} - -// Trace represents the portID and channelID the token arrived through. -// When a token is sent to a new chain, the portID and channelID of the -// destination chain are added to a token's trace. -message Trace { - option (gogoproto.goproto_stringer) = false; - string port_id = 1; - string channel_id = 2; + repeated ibc.applications.transfer.v1.Hop trace = 3 [(gogoproto.nullable) = false]; }