diff --git a/CHANGELOG.md b/CHANGELOG.md index 226f63967b6..e6ff9743461 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking * (core) [\#227](https://github.com/cosmos/ibc-go/pull/227) Remove sdk.Result from application callbacks +* (transfer) [\#350](https://github.com/cosmos/ibc-go/pull/350) Change FungibleTokenPacketData to use a string for the Amount field. This enables token transfers with amounts previously restricted by uint64. Up to the maximum uint256 value is supported. ### State Machine Breaking diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 9b43455b154..f94fbc18457 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -6,7 +6,6 @@ - [ibc/applications/transfer/v1/transfer.proto](#ibc/applications/transfer/v1/transfer.proto) - [DenomTrace](#ibc.applications.transfer.v1.DenomTrace) - - [FungibleTokenPacketData](#ibc.applications.transfer.v1.FungibleTokenPacketData) - [Params](#ibc.applications.transfer.v1.Params) - [ibc/applications/transfer/v1/genesis.proto](#ibc/applications/transfer/v1/genesis.proto) @@ -37,6 +36,9 @@ - [Msg](#ibc.applications.transfer.v1.Msg) +- [ibc/applications/transfer/v2/packet.proto](#ibc/applications/transfer/v2/packet.proto) + - [FungibleTokenPacketData](#ibc.applications.transfer.v2.FungibleTokenPacketData) + - [ibc/core/channel/v1/channel.proto](#ibc/core/channel/v1/channel.proto) - [Acknowledgement](#ibc.core.channel.v1.Acknowledgement) - [Channel](#ibc.core.channel.v1.Channel) @@ -270,26 +272,6 @@ source tracing information path. - - -### FungibleTokenPacketData -FungibleTokenPacketData defines a struct for the packet payload -See FungibleTokenPacketData spec: -https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `denom` | [string](#string) | | the token denomination to be transferred | -| `amount` | [uint64](#uint64) | | the token amount to be transferred | -| `sender` | [string](#string) | | the sender address | -| `receiver` | [string](#string) | | the recipient address on the destination chain | - - - - - - ### Params @@ -675,6 +657,42 @@ Msg defines the ibc/transfer Msg service. + +

Top

+ +## ibc/applications/transfer/v2/packet.proto + + + + + +### FungibleTokenPacketData +FungibleTokenPacketData defines a struct for the packet payload +See FungibleTokenPacketData spec: +https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `denom` | [string](#string) | | the token denomination to be transferred | +| `amount` | [string](#string) | | the token amount to be transferred | +| `sender` | [string](#string) | | the sender address | +| `receiver` | [string](#string) | | the recipient address on the destination chain | + + + + + + + + + + + + + + +

Top

diff --git a/modules/apps/transfer/keeper/MBT_README.md b/modules/apps/transfer/keeper/MBT_README.md index 8a5930f6d39..3cad1e58993 100644 --- a/modules/apps/transfer/keeper/MBT_README.md +++ b/modules/apps/transfer/keeper/MBT_README.md @@ -48,4 +48,4 @@ docker run --rm -v $(pwd):/var/apalache apalache/mc $@ ``` -In case of any questions please don't hesitate to contact Andrey Kuprianov (andrey@informal.systems). \ No newline at end of file +In case of any questions please don't hesitate to contact Andrey Kuprianov (andrey@informal.systems). diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index db425f24507..31d6a3823a5 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -30,7 +30,7 @@ type TlaBalance struct { type TlaFungibleTokenPacketData struct { Sender string `json:"sender"` Receiver string `json:"receiver"` - Amount int `json:"amount"` + Amount string `json:"amount"` Denom []string `json:"denom"` } @@ -143,7 +143,7 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack DestPort: packet.DestPort, Data: types.NewFungibleTokenPacketData( DenomFromTla(packet.Data.Denom), - uint64(packet.Data.Amount), + packet.Data.Amount, AddressFromString(packet.Data.Sender), AddressFromString(packet.Data.Receiver)), } @@ -333,11 +333,15 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { denom := denomTrace.IBCDenom() err = sdk.ValidateDenom(denom) if err == nil { + amount, ok := sdk.NewIntFromString(tc.packet.Data.Amount) + if !ok { + panic("MBT failed to parse amount from string") + } err = suite.chainB.GetSimApp().TransferKeeper.SendTransfer( suite.chainB.GetContext(), tc.packet.SourcePort, tc.packet.SourceChannel, - sdk.NewCoin(denom, sdk.NewIntFromUint64(tc.packet.Data.Amount)), + sdk.NewCoin(denom, amount), sender, tc.packet.Data.Receiver, clienttypes.NewHeight(0, 110), diff --git a/modules/apps/transfer/keeper/model_based_tests/Test5Packets.json b/modules/apps/transfer/keeper/model_based_tests/Test5Packets.json index 6ccdccc8aeb..5cb9e206ea5 100644 --- a/modules/apps/transfer/keeper/model_based_tests/Test5Packets.json +++ b/modules/apps/transfer/keeper/model_based_tests/Test5Packets.json @@ -8,7 +8,7 @@ "data": { "sender": "a3", "receiver": "a3", - "amount": 2, + "amount": "2", "denom": [ "", "", @@ -79,7 +79,7 @@ "data": { "sender": "a1", "receiver": "a3", - "amount": 1, + "amount": "1", "denom": [ "cosmos-hub", "", @@ -165,7 +165,7 @@ "data": { "sender": "a2", "receiver": "a2", - "amount": 4, + "amount": "4", "denom": [ "", "", @@ -266,7 +266,7 @@ "data": { "sender": "", "receiver": "a2", - "amount": 4, + "amount": "4", "denom": [ "", "", @@ -382,7 +382,7 @@ "data": { "sender": "a1", "receiver": "", - "amount": 1, + "amount": "1", "denom": [ "transfer", "channel-0", @@ -489,4 +489,4 @@ ], "error": true } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/Test5PacketsAllDifferentPass.json b/modules/apps/transfer/keeper/model_based_tests/Test5PacketsAllDifferentPass.json index 6a039f3eca4..80370205b15 100644 --- a/modules/apps/transfer/keeper/model_based_tests/Test5PacketsAllDifferentPass.json +++ b/modules/apps/transfer/keeper/model_based_tests/Test5PacketsAllDifferentPass.json @@ -8,7 +8,7 @@ "data": { "sender": "a3", "receiver": "a2", - "amount": 3, + "amount": "3", "denom": [ "", "", @@ -79,7 +79,7 @@ "data": { "sender": "a2", "receiver": "a1", - "amount": 3, + "amount": "3", "denom": [ "transfer", "channel-1", @@ -180,7 +180,7 @@ "data": { "sender": "a1", "receiver": "a2", - "amount": 3, + "amount": "3", "denom": [ "", "", @@ -311,7 +311,7 @@ "data": { "sender": "a1", "receiver": "", - "amount": 2, + "amount": "2", "denom": [ "", "channel-0", @@ -457,7 +457,7 @@ "data": { "sender": "a3", "receiver": "a3", - "amount": 1, + "amount": "1", "denom": [ "", "", @@ -609,4 +609,4 @@ ], "error": false } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorFail.json b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorFail.json index f1f553210b5..d5c89950e2f 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorFail.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorFail.json @@ -8,7 +8,7 @@ "data": { "sender": "a1", "receiver": "a2", - "amount": 1, + "amount": "1", "denom": [ "cosmos-hub", "transfer", @@ -55,4 +55,4 @@ ], "error": true } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorPass.json b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorPass.json index 3fbfe7fdf09..3aeb93ca214 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorPass.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementErrorPass.json @@ -8,7 +8,7 @@ "data": { "sender": "", "receiver": "a1", - "amount": 1, + "amount": "1", "denom": [ "", "", @@ -79,7 +79,7 @@ "data": { "sender": "a1", "receiver": "a2", - "amount": 1, + "amount": "1", "denom": [ "transfer", "channel-1", @@ -156,4 +156,4 @@ ], "error": false } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultFail.json b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultFail.json index 9110a38ab65..b2424d3efc6 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultFail.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultFail.json @@ -8,7 +8,7 @@ "data": { "sender": "a1", "receiver": "a2", - "amount": 1, + "amount": "1", "denom": [ "cosmos-hub", "transfer", @@ -55,4 +55,4 @@ ], "error": true } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultPass.json b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultPass.json index 5215df7da33..1f1135a2d34 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultPass.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvAcknowledgementResultPass.json @@ -8,7 +8,7 @@ "data": { "sender": "a1", "receiver": "a2", - "amount": 1, + "amount": "1", "denom": [ "cosmos-hub", "transfer", @@ -55,4 +55,4 @@ ], "error": false } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketFail.json b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketFail.json index 9a7e8c406e7..f683c8fac8c 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketFail.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketFail.json @@ -8,7 +8,7 @@ "data": { "sender": "", "receiver": "", - "amount": 1, + "amount": "1", "denom": [ "", "", @@ -55,4 +55,4 @@ ], "error": true } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketPass.json b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketPass.json index 35f94c57208..6da859106d8 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketPass.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnRecvPacketPass.json @@ -8,7 +8,7 @@ "data": { "sender": "", "receiver": "a2", - "amount": 1, + "amount": "1", "denom": [ "", "", @@ -70,4 +70,4 @@ ], "error": false } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutFail.json b/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutFail.json index a78ed85ca58..8b7c8228065 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutFail.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutFail.json @@ -8,7 +8,7 @@ "data": { "sender": "a1", "receiver": "a2", - "amount": 1, + "amount": "1", "denom": [ "cosmos-hub", "transfer", @@ -55,4 +55,4 @@ ], "error": true } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutPass.json b/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutPass.json index 3136aace654..33d9c1a4e59 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutPass.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestOnTimeoutPass.json @@ -8,7 +8,7 @@ "data": { "sender": "a3", "receiver": "a1", - "amount": 1, + "amount": "1", "denom": [ "", "", @@ -79,7 +79,7 @@ "data": { "sender": "a1", "receiver": "", - "amount": 1, + "amount": "1", "denom": [ "transfer", "channel-1", @@ -156,4 +156,4 @@ ], "error": false } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestSendTransferFail.json b/modules/apps/transfer/keeper/model_based_tests/TestSendTransferFail.json index 01d589d8677..4c3412e3ba8 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestSendTransferFail.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestSendTransferFail.json @@ -8,7 +8,7 @@ "data": { "sender": "", "receiver": "", - "amount": 1, + "amount": "1", "denom": [ "", "", @@ -55,4 +55,4 @@ ], "error": true } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestSendTransferPass.json b/modules/apps/transfer/keeper/model_based_tests/TestSendTransferPass.json index 452d2b3aa94..492b59ae969 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestSendTransferPass.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestSendTransferPass.json @@ -8,7 +8,7 @@ "data": { "sender": "a3", "receiver": "a2", - "amount": 1, + "amount": "1", "denom": [ "", "", @@ -79,7 +79,7 @@ "data": { "sender": "a2", "receiver": "a1", - "amount": 1, + "amount": "1", "denom": [ "transfer", "channel-0", @@ -171,4 +171,4 @@ ], "error": false } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/model_based_tests/TestUnescrowTokens.json b/modules/apps/transfer/keeper/model_based_tests/TestUnescrowTokens.json index 98552207047..b4ebe81c70d 100644 --- a/modules/apps/transfer/keeper/model_based_tests/TestUnescrowTokens.json +++ b/modules/apps/transfer/keeper/model_based_tests/TestUnescrowTokens.json @@ -8,7 +8,7 @@ "data": { "sender": "a1", "receiver": "a3", - "amount": 5, + "amount": "5", "denom": [ "", "", @@ -79,7 +79,7 @@ "data": { "sender": "a3", "receiver": "a1", - "amount": 3, + "amount": "3", "denom": [ "", "", @@ -180,7 +180,7 @@ "data": { "sender": "a1", "receiver": "a1", - "amount": 1, + "amount": "1", "denom": [ "transfer", "channel-0", @@ -302,4 +302,4 @@ ], "error": false } -] \ No newline at end of file +] diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 161295d0b70..5f9090a082b 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -5,10 +5,10 @@ import ( "strings" "github.com/armon/go-metrics" - "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/ibc-go/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" @@ -144,7 +144,7 @@ func (k Keeper) SendTransfer( } packetData := types.NewFungibleTokenPacketData( - fullDenomPath, token.Amount.Uint64(), sender.String(), receiver, + fullDenomPath, token.Amount.String(), sender.String(), receiver, ) packet := channeltypes.NewPacket( @@ -163,11 +163,13 @@ func (k Keeper) SendTransfer( } defer func() { - telemetry.SetGaugeWithLabels( - []string{"tx", "msg", "ibc", "transfer"}, - float32(token.Amount.Int64()), - []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, fullDenomPath)}, - ) + if token.Amount.IsInt64() { + telemetry.SetGaugeWithLabels( + []string{"tx", "msg", "ibc", "transfer"}, + float32(token.Amount.Int64()), + []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, fullDenomPath)}, + ) + } telemetry.IncrCounterWithLabels( []string{"ibc", types.ModuleName, "send"}, @@ -200,6 +202,12 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t return err } + // parse the transfer amount + transferAmount, ok := sdk.NewIntFromString(data.Amount) + if !ok { + return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into sdk.Int", data.Amount) + } + labels := []metrics.Label{ telemetry.NewLabel(coretypes.LabelSourcePort, packet.GetSourcePort()), telemetry.NewLabel(coretypes.LabelSourceChannel, packet.GetSourceChannel()), @@ -229,7 +237,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t if denomTrace.Path != "" { denom = denomTrace.IBCDenom() } - token := sdk.NewCoin(denom, sdk.NewIntFromUint64(data.Amount)) + token := sdk.NewCoin(denom, transferAmount) // unescrow tokens escrowAddress := types.GetEscrowAddress(packet.GetDestPort(), packet.GetDestChannel()) @@ -242,11 +250,13 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t } defer func() { - telemetry.SetGaugeWithLabels( - []string{"ibc", types.ModuleName, "packet", "receive"}, - float32(data.Amount), - []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, unprefixedDenom)}, - ) + if transferAmount.IsInt64() { + telemetry.SetGaugeWithLabels( + []string{"ibc", types.ModuleName, "packet", "receive"}, + float32(transferAmount.Int64()), + []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, unprefixedDenom)}, + ) + } telemetry.IncrCounterWithLabels( []string{"ibc", types.ModuleName, "receive"}, @@ -283,8 +293,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t sdk.NewAttribute(types.AttributeKeyDenom, voucherDenom), ), ) - - voucher := sdk.NewCoin(voucherDenom, sdk.NewIntFromUint64(data.Amount)) + voucher := sdk.NewCoin(voucherDenom, transferAmount) // mint new tokens if the source of the transfer is the same chain if err := k.bankKeeper.MintCoins( @@ -301,11 +310,13 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t } defer func() { - telemetry.SetGaugeWithLabels( - []string{"ibc", types.ModuleName, "packet", "receive"}, - float32(data.Amount), - []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, data.Denom)}, - ) + if transferAmount.IsInt64() { + telemetry.SetGaugeWithLabels( + []string{"ibc", types.ModuleName, "packet", "receive"}, + float32(transferAmount.Int64()), + []metrics.Label{telemetry.NewLabel(coretypes.LabelDenom, data.Denom)}, + ) + } telemetry.IncrCounterWithLabels( []string{"ibc", types.ModuleName, "receive"}, @@ -350,7 +361,12 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // parse the denomination from the full denom path trace := types.ParseDenomTrace(data.Denom) - token := sdk.NewCoin(trace.IBCDenom(), sdk.NewIntFromUint64(data.Amount)) + // parse the transfer amount + transferAmount, ok := sdk.NewIntFromString(data.Amount) + if !ok { + return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into sdk.Int", data.Amount) + } + token := sdk.NewCoin(trace.IBCDenom(), transferAmount) // decode the sender address sender, err := sdk.AccAddressFromBech32(data.Sender) diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 4c383f0948f..02959303ab2 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -37,7 +37,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { func() { // send coin from chainA back to chainB suite.coordinator.CreateTransferChannels(path) - amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.DefaultBondDenom, 100) + amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.DefaultBondDenom, sdk.NewInt(100)) }, false, true}, {"source channel not found", func() { @@ -71,7 +71,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { {"send from module account failed", func() { suite.coordinator.CreateTransferChannels(path) - amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, " randomdenom", 100) + amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, " randomdenom", sdk.NewInt(100)) }, false, false}, {"channel capability not found", func() { @@ -102,7 +102,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { suite.Require().NoError(err) // message committed // receive coin on chainA from chainB - fungibleTokenPacket := types.NewFungibleTokenPacketData(coinFromBToA.Denom, coinFromBToA.Amount.Uint64(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String()) + fungibleTokenPacket := types.NewFungibleTokenPacketData(coinFromBToA.Denom, coinFromBToA.Amount.String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String()) packet := channeltypes.NewPacket(fungibleTokenPacket.GetBytes(), 1, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, clienttypes.NewHeight(0, 110), 0) // get proof of packet commitment from chainB @@ -190,7 +190,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { suite.Require().NoError(err) // message committed // relay send packet - fungibleTokenPacket := types.NewFungibleTokenPacketData(coinFromBToA.Denom, coinFromBToA.Amount.Uint64(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String()) + fungibleTokenPacket := types.NewFungibleTokenPacketData(coinFromBToA.Denom, coinFromBToA.Amount.String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String()) packet := channeltypes.NewPacket(fungibleTokenPacket.GetBytes(), 1, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, clienttypes.NewHeight(0, 110), 0) ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) err = path.RelayPacket(packet, ack.Acknowledgement()) @@ -211,7 +211,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { tc.malleate() - data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.Uint64(), suite.chainA.SenderAccount.GetAddress().String(), receiver) + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), receiver) packet := channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(0, 100), 0) err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -280,7 +280,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { tc.malleate() - data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.Uint64(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(0, 100), 0) preCoin := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), trace.IBCDenom()) @@ -366,7 +366,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { tc.malleate() - data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.Uint64(), sender, suite.chainB.SenderAccount.GetAddress().String()) + data := types.NewFungibleTokenPacketData(trace.GetFullDenomPath(), amount.String(), sender, suite.chainB.SenderAccount.GetAddress().String()) packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(0, 100), 0) preCoin := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), trace.IBCDenom()) diff --git a/modules/apps/transfer/module.go b/modules/apps/transfer/module.go index 72575d0c602..79309b2fb8b 100644 --- a/modules/apps/transfer/module.go +++ b/modules/apps/transfer/module.go @@ -347,7 +347,7 @@ func (am AppModule) OnRecvPacket( sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), sdk.NewAttribute(types.AttributeKeyDenom, data.Denom), - sdk.NewAttribute(types.AttributeKeyAmount, fmt.Sprintf("%d", data.Amount)), + sdk.NewAttribute(types.AttributeKeyAmount, data.Amount), sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())), ), ) @@ -382,7 +382,7 @@ func (am AppModule) OnAcknowledgementPacket( sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver), sdk.NewAttribute(types.AttributeKeyDenom, data.Denom), - sdk.NewAttribute(types.AttributeKeyAmount, fmt.Sprintf("%d", data.Amount)), + sdk.NewAttribute(types.AttributeKeyAmount, data.Amount), sdk.NewAttribute(types.AttributeKeyAck, ack.String()), ), ) @@ -428,7 +428,7 @@ func (am AppModule) OnTimeoutPacket( sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(types.AttributeKeyRefundReceiver, data.Sender), sdk.NewAttribute(types.AttributeKeyRefundDenom, data.Denom), - sdk.NewAttribute(types.AttributeKeyRefundAmount, fmt.Sprintf("%d", data.Amount)), + sdk.NewAttribute(types.AttributeKeyRefundAmount, data.Amount), ), ) diff --git a/modules/apps/transfer/transfer_test.go b/modules/apps/transfer/transfer_test.go index 030fb1bd14c..948a6b2cf4b 100644 --- a/modules/apps/transfer/transfer_test.go +++ b/modules/apps/transfer/transfer_test.go @@ -48,7 +48,9 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { // originalBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom) timeoutHeight := clienttypes.NewHeight(0, 110) - coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) + amount, ok := sdk.NewIntFromString("9223372036854775808") // 2^63 (one above int64) + suite.Require().True(ok) + coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, amount) // send from chainA to chainB msg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coinToSendToB, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0) @@ -57,7 +59,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { suite.Require().NoError(err) // message committed // relay send - fungibleTokenPacket := types.NewFungibleTokenPacketData(coinToSendToB.Denom, coinToSendToB.Amount.Uint64(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) + fungibleTokenPacket := types.NewFungibleTokenPacketData(coinToSendToB.Denom, coinToSendToB.Amount.String(), suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) packet := channeltypes.NewPacket(fungibleTokenPacket.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0) ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) err = path.RelayPacket(packet, ack.Acknowledgement()) @@ -67,7 +69,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { voucherDenomTrace := types.ParseDenomTrace(types.GetPrefixedDenom(packet.GetDestPort(), packet.GetDestChannel(), sdk.DefaultBondDenom)) balance := suite.chainB.GetSimApp().BankKeeper.GetBalance(suite.chainB.GetContext(), suite.chainB.SenderAccount.GetAddress(), voucherDenomTrace.IBCDenom()) - coinSentFromAToB := types.GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.DefaultBondDenom, 100) + coinSentFromAToB := types.GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sdk.DefaultBondDenom, amount) suite.Require().Equal(coinSentFromAToB, balance) // setup between chainB to chainC @@ -86,12 +88,12 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { // relay send // NOTE: fungible token is prefixed with the full trace in order to verify the packet commitment fullDenomPath := types.GetPrefixedDenom(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, voucherDenomTrace.GetFullDenomPath()) - fungibleTokenPacket = types.NewFungibleTokenPacketData(voucherDenomTrace.GetFullDenomPath(), coinSentFromAToB.Amount.Uint64(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String()) + fungibleTokenPacket = types.NewFungibleTokenPacketData(voucherDenomTrace.GetFullDenomPath(), coinSentFromAToB.Amount.String(), suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String()) packet = channeltypes.NewPacket(fungibleTokenPacket.GetBytes(), 1, pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, timeoutHeight, 0) err = pathBtoC.RelayPacket(packet, ack.Acknowledgement()) suite.Require().NoError(err) // relay committed - coinSentFromBToC := sdk.NewInt64Coin(types.ParseDenomTrace(fullDenomPath).IBCDenom(), 100) + coinSentFromBToC := sdk.NewCoin(types.ParseDenomTrace(fullDenomPath).IBCDenom(), amount) balance = suite.chainC.GetSimApp().BankKeeper.GetBalance(suite.chainC.GetContext(), suite.chainC.SenderAccount.GetAddress(), coinSentFromBToC.Denom) // check that the balance is updated on chainC @@ -109,7 +111,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { // relay send // NOTE: fungible token is prefixed with the full trace in order to verify the packet commitment - fungibleTokenPacket = types.NewFungibleTokenPacketData(fullDenomPath, coinSentFromBToC.Amount.Uint64(), suite.chainC.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) + fungibleTokenPacket = types.NewFungibleTokenPacketData(fullDenomPath, coinSentFromBToC.Amount.String(), suite.chainC.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String()) packet = channeltypes.NewPacket(fungibleTokenPacket.GetBytes(), 1, pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, timeoutHeight, 0) err = pathBtoC.RelayPacket(packet, ack.Acknowledgement()) suite.Require().NoError(err) // relay committed diff --git a/modules/apps/transfer/types/coin.go b/modules/apps/transfer/types/coin.go index 08ae9a8d325..a3491e2bf09 100644 --- a/modules/apps/transfer/types/coin.go +++ b/modules/apps/transfer/types/coin.go @@ -42,7 +42,7 @@ func GetPrefixedDenom(portID, channelID, baseDenom string) string { // GetTransferCoin creates a transfer coin with the port ID and channel ID // prefixed to the base denom. -func GetTransferCoin(portID, channelID, baseDenom string, amount int64) sdk.Coin { +func GetTransferCoin(portID, channelID, baseDenom string, amount sdk.Int) sdk.Coin { denomTrace := ParseDenomTrace(GetPrefixedDenom(portID, channelID, baseDenom)) - return sdk.NewInt64Coin(denomTrace.IBCDenom(), amount) + return sdk.NewCoin(denomTrace.IBCDenom(), amount) } diff --git a/modules/apps/transfer/types/packet.go b/modules/apps/transfer/types/packet.go index d726577f6f5..a7384c47486 100644 --- a/modules/apps/transfer/types/packet.go +++ b/modules/apps/transfer/types/packet.go @@ -23,7 +23,7 @@ var ( // NewFungibleTokenPacketData contructs a new FungibleTokenPacketData instance func NewFungibleTokenPacketData( - denom string, amount uint64, + denom string, amount string, sender, receiver string, ) FungibleTokenPacketData { return FungibleTokenPacketData{ @@ -38,8 +38,12 @@ func NewFungibleTokenPacketData( // NOTE: The addresses formats are not validated as the sender and recipient can have different // formats defined by their corresponding chains that are not known to IBC. func (ftpd FungibleTokenPacketData) ValidateBasic() error { - if ftpd.Amount == 0 { - return sdkerrors.Wrap(ErrInvalidAmount, "amount cannot be 0") + amount, ok := sdk.NewIntFromString(ftpd.Amount) + if !ok { + return sdkerrors.Wrapf(ErrInvalidAmount, "unable to parse transfer amount (%s) into sdk.Int", ftpd.Amount) + } + if !amount.IsPositive() { + return sdkerrors.Wrapf(ErrInvalidAmount, "amount must be strictly positive: got %d", amount) } if strings.TrimSpace(ftpd.Sender) == "" { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be blank") diff --git a/modules/apps/transfer/types/packet.pb.go b/modules/apps/transfer/types/packet.pb.go new file mode 100644 index 00000000000..486545b551f --- /dev/null +++ b/modules/apps/transfer/types/packet.pb.go @@ -0,0 +1,481 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/transfer/v2/packet.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// FungibleTokenPacketData defines a struct for the packet payload +// See FungibleTokenPacketData spec: +// https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures +type FungibleTokenPacketData struct { + // the token denomination to be transferred + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` + // the token amount to be transferred + Amount string `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount,omitempty"` + // the sender address + Sender string `protobuf:"bytes,3,opt,name=sender,proto3" json:"sender,omitempty"` + // the recipient address on the destination chain + Receiver string `protobuf:"bytes,4,opt,name=receiver,proto3" json:"receiver,omitempty"` +} + +func (m *FungibleTokenPacketData) Reset() { *m = FungibleTokenPacketData{} } +func (m *FungibleTokenPacketData) String() string { return proto.CompactTextString(m) } +func (*FungibleTokenPacketData) ProtoMessage() {} +func (*FungibleTokenPacketData) Descriptor() ([]byte, []int) { + return fileDescriptor_653ca2ce9a5ca313, []int{0} +} +func (m *FungibleTokenPacketData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FungibleTokenPacketData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FungibleTokenPacketData.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 *FungibleTokenPacketData) XXX_Merge(src proto.Message) { + xxx_messageInfo_FungibleTokenPacketData.Merge(m, src) +} +func (m *FungibleTokenPacketData) XXX_Size() int { + return m.Size() +} +func (m *FungibleTokenPacketData) XXX_DiscardUnknown() { + xxx_messageInfo_FungibleTokenPacketData.DiscardUnknown(m) +} + +var xxx_messageInfo_FungibleTokenPacketData proto.InternalMessageInfo + +func (m *FungibleTokenPacketData) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *FungibleTokenPacketData) GetAmount() string { + if m != nil { + return m.Amount + } + return "" +} + +func (m *FungibleTokenPacketData) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *FungibleTokenPacketData) GetReceiver() string { + if m != nil { + return m.Receiver + } + return "" +} + +func init() { + proto.RegisterType((*FungibleTokenPacketData)(nil), "ibc.applications.transfer.v2.FungibleTokenPacketData") +} + +func init() { + proto.RegisterFile("ibc/applications/transfer/v2/packet.proto", fileDescriptor_653ca2ce9a5ca313) +} + +var fileDescriptor_653ca2ce9a5ca313 = []byte{ + // 239 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x8f, 0xbf, 0x4a, 0xc5, 0x30, + 0x14, 0x87, 0x1b, 0xff, 0x5c, 0x34, 0x63, 0x11, 0x2d, 0x22, 0x41, 0x9c, 0x74, 0x30, 0x81, 0xab, + 0x4f, 0x20, 0xe2, 0x28, 0x22, 0x4e, 0x6e, 0x49, 0x7a, 0xac, 0xe1, 0x36, 0x39, 0x21, 0x49, 0x0b, + 0xe2, 0x4b, 0xf8, 0x58, 0x8e, 0x77, 0x74, 0x94, 0xf6, 0x45, 0xe4, 0xa6, 0x2a, 0x1d, 0xbf, 0xef, + 0xfc, 0xce, 0xf0, 0xd1, 0x0b, 0xa3, 0xb4, 0x90, 0xde, 0xb7, 0x46, 0xcb, 0x64, 0xd0, 0x45, 0x91, + 0x82, 0x74, 0xf1, 0x05, 0x82, 0xe8, 0x97, 0xc2, 0x4b, 0xbd, 0x82, 0xc4, 0x7d, 0xc0, 0x84, 0xe5, + 0x89, 0x51, 0x9a, 0xcf, 0xa7, 0xfc, 0x6f, 0xca, 0xfb, 0xe5, 0xd9, 0x3b, 0x3d, 0xba, 0xeb, 0x5c, + 0x63, 0x54, 0x0b, 0x4f, 0xb8, 0x02, 0xf7, 0x90, 0x5f, 0x6f, 0x65, 0x92, 0xe5, 0x01, 0xdd, 0xad, + 0xc1, 0xa1, 0xad, 0xc8, 0x29, 0x39, 0xdf, 0x7f, 0x9c, 0xa0, 0x3c, 0xa4, 0x0b, 0x69, 0xb1, 0x73, + 0xa9, 0xda, 0xca, 0xfa, 0x97, 0x36, 0x3e, 0x82, 0xab, 0x21, 0x54, 0xdb, 0x93, 0x9f, 0xa8, 0x3c, + 0xa6, 0x7b, 0x01, 0x34, 0x98, 0x1e, 0x42, 0xb5, 0x93, 0x2f, 0xff, 0x7c, 0x73, 0xff, 0x39, 0x30, + 0xb2, 0x1e, 0x18, 0xf9, 0x1e, 0x18, 0xf9, 0x18, 0x59, 0xb1, 0x1e, 0x59, 0xf1, 0x35, 0xb2, 0xe2, + 0xf9, 0xba, 0x31, 0xe9, 0xb5, 0x53, 0x5c, 0xa3, 0x15, 0x1a, 0xa3, 0xc5, 0x28, 0x8c, 0xd2, 0x97, + 0x0d, 0x0a, 0x8b, 0x75, 0xd7, 0x42, 0xdc, 0xc4, 0xcf, 0xa2, 0xd3, 0x9b, 0x87, 0xa8, 0x16, 0xb9, + 0xf8, 0xea, 0x27, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x65, 0xe9, 0x98, 0x1e, 0x01, 0x00, 0x00, +} + +func (m *FungibleTokenPacketData) 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 *FungibleTokenPacketData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FungibleTokenPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Receiver) > 0 { + i -= len(m.Receiver) + copy(dAtA[i:], m.Receiver) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Receiver))) + i-- + dAtA[i] = 0x22 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0x1a + } + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0x12 + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPacket(dAtA []byte, offset int, v uint64) int { + offset -= sovPacket(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *FungibleTokenPacketData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.Receiver) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + return n +} + +func sovPacket(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPacket(x uint64) (n int) { + return sovPacket(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *FungibleTokenPacketData) 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 ErrIntOverflowPacket + } + 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: FungibleTokenPacketData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FungibleTokenPacketData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + 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 ErrInvalidLengthPacket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + 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 ErrInvalidLengthPacket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + 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 ErrInvalidLengthPacket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + 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 ErrInvalidLengthPacket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Receiver = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPacket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPacket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPacket(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPacket + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPacket + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPacket + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPacket + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPacket + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPacket + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPacket = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPacket = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPacket = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index 6b16095b0b5..e5d21d648d2 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -7,8 +7,10 @@ import ( ) const ( - denom = "transfer/gaiachannel/atom" - amount = uint64(100) + denom = "transfer/gaiachannel/atom" + amount = "100" + largeAmount = "18446744073709551616" // one greater than largest uint64 (^uint64(0)) + invalidLargeAmount = "115792089237316195423570985008687907853269984665640564039457584007913129639936" // 2^256 ) // TestFungibleTokenPacketDataValidateBasic tests ValidateBasic for FungibleTokenPacketData @@ -19,8 +21,12 @@ func TestFungibleTokenPacketDataValidateBasic(t *testing.T) { expPass bool }{ {"valid packet", NewFungibleTokenPacketData(denom, amount, addr1, addr2), true}, + {"valid packet with large amount", NewFungibleTokenPacketData(denom, largeAmount, addr1, addr2), true}, {"invalid denom", NewFungibleTokenPacketData("", amount, addr1, addr2), false}, - {"invalid amount", NewFungibleTokenPacketData(denom, 0, addr1, addr2), false}, + {"invalid empty amount", NewFungibleTokenPacketData(denom, "", addr1, addr2), false}, + {"invalid zero amount", NewFungibleTokenPacketData(denom, "0", addr1, addr2), false}, + {"invalid negative amount", NewFungibleTokenPacketData(denom, "-1", addr1, addr2), false}, + {"invalid large amount", NewFungibleTokenPacketData(denom, invalidLargeAmount, addr1, addr2), false}, {"missing sender address", NewFungibleTokenPacketData(denom, amount, emptyAddr, addr2), false}, {"missing recipient address", NewFungibleTokenPacketData(denom, amount, addr1, emptyAddr), false}, } diff --git a/modules/apps/transfer/types/transfer.pb.go b/modules/apps/transfer/types/transfer.pb.go index f03b128f053..95df2214710 100644 --- a/modules/apps/transfer/types/transfer.pb.go +++ b/modules/apps/transfer/types/transfer.pb.go @@ -23,81 +23,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// FungibleTokenPacketData defines a struct for the packet payload -// See FungibleTokenPacketData spec: -// https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures -type FungibleTokenPacketData struct { - // the token denomination to be transferred - Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` - // the token amount to be transferred - Amount uint64 `protobuf:"varint,2,opt,name=amount,proto3" json:"amount,omitempty"` - // the sender address - Sender string `protobuf:"bytes,3,opt,name=sender,proto3" json:"sender,omitempty"` - // the recipient address on the destination chain - Receiver string `protobuf:"bytes,4,opt,name=receiver,proto3" json:"receiver,omitempty"` -} - -func (m *FungibleTokenPacketData) Reset() { *m = FungibleTokenPacketData{} } -func (m *FungibleTokenPacketData) String() string { return proto.CompactTextString(m) } -func (*FungibleTokenPacketData) ProtoMessage() {} -func (*FungibleTokenPacketData) Descriptor() ([]byte, []int) { - return fileDescriptor_5041673e96e97901, []int{0} -} -func (m *FungibleTokenPacketData) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *FungibleTokenPacketData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_FungibleTokenPacketData.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 *FungibleTokenPacketData) XXX_Merge(src proto.Message) { - xxx_messageInfo_FungibleTokenPacketData.Merge(m, src) -} -func (m *FungibleTokenPacketData) XXX_Size() int { - return m.Size() -} -func (m *FungibleTokenPacketData) XXX_DiscardUnknown() { - xxx_messageInfo_FungibleTokenPacketData.DiscardUnknown(m) -} - -var xxx_messageInfo_FungibleTokenPacketData proto.InternalMessageInfo - -func (m *FungibleTokenPacketData) GetDenom() string { - if m != nil { - return m.Denom - } - return "" -} - -func (m *FungibleTokenPacketData) GetAmount() uint64 { - if m != nil { - return m.Amount - } - return 0 -} - -func (m *FungibleTokenPacketData) GetSender() string { - if m != nil { - return m.Sender - } - return "" -} - -func (m *FungibleTokenPacketData) GetReceiver() string { - if m != nil { - return m.Receiver - } - return "" -} - // DenomTrace contains the base denomination for ICS20 fungible tokens and the // source tracing information path. type DenomTrace struct { @@ -112,7 +37,7 @@ func (m *DenomTrace) Reset() { *m = DenomTrace{} } func (m *DenomTrace) String() string { return proto.CompactTextString(m) } func (*DenomTrace) ProtoMessage() {} func (*DenomTrace) Descriptor() ([]byte, []int) { - return fileDescriptor_5041673e96e97901, []int{1} + return fileDescriptor_5041673e96e97901, []int{0} } func (m *DenomTrace) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -172,7 +97,7 @@ func (m *Params) Reset() { *m = Params{} } func (m *Params) String() string { return proto.CompactTextString(m) } func (*Params) ProtoMessage() {} func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_5041673e96e97901, []int{2} + return fileDescriptor_5041673e96e97901, []int{1} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -216,7 +141,6 @@ func (m *Params) GetReceiveEnabled() bool { } func init() { - proto.RegisterType((*FungibleTokenPacketData)(nil), "ibc.applications.transfer.v1.FungibleTokenPacketData") proto.RegisterType((*DenomTrace)(nil), "ibc.applications.transfer.v1.DenomTrace") proto.RegisterType((*Params)(nil), "ibc.applications.transfer.v1.Params") } @@ -226,79 +150,26 @@ func init() { } var fileDescriptor_5041673e96e97901 = []byte{ - // 365 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x91, 0xc1, 0xaa, 0xda, 0x40, - 0x14, 0x86, 0x8d, 0xb5, 0xa2, 0xd3, 0xd2, 0xc2, 0x54, 0x34, 0x48, 0x1b, 0x25, 0x2b, 0xa1, 0x34, - 0x41, 0xda, 0x95, 0x9b, 0x82, 0xb5, 0x5d, 0x16, 0x09, 0xae, 0xba, 0x91, 0x99, 0xc9, 0x69, 0x1c, - 0x4c, 0x66, 0xc2, 0xcc, 0x44, 0x90, 0x3e, 0x41, 0x77, 0x7d, 0xac, 0x2e, 0x5d, 0xde, 0x95, 0x5c, - 0xf4, 0x0d, 0x7c, 0x82, 0x4b, 0x26, 0x21, 0xc8, 0xdd, 0x9d, 0xef, 0x9c, 0xff, 0x3f, 0xe7, 0xc0, - 0x8f, 0x3e, 0x72, 0xca, 0x42, 0x92, 0xe7, 0x29, 0x67, 0xc4, 0x70, 0x29, 0x74, 0x68, 0x14, 0x11, - 0xfa, 0x37, 0xa8, 0xf0, 0x30, 0x6f, 0xea, 0x20, 0x57, 0xd2, 0x48, 0xfc, 0x9e, 0x53, 0x16, 0xdc, - 0x8b, 0x83, 0x46, 0x70, 0x98, 0x8f, 0x07, 0x89, 0x4c, 0xa4, 0x15, 0x86, 0x65, 0x55, 0x79, 0xfc, - 0x3f, 0x68, 0xf4, 0xa3, 0x10, 0x09, 0xa7, 0x29, 0x6c, 0xe4, 0x1e, 0xc4, 0x9a, 0xb0, 0x3d, 0x98, - 0x15, 0x31, 0x04, 0x0f, 0xd0, 0xcb, 0x18, 0x84, 0xcc, 0x5c, 0x67, 0xea, 0xcc, 0xfa, 0x51, 0x05, - 0x78, 0x88, 0xba, 0x24, 0x93, 0x85, 0x30, 0x6e, 0x7b, 0xea, 0xcc, 0x3a, 0x51, 0x4d, 0x65, 0x5f, - 0x83, 0x88, 0x41, 0xb9, 0x2f, 0xac, 0xbc, 0x26, 0x3c, 0x46, 0x3d, 0x05, 0x0c, 0xf8, 0x01, 0x94, - 0xdb, 0xb1, 0x93, 0x86, 0xfd, 0xaf, 0x08, 0xad, 0xca, 0xa5, 0x1b, 0x45, 0x18, 0x60, 0x8c, 0x3a, - 0x39, 0x31, 0xbb, 0xfa, 0x9c, 0xad, 0xf1, 0x07, 0x84, 0x28, 0xd1, 0xb0, 0xad, 0x1e, 0x69, 0xdb, - 0x49, 0xbf, 0xec, 0x58, 0x9f, 0xff, 0xd7, 0x41, 0xdd, 0x35, 0x51, 0x24, 0xd3, 0x78, 0x81, 0x5e, - 0x97, 0x17, 0xb7, 0x20, 0x08, 0x4d, 0x21, 0xb6, 0x5b, 0x7a, 0xcb, 0xd1, 0xed, 0x3c, 0x79, 0x77, - 0x24, 0x59, 0xba, 0xf0, 0xef, 0xa7, 0x7e, 0xf4, 0xaa, 0xc4, 0xef, 0x15, 0xe1, 0x6f, 0xe8, 0x6d, - 0xfd, 0x53, 0x63, 0x6f, 0x5b, 0xfb, 0xf8, 0x76, 0x9e, 0x0c, 0x2b, 0xfb, 0x33, 0x81, 0x1f, 0xbd, - 0xa9, 0x3b, 0xf5, 0x92, 0xe5, 0xcf, 0xff, 0x17, 0xcf, 0x39, 0x5d, 0x3c, 0xe7, 0xf1, 0xe2, 0x39, - 0xff, 0xae, 0x5e, 0xeb, 0x74, 0xf5, 0x5a, 0x0f, 0x57, 0xaf, 0xf5, 0xeb, 0x4b, 0xc2, 0xcd, 0xae, - 0xa0, 0x01, 0x93, 0x59, 0xc8, 0xa4, 0xce, 0xa4, 0x0e, 0x39, 0x65, 0x9f, 0x12, 0x19, 0x66, 0x32, - 0x2e, 0x52, 0xd0, 0x65, 0xc2, 0x77, 0xc9, 0x9a, 0x63, 0x0e, 0x9a, 0x76, 0x6d, 0x40, 0x9f, 0x9f, - 0x02, 0x00, 0x00, 0xff, 0xff, 0xbd, 0xbc, 0x5f, 0xc9, 0x03, 0x02, 0x00, 0x00, -} - -func (m *FungibleTokenPacketData) 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 *FungibleTokenPacketData) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *FungibleTokenPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Receiver) > 0 { - i -= len(m.Receiver) - copy(dAtA[i:], m.Receiver) - i = encodeVarintTransfer(dAtA, i, uint64(len(m.Receiver))) - i-- - dAtA[i] = 0x22 - } - if len(m.Sender) > 0 { - i -= len(m.Sender) - copy(dAtA[i:], m.Sender) - i = encodeVarintTransfer(dAtA, i, uint64(len(m.Sender))) - i-- - dAtA[i] = 0x1a - } - if m.Amount != 0 { - i = encodeVarintTransfer(dAtA, i, uint64(m.Amount)) - i-- - dAtA[i] = 0x10 - } - if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintTransfer(dAtA, i, uint64(len(m.Denom))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil + // 296 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0xc1, 0x4a, 0x03, 0x31, + 0x10, 0x86, 0x9b, 0x22, 0xc5, 0x46, 0x51, 0x88, 0xa2, 0xa5, 0x68, 0x2a, 0x7b, 0x12, 0xc4, 0x0d, + 0x45, 0x4f, 0xbd, 0x08, 0x55, 0xaf, 0x22, 0xc5, 0x93, 0x97, 0x92, 0x64, 0xc7, 0x6d, 0x60, 0xb3, + 0x59, 0x92, 0xb4, 0xd0, 0x47, 0xf0, 0xe6, 0x63, 0x79, 0xec, 0xd1, 0x53, 0x91, 0xf6, 0x0d, 0xfa, + 0x04, 0xb2, 0x69, 0x59, 0x16, 0x6f, 0xff, 0xcc, 0x7c, 0xdf, 0x1c, 0x7e, 0x7c, 0xa3, 0x84, 0x64, + 0xbc, 0x28, 0x32, 0x25, 0xb9, 0x57, 0x26, 0x77, 0xcc, 0x5b, 0x9e, 0xbb, 0x0f, 0xb0, 0x6c, 0xd6, + 0xaf, 0x72, 0x5c, 0x58, 0xe3, 0x0d, 0xb9, 0x50, 0x42, 0xc6, 0x75, 0x38, 0xae, 0x80, 0x59, 0xbf, + 0x7b, 0x9a, 0x9a, 0xd4, 0x04, 0x90, 0x95, 0x69, 0xeb, 0x44, 0x0f, 0x18, 0x3f, 0x41, 0x6e, 0xf4, + 0x9b, 0xe5, 0x12, 0x08, 0xc1, 0x7b, 0x05, 0xf7, 0x93, 0x0e, 0xba, 0x42, 0xd7, 0xed, 0x51, 0xc8, + 0xe4, 0x12, 0x63, 0xc1, 0x1d, 0x8c, 0x93, 0x12, 0xeb, 0x34, 0xc3, 0xa5, 0x5d, 0x6e, 0x82, 0x17, + 0x7d, 0x22, 0xdc, 0x7a, 0xe5, 0x96, 0x6b, 0x47, 0x06, 0xf8, 0xd0, 0x41, 0x9e, 0x8c, 0x21, 0xe7, + 0x22, 0x83, 0x24, 0x7c, 0xd9, 0x1f, 0x9e, 0x6f, 0x96, 0xbd, 0x93, 0x39, 0xd7, 0xd9, 0x20, 0xaa, + 0x5f, 0xa3, 0xd1, 0x41, 0x39, 0x3e, 0x6f, 0x27, 0xf2, 0x88, 0x8f, 0x2d, 0x48, 0x50, 0x33, 0xa8, + 0xf4, 0x66, 0xd0, 0xbb, 0x9b, 0x65, 0xef, 0x6c, 0xab, 0xff, 0x03, 0xa2, 0xd1, 0xd1, 0x6e, 0xb3, + 0x7b, 0x32, 0x7c, 0xf9, 0x5e, 0x51, 0xb4, 0x58, 0x51, 0xf4, 0xbb, 0xa2, 0xe8, 0x6b, 0x4d, 0x1b, + 0x8b, 0x35, 0x6d, 0xfc, 0xac, 0x69, 0xe3, 0xfd, 0x3e, 0x55, 0x7e, 0x32, 0x15, 0xb1, 0x34, 0x9a, + 0x49, 0xe3, 0xb4, 0x71, 0x4c, 0x09, 0x79, 0x9b, 0x1a, 0xa6, 0x4d, 0x32, 0xcd, 0xc0, 0x95, 0x25, + 0xd7, 0xca, 0xf5, 0xf3, 0x02, 0x9c, 0x68, 0x85, 0x8e, 0xee, 0xfe, 0x02, 0x00, 0x00, 0xff, 0xff, + 0xac, 0xa4, 0x13, 0xf0, 0x86, 0x01, 0x00, 0x00, } func (m *DenomTrace) Marshal() (dAtA []byte, err error) { @@ -392,30 +263,6 @@ func encodeVarintTransfer(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *FungibleTokenPacketData) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovTransfer(uint64(l)) - } - if m.Amount != 0 { - n += 1 + sovTransfer(uint64(m.Amount)) - } - l = len(m.Sender) - if l > 0 { - n += 1 + l + sovTransfer(uint64(l)) - } - l = len(m.Receiver) - if l > 0 { - n += 1 + l + sovTransfer(uint64(l)) - } - return n -} - func (m *DenomTrace) Size() (n int) { if m == nil { return 0 @@ -454,171 +301,6 @@ func sovTransfer(x uint64) (n int) { func sozTransfer(x uint64) (n int) { return sovTransfer(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *FungibleTokenPacketData) 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 ErrIntOverflowTransfer - } - 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: FungibleTokenPacketData: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: FungibleTokenPacketData: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTransfer - } - 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 ErrInvalidLengthTransfer - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTransfer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Denom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) - } - m.Amount = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTransfer - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Amount |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTransfer - } - 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 ErrInvalidLengthTransfer - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTransfer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Sender = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTransfer - } - 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 ErrInvalidLengthTransfer - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTransfer - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Receiver = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTransfer(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTransfer - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *DenomTrace) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/proto/ibc/applications/transfer/v1/transfer.proto b/proto/ibc/applications/transfer/v1/transfer.proto index b1c41f6a511..69c0486c088 100644 --- a/proto/ibc/applications/transfer/v1/transfer.proto +++ b/proto/ibc/applications/transfer/v1/transfer.proto @@ -6,19 +6,6 @@ option go_package = "github.com/cosmos/ibc-go/modules/apps/transfer/types"; import "gogoproto/gogo.proto"; -// FungibleTokenPacketData defines a struct for the packet payload -// See FungibleTokenPacketData spec: -// https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures -message FungibleTokenPacketData { - // the token denomination to be transferred - string denom = 1; - // the token amount to be transferred - uint64 amount = 2; - // the sender address - string sender = 3; - // the recipient address on the destination chain - string receiver = 4; -} // DenomTrace contains the base denomination for ICS20 fungible tokens and the // source tracing information path. diff --git a/proto/ibc/applications/transfer/v2/packet.proto b/proto/ibc/applications/transfer/v2/packet.proto new file mode 100644 index 00000000000..d7caa354106 --- /dev/null +++ b/proto/ibc/applications/transfer/v2/packet.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package ibc.applications.transfer.v2; + +option go_package = "github.com/cosmos/ibc-go/modules/apps/transfer/types"; + +// FungibleTokenPacketData defines a struct for the packet payload +// See FungibleTokenPacketData spec: +// https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures +message FungibleTokenPacketData { + // the token denomination to be transferred + string denom = 1; + // the token amount to be transferred + string amount = 2; + // the sender address + string sender = 3; + // the recipient address on the destination chain + string receiver = 4; +} + diff --git a/testing/chain.go b/testing/chain.go index c012f383767..e9b2a38241a 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -82,9 +82,12 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain { // generate genesis account senderPrivKey := secp256k1.GenPrivKey() acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + amount, ok := sdk.NewIntFromString("10000000000000000000") + require.True(t, ok) + balance := banktypes.Balance{ Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)), } app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance)