diff --git a/.github/workflows/build-wasm-simd-image-from-tag.yml b/.github/workflows/build-wasm-simd-image-from-tag.yml index 185e2e6ce31..7503201f341 100644 --- a/.github/workflows/build-wasm-simd-image-from-tag.yml +++ b/.github/workflows/build-wasm-simd-image-from-tag.yml @@ -21,24 +21,36 @@ jobs: with: ref: "${{ env.GIT_TAG }}" fetch-depth: 0 + - uses: actions/setup-python@v5 with: python-version: '3.10' - name: Install dependencies run: make python-install-deps + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Log in to the Container registry uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build image - run: | - version="$(scripts/get-libwasm-version.py --get-version)" - checksum="$(scripts/get-libwasm-version.py --get-checksum)" - - # remove all `/` or `+` characters from the docker tag and replace them with a -. - # this ensures the docker tag is valid. - docker_tag="$(echo $GIT_TAG | sed 's/[^a-zA-Z0-9\.]/-/g')" - docker build . -t "${REGISTRY}/${ORG}/${IMAGE_NAME}:${docker_tag}" -f modules/light-clients/08-wasm/Dockerfile --build-arg LIBWASM_VERSION=${version} --build-arg LIBWASM_CHECKSUM=${checksum} - docker push "${REGISTRY}/${ORG}/${IMAGE_NAME}:${docker_tag}" + + - name: Get arguments and docker tag + run: | + echo "LIBWASM_VERSION=$(scripts/get-libwasm-version.py --get-version)" >> $GITHUB_ENV + # remove all `/` or `+` characters from the docker tag and replace them with a -. + # this ensures the docker tag is valid. + echo "DOCKER_TAG=$(echo $GIT_TAG | sed 's/[^a-zA-Z0-9\.]/-/g')" >> $GITHUB_ENV + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64, + push: true + tags: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} + file: modules/light-clients/08-wasm/Dockerfile + build-args: LIBWASM_VERSION=${{ env.LIBWASM_VERSION }} diff --git a/.github/workflows/wasm-client.yml b/.github/workflows/wasm-client.yml index 187550bec23..db3969df877 100644 --- a/.github/workflows/wasm-client.yml +++ b/.github/workflows/wasm-client.yml @@ -41,7 +41,7 @@ jobs: - name: Install compiler for arm64. run: | sudo apt-get update - sudo apt-get install -y gcc-aarch64-linux-gnu + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV if: matrix.go-arch == 'arm64' - name: Build wasm-client diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index 33f3c6b2be0..3ca820500c3 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -32,6 +32,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" ibctmtypes "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -71,6 +72,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, testutil.TestEncodingConfig) { connectiontypes.RegisterInterfaces(cfg.InterfaceRegistry) ibctmtypes.RegisterInterfaces(cfg.InterfaceRegistry) wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry) + channeltypesv2.RegisterInterfaces(cfg.InterfaceRegistry) // all other types upgradetypes.RegisterInterfaces(cfg.InterfaceRegistry) diff --git a/modules/apps/29-fee/ica_test.go b/modules/apps/29-fee/ica_test.go index dceb5ed938d..a90a18c58b1 100644 --- a/modules/apps/29-fee/ica_test.go +++ b/modules/apps/29-fee/ica_test.go @@ -166,7 +166,7 @@ func (suite *FeeTestSuite) TestFeeInterchainAccounts() { packet := buildInterchainAccountsPacket(path, icaPacketData.GetBytes(), 1) // write packet commitment to state on chainA and commit state - commitment := channeltypes.CommitPacket(suite.chainA.GetSimApp().AppCodec(), packet) + commitment := channeltypes.CommitPacket(packet) suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, 1, commitment) suite.chainA.NextBlock() diff --git a/modules/apps/callbacks/go.mod b/modules/apps/callbacks/go.mod index eef82a93f53..147b6a4bf4c 100644 --- a/modules/apps/callbacks/go.mod +++ b/modules/apps/callbacks/go.mod @@ -62,6 +62,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v1.2.0 // indirect + github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect github.com/cosmos/ics23/go v0.11.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect github.com/danieljoos/wincred v1.2.1 // indirect diff --git a/modules/apps/callbacks/go.sum b/modules/apps/callbacks/go.sum index 956643bef70..da4ef3dd96e 100644 --- a/modules/apps/callbacks/go.sum +++ b/modules/apps/callbacks/go.sum @@ -350,6 +350,8 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM= github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI= +github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI= +github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index c6445645c23..95d4681b9b9 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -184,7 +184,7 @@ func (im IBCModule) OnRecvPacket( events.EmitOnRecvPacketEvent(ctx, data, ack, ackErr) }() - data, ackErr = types.UnmarshalPacketData(packet.GetData(), channelVersion) + data, ackErr = types.UnmarshalPacketData(packet.GetData(), channelVersion, "") if ackErr != nil { ack = channeltypes.NewErrorAcknowledgement(ackErr) im.keeper.Logger(ctx).Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence)) @@ -221,7 +221,7 @@ func (im IBCModule) OnAcknowledgementPacket( return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) } - data, err := types.UnmarshalPacketData(packet.GetData(), channelVersion) + data, err := types.UnmarshalPacketData(packet.GetData(), channelVersion, "") if err != nil { return err } @@ -242,7 +242,7 @@ func (im IBCModule) OnTimeoutPacket( packet channeltypes.Packet, relayer sdk.AccAddress, ) error { - data, err := types.UnmarshalPacketData(packet.GetData(), channelVersion) + data, err := types.UnmarshalPacketData(packet.GetData(), channelVersion, "") if err != nil { return err } @@ -305,6 +305,6 @@ func (im IBCModule) UnmarshalPacketData(ctx context.Context, portID string, chan return types.FungibleTokenPacketDataV2{}, "", errorsmod.Wrapf(ibcerrors.ErrNotFound, "app version not found for port %s and channel %s", portID, channelID) } - ftpd, err := types.UnmarshalPacketData(bz, ics20Version) + ftpd, err := types.UnmarshalPacketData(bz, ics20Version, "") return ftpd, ics20Version, err } diff --git a/modules/apps/transfer/keeper/export_test.go b/modules/apps/transfer/keeper/export_test.go index 5efd6a85910..3a2334abd99 100644 --- a/modules/apps/transfer/keeper/export_test.go +++ b/modules/apps/transfer/keeper/export_test.go @@ -29,10 +29,10 @@ func (k Keeper) GetAllDenomTraces(ctx sdk.Context) []internaltypes.DenomTrace { return traces } -// TokenFromCoin is a wrapper around tokenFromCoin for testing purposes. -func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) { - return k.tokenFromCoin(ctx, coin) -} +// // TokenFromCoin is a wrapper around tokenFromCoin for testing purposes. +// func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) { +// return k.tokenFromCoin(ctx, coin) +// } // UnwindHops is a wrapper around unwindHops for testing purposes. func (k Keeper) UnwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgTransfer, error) { @@ -54,11 +54,6 @@ func (k Keeper) GetAllForwardedPackets(ctx sdk.Context) []types.ForwardedPacket return k.getAllForwardedPackets(ctx) } -// IsBlockedAddr is a wrapper around isBlockedAddr for testing purposes -func (k Keeper) IsBlockedAddr(addr sdk.AccAddress) bool { - return k.isBlockedAddr(addr) -} - // CreatePacketDataBytesFromVersion is a wrapper around createPacketDataBytesFromVersion for testing purposes func CreatePacketDataBytesFromVersion(appVersion, sender, receiver, memo string, tokens types.Tokens, hops []types.Hop) ([]byte, error) { return createPacketDataBytesFromVersion(appVersion, sender, receiver, memo, tokens, hops) diff --git a/modules/apps/transfer/keeper/forwarding.go b/modules/apps/transfer/keeper/forwarding.go index cb68b9d919a..967fed6beff 100644 --- a/modules/apps/transfer/keeper/forwarding.go +++ b/modules/apps/transfer/keeper/forwarding.go @@ -22,7 +22,7 @@ func (k Keeper) forwardPacket(ctx context.Context, data types.FungibleTokenPacke } // sending from module account (used as a temporary forward escrow) to the original receiver address. - sender := k.authKeeper.GetModuleAddress(types.ModuleName) + sender := k.AuthKeeper.GetModuleAddress(types.ModuleName) msg := types.NewMsgTransfer( data.Forwarding.Hops[0].PortId, @@ -68,7 +68,7 @@ func (k Keeper) revertForwardedPacket(ctx context.Context, forwardedPacket chann 2. Burning voucher tokens if the funds are foreign */ - forwardingAddr := k.authKeeper.GetModuleAddress(types.ModuleName) + forwardingAddr := k.AuthKeeper.GetModuleAddress(types.ModuleName) escrow := types.GetEscrowAddress(forwardedPacket.DestinationPort, forwardedPacket.DestinationChannel) // we can iterate over the received tokens of forwardedPacket by iterating over the sent tokens of failedPacketData @@ -83,12 +83,12 @@ func (k Keeper) revertForwardedPacket(ctx context.Context, forwardedPacket chann // given that the packet is being reversed, we check the DestinationChannel and DestinationPort // of the forwardedPacket to see if a hop was added to the trace during the receive step if token.Denom.HasPrefix(forwardedPacket.DestinationPort, forwardedPacket.DestinationChannel) { - if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(coin)); err != nil { + if err := k.BankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(coin)); err != nil { return err } } else { // send it back to the escrow address - if err := k.escrowCoin(ctx, forwardingAddr, escrow, coin); err != nil { + if err := k.EscrowCoin(ctx, forwardingAddr, escrow, coin); err != nil { return err } } @@ -101,7 +101,7 @@ func (k Keeper) revertForwardedPacket(ctx context.Context, forwardedPacket chann func (k Keeper) getReceiverFromPacketData(data types.FungibleTokenPacketDataV2) (sdk.AccAddress, error) { if data.HasForwarding() { // since data.Receiver can potentially be a non-CosmosSDK AccAddress, we return early if the packet should be forwarded - return k.authKeeper.GetModuleAddress(types.ModuleName), nil + return k.AuthKeeper.GetModuleAddress(types.ModuleName), nil } receiver, err := sdk.AccAddressFromBech32(data.Receiver) diff --git a/modules/apps/transfer/keeper/genesis.go b/modules/apps/transfer/keeper/genesis.go index d9653ce3c6c..330c6f0360d 100644 --- a/modules/apps/transfer/keeper/genesis.go +++ b/modules/apps/transfer/keeper/genesis.go @@ -12,7 +12,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { for _, denom := range state.Denoms { k.SetDenom(ctx, denom) - k.setDenomMetadata(ctx, denom) + k.SetDenomMetadata(ctx, denom) } k.SetParams(ctx, state.Params) diff --git a/modules/apps/transfer/keeper/invariants.go b/modules/apps/transfer/keeper/invariants.go index dded2822ec9..3dc8f95b458 100644 --- a/modules/apps/transfer/keeper/invariants.go +++ b/modules/apps/transfer/keeper/invariants.go @@ -33,7 +33,7 @@ func TotalEscrowPerDenomInvariants(k *Keeper) sdk.Invariant { transferChannels := k.channelKeeper.GetAllChannelsWithPortPrefix(ctx, portID) for _, channel := range transferChannels { escrowAddress := types.GetEscrowAddress(portID, channel.ChannelId) - escrowBalances := k.bankKeeper.GetAllBalances(ctx, escrowAddress) + escrowBalances := k.BankKeeper.GetAllBalances(ctx, escrowAddress) actualTotalEscrowed = actualTotalEscrowed.Add(escrowBalances...) } diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 1ebb14ace71..f51a3d9cf3d 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -20,6 +20,7 @@ import ( cmtbytes "github.com/cometbft/cometbft/libs/bytes" "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + typesv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" @@ -34,8 +35,8 @@ type Keeper struct { ics4Wrapper porttypes.ICS4Wrapper channelKeeper types.ChannelKeeper - authKeeper types.AccountKeeper - bankKeeper types.BankKeeper + AuthKeeper types.AccountKeeper + BankKeeper types.BankKeeper // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. @@ -68,8 +69,8 @@ func NewKeeper( legacySubspace: legacySubspace, ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, - authKeeper: authKeeper, - bankKeeper: bankKeeper, + AuthKeeper: authKeeper, + BankKeeper: bankKeeper, authority: authority, } } @@ -195,8 +196,8 @@ func (k Keeper) IterateDenoms(ctx context.Context, cb func(denom types.Denom) bo } } -// setDenomMetadata sets an IBC token's denomination metadata -func (k Keeper) setDenomMetadata(ctx context.Context, denom types.Denom) { +// SetDenomMetadata sets an IBC token's denomination metadata +func (k Keeper) SetDenomMetadata(ctx context.Context, denom types.Denom) { metadata := banktypes.Metadata{ Description: fmt.Sprintf("IBC token from %s", denom.Path()), DenomUnits: []*banktypes.DenomUnit{ @@ -214,7 +215,7 @@ func (k Keeper) setDenomMetadata(ctx context.Context, denom types.Denom) { Symbol: strings.ToUpper(denom.Base), } - k.bankKeeper.SetDenomMetaData(ctx, metadata) + k.BankKeeper.SetDenomMetaData(ctx, metadata) } // GetTotalEscrowForDenom gets the total amount of source chain tokens that @@ -346,6 +347,20 @@ func (k Keeper) getAllForwardedPackets(ctx context.Context) []types.ForwardedPac return packets } +// TODO This should go in keeperV2, bu there's no storeService there. +// SetForwardedPacketSequenceAndDestinationChannel stores the sequence and the destinationChannel for a forwarded packet. +func (k Keeper) SetForwardedPacketSequenceAndDestinationChannel(ctx context.Context, portID, channelID string, sequence uint64, destChannel string) { + store := k.storeService.OpenKVStore(ctx) + bigEndianBz := sdk.Uint64ToBigEndian(sequence) + destChannelBz := []byte(destChannel) + if err := store.Set(typesv2.ForwardedPacketSequenceKey(portID, channelID), bigEndianBz); err != nil { + panic(err) + } + if err := store.Set(typesv2.ForwardedPacketDestinationChannelKey(portID, channelID), destChannelBz); err != nil { + panic(err) + } +} + // iterateForwardedPackets iterates over the forward packets in the store and performs a callback function. func (k Keeper) iterateForwardedPackets(ctx context.Context, cb func(packet types.ForwardedPacket) bool) { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) @@ -385,11 +400,11 @@ func (k Keeper) iterateForwardedPackets(ctx context.Context, cb func(packet type // IsBlockedAddr checks if the given address is allowed to send or receive tokens. // The module account is always allowed to send and receive tokens. -func (k Keeper) isBlockedAddr(addr sdk.AccAddress) bool { - moduleAddr := k.authKeeper.GetModuleAddress(types.ModuleName) +func (k Keeper) IsBlockedAddr(addr sdk.AccAddress) bool { + moduleAddr := k.AuthKeeper.GetModuleAddress(types.ModuleName) if addr.Equals(moduleAddr) { return false } - return k.bankKeeper.BlockedAddr(addr) + return k.BankKeeper.BlockedAddr(addr) } diff --git a/modules/apps/transfer/keeper/migrations.go b/modules/apps/transfer/keeper/migrations.go index ab1e526d4a2..bc82b83c21a 100644 --- a/modules/apps/transfer/keeper/migrations.go +++ b/modules/apps/transfer/keeper/migrations.go @@ -43,7 +43,7 @@ func (m Migrator) MigrateDenomMetadata(ctx sdk.Context) error { m.keeper.iterateDenomTraces(ctx, func(dt internaltypes.DenomTrace) (stop bool) { // check if the metadata for the given denom trace does not already exist - if !m.keeper.bankKeeper.HasDenomMetaData(ctx, dt.IBCDenom()) { + if !m.keeper.BankKeeper.HasDenomMetaData(ctx, dt.IBCDenom()) { m.keeper.setDenomMetadataWithDenomTrace(ctx, dt) } return false @@ -61,7 +61,7 @@ func (m Migrator) MigrateTotalEscrowForDenom(ctx sdk.Context) error { transferChannels := m.keeper.channelKeeper.GetAllChannelsWithPortPrefix(ctx, portID) for _, channel := range transferChannels { escrowAddress := types.GetEscrowAddress(portID, channel.ChannelId) - escrowBalances := m.keeper.bankKeeper.GetAllBalances(ctx, escrowAddress) + escrowBalances := m.keeper.BankKeeper.GetAllBalances(ctx, escrowAddress) totalEscrowed = totalEscrowed.Add(escrowBalances...) } @@ -164,5 +164,5 @@ func (k Keeper) setDenomMetadataWithDenomTrace(ctx sdk.Context, denomTrace inter Symbol: strings.ToUpper(denomTrace.BaseDenom), } - k.bankKeeper.SetDenomMetaData(ctx, metadata) + k.BankKeeper.SetDenomMetaData(ctx, metadata) } diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index b0cb57398b7..4a85249ce5b 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -29,11 +29,11 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. coins := msg.GetCoins() - if err := k.bankKeeper.IsSendEnabledCoins(ctx, coins...); err != nil { + if err := k.BankKeeper.IsSendEnabledCoins(ctx, coins...); err != nil { return nil, errorsmod.Wrapf(types.ErrSendDisabled, err.Error()) } - if k.isBlockedAddr(sender) { + if k.IsBlockedAddr(sender) { return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) } @@ -82,7 +82,7 @@ func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgT msg.Forwarding.Hops = append(unwindHops[1:], msg.Forwarding.Hops...) msg.Forwarding.Unwind = false - // Message is validate again, this would only fail if hops now exceeds maximum allowed. + // Message is validated again, this would only fail if hops now exceeds maximum allowed. if err := msg.ValidateBasic(); err != nil { return nil, err } @@ -98,7 +98,7 @@ func (k Keeper) getUnwindHops(ctx sdk.Context, coins sdk.Coins) ([]types.Hop, er return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "coins cannot be empty") } - token, err := k.tokenFromCoin(ctx, coins[0]) + token, err := k.TokenFromCoin(ctx, coins[0]) if err != nil { return nil, err } @@ -109,7 +109,7 @@ func (k Keeper) getUnwindHops(ctx sdk.Context, coins sdk.Coins) ([]types.Hop, er unwindTrace := token.Denom.Trace for _, coin := range coins[1:] { - token, err := k.tokenFromCoin(ctx, coin) + token, err := k.TokenFromCoin(ctx, coin) if err != nil { return nil, err } diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 71ef740132c..a6921e211b9 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -96,10 +96,10 @@ func (k Keeper) sendTransfer( for _, coin := range coins { // Using types.UnboundedSpendLimit allows us to send the entire balance of a given denom. if coin.Amount.Equal(types.UnboundedSpendLimit()) { - coin.Amount = k.bankKeeper.GetBalance(ctx, sender, coin.Denom).Amount + coin.Amount = k.BankKeeper.GetBalance(ctx, sender, coin.Denom).Amount } - token, err := k.tokenFromCoin(ctx, coin) + token, err := k.TokenFromCoin(ctx, coin) if err != nil { return 0, err } @@ -112,13 +112,13 @@ func (k Keeper) sendTransfer( // the token, then we must be returning the token back to the chain they originated from if token.Denom.HasPrefix(sourcePort, sourceChannel) { // transfer the coins to the module account and burn them - if err := k.bankKeeper.SendCoinsFromAccountToModule( + if err := k.BankKeeper.SendCoinsFromAccountToModule( ctx, sender, types.ModuleName, sdk.NewCoins(coin), ); err != nil { return 0, err } - if err := k.bankKeeper.BurnCoins( + if err := k.BankKeeper.BurnCoins( ctx, types.ModuleName, sdk.NewCoins(coin), ); err != nil { // NOTE: should not happen as the module account was @@ -129,7 +129,7 @@ func (k Keeper) sendTransfer( } else { // obtain the escrow address for the source channel end escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel) - if err := k.escrowCoin(ctx, sender, escrowAddress, coin); err != nil { + if err := k.EscrowCoin(ctx, sender, escrowAddress, coin); err != nil { return 0, err } } @@ -178,7 +178,7 @@ func (k Keeper) OnRecvPacket(ctx context.Context, packet channeltypes.Packet, da return err } - if k.isBlockedAddr(receiver) { + if k.IsBlockedAddr(receiver) { return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver) } @@ -206,7 +206,7 @@ func (k Keeper) OnRecvPacket(ctx context.Context, packet channeltypes.Packet, da coin := sdk.NewCoin(token.Denom.IBCDenom(), transferAmount) escrowAddress := types.GetEscrowAddress(packet.GetDestPort(), packet.GetDestChannel()) - if err := k.unescrowCoin(ctx, escrowAddress, receiver, coin); err != nil { + if err := k.UnescrowCoin(ctx, escrowAddress, receiver, coin); err != nil { return err } @@ -224,8 +224,8 @@ func (k Keeper) OnRecvPacket(ctx context.Context, packet channeltypes.Packet, da } voucherDenom := token.Denom.IBCDenom() - if !k.bankKeeper.HasDenomMetaData(ctx, voucherDenom) { - k.setDenomMetadata(ctx, token.Denom) + if !k.BankKeeper.HasDenomMetaData(ctx, voucherDenom) { + k.SetDenomMetadata(ctx, token.Denom) } events.EmitDenomEvent(ctx, token) @@ -233,15 +233,15 @@ func (k Keeper) OnRecvPacket(ctx context.Context, packet channeltypes.Packet, da voucher := sdk.NewCoin(voucherDenom, transferAmount) // mint new tokens if the source of the transfer is the same chain - if err := k.bankKeeper.MintCoins( + if err := k.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins(voucher), ); err != nil { return errorsmod.Wrap(err, "failed to mint IBC tokens") } // send to receiver - moduleAddr := k.authKeeper.GetModuleAddress(types.ModuleName) - if err := k.bankKeeper.SendCoins( + moduleAddr := k.AuthKeeper.GetModuleAddress(types.ModuleName) + if err := k.BankKeeper.SendCoins( ctx, moduleAddr, receiver, sdk.NewCoins(voucher), ); err != nil { return errorsmod.Wrapf(err, "failed to send coins to receiver %s", receiver.String()) @@ -346,14 +346,14 @@ func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Pack if err != nil { return err } - if k.isBlockedAddr(sender) { + if k.IsBlockedAddr(sender) { return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", sender) } // escrow address for unescrowing tokens back to sender escrowAddress := types.GetEscrowAddress(packet.GetSourcePort(), packet.GetSourceChannel()) - moduleAccountAddr := k.authKeeper.GetModuleAddress(types.ModuleName) + moduleAccountAddr := k.AuthKeeper.GetModuleAddress(types.ModuleName) for _, token := range data.Tokens { coin, err := token.ToCoin() if err != nil { @@ -364,17 +364,17 @@ func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Pack // then the tokens were burnt when the packet was sent and we must mint new tokens if token.Denom.HasPrefix(packet.GetSourcePort(), packet.GetSourceChannel()) { // mint vouchers back to sender - if err := k.bankKeeper.MintCoins( + if err := k.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins(coin), ); err != nil { return err } - if err := k.bankKeeper.SendCoins(ctx, moduleAccountAddr, sender, sdk.NewCoins(coin)); err != nil { + if err := k.BankKeeper.SendCoins(ctx, moduleAccountAddr, sender, sdk.NewCoins(coin)); err != nil { panic(fmt.Errorf("unable to send coins from module to account despite previously minting coins to module account: %v", err)) } } else { - if err := k.unescrowCoin(ctx, escrowAddress, sender, coin); err != nil { + if err := k.UnescrowCoin(ctx, escrowAddress, sender, coin); err != nil { return err } } @@ -383,10 +383,11 @@ func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Pack return nil } -// escrowCoin will send the given coin from the provided sender to the escrow address. It will also +// EscrowCoin will send the given coin from the provided sender to the escrow address. It will also // update the total escrowed amount by adding the escrowed coin's amount to the current total escrow. -func (k Keeper) escrowCoin(ctx context.Context, sender, escrowAddress sdk.AccAddress, coin sdk.Coin) error { - if err := k.bankKeeper.SendCoins(ctx, sender, escrowAddress, sdk.NewCoins(coin)); err != nil { + +func (k Keeper) EscrowCoin(ctx context.Context, sender, escrowAddress sdk.AccAddress, coin sdk.Coin) error { + if err := k.BankKeeper.SendCoins(ctx, sender, escrowAddress, sdk.NewCoins(coin)); err != nil { // failure is expected for insufficient balances return err } @@ -399,10 +400,10 @@ func (k Keeper) escrowCoin(ctx context.Context, sender, escrowAddress sdk.AccAdd return nil } -// unescrowCoin will send the given coin from the escrow address to the provided receiver. It will also +// UnescrowCoin will send the given coin from the escrow address to the provided receiver. It will also // update the total escrow by deducting the unescrowed coin's amount from the current total escrow. -func (k Keeper) unescrowCoin(ctx context.Context, escrowAddress, receiver sdk.AccAddress, coin sdk.Coin) error { - if err := k.bankKeeper.SendCoins(ctx, escrowAddress, receiver, sdk.NewCoins(coin)); err != nil { +func (k Keeper) UnescrowCoin(ctx context.Context, escrowAddress, receiver sdk.AccAddress, coin sdk.Coin) error { + if err := k.BankKeeper.SendCoins(ctx, escrowAddress, receiver, sdk.NewCoins(coin)); err != nil { // NOTE: this error is only expected to occur given an unexpected bug or a malicious // counterparty module. The bug may occur in bank or any part of the code that allows // the escrow address to be drained. A malicious counterparty module could drain the @@ -419,7 +420,7 @@ func (k Keeper) unescrowCoin(ctx context.Context, escrowAddress, receiver sdk.Ac } // tokenFromCoin constructs an IBC token given an SDK coin. -func (k Keeper) tokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) { +func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) { // if the coin does not have an IBC denom, return as is if !strings.HasPrefix(coin.Denom, "ibc/") { return types.Token{ diff --git a/modules/apps/transfer/types/denom.go b/modules/apps/transfer/types/denom.go index 03c4bb19f04..8846d876ce2 100644 --- a/modules/apps/transfer/types/denom.go +++ b/modules/apps/transfer/types/denom.go @@ -14,6 +14,7 @@ import ( cmtbytes "github.com/cometbft/cometbft/libs/bytes" cmttypes "github.com/cometbft/cometbft/types" + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" ) @@ -167,7 +168,7 @@ func ExtractDenomFromPath(fullPath string) Denom { // 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]) { + if i < length-1 && length > 2 && (channeltypes.IsValidChannelID(denomSplit[i+1]) || clienttypes.IsValidClientID(denomSplit[i+1])) { trace = append(trace, NewHop(denomSplit[i], denomSplit[i+1])) } else { baseDenomSlice = denomSplit[i:] diff --git a/modules/apps/transfer/types/denom_test.go b/modules/apps/transfer/types/denom_test.go index 6a240af3e84..d6d47c78e56 100644 --- a/modules/apps/transfer/types/denom_test.go +++ b/modules/apps/transfer/types/denom_test.go @@ -20,6 +20,11 @@ func (suite *TypesTestSuite) TestDenomsValidate() { types.Denoms{}, nil, }, + { + "valid trace with client id", + types.Denoms{types.NewDenom("uatom", types.NewHop("transfer", "07-tendermint-0"))}, + nil, + }, { "valid multiple trace info", types.Denoms{types.NewDenom("uatom", types.NewHop("transfer", "channel-1"), types.NewHop("transfer", "channel-2"))}, @@ -79,6 +84,16 @@ func (suite *TypesTestSuite) TestPath() { types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), "transfer/channel-0/uatom", }, + { + "1 hop denom with client id", + types.NewDenom("uatom", types.NewHop("transfer", "07-tendermint-0")), + "transfer/07-tendermint-0/uatom", + }, + { + "1 hop denom with client id and slashes", + types.NewDenom("gamm/pool/osmo", types.NewHop("transfer", "07-tendermint-0")), + "transfer/07-tendermint-0/gamm/pool/osmo", + }, { "2 hop denom", types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), @@ -202,6 +217,13 @@ func (suite *TypesTestSuite) TestDenomChainSource() { "channel-0", false, }, + { + "sender chain is source: single trace with client id", + types.NewDenom("ubtc", types.NewHop("transfer", "07-tendermint-0")), + "transfer", + "channel-0", + false, + }, { "sender chain is source: swapped portID and channelID", types.NewDenom("uatom", types.NewHop("transfer", "channel-0")), @@ -226,6 +248,13 @@ func (suite *TypesTestSuite) TestDenomChainSource() { "channel-0", true, }, + { + "receiver chain is source: single trace with client id", + types.NewDenom("ubtc", types.NewHop("transfer", "07-tendermint-0")), + "transfer", + "07-tendermint-0", + true, + }, { "receiver chain is source: multi-trace", types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")), @@ -284,6 +313,7 @@ func TestExtractDenomFromPath(t *testing.T) { {"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 with client id", "transfer/07-tendermint-0/atom", types.NewDenom("atom", types.NewHop("transfer", "07-tendermint-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"))}, diff --git a/modules/apps/transfer/types/packet.go b/modules/apps/transfer/types/packet.go index 209c721d75b..968e996c08f 100644 --- a/modules/apps/transfer/types/packet.go +++ b/modules/apps/transfer/types/packet.go @@ -23,6 +23,11 @@ var ( _ ibcexported.PacketDataProvider = (*FungibleTokenPacketDataV2)(nil) ) +const ( + EncodingJSON = "application/json" + EncodingProtobuf = "application/x-protobuf" +) + // NewFungibleTokenPacketData constructs a new FungibleTokenPacketData instance func NewFungibleTokenPacketData( denom string, amount string, @@ -208,34 +213,78 @@ func (ftpd FungibleTokenPacketDataV2) HasForwarding() bool { } // UnmarshalPacketData attempts to unmarshal the provided packet data bytes into a FungibleTokenPacketDataV2. -// The version of ics20 should be provided and should be either ics20-1 or ics20-2. -func UnmarshalPacketData(bz []byte, ics20Version string) (FungibleTokenPacketDataV2, error) { +func UnmarshalPacketData(bz []byte, ics20Version string, encoding string) (FungibleTokenPacketDataV2, error) { + const failedUnmarshalingErrorMsg = "cannot unmarshal %s transfer packet data: %s" + + // Depending on the ics20 version, we use a different default encoding (json for V1, proto for V2) + // and we have a different type to unmarshal the data into. + var data proto.Message switch ics20Version { case V1: - var datav1 FungibleTokenPacketData - if err := json.Unmarshal(bz, &datav1); err != nil { - return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot unmarshal ICS20-V1 transfer packet data: %s", err.Error()) + if encoding == "" { + encoding = EncodingJSON } - - return PacketDataV1ToV2(datav1) + data = &FungibleTokenPacketData{} case V2: - var datav2 FungibleTokenPacketDataV2 - if err := unknownproto.RejectUnknownFieldsStrict(bz, &datav2, unknownproto.DefaultAnyResolver{}); err != nil { - return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot unmarshal ICS20-V2 transfer packet data: %s", err.Error()) + if encoding == "" { + encoding = EncodingProtobuf } + data = &FungibleTokenPacketDataV2{} + default: + return FungibleTokenPacketDataV2{}, errorsmod.Wrap(ErrInvalidVersion, ics20Version) + } - if err := proto.Unmarshal(bz, &datav2); err != nil { - return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot unmarshal ICS20-V2 transfer packet data: %s", err.Error()) + errorMsgVersion := "ICS20-V2" + if ics20Version == V1 { + errorMsgVersion = "ICS20-V1" + } + + // Here we perform the unmarshaling based on the specified encoding. + // The functions act on the generic "data" variable which is of type proto.Message (an interface). + // The underlying type is either FungibleTokenPacketData or FungibleTokenPacketDataV2, based on the value + // of "ics20Version". + switch encoding { + case EncodingJSON: + if err := json.Unmarshal(bz, &data); err != nil { + return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, failedUnmarshalingErrorMsg, errorMsgVersion, err.Error()) + } + case EncodingProtobuf: + if err := unknownproto.RejectUnknownFieldsStrict(bz, data, unknownproto.DefaultAnyResolver{}); err != nil { + return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, failedUnmarshalingErrorMsg, errorMsgVersion, err.Error()) } - if err := datav2.ValidateBasic(); err != nil { - return FungibleTokenPacketDataV2{}, err + if err := proto.Unmarshal(bz, data); err != nil { + return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, failedUnmarshalingErrorMsg, errorMsgVersion, err.Error()) } - return datav2, nil default: - return FungibleTokenPacketDataV2{}, errorsmod.Wrap(ErrInvalidVersion, ics20Version) + return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid encoding provided, must be either empty or one of [%q, %q], got %s", EncodingJSON, EncodingProtobuf, encoding) + } + + // When the unmarshaling is done, we want to retrieve the underlying data type based on the value of ics20Version + // If it's v1, we convert the data to FungibleTokenPacketData and then call the conversion function to construct + // the v2 type. + if ics20Version == V1 { + datav1, ok := data.(*FungibleTokenPacketData) + if !ok { + // We should never get here, as we manually constructed the type at the beginning of the file + return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot convert proto message into FungibleTokenPacketData") + } + // The call to ValidateBasic for V1 is done inside PacketDataV1toV2. + return PacketDataV1ToV2(*datav1) + } + + // If it's v2, we convert the data to FungibleTokenPacketDataV2, validate it and return it. + datav2, ok := data.(*FungibleTokenPacketDataV2) + if !ok { + // We should never get here, as we manually constructed the type at the beginning of the file + return FungibleTokenPacketDataV2{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot convert proto message into FungibleTokenPacketDataV2") + } + + if err := datav2.ValidateBasic(); err != nil { + return FungibleTokenPacketDataV2{}, err } + return *datav2, nil } // PacketDataV1ToV2 converts a v1 packet data to a v2 packet data. The packet data is validated diff --git a/modules/apps/transfer/types/packet.pb.go b/modules/apps/transfer/types/packet.pb.go index 2cf81795e7b..5d7e3025299 100644 --- a/modules/apps/transfer/types/packet.pb.go +++ b/modules/apps/transfer/types/packet.pb.go @@ -199,6 +199,8 @@ type ForwardingPacketData struct { DestinationMemo string `protobuf:"bytes,1,opt,name=destination_memo,json=destinationMemo,proto3" json:"destination_memo,omitempty"` // optional intermediate path through which packet will be forwarded. Hops []Hop `protobuf:"bytes,2,rep,name=hops,proto3" json:"hops"` + // timeout for the packet + TimeoutTimestamp uint64 `protobuf:"varint,3,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty"` } func (m *ForwardingPacketData) Reset() { *m = ForwardingPacketData{} } @@ -248,6 +250,13 @@ func (m *ForwardingPacketData) GetHops() []Hop { return nil } +func (m *ForwardingPacketData) GetTimeoutTimestamp() uint64 { + if m != nil { + return m.TimeoutTimestamp + } + return 0 +} + func init() { proto.RegisterType((*FungibleTokenPacketData)(nil), "ibc.applications.transfer.v2.FungibleTokenPacketData") proto.RegisterType((*FungibleTokenPacketDataV2)(nil), "ibc.applications.transfer.v2.FungibleTokenPacketDataV2") @@ -259,34 +268,35 @@ func init() { } var fileDescriptor_653ca2ce9a5ca313 = []byte{ - // 418 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0xc7, 0x93, 0x34, 0x5b, 0x74, 0xf6, 0xa0, 0x0c, 0x45, 0x63, 0x91, 0xb8, 0xd6, 0x4b, 0x17, - 0x71, 0x86, 0x8d, 0x07, 0x11, 0x4f, 0x2e, 0xb2, 0x78, 0x11, 0x74, 0x11, 0x11, 0x2f, 0x32, 0x99, - 0xcc, 0x66, 0x87, 0x36, 0xf3, 0xc2, 0xcc, 0x24, 0xe2, 0x45, 0xfc, 0x06, 0xfa, 0xb1, 0x7a, 0xec, - 0xd1, 0x93, 0x48, 0xfb, 0x45, 0x24, 0x93, 0xd8, 0xe6, 0x60, 0x73, 0x7b, 0xef, 0x9f, 0xff, 0xfb, - 0xf3, 0x9b, 0x97, 0x87, 0x4e, 0x65, 0xca, 0x29, 0x2b, 0xcb, 0xa5, 0xe4, 0xcc, 0x4a, 0x50, 0x86, - 0x5a, 0xcd, 0x94, 0xb9, 0x12, 0x9a, 0xd6, 0x09, 0x2d, 0x19, 0x5f, 0x08, 0x4b, 0x4a, 0x0d, 0x16, - 0xf0, 0x7d, 0x99, 0x72, 0xd2, 0xb7, 0x92, 0x7f, 0x56, 0x52, 0x27, 0xd3, 0xf9, 0x60, 0x90, 0x85, - 0x85, 0x50, 0x6d, 0xce, 0x74, 0x92, 0x43, 0x0e, 0xae, 0xa4, 0x4d, 0xd5, 0xa9, 0x8f, 0x07, 0xe6, - 0xcf, 0x76, 0x75, 0x6b, 0x9e, 0xfd, 0xf0, 0xd1, 0xdd, 0x8b, 0x4a, 0xe5, 0x32, 0x5d, 0x8a, 0xf7, - 0x4d, 0xf4, 0x5b, 0x07, 0xfa, 0x8a, 0x59, 0x86, 0x27, 0xe8, 0x28, 0x13, 0x0a, 0x8a, 0xc8, 0x3f, - 0xf1, 0xe7, 0x37, 0x2f, 0xdb, 0x06, 0xdf, 0x41, 0x63, 0x56, 0x40, 0xa5, 0x6c, 0x14, 0x38, 0xb9, - 0xeb, 0x1a, 0xdd, 0x08, 0x95, 0x09, 0x1d, 0x8d, 0x5a, 0xbd, 0xed, 0xf0, 0x14, 0xdd, 0xd0, 0x82, - 0x0b, 0x59, 0x0b, 0x1d, 0x85, 0xee, 0xcb, 0xae, 0xc7, 0x18, 0x85, 0x85, 0x28, 0x20, 0x3a, 0x72, - 0xba, 0xab, 0x67, 0xdf, 0x03, 0x74, 0xef, 0x00, 0xd1, 0x87, 0x04, 0xbf, 0x44, 0x63, 0xb7, 0x01, - 0x13, 0xf9, 0x27, 0xa3, 0xf9, 0x71, 0xf2, 0x88, 0x0c, 0xed, 0x92, 0xb8, 0x80, 0xf3, 0x70, 0xf5, - 0xfb, 0x81, 0x77, 0xd9, 0x0d, 0xf6, 0x40, 0x83, 0x83, 0xa0, 0xa3, 0x03, 0xa0, 0xe1, 0x1e, 0x14, - 0x7f, 0x44, 0xe8, 0x0a, 0xf4, 0x17, 0xa6, 0x33, 0xa9, 0x72, 0xf7, 0x84, 0xe3, 0x24, 0x19, 0xc6, - 0xb9, 0xd8, 0xf9, 0xf7, 0x8f, 0xea, 0xe8, 0x7a, 0x59, 0xb3, 0x6f, 0x68, 0xf2, 0x3f, 0x27, 0x3e, - 0x45, 0xb7, 0x33, 0x61, 0xac, 0x54, 0x2e, 0xfa, 0xb3, 0x23, 0x6a, 0xff, 0xcd, 0xad, 0x9e, 0xfe, - 0xa6, 0x81, 0x7b, 0x81, 0xc2, 0x6b, 0x28, 0x4d, 0x14, 0xb8, 0x2d, 0x3d, 0x1c, 0xc2, 0x3a, 0x23, - 0xaf, 0xa1, 0xec, 0x28, 0xdc, 0xd0, 0xf9, 0xbb, 0xd5, 0x26, 0xf6, 0xd7, 0x9b, 0xd8, 0xff, 0xb3, - 0x89, 0xfd, 0x9f, 0xdb, 0xd8, 0x5b, 0x6f, 0x63, 0xef, 0xd7, 0x36, 0xf6, 0x3e, 0x3d, 0xcb, 0xa5, - 0xbd, 0xae, 0x52, 0xc2, 0xa1, 0xa0, 0x1c, 0x4c, 0x01, 0x86, 0xca, 0x94, 0x3f, 0xc9, 0x81, 0xd6, - 0xcf, 0x69, 0x01, 0x59, 0xb5, 0x14, 0xa6, 0xb9, 0xbd, 0xde, 0xcd, 0xd9, 0xaf, 0xa5, 0x30, 0xe9, - 0xd8, 0x9d, 0xdb, 0xd3, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x73, 0xe7, 0x36, 0x26, 0x03, - 0x00, 0x00, + // 444 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0x9b, 0x36, 0xab, 0xc0, 0x3b, 0x30, 0xac, 0x0a, 0x42, 0x85, 0xc2, 0x28, 0x97, 0x4e, + 0x13, 0xb1, 0x16, 0x0e, 0x08, 0x71, 0x62, 0x42, 0x13, 0x17, 0x24, 0xa8, 0x26, 0x84, 0xb8, 0x4c, + 0x8e, 0xe3, 0x65, 0xd6, 0x6a, 0x3f, 0xcb, 0x76, 0x82, 0xb8, 0xf1, 0x0d, 0xe0, 0x7b, 0xf0, 0x45, + 0x76, 0xdc, 0x91, 0x13, 0x42, 0xed, 0x17, 0x41, 0x71, 0xb2, 0x2e, 0x07, 0x9a, 0x53, 0xde, 0xfb, + 0xfb, 0xef, 0xbf, 0x7e, 0x7e, 0x79, 0xe8, 0x40, 0x64, 0x8c, 0x50, 0xad, 0x97, 0x82, 0x51, 0x27, + 0x40, 0x59, 0xe2, 0x0c, 0x55, 0xf6, 0x9c, 0x1b, 0x52, 0xa5, 0x44, 0x53, 0x76, 0xc9, 0x5d, 0xa2, + 0x0d, 0x38, 0xc0, 0x8f, 0x45, 0xc6, 0x92, 0xae, 0x35, 0xb9, 0xb1, 0x26, 0x55, 0x3a, 0x9d, 0xf7, + 0x06, 0x39, 0xb8, 0xe4, 0xaa, 0xc9, 0x99, 0x4e, 0x0a, 0x28, 0xc0, 0x97, 0xa4, 0xae, 0x5a, 0xf5, + 0xb0, 0xe7, 0xfe, 0xd1, 0xa6, 0x6e, 0xcc, 0xb3, 0x1f, 0x01, 0x7a, 0x78, 0x52, 0xaa, 0x42, 0x64, + 0x4b, 0x7e, 0x5a, 0x47, 0x7f, 0xf0, 0xa0, 0x6f, 0xa9, 0xa3, 0x78, 0x82, 0x76, 0x72, 0xae, 0x40, + 0x46, 0xc1, 0x7e, 0x30, 0xbf, 0xbb, 0x68, 0x1a, 0xfc, 0x00, 0x8d, 0xa9, 0x84, 0x52, 0xb9, 0x68, + 0xe8, 0xe5, 0xb6, 0xab, 0x75, 0xcb, 0x55, 0xce, 0x4d, 0x34, 0x6a, 0xf4, 0xa6, 0xc3, 0x53, 0x74, + 0xc7, 0x70, 0xc6, 0x45, 0xc5, 0x4d, 0x14, 0xfa, 0x93, 0x4d, 0x8f, 0x31, 0x0a, 0x25, 0x97, 0x10, + 0xed, 0x78, 0xdd, 0xd7, 0xb3, 0xef, 0x43, 0xf4, 0x68, 0x0b, 0xd1, 0xa7, 0x14, 0xbf, 0x41, 0x63, + 0x3f, 0x01, 0x1b, 0x05, 0xfb, 0xa3, 0xf9, 0x6e, 0xfa, 0x2c, 0xe9, 0x9b, 0x65, 0xe2, 0x03, 0x8e, + 0xc3, 0xab, 0x3f, 0x4f, 0x06, 0x8b, 0xf6, 0x62, 0x07, 0x74, 0xb8, 0x15, 0x74, 0xb4, 0x05, 0x34, + 0xbc, 0x05, 0xc5, 0x9f, 0x11, 0x3a, 0x07, 0xf3, 0x95, 0x9a, 0x5c, 0xa8, 0xc2, 0x3f, 0x61, 0x37, + 0x4d, 0xfb, 0x71, 0x4e, 0x36, 0xfe, 0xdb, 0x47, 0xb5, 0x74, 0x9d, 0xac, 0xd9, 0xaf, 0x00, 0x4d, + 0xfe, 0x67, 0xc5, 0x07, 0x68, 0x2f, 0xe7, 0xd6, 0x09, 0xe5, 0xb3, 0xcf, 0x3c, 0x52, 0xf3, 0x73, + 0xee, 0x75, 0xf4, 0xf7, 0x35, 0xdd, 0x6b, 0x14, 0x5e, 0x80, 0xb6, 0xd1, 0xd0, 0x8f, 0xe9, 0x69, + 0x1f, 0xd7, 0x51, 0xf2, 0x0e, 0x74, 0x8b, 0xe1, 0x2f, 0xe1, 0x43, 0x74, 0xdf, 0x09, 0xc9, 0xa1, + 0x74, 0x67, 0xf5, 0xd7, 0x3a, 0x2a, 0xb5, 0x9f, 0x49, 0xb8, 0xd8, 0x6b, 0x0f, 0x4e, 0x6f, 0xf4, + 0xe3, 0x8f, 0x57, 0xab, 0x38, 0xb8, 0x5e, 0xc5, 0xc1, 0xdf, 0x55, 0x1c, 0xfc, 0x5c, 0xc7, 0x83, + 0xeb, 0x75, 0x3c, 0xf8, 0xbd, 0x8e, 0x07, 0x5f, 0x5e, 0x16, 0xc2, 0x5d, 0x94, 0x59, 0xc2, 0x40, + 0x12, 0x06, 0x56, 0x82, 0x25, 0x22, 0x63, 0xcf, 0x0b, 0x20, 0xd5, 0x2b, 0x22, 0x21, 0x2f, 0x97, + 0xdc, 0xd6, 0x9b, 0xda, 0xd9, 0x50, 0xf7, 0x4d, 0x73, 0x9b, 0x8d, 0xfd, 0x72, 0xbe, 0xf8, 0x17, + 0x00, 0x00, 0xff, 0xff, 0x6d, 0xd5, 0xdf, 0x27, 0x54, 0x03, 0x00, 0x00, } func (m *FungibleTokenPacketData) Marshal() (dAtA []byte, err error) { @@ -435,6 +445,11 @@ func (m *ForwardingPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.TimeoutTimestamp != 0 { + i = encodeVarintPacket(dAtA, i, uint64(m.TimeoutTimestamp)) + i-- + dAtA[i] = 0x18 + } if len(m.Hops) > 0 { for iNdEx := len(m.Hops) - 1; iNdEx >= 0; iNdEx-- { { @@ -544,6 +559,9 @@ func (m *ForwardingPacketData) Size() (n int) { n += 1 + l + sovPacket(uint64(l)) } } + if m.TimeoutTimestamp != 0 { + n += 1 + sovPacket(uint64(m.TimeoutTimestamp)) + } return n } @@ -1071,6 +1089,25 @@ func (m *ForwardingPacketData) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutTimestamp", wireType) + } + m.TimeoutTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutTimestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipPacket(dAtA[iNdEx:]) diff --git a/modules/apps/transfer/types/packet_test.go b/modules/apps/transfer/types/packet_test.go index 254cec03522..db166b2b8d8 100644 --- a/modules/apps/transfer/types/packet_test.go +++ b/modules/apps/transfer/types/packet_test.go @@ -765,7 +765,7 @@ func TestUnmarshalPacketData(t *testing.T) { tc.malleate() - packetData, err := types.UnmarshalPacketData(packetDataBz, version) + packetData, err := types.UnmarshalPacketData(packetDataBz, version, "") expPass := tc.expError == nil if expPass { @@ -819,7 +819,7 @@ func TestV2ForwardsCompatibilityFails(t *testing.T) { tc.malleate() - packetData, err := types.UnmarshalPacketData(packetDataBz, types.V2) + packetData, err := types.UnmarshalPacketData(packetDataBz, types.V2, types.EncodingProtobuf) expPass := tc.expError == nil if expPass { diff --git a/modules/apps/transfer/v2/ibc_module.go b/modules/apps/transfer/v2/ibc_module.go new file mode 100644 index 00000000000..8a360e0f3ea --- /dev/null +++ b/modules/apps/transfer/v2/ibc_module.go @@ -0,0 +1,137 @@ +package v2 + +import ( + "context" + "fmt" + + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/internal/events" + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/keeper" + channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + "github.com/cosmos/ibc-go/v9/modules/core/api" + + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" +) + +var _ api.IBCModule = (*IBCModule)(nil) + +// NewIBCModule creates a new IBCModule given the keeper +func NewIBCModule(k *keeper.Keeper) *IBCModule { + return &IBCModule{ + keeper: k, + } +} + +type IBCModule struct { + keeper *keeper.Keeper +} + +func (im *IBCModule) OnSendPacket(goCtx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload types.Payload, signer sdk.AccAddress) error { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !im.keeper.GetParams(ctx).SendEnabled { + return transfertypes.ErrSendDisabled + } + + if im.keeper.IsBlockedAddr(signer) { + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", signer) + } + + data, err := transfertypes.UnmarshalPacketData(payload.Value, payload.Version, payload.Encoding) + if err != nil { + return err + } + + return im.keeper.OnSendPacket(ctx, sourceChannel, payload, data, signer) +} + +func (im *IBCModule) OnRecvPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload types.Payload, relayer sdk.AccAddress) types.RecvPacketResult { + var ( + ackErr error + data transfertypes.FungibleTokenPacketDataV2 + ) + + ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) + recvResult := types.RecvPacketResult{ + Status: types.PacketStatus_Success, + Acknowledgement: ack.Acknowledgement(), + } + // we are explicitly wrapping this emit event call in an anonymous function so that + // the packet data is evaluated after it has been assigned a value. + defer func() { + events.EmitOnRecvPacketEvent(ctx, data, ack, ackErr) + }() + + + data, ackErr = transfertypes.UnmarshalPacketData(payload.Value, payload.Version, payload.Encoding) + if ackErr != nil { + ack = channeltypes.NewErrorAcknowledgement(ackErr) + im.keeper.Logger(ctx).Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), sequence)) + return types.RecvPacketResult{ + Status: types.PacketStatus_Failure, + Acknowledgement: ack.Acknowledgement(), + } + } + + if ackErr = im.keeper.OnRecvPacket(ctx, sourceChannel, destinationChannel, payload, data); ackErr != nil { + ack = channeltypes.NewErrorAcknowledgement(ackErr) + im.keeper.Logger(ctx).Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), sequence)) + return types.RecvPacketResult{ + Status: types.PacketStatus_Failure, + Acknowledgement: ack.Acknowledgement(), + } + } + + im.keeper.Logger(ctx).Info("successfully handled ICS-20 packet", "sequence", sequence) + + if data.HasForwarding() { + // NOTE: acknowledgement will be written asynchronously + return types.RecvPacketResult{ + Status: types.PacketStatus_Async, + } + } + + // NOTE: acknowledgement will be written synchronously during IBC handler execution. + return recvResult +} + + +func (im *IBCModule) OnTimeoutPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload types.Payload, relayer sdk.AccAddress) error { + data, err := transfertypes.UnmarshalPacketData(payload.Value, payload.Version, payload.Encoding) + if err != nil { + return err + } + + // refund tokens + if err := im.keeper.OnTimeoutPacket(ctx, payload.SourcePort, sourceChannel, data); err != nil { + return err + } + + events.EmitOnTimeoutEvent(ctx, data) + return nil +} + +func (im *IBCModule) OnAcknowledgementPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, acknowledgement []byte, payload types.Payload, relayer sdk.AccAddress) error { + var ack channeltypes.Acknowledgement + if err := transfertypes.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { + return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) + } + + data, err := transfertypes.UnmarshalPacketData(payload.Value, payload.Version, payload.Encoding) + if err != nil { + return err + } + + if err := im.keeper.OnAcknowledgementPacket(ctx, payload.SourcePort, sourceChannel, data, ack); err != nil { + return err + } + + events.EmitOnAcknowledgementPacketEvent(ctx, data, ack) + return nil +} diff --git a/modules/apps/transfer/v2/keeper/forwarding_test.go b/modules/apps/transfer/v2/keeper/forwarding_test.go new file mode 100644 index 00000000000..91f4fc0d531 --- /dev/null +++ b/modules/apps/transfer/v2/keeper/forwarding_test.go @@ -0,0 +1,160 @@ +package keeper_test + +import ( + "testing" + + testifysuite "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + typesv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +type ForwardingTestSuite struct { + testifysuite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + chainC *ibctesting.TestChain + chainD *ibctesting.TestChain +} + +func TestForwardingTestSuite(t *testing.T) { + testifysuite.Run(t, new(ForwardingTestSuite)) +} + +func (suite *ForwardingTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 4) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3)) + suite.chainD = suite.coordinator.GetChain(ibctesting.GetChainID(4)) +} + +func (suite *ForwardingTestSuite) setupForwardingPaths() (pathAtoB, pathBtoC *ibctesting.Path) { + pathAtoB = ibctesting.NewTransferPath(suite.chainA, suite.chainB) + pathBtoC = ibctesting.NewTransferPath(suite.chainB, suite.chainC) + pathAtoB.SetupV2() + pathBtoC.SetupV2() + + return pathAtoB, pathBtoC +} + +// TestSuccessfulForward tests a successful transfer from A to C through B. +func (suite *ForwardingTestSuite) TestSuccessfulForward() { + /* + Given the following topology: + chain A (channel 0) -> (channel-0) chain B (channel-1) -> (channel-0) chain C + stake transfer/channel-0/stake transfer/channel-0/transfer/channel-0/stake + We want to trigger: + 1. A sends B over channel-0. + 2. Receive on B. + 2.1 B sends C over channel-1 + 3. Receive on C. + At this point we want to assert: + A: escrowA = amount,stake + B: escrowB = amount,transfer/channel-0/denom + C: finalReceiver = amount,transfer/channel-0/transfer/channel-0/denom + */ + + pathAtoB, pathBtoC := suite.setupForwardingPaths() + + sender := suite.chainA.SenderAccounts[0].SenderAccount + receiver := suite.chainC.SenderAccounts[0].SenderAccount + + timeoutTimestamp := suite.chainA.GetTimeoutTimestampSecs() + msg := &typesv2.MsgTransfer{ + SourceChannel: pathAtoB.EndpointA.ChannelID, + SourcePort: pathAtoB.EndpointA.ChannelConfig.PortID, + DestinationPort: pathAtoB.EndpointB.ChannelConfig.PortID, + Version: transfertypes.V2, + Encoding: transfertypes.EncodingProtobuf, + Sender: sender.GetAddress().String(), + Receiver: receiver.GetAddress().String(), + TimeoutTimestamp: timeoutTimestamp, + Memo: "", + Tokens: sdk.NewCoins(ibctesting.TestCoin), + Forwarding: &transfertypes.Forwarding{ + Unwind: false, + Hops: []transfertypes.Hop{ + {PortId: pathBtoC.EndpointA.ChannelConfig.PortID, ChannelId: pathBtoC.EndpointA.ChannelID}, + }, + }, + } + result, err := suite.chainA.SendMsgs(msg) + suite.Require().NoError(err) // message committed + suite.Require().NotNil(result) + + // parse the packet from result events and recv packet on chainB + //packetFromAtoB, err := ibctesting.ParsePacketFromEvents(result.Events) + //suite.Require().NoError(err) + //suite.Require().NotNil(packetFromAtoB) + + // err = pathAtoB.EndpointB.UpdateClient() + // suite.Require().NoError(err) + + // result, err = pathAtoB.EndpointB.RecvPacketWithResult(packetFromAtoB) + // suite.Require().NoError(err) + // suite.Require().NotNil(result) + + // Check that Escrow A has amount + //suite.assertAmountOnChain(suite.chainA, escrow, amount, sdk.DefaultBondDenom) + + // // denom path: transfer/channel-0 + // 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) + // suite.Require().NoError(err) + // suite.Require().NotNil(packetFromBtoC) + + // err = pathBtoC.EndpointA.UpdateClient() + // suite.Require().NoError(err) + + // err = pathBtoC.EndpointB.UpdateClient() + // suite.Require().NoError(err) + + // // B should have stored the forwarded packet. + // _, found := suite.chainB.GetSimApp().TransferKeeper.GetForwardedPacket(suite.chainB.GetContext(), packetFromBtoC.SourcePort, packetFromBtoC.SourceChannel, packetFromBtoC.Sequence) + // suite.Require().True(found, "Chain B should have stored the forwarded packet") + + // result, err = pathBtoC.EndpointB.RecvPacketWithResult(packetFromBtoC) + // suite.Require().NoError(err) + // suite.Require().NotNil(result) + + // // transfer/channel-0/transfer/channel-0/denom + // // Check that the final receiver has received the expected tokens. + // 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()) + + // successAck := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) + // successAckBz := channeltypes.CommitAcknowledgement(successAck.Acknowledgement()) + // ackOnC := suite.chainC.GetAcknowledgement(packetFromBtoC) + // suite.Require().Equal(successAckBz, ackOnC) + + // // Ack back to B + // err = pathBtoC.EndpointB.UpdateClient() + // suite.Require().NoError(err) + + // err = pathBtoC.EndpointA.AcknowledgePacket(packetFromBtoC, successAck.Acknowledgement()) + // suite.Require().NoError(err) + + // ackOnB := suite.chainB.GetAcknowledgement(packetFromAtoB) + // suite.Require().Equal(successAckBz, ackOnB) + + // // B should now have deleted the forwarded packet. + // _, found = suite.chainB.GetSimApp().TransferKeeper.GetForwardedPacket(suite.chainB.GetContext(), packetFromBtoC.SourcePort, packetFromBtoC.SourceChannel, packetFromBtoC.Sequence) + // suite.Require().False(found, "Chain B should have deleted the forwarded packet") + + // // Ack back to A + // err = pathAtoB.EndpointA.UpdateClient() + // suite.Require().NoError(err) + + // err = pathAtoB.EndpointA.AcknowledgePacket(packetFromAtoB, successAck.Acknowledgement()) + // suite.Require().NoError(err) +} diff --git a/modules/apps/transfer/v2/keeper/keeper.go b/modules/apps/transfer/v2/keeper/keeper.go new file mode 100644 index 00000000000..54e400efa41 --- /dev/null +++ b/modules/apps/transfer/v2/keeper/keeper.go @@ -0,0 +1,431 @@ +package keeper + +import ( + "context" + "fmt" + "slices" + + errorsmod "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/gogoproto/proto" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/internal/events" + transferkeeper "github.com/cosmos/ibc-go/v9/modules/apps/transfer/keeper" + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + typesv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types" + + channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channelkeeperv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" +) + +var _ typesv2.MsgServer = (*Keeper)(nil) + +type Keeper struct { + transferkeeper.Keeper + channelKeeperV2 *channelkeeperv2.Keeper + msgServiceRouter *baseapp.MsgServiceRouter +} + +func NewKeeper(transferKeeper transferkeeper.Keeper, channelKeeperV2 *channelkeeperv2.Keeper, msgServiceRouter *baseapp.MsgServiceRouter) *Keeper { + return &Keeper{ + Keeper: transferKeeper, + channelKeeperV2: channelKeeperV2, + msgServiceRouter: msgServiceRouter, + } +} + +func (k *Keeper) Transfer(goCtx context.Context, msg *typesv2.MsgTransfer) (*typesv2.MsgTransferResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !k.GetParams(ctx).SendEnabled { + return nil, types.ErrSendDisabled + } + + sender, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, err + } + + if err := k.BankKeeper.IsSendEnabledCoins(ctx, msg.Tokens...); err != nil { + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, err.Error()) + } + + if k.IsBlockedAddr(sender) { + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) + } + + if msg.Forwarding.GetUnwind() { + msg, err = k.unwindHops(ctx, msg) + if err != nil { + return nil, err + } + } + + tokens := []types.Token{} + for _, c := range msg.Tokens { + t, err := k.Keeper.TokenFromCoin(ctx, c) + if err != nil { + return nil, err + } + tokens = append(tokens, t) + } + fowardingPacketData := types.NewForwardingPacketData(msg.Memo /* TODO is this correct? */, msg.Forwarding.Hops...) + data := types.NewFungibleTokenPacketDataV2(tokens, msg.Sender, msg.Receiver, msg.Memo, fowardingPacketData) + dataBz, err := data.Marshal() + if err != nil { + return nil, err + } + + //TODO bznein use msgtransfer instead of sendpacket + payload := channeltypesv2.NewPayload(msg.SourcePort, msg.DestinationPort, msg.Version, msg.Encoding, dataBz) + msgSendPacket := channeltypesv2.NewMsgSendPacket(msg.SourceChannel, msg.TimeoutTimestamp, msg.Sender, payload) + + handler := k.msgServiceRouter.Handler(msgSendPacket) + res, err := handler(ctx, msgSendPacket) + if err != nil { + return nil, err + } + + sequence, err := k.GetSequenceFromSendPacketResult(res) + if err != nil { + return nil, err + } + + return &typesv2.MsgTransferResponse{Sequence: sequence}, nil +} + +// TODO move somewhere else? +func (k *Keeper) GetSequenceFromSendPacketResult(result *sdk.Result) (uint64, error) { + //var msgData sdk.TxMsgData + //err := proto.Unmarshal(result.MsgResponses[0].Value, &msgData) + //if err != nil { + // return 0, err + //} + msgResponse := result.MsgResponses[0] + var resp channeltypesv2.MsgSendPacketResponse + err := proto.Unmarshal(msgResponse.Value, &resp) + if err != nil { + return 0, err + } + return resp.Sequence, nil +} + +// unwindHops unwinds the hops present in the tokens denomination and returns the message modified to reflect +// the unwound path to take. It assumes that only a single token is present (as this is verified in ValidateBasic) +// in the tokens list and ensures that the token is not native to the chain. +func (k Keeper) unwindHops(ctx sdk.Context, msg *typesv2.MsgTransfer) (*typesv2.MsgTransfer, error) { + unwindHops, err := k.getUnwindHops(ctx, msg.Tokens) + if err != nil { + return nil, err + } + + // Update message fields. + msg.SourceChannel, msg.SourcePort = unwindHops[0].ChannelId, unwindHops[0].PortId + msg.Forwarding.Hops = append(unwindHops[1:], msg.Forwarding.Hops...) + msg.Forwarding.Unwind = false + + // TODO implement validation (create GH issue) + // // Message is validate again, this would only fail if hops now exceeds maximum allowed. + // if err := msg.ValidateBasic(); err != nil { + // return nil, err + // } + return msg, nil +} + +// getUnwindHops returns the hops to be used during unwinding. If coins consists of more than +// one coin, all coins must have the exact same trace, else an error is returned. getUnwindHops +// also validates that the coins are not native to the chain. +func (k Keeper) getUnwindHops(ctx sdk.Context, coins sdk.Coins) ([]types.Hop, error) { + // Sanity: validation for MsgTransfer ensures coins are not empty. + if len(coins) == 0 { + return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "coins cannot be empty") + } + + token, err := k.TokenFromCoin(ctx, coins[0]) + if err != nil { + return nil, err + } + + if token.Denom.IsNative() { + return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "cannot unwind a native token") + } + + unwindTrace := token.Denom.Trace + for _, coin := range coins[1:] { + token, err := k.TokenFromCoin(ctx, coin) + if err != nil { + return nil, err + } + + // Implicitly ensures coin we're iterating over is not native. + if !slices.Equal(token.Denom.Trace, unwindTrace) { + return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "cannot unwind tokens with different traces.") + } + } + + return unwindTrace, nil +} + +func (k *Keeper) OnSendPacket(ctx context.Context, sourceChannel string, payload channeltypesv2.Payload, data types.FungibleTokenPacketDataV2, sender sdk.AccAddress) error { + for _, token := range data.Tokens { + coin, err := token.ToCoin() + if err != nil { + return err + } + + if coin.Amount.Equal(types.UnboundedSpendLimit()) { + coin.Amount = k.BankKeeper.GetBalance(ctx, sender, coin.Denom).Amount + } + + // NOTE: SendTransfer simply sends the denomination as it exists on its own + // chain inside the packet data. The receiving chain will perform denom + // prefixing as necessary. + + // if the denom is prefixed by the port and channel on which we are sending + // the token, then we must be returning the token back to the chain they originated from + if token.Denom.HasPrefix(payload.SourcePort, sourceChannel) { + // transfer the coins to the module account and burn them + if err := k.BankKeeper.SendCoinsFromAccountToModule( + ctx, sender, types.ModuleName, sdk.NewCoins(coin), + ); err != nil { + return err + } + + if err := k.BankKeeper.BurnCoins( + ctx, types.ModuleName, sdk.NewCoins(coin), + ); err != nil { + // NOTE: should not happen as the module account was + // retrieved on the step above and it has enough balance + // to burn. + panic(fmt.Errorf("cannot burn coins after a successful send to a module account: %v", err)) + } + } else { + // obtain the escrow address for the source channel end + escrowAddress := types.GetEscrowAddress(payload.SourcePort, sourceChannel) + if err := k.EscrowCoin(ctx, sender, escrowAddress, coin); err != nil { + return err + } + } + } + + // TODO: events + // events.EmitTransferEvent(ctx, sender.String(), receiver, tokens, memo, hops) + + // TODO: telemetry + // telemetry.ReportTransfer(sourcePort, sourceChannel, destinationPort, destinationChannel, tokens) + + return nil +} + +func (k *Keeper) OnRecvPacket(ctx context.Context, sourceChannel, destChannel string, payload channeltypesv2.Payload, data types.FungibleTokenPacketDataV2) error { + // validate packet data upon receiving + if err := data.ValidateBasic(); err != nil { + return errorsmod.Wrapf(err, "error validating ICS-20 transfer packet data") + } + + if !k.GetParams(ctx).ReceiveEnabled { + return types.ErrReceiveDisabled + } + + receiver, err := sdk.AccAddressFromBech32(data.Receiver) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "failed to decode receiver address %s: %v", data.Receiver, err) + } + + if k.IsBlockedAddr(receiver) { + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver) + } + + receivedCoins := make(sdk.Coins, 0, len(data.Tokens)) + for _, token := range data.Tokens { + // parse the transfer amount + transferAmount, ok := sdkmath.NewIntFromString(token.Amount) + if !ok { + return errorsmod.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount: %s", token.Amount) + } + + // This is the prefix that would have been prefixed to the denomination + // on sender chain IF and only if the token originally came from the + // receiving chain. + // + // NOTE: We use SourcePort and SourceChannel here, because the counterparty + // chain would have prefixed with DestPort and DestChannel when originally + // receiving this token. + if token.Denom.HasPrefix(payload.SourcePort, sourceChannel) { + // sender chain is not the source, unescrow tokens + + // remove prefix added by sender chain + token.Denom.Trace = token.Denom.Trace[1:] + + coin := sdk.NewCoin(token.Denom.IBCDenom(), transferAmount) + + escrowAddress := types.GetEscrowAddress(payload.DestinationPort, destChannel) + if err := k.UnescrowCoin(ctx, escrowAddress, receiver, coin); err != nil { + return err + } + + // Appending token. The new denom has been computed + receivedCoins = append(receivedCoins, coin) + } else { + // 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.Hop{types.NewHop(payload.DestinationPort, destChannel)} + token.Denom.Trace = append(trace, token.Denom.Trace...) + + if !k.HasDenom(ctx, token.Denom.Hash()) { + k.SetDenom(ctx, token.Denom) + } + + voucherDenom := token.Denom.IBCDenom() + if !k.BankKeeper.HasDenomMetaData(ctx, voucherDenom) { + k.SetDenomMetadata(ctx, token.Denom) + } + + events.EmitDenomEvent(ctx, token) + + voucher := sdk.NewCoin(voucherDenom, transferAmount) + + // mint new tokens if the source of the transfer is the same chain + if err := k.BankKeeper.MintCoins( + ctx, types.ModuleName, sdk.NewCoins(voucher), + ); err != nil { + return errorsmod.Wrap(err, "failed to mint IBC tokens") + } + + // send to receiver + moduleAddr := k.AuthKeeper.GetModuleAddress(types.ModuleName) + if err := k.BankKeeper.SendCoins( + ctx, moduleAddr, receiver, sdk.NewCoins(voucher), + ); err != nil { + return errorsmod.Wrapf(err, "failed to send coins to receiver %s", receiver.String()) + } + + receivedCoins = append(receivedCoins, voucher) + } + } + + if data.HasForwarding() { + // we are now sending from the forward escrow address to the final receiver address. + if err := k.forwardPacket(ctx, destChannel, data, payload, receivedCoins); err != nil { + return err + } + } + + // TODO: telemetry + //telemetry.ReportOnRecvPacket(packet, data.Tokens) + + // The ibc_module.go module will return the proper ack. + return nil +} + +// TODO move to a different file +// forwardPacket forwards a fungible FungibleTokenPacketDataV2 to the next hop in the forwarding path. +func (k Keeper) forwardPacket(ctx context.Context, destChannel string, data types.FungibleTokenPacketDataV2, payload channeltypesv2.Payload, receivedCoins sdk.Coins) error { + newForwardingPacketData := types.NewForwardingPacketData(data.Forwarding.DestinationMemo) + if len(data.Forwarding.Hops) > 1 { + // remove the first hop since we are going to send to the first hop now and we want to propagate the rest of the hops to the receiver + newForwardingPacketData.Hops = data.Forwarding.Hops[1:] + } + + memo := data.Memo + if len(newForwardingPacketData.Hops) > 0 { + memo = "" + } + + // sending from module account (used as a temporary forward escrow) to the original receiver address. + sender := k.AuthKeeper.GetModuleAddress(types.ModuleName) + + newPacketData := types.NewFungibleTokenPacketDataV2(data.Tokens, data.Sender, data.Receiver, memo, newForwardingPacketData) + + pdBz, err := newPacketData.Marshal() + if err != nil { + return err + } + payload.Value = pdBz + + msg := channeltypesv2.NewMsgSendPacket( + data.Forwarding.Hops[0].ChannelId, + data.Forwarding.TimeoutTimestamp, + sender.String(), + payload, + ) + + handler := k.msgServiceRouter.Handler(&channeltypesv2.MsgSendPacket{}) + res, err := handler(sdk.UnwrapSDKContext(ctx), msg) + if err != nil { + return err + } + sequence, err := k.GetSequenceFromSendPacketResult(res) + if err != nil { + return err + } + k.SetForwardedPacketSequenceAndDestinationChannel(ctx, data.Forwarding.Hops[0].PortId, data.Forwarding.Hops[0].ChannelId, sequence, destChannel) + return nil +} + +func (k *Keeper) OnAcknowledgementPacket(ctx context.Context, sourcePort, sourceChannel string, data types.FungibleTokenPacketDataV2, ack channeltypes.Acknowledgement) error { + switch ack.Response.(type) { + case *channeltypes.Acknowledgement_Result: + // the acknowledgement succeeded on the receiving chain so nothing + // needs to be executed and no error needs to be returned + return nil + case *channeltypes.Acknowledgement_Error: + // We refund the tokens from the escrow address to the sender + return k.refundPacketTokens(ctx, sourcePort, sourceChannel, data) + default: + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected one of [%T, %T], got %T", channeltypes.Acknowledgement_Result{}, channeltypes.Acknowledgement_Error{}, ack.Response) + } +} + +func (k *Keeper) OnTimeoutPacket(ctx context.Context, sourcePort, sourceChannel string, data types.FungibleTokenPacketDataV2) error { + return k.refundPacketTokens(ctx, sourcePort, sourceChannel, data) +} + +func (k Keeper) refundPacketTokens(ctx context.Context, sourcePort, sourceChannel string, data types.FungibleTokenPacketDataV2) error { + // NOTE: packet data type already checked in handler.go + + sender, err := sdk.AccAddressFromBech32(data.Sender) + if err != nil { + return err + } + if k.IsBlockedAddr(sender) { + return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to receive funds", sender) + } + + // escrow address for unescrowing tokens back to sender + escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel) + + moduleAccountAddr := k.AuthKeeper.GetModuleAddress(types.ModuleName) + for _, token := range data.Tokens { + coin, err := token.ToCoin() + if err != nil { + return err + } + + // if the token we must refund is prefixed by the source port and channel + // then the tokens were burnt when the packet was sent and we must mint new tokens + if token.Denom.HasPrefix(sourcePort, sourceChannel) { + // mint vouchers back to sender + if err := k.BankKeeper.MintCoins( + ctx, types.ModuleName, sdk.NewCoins(coin), + ); err != nil { + return err + } + + if err := k.BankKeeper.SendCoins(ctx, moduleAccountAddr, sender, sdk.NewCoins(coin)); err != nil { + panic(fmt.Errorf("unable to send coins from module to account despite previously minting coins to module account: %v", err)) + } + } else { + if err := k.UnescrowCoin(ctx, escrowAddress, sender, coin); err != nil { + return err + } + } + } + + return nil +} diff --git a/modules/apps/transfer/v2/keeper/keeper_test.go b/modules/apps/transfer/v2/keeper/keeper_test.go new file mode 100644 index 00000000000..69836b14120 --- /dev/null +++ b/modules/apps/transfer/v2/keeper/keeper_test.go @@ -0,0 +1,58 @@ +package keeper_test + +import ( + "fmt" + "testing" + + testifysuite "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +type KeeperTestSuite struct { + testifysuite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + chainC *ibctesting.TestChain +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3)) +} + +type amountType int + +const ( + escrow amountType = iota + balance +) + +func (suite *KeeperTestSuite) assertAmountOnChain(chain *ibctesting.TestChain, balanceType amountType, amount sdkmath.Int, denom string) { + var total sdk.Coin + switch balanceType { + case escrow: + total = chain.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(chain.GetContext(), denom) + totalV2 := chain.GetSimApp().TransferKeeperV2.GetTotalEscrowForDenom(chain.GetContext(), denom) + suite.Require().Equal(total, totalV2, "escrow balance mismatch") + case balance: + total = chain.GetSimApp().BankKeeper.GetBalance(chain.GetContext(), chain.SenderAccounts[0].SenderAccount.GetAddress(), denom) + default: + suite.Fail("invalid amountType %s", balanceType) + } + suite.Require().Equal(amount, total.Amount, fmt.Sprintf("Chain %s: got balance of %s, wanted %s", chain.Name(), total.Amount.String(), amount.String())) +} + +func TestKeeperTestSuite(t *testing.T) { + testifysuite.Run(t, new(KeeperTestSuite)) +} diff --git a/modules/apps/transfer/v2/keeper/msg_server_test.go b/modules/apps/transfer/v2/keeper/msg_server_test.go new file mode 100644 index 00000000000..1e4c270c4ec --- /dev/null +++ b/modules/apps/transfer/v2/keeper/msg_server_test.go @@ -0,0 +1,594 @@ +package keeper_test + +import ( + "bytes" + "time" + + sdkmath "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" +) + +// TestMsgSendPacketTransfer tests the MsgSendPacket rpc handler for the transfer v2 application. +func (suite *KeeperTestSuite) TestMsgSendPacketTransfer() { + var payload channeltypesv2.Payload + var path *ibctesting.Path + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: send transfers disabled", + func() { + suite.chainA.GetSimApp().TransferKeeperV2.SetParams(suite.chainA.GetContext(), + transfertypes.Params{ + SendEnabled: false, + }, + ) + }, + transfertypes.ErrSendDisabled, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + tokens := []transfertypes.Token{ + { + Denom: transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + Trace: nil, + }, + Amount: ibctesting.DefaultCoinAmount.String(), + }, + } + + ftpd := transfertypes.NewFungibleTokenPacketDataV2(tokens, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", transfertypes.ForwardingPacketData{}) + bz := suite.chainA.Codec.MustMarshal(&ftpd) + + timestamp := suite.chainA.GetTimeoutTimestampSecs() + payload = channeltypesv2.NewPayload(transfertypes.ModuleName, transfertypes.ModuleName, transfertypes.V2, transfertypes.EncodingProtobuf, bz) + + tc.malleate() + + packet, err := path.EndpointA.MsgSendPacket(timestamp, payload) + + expPass := tc.expError == nil + if expPass { + + // ensure every token sent is escrowed. + for _, t := range tokens { + escrowedAmount := suite.chainA.GetSimApp().TransferKeeperV2.GetTotalEscrowForDenom(suite.chainA.GetContext(), t.Denom.IBCDenom()) + expected, err := t.ToCoin() + suite.Require().NoError(err) + suite.Require().Equal(expected, escrowedAmount, "escrowed amount is not equal to expected amount") + } + suite.Require().NoError(err) + suite.Require().NotEmpty(packet) + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q but got %q", tc.expError, err) + suite.Require().Empty(packet) + } + }) + } +} + +// TestMsgRecvPacketTransfer tests the MsgRecvPacket rpc handler for the transfer v2 application. +func (suite *KeeperTestSuite) TestMsgRecvPacketTransfer() { + var ( + path *ibctesting.Path + packet channeltypesv2.Packet + expectedAck channeltypesv2.Acknowledgement + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: invalid destination channel on received packet", + func() { + packet.DestinationChannel = ibctesting.InvalidID + }, + channeltypesv2.ErrChannelNotFound, + }, + { + "failure: counter party channel does not match source channel", + func() { + packet.SourceChannel = ibctesting.InvalidID + }, + channeltypes.ErrInvalidChannelIdentifier, + }, + { + "failure: receive is disabled", + func() { + expectedAck.AppAcknowledgements[0] = channeltypes.NewErrorAcknowledgement(transfertypes.ErrReceiveDisabled).Acknowledgement() + suite.chainB.GetSimApp().TransferKeeperV2.SetParams(suite.chainB.GetContext(), + transfertypes.Params{ + ReceiveEnabled: false, + }) + }, + nil, + }, + // TODO: async tests + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + tokens := []transfertypes.Token{ + { + Denom: transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + Trace: nil, + }, + Amount: ibctesting.DefaultCoinAmount.String(), + }, + } + + ftpd := transfertypes.NewFungibleTokenPacketDataV2(tokens, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", transfertypes.ForwardingPacketData{}) + bz := suite.chainA.Codec.MustMarshal(&ftpd) + + timestamp := suite.chainA.GetTimeoutTimestampSecs() + payload := channeltypesv2.NewPayload(transfertypes.ModuleName, transfertypes.ModuleName, transfertypes.V2, transfertypes.EncodingProtobuf, bz) + var err error + packet, err = path.EndpointA.MsgSendPacket(timestamp, payload) + suite.Require().NoError(err) + + // by default, we assume a successful acknowledgement will be written. + ackBytes := channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement() + expectedAck = channeltypesv2.Acknowledgement{AppAcknowledgements: [][]byte{ackBytes}} + tc.malleate() + + err = path.EndpointB.MsgRecvPacket(packet) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + actualAckHash := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeperV2.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence) + expectedHash := channeltypesv2.CommitAcknowledgement(expectedAck) + + suite.Require().Equal(expectedHash, actualAckHash) + + denom := transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + Trace: []transfertypes.Hop{ + transfertypes.NewHop(payload.DestinationPort, packet.DestinationChannel), + }, + } + + actualBalance := path.EndpointB.Chain.GetSimApp().TransferKeeperV2.BankKeeper.GetBalance(suite.chainB.GetContext(), suite.chainB.SenderAccount.GetAddress(), denom.IBCDenom()) + + var expectedBalance sdk.Coin + // on a successful ack we expect the full amount to be transferred + if bytes.Equal(expectedAck.AppAcknowledgements[0], ackBytes) { + expectedBalance = sdk.NewCoin(denom.IBCDenom(), ibctesting.DefaultCoinAmount) + } else { + // otherwise the tokens do not make it to the address. + expectedBalance = sdk.NewCoin(denom.IBCDenom(), sdkmath.NewInt(0)) + } + + suite.Require().Equal(expectedBalance.Amount, actualBalance.Amount) + + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q but got %q", tc.expError, err) + } + }) + } +} + +// TestMsgAckPacketTransfer tests the MsgAcknowledgePacket rpc handler for the transfer v2 application. +func (suite *KeeperTestSuite) TestMsgAckPacketTransfer() { + var ( + path *ibctesting.Path + packet channeltypesv2.Packet + expectedAck channeltypesv2.Acknowledgement + ) + + testCases := []struct { + name string + malleate func() + expError error + causeFailureOnRecv bool + }{ + { + "success", + func() {}, + nil, + false, + }, + { + "failure: proof verification failure", + func() { + expectedAck.AppAcknowledgements[0] = mockv2.MockFailRecvPacketResult.Acknowledgement + }, + commitmenttypes.ErrInvalidProof, + false, + }, + { + "failure: escrowed tokens are refunded", + func() { + expectedAck.AppAcknowledgements[0] = channeltypes.NewErrorAcknowledgement(transfertypes.ErrReceiveDisabled).Acknowledgement() + }, + nil, + true, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + tokens := []transfertypes.Token{ + { + Denom: transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + Trace: nil, + }, + Amount: ibctesting.DefaultCoinAmount.String(), + }, + } + + ftpd := transfertypes.NewFungibleTokenPacketDataV2(tokens, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", transfertypes.ForwardingPacketData{}) + bz := suite.chainA.Codec.MustMarshal(&ftpd) + + timestamp := suite.chainA.GetTimeoutTimestampSecs() + payload := channeltypesv2.NewPayload(transfertypes.ModuleName, transfertypes.ModuleName, transfertypes.V2, transfertypes.EncodingProtobuf, bz) + + var err error + packet, err = path.EndpointA.MsgSendPacket(timestamp, payload) + suite.Require().NoError(err) + + if tc.causeFailureOnRecv { + // ensure that the recv packet fails at the application level, but succeeds at the IBC handler level + // this will ensure that a failed ack will be written to state. + suite.chainB.GetSimApp().TransferKeeperV2.SetParams(suite.chainB.GetContext(), + transfertypes.Params{ + ReceiveEnabled: false, + }) + } + + err = path.EndpointB.MsgRecvPacket(packet) + suite.Require().NoError(err) + + ackBytes := channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement() + expectedAck = channeltypesv2.Acknowledgement{AppAcknowledgements: [][]byte{ackBytes}} + tc.malleate() + + err = path.EndpointA.MsgAcknowledgePacket(packet, expectedAck) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + if bytes.Equal(expectedAck.AppAcknowledgements[0], ackBytes) { + // tokens remain escrowed + for _, t := range tokens { + escrowedAmount := suite.chainA.GetSimApp().TransferKeeperV2.GetTotalEscrowForDenom(suite.chainA.GetContext(), t.Denom.IBCDenom()) + expected, err := t.ToCoin() + suite.Require().NoError(err) + suite.Require().Equal(expected, escrowedAmount, "escrowed amount is not equal to expected amount") + } + } else { + // tokens have been unescrowed + for _, t := range tokens { + escrowedAmount := suite.chainA.GetSimApp().TransferKeeperV2.GetTotalEscrowForDenom(suite.chainA.GetContext(), t.Denom.IBCDenom()) + suite.Require().Equal(sdk.NewCoin(t.Denom.IBCDenom(), sdkmath.NewInt(0)), escrowedAmount, "escrowed amount is not equal to expected amount") + } + } + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q but got %q", tc.expError, err) + } + }) + } +} + +// TestMsgTimeoutPacketTransfer tests the MsgTimeoutPacket rpc handler for the transfer v2 application. +func (suite *KeeperTestSuite) TestMsgTimeoutPacketTransfer() { + var ( + path *ibctesting.Path + packet channeltypesv2.Packet + timeoutTimestamp uint64 + ) + + testCases := []struct { + name string + malleate func() + timeoutPacket bool + expError error + }{ + { + "success", + func() {}, + true, + nil, + }, + { + "failure: packet has not timed out", + func() {}, + false, + channeltypes.ErrTimeoutNotReached, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + tokens := []transfertypes.Token{ + { + Denom: transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + Trace: nil, + }, + Amount: ibctesting.DefaultCoinAmount.String(), + }, + } + + ftpd := transfertypes.NewFungibleTokenPacketDataV2(tokens, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", transfertypes.ForwardingPacketData{}) + bz := suite.chainA.Codec.MustMarshal(&ftpd) + + timeoutTimestamp = uint64(suite.chainA.GetContext().BlockTime().Unix()) + uint64(time.Hour.Seconds()) + payload := channeltypesv2.NewPayload(transfertypes.ModuleName, transfertypes.ModuleName, transfertypes.V2, transfertypes.EncodingProtobuf, bz) + + var err error + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, payload) + suite.Require().NoError(err) + + if tc.timeoutPacket { + suite.coordinator.IncrementTimeBy(time.Hour * 2) + } + + // ensure that chainA has an update to date client of chain B. + suite.Require().NoError(path.EndpointA.UpdateClient()) + + tc.malleate() + + err = path.EndpointA.MsgTimeoutPacket(packet) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + // ensure funds are un-escrowed + for _, t := range tokens { + escrowedAmount := suite.chainA.GetSimApp().TransferKeeperV2.GetTotalEscrowForDenom(suite.chainA.GetContext(), t.Denom.IBCDenom()) + suite.Require().Equal(sdk.NewCoin(t.Denom.IBCDenom(), sdkmath.NewInt(0)), escrowedAmount, "escrowed amount is not equal to expected amount") + } + + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q but got %q", tc.expError, err) + // tokens remain escrowed if there is a timeout failure + for _, t := range tokens { + escrowedAmount := suite.chainA.GetSimApp().TransferKeeperV2.GetTotalEscrowForDenom(suite.chainA.GetContext(), t.Denom.IBCDenom()) + expected, err := t.ToCoin() + suite.Require().NoError(err) + suite.Require().Equal(expected, escrowedAmount, "escrowed amount is not equal to expected amount") + } + } + }) + } +} + +func (suite *KeeperTestSuite) TestV2RetainsFungibility() { + suite.SetupTest() + + path := ibctesting.NewTransferPath(suite.chainA, suite.chainB) + path.Setup() + + pathv2 := ibctesting.NewPath(suite.chainB, suite.chainC) + pathv2.SetupV2() + + denomA := transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + } + + denomAtoB := transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + Trace: []transfertypes.Hop{ + transfertypes.NewHop(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), + }, + } + + denomBtoC := transfertypes.Denom{ + Base: sdk.DefaultBondDenom, + Trace: []transfertypes.Hop{ + transfertypes.NewHop(transfertypes.ModuleName, pathv2.EndpointB.ChannelID), + transfertypes.NewHop(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), + }, + } + + ackBytes := channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement() + successfulAck := channeltypesv2.Acknowledgement{AppAcknowledgements: [][]byte{ackBytes}} + + originalAmount, ok := sdkmath.NewIntFromString(ibctesting.DefaultGenesisAccBalance) + suite.Require().True(ok) + + suite.Run("between A and B", func() { + var packet channeltypes.Packet + suite.Run("transfer packet", func() { + transferMsg := transfertypes.NewMsgTransfer( + path.EndpointA.ChannelConfig.PortID, + path.EndpointA.ChannelID, + sdk.NewCoins(sdk.NewCoin(denomA.IBCDenom(), ibctesting.TestCoin.Amount)), + suite.chainA.SenderAccount.GetAddress().String(), + suite.chainB.SenderAccount.GetAddress().String(), + clienttypes.ZeroHeight(), + suite.chainA.GetTimeoutTimestamp(), + "memo", + nil, + ) + + result, err := suite.chainA.SendMsgs(transferMsg) + suite.Require().NoError(err) // message committed + + remainingAmount := originalAmount.Sub(ibctesting.DefaultCoinAmount) + suite.assertAmountOnChain(suite.chainA, balance, remainingAmount, denomA.IBCDenom()) + + packet, err = ibctesting.ParsePacketFromEvents(result.Events) + suite.Require().NoError(err) + }) + + suite.Run("recv and ack packet", func() { + err := path.RelayPacket(packet) + suite.Require().NoError(err) + }) + }) + + suite.Run("between B and C", func() { + var packetV2 channeltypesv2.Packet + + suite.Run("send packet", func() { + tokens := []transfertypes.Token{ + { + Denom: denomAtoB, + Amount: ibctesting.DefaultCoinAmount.String(), + }, + } + + ftpd := transfertypes.NewFungibleTokenPacketDataV2(tokens, suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String(), "", transfertypes.ForwardingPacketData{}) + bz := suite.chainB.Codec.MustMarshal(&ftpd) + + timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Unix()) + uint64(time.Hour.Seconds()) + payload := channeltypesv2.NewPayload(transfertypes.ModuleName, transfertypes.ModuleName, transfertypes.V2, transfertypes.EncodingProtobuf, bz) + + var err error + packetV2, err = pathv2.EndpointA.MsgSendPacket(timeoutTimestamp, payload) + suite.Require().NoError(err) + // the escrow account on chain B should have escrowed the tokens after sending from B to C + suite.assertAmountOnChain(suite.chainB, escrow, ibctesting.DefaultCoinAmount, denomAtoB.IBCDenom()) + }) + + suite.Run("recv packet", func() { + err := pathv2.EndpointB.MsgRecvPacket(packetV2) + suite.Require().NoError(err) + + // the receiving chain should have received the tokens + suite.assertAmountOnChain(suite.chainC, balance, ibctesting.DefaultCoinAmount, denomBtoC.IBCDenom()) + }) + + suite.Run("ack packet", func() { + err := pathv2.EndpointA.MsgAcknowledgePacket(packetV2, successfulAck) + suite.Require().NoError(err) + }) + }) + + suite.Run("between C and B", func() { + var packetV2 channeltypesv2.Packet + + suite.Run("send packet", func() { + // send from C to B + tokens := []transfertypes.Token{ + { + Denom: denomBtoC, + Amount: ibctesting.DefaultCoinAmount.String(), + }, + } + + ftpd := transfertypes.NewFungibleTokenPacketDataV2(tokens, suite.chainC.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "", transfertypes.ForwardingPacketData{}) + bz := suite.chainC.Codec.MustMarshal(&ftpd) + + timeoutTimestamp := uint64(suite.chainC.GetContext().BlockTime().Unix()) + uint64(time.Hour.Seconds()) + payload := channeltypesv2.NewPayload(transfertypes.ModuleName, transfertypes.ModuleName, transfertypes.V2, transfertypes.EncodingProtobuf, bz) + + var err error + packetV2, err = pathv2.EndpointB.MsgSendPacket(timeoutTimestamp, payload) + suite.Require().NoError(err) + + // tokens have been sent from chain C, and the balance is now empty. + suite.assertAmountOnChain(suite.chainC, balance, sdkmath.NewInt(0), denomBtoC.IBCDenom()) + }) + + suite.Run("recv packet", func() { + err := pathv2.EndpointA.MsgRecvPacket(packetV2) + suite.Require().NoError(err) + + // chain B should have received the tokens from chain C. + suite.assertAmountOnChain(suite.chainB, balance, ibctesting.DefaultCoinAmount, denomAtoB.IBCDenom()) + }) + + suite.Run("ack packet", func() { + err := pathv2.EndpointB.MsgAcknowledgePacket(packetV2, successfulAck) + suite.Require().NoError(err) + }) + }) + + suite.Run("between B and A", func() { + var packet channeltypes.Packet + + suite.Run("transfer packet", func() { + // send from B to A using MsgTransfer + transferMsg := transfertypes.NewMsgTransfer( + path.EndpointB.ChannelConfig.PortID, + path.EndpointB.ChannelID, + sdk.NewCoins(sdk.NewCoin(denomAtoB.IBCDenom(), ibctesting.TestCoin.Amount)), + suite.chainB.SenderAccount.GetAddress().String(), + suite.chainA.SenderAccount.GetAddress().String(), + clienttypes.ZeroHeight(), + suite.chainB.GetTimeoutTimestamp(), + "memo", + nil, + ) + + result, err := suite.chainB.SendMsgs(transferMsg) + suite.Require().NoError(err) // message committed + + suite.assertAmountOnChain(suite.chainB, balance, sdkmath.NewInt(0), denomAtoB.IBCDenom()) + + packet, err = ibctesting.ParsePacketFromEvents(result.Events) + suite.Require().NoError(err) + }) + suite.Run("recv and ack packet", func() { + // in order to recv in the other direction, we create a new path and recv + // on that with the endpoints reversed. + err := path.Reversed().RelayPacket(packet) + suite.Require().NoError(err) + + suite.assertAmountOnChain(suite.chainA, balance, originalAmount, denomA.IBCDenom()) + }) + }) +} diff --git a/modules/apps/transfer/v2/module.go b/modules/apps/transfer/v2/module.go new file mode 100644 index 00000000000..aca7987a190 --- /dev/null +++ b/modules/apps/transfer/v2/module.go @@ -0,0 +1,165 @@ +package v2 + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "cosmossdk.io/core/appmodule" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/client/cli" + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/simulation" + typesv1 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/keeper" + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types" + + "github.com/cosmos/ibc-go/v9/modules/core/api" +) + +var ( + _ module.AppModule = (*AppModule)(nil) + _ module.AppModuleBasic = (*AppModuleBasic)(nil) + _ module.AppModuleSimulation = (*AppModule)(nil) + _ module.HasGenesis = (*AppModule)(nil) + _ module.HasName = (*AppModule)(nil) + _ module.HasConsensusVersion = (*AppModule)(nil) + _ module.HasInvariants = (*AppModule)(nil) + _ module.HasServices = (*AppModule)(nil) + _ module.HasProposalMsgs = (*AppModule)(nil) + _ appmodule.AppModule = (*AppModule)(nil) + + _ api.IBCModule = (*IBCModule)(nil) +) + +// AppModuleBasic is the IBC Transfer AppModuleBasic +type AppModuleBasic struct{} + +// Name implements AppModuleBasic interface +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (AppModule) IsAppModule() {} + +// RegisterLegacyAminoCodec implements AppModuleBasic interface +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + // types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers module concrete types into protobuf Any. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// DefaultGenesis returns default genesis state as raw bytes for the ibc +// transfer module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(typesv1.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the ibc transfer module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var gs typesv1.GenesisState + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return gs.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-transfer module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd implements AppModuleBasic interface +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.NewTxCmd() +} + +// GetQueryCmd implements AppModuleBasic interface +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// AppModule represents the AppModule for this module +type AppModule struct { + AppModuleBasic + keeper *keeper.Keeper +} + +// NewAppModule creates a new 20-transfer module +func NewAppModule(k *keeper.Keeper) AppModule { + return AppModule{ + keeper: k, + } +} + +// RegisterInvariants implements the AppModule interface +func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { + // TODO(bznein) figure out what is this + // keeper.RegisterInvariants(ir, &am.keeper) +} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + // typesv1.RegisterQueryServer(cfg.QueryServer(), am.keeper) + // typesv1.RegisterQueryV2Server(cfg.QueryServer(), am.keeper) +} + +// InitGenesis performs genesis initialization for the ibc-transfer module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { + var genesisState typesv1.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) +} + +// ExportGenesis returns the exported genesis state as raw bytes for the ibc-transfer +// module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion defining the current version of transfer. +func (AppModule) ConsensusVersion() uint64 { return 6 } + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the transfer module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() +} + +// RegisterStoreDecoder registers a decoder for transfer module's types +func (AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { + sdr[types.ModuleName] = simulation.NewDecodeStore() +} + +// WeightedOperations returns the all the transfer module operations with their respective weights. +func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return nil +} diff --git a/modules/apps/transfer/v2/types/codec.go b/modules/apps/transfer/v2/types/codec.go new file mode 100644 index 00000000000..3f8f9de2e3b --- /dev/null +++ b/modules/apps/transfer/v2/types/codec.go @@ -0,0 +1,23 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterInterfaces register the ibc transfer module interfaces to protobuf +// Any. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgTransfer{}) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +// ModuleCdc references the global x/ibc-transfer module codec. Note, the codec +// should ONLY be used in certain instances of tests and for JSON encoding. +// +// The actual codec used for serialization should be provided to x/ibc transfer and +// defined at the application level. +var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) diff --git a/modules/apps/transfer/v2/types/denom.go b/modules/apps/transfer/v2/types/denom.go new file mode 100644 index 00000000000..71ee94b91e8 --- /dev/null +++ b/modules/apps/transfer/v2/types/denom.go @@ -0,0 +1,3 @@ +package types + +type Denoms []Denom diff --git a/modules/apps/transfer/v2/types/forwarding.go b/modules/apps/transfer/v2/types/forwarding.go new file mode 100644 index 00000000000..e3d0a7c7974 --- /dev/null +++ b/modules/apps/transfer/v2/types/forwarding.go @@ -0,0 +1,31 @@ +package types + +import ( + "fmt" + + "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" +) + +// String returns the Hop in the format: +// / +func (h Hop) String() string { + return fmt.Sprintf("%s/%s", h.PortId, h.ChannelId) +} + +// V1HopsToV2Hops converts a slice of v1 Hop to a slice of V2 Hop. +func V1HopsToV2Hops(hops []types.Hop) []Hop { + v2hops := make([]Hop, len(hops)) + for i, h := range hops { + v2hops[i] = Hop{PortId: h.PortId, ChannelId: h.ChannelId} + } + return v2hops +} + +// V2HopsToV1Hops converts a slice of v2 Hop to a slice of V1 Hop. +func V2HopsToV1Hops(hops []Hop) []types.Hop { + v1hops := make([]types.Hop, len(hops)) + for i, h := range hops { + v1hops[i] = types.Hop{PortId: h.PortId, ChannelId: h.ChannelId} + } + return v1hops +} diff --git a/modules/apps/transfer/v2/types/genesis.pb.go b/modules/apps/transfer/v2/types/genesis.pb.go new file mode 100644 index 00000000000..e57de0d75cb --- /dev/null +++ b/modules/apps/transfer/v2/types/genesis.pb.go @@ -0,0 +1,812 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/transfer/v2/genesis.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + types2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + 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 + +// GenesisState defines the ibc-transfer genesis state +type GenesisState struct { + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + Denoms Denoms `protobuf:"bytes,2,rep,name=denoms,proto3,castrepeated=Denoms" json:"denoms"` + Params types.Params `protobuf:"bytes,3,opt,name=params,proto3" json:"params"` + // total_escrowed contains the total amount of tokens escrowed + // by the transfer module + TotalEscrowed github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=total_escrowed,json=totalEscrowed,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"total_escrowed"` + // forwarded_packets contains the forwarded packets stored as part of the + // packet forwarding lifecycle + ForwardedPackets []ForwardedPacket `protobuf:"bytes,5,rep,name=forwarded_packets,json=forwardedPackets,proto3" json:"forwarded_packets"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_62efebb47a9093ed, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *GenesisState) GetDenoms() Denoms { + if m != nil { + return m.Denoms + } + return nil +} + +func (m *GenesisState) GetParams() types.Params { + if m != nil { + return m.Params + } + return types.Params{} +} + +func (m *GenesisState) GetTotalEscrowed() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.TotalEscrowed + } + return nil +} + +func (m *GenesisState) GetForwardedPackets() []ForwardedPacket { + if m != nil { + return m.ForwardedPackets + } + return nil +} + +// ForwardedPacket defines the genesis type necessary to retrieve and store forwarded packets. +type ForwardedPacket struct { + ForwardKey types2.PacketId `protobuf:"bytes,1,opt,name=forward_key,json=forwardKey,proto3" json:"forward_key"` + Packet types2.Packet `protobuf:"bytes,2,opt,name=packet,proto3" json:"packet"` +} + +func (m *ForwardedPacket) Reset() { *m = ForwardedPacket{} } +func (m *ForwardedPacket) String() string { return proto.CompactTextString(m) } +func (*ForwardedPacket) ProtoMessage() {} +func (*ForwardedPacket) Descriptor() ([]byte, []int) { + return fileDescriptor_62efebb47a9093ed, []int{1} +} +func (m *ForwardedPacket) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ForwardedPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ForwardedPacket.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 *ForwardedPacket) XXX_Merge(src proto.Message) { + xxx_messageInfo_ForwardedPacket.Merge(m, src) +} +func (m *ForwardedPacket) XXX_Size() int { + return m.Size() +} +func (m *ForwardedPacket) XXX_DiscardUnknown() { + xxx_messageInfo_ForwardedPacket.DiscardUnknown(m) +} + +var xxx_messageInfo_ForwardedPacket proto.InternalMessageInfo + +func (m *ForwardedPacket) GetForwardKey() types2.PacketId { + if m != nil { + return m.ForwardKey + } + return types2.PacketId{} +} + +func (m *ForwardedPacket) GetPacket() types2.Packet { + if m != nil { + return m.Packet + } + return types2.Packet{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "ibc.applications.transfer.v2.GenesisState") + proto.RegisterType((*ForwardedPacket)(nil), "ibc.applications.transfer.v2.ForwardedPacket") +} + +func init() { + proto.RegisterFile("ibc/applications/transfer/v2/genesis.proto", fileDescriptor_62efebb47a9093ed) +} + +var fileDescriptor_62efebb47a9093ed = []byte{ + // 485 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0x9b, 0x6d, 0x04, 0xe1, 0xc2, 0x80, 0x08, 0x89, 0x30, 0x20, 0x2b, 0x83, 0x43, 0x04, + 0xaa, 0x4d, 0xc3, 0x69, 0x1c, 0xcb, 0x00, 0x4d, 0xbb, 0x4c, 0x85, 0x13, 0x97, 0xe2, 0xd8, 0x6e, + 0x66, 0xb5, 0xc9, 0x1b, 0xd9, 0x5e, 0xa7, 0x7e, 0x09, 0x84, 0xf8, 0x18, 0x7c, 0x92, 0x1d, 0x77, + 0xe4, 0x04, 0xa8, 0xfd, 0x22, 0xc8, 0x8e, 0xcb, 0x9f, 0x21, 0xe5, 0xd4, 0xf7, 0x75, 0x9f, 0xe7, + 0x79, 0xed, 0x5f, 0x5e, 0xf4, 0x54, 0xe6, 0x8c, 0xd0, 0xba, 0x9e, 0x49, 0x46, 0x8d, 0x84, 0x4a, + 0x13, 0xa3, 0x68, 0xa5, 0x27, 0x42, 0x91, 0x79, 0x46, 0x0a, 0x51, 0x09, 0x2d, 0x35, 0xae, 0x15, + 0x18, 0x88, 0x1e, 0xc8, 0x9c, 0xe1, 0xbf, 0xb5, 0x78, 0xad, 0xc5, 0xf3, 0x6c, 0xe7, 0x59, 0x4b, + 0xd2, 0xe0, 0x77, 0xdd, 0x44, 0xed, 0xa4, 0xad, 0x63, 0x0d, 0x4c, 0x45, 0xe5, 0x95, 0x8f, 0xac, + 0x92, 0x81, 0x12, 0x84, 0x9d, 0xd0, 0xaa, 0x12, 0x33, 0x9b, 0xe6, 0x4b, 0x2f, 0x49, 0x18, 0xe8, + 0x12, 0x34, 0xc9, 0xa9, 0x16, 0x64, 0x3e, 0xc8, 0x85, 0xa1, 0x03, 0xc2, 0x40, 0xae, 0x23, 0xee, + 0x14, 0x50, 0x80, 0x2b, 0x89, 0xad, 0x9a, 0xd3, 0xbd, 0x4f, 0x9b, 0xe8, 0xfa, 0xdb, 0xe6, 0x7d, + 0xef, 0x0c, 0x35, 0x22, 0xba, 0x8b, 0xae, 0xd6, 0xa0, 0xcc, 0x58, 0xf2, 0x38, 0xe8, 0x05, 0xe9, + 0xb5, 0x51, 0x68, 0xdb, 0x43, 0x1e, 0x1d, 0xa1, 0x90, 0x8b, 0x0a, 0x4a, 0x1d, 0x6f, 0xf4, 0x36, + 0xd3, 0x6e, 0xf6, 0x18, 0xb7, 0x81, 0xc0, 0x07, 0x56, 0x3b, 0xdc, 0x3e, 0xff, 0xbe, 0xdb, 0xf9, + 0xfa, 0x63, 0x37, 0x74, 0xad, 0x1e, 0xf9, 0x88, 0x68, 0x88, 0xc2, 0x9a, 0x2a, 0x5a, 0xea, 0x78, + 0xb3, 0x17, 0xa4, 0xdd, 0xec, 0x49, 0x5b, 0xd8, 0x00, 0x1f, 0x3b, 0xed, 0x70, 0xcb, 0xa6, 0x8d, + 0xbc, 0x33, 0x52, 0x68, 0xdb, 0x80, 0xa1, 0xb3, 0xb1, 0xd0, 0x4c, 0xc1, 0x99, 0xe0, 0xf1, 0x96, + 0xbb, 0xd8, 0x3d, 0xdc, 0x90, 0xc0, 0x96, 0x04, 0xf6, 0x24, 0xf0, 0x2b, 0x90, 0xd5, 0xf0, 0xb9, + 0xbf, 0x4e, 0x5a, 0x48, 0x73, 0x72, 0x9a, 0x63, 0x06, 0x25, 0xf1, 0xd8, 0x9a, 0x9f, 0xbe, 0xe6, + 0x53, 0x62, 0x16, 0xb5, 0xd0, 0xce, 0xa0, 0x47, 0x37, 0xdc, 0x88, 0xd7, 0x7e, 0x42, 0xf4, 0x11, + 0xdd, 0x9e, 0x80, 0x3a, 0xa3, 0x8a, 0x0b, 0x3e, 0xae, 0x29, 0x9b, 0x0a, 0xa3, 0xe3, 0x2b, 0x6e, + 0x6c, 0xbf, 0x9d, 0xc7, 0x9b, 0xb5, 0xed, 0xd8, 0xb9, 0xfc, 0x5b, 0x6e, 0x4d, 0xfe, 0x3d, 0xd6, + 0x7b, 0x5f, 0x02, 0x74, 0xf3, 0x92, 0x36, 0x3a, 0x40, 0x5d, 0xaf, 0x1b, 0x4f, 0xc5, 0xc2, 0x7d, + 0x97, 0x6e, 0xf6, 0xd0, 0xcd, 0xb3, 0x3b, 0x81, 0xd7, 0x8b, 0xe0, 0x48, 0x59, 0xc7, 0x21, 0xf7, + 0xf9, 0xc8, 0xfb, 0x8e, 0xc4, 0x22, 0xda, 0xb7, 0xcc, 0xed, 0xbf, 0xf1, 0x86, 0x0b, 0xb8, 0xdf, + 0x12, 0xf0, 0x07, 0xb5, 0xeb, 0xde, 0x9f, 0x2f, 0x93, 0xe0, 0x62, 0x99, 0x04, 0x3f, 0x97, 0x49, + 0xf0, 0x79, 0x95, 0x74, 0x2e, 0x56, 0x49, 0xe7, 0xdb, 0x2a, 0xe9, 0x7c, 0x78, 0xf9, 0x3f, 0x49, + 0x99, 0xb3, 0x7e, 0x01, 0x64, 0xbe, 0x4f, 0x4a, 0xe0, 0xa7, 0x33, 0xa1, 0xed, 0x8a, 0x5f, 0x5a, + 0x6d, 0x4b, 0x38, 0x0f, 0xdd, 0x0a, 0xbe, 0xf8, 0x15, 0x00, 0x00, 0xff, 0xff, 0x19, 0xa5, 0x16, + 0x45, 0x7e, 0x03, 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ForwardedPackets) > 0 { + for iNdEx := len(m.ForwardedPackets) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ForwardedPackets[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.TotalEscrowed) > 0 { + for iNdEx := len(m.TotalEscrowed) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TotalEscrowed[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Denoms) > 0 { + for iNdEx := len(m.Denoms) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Denoms[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ForwardedPacket) 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 *ForwardedPacket) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ForwardedPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Packet.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.ForwardKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Denoms) > 0 { + for _, e := range m.Denoms { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.TotalEscrowed) > 0 { + for _, e := range m.TotalEscrowed { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ForwardedPackets) > 0 { + for _, e := range m.ForwardedPackets { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *ForwardedPacket) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ForwardKey.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.Packet.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: 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 ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + 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 Denoms", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denoms = append(m.Denoms, Denom{}) + if err := m.Denoms[len(m.Denoms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalEscrowed", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TotalEscrowed = append(m.TotalEscrowed, types1.Coin{}) + if err := m.TotalEscrowed[len(m.TotalEscrowed)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ForwardedPackets", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ForwardedPackets = append(m.ForwardedPackets, ForwardedPacket{}) + if err := m.ForwardedPackets[len(m.ForwardedPackets)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ForwardedPacket) 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 ErrIntOverflowGenesis + } + 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: ForwardedPacket: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ForwardedPacket: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ForwardKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ForwardKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Packet", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Packet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/apps/transfer/v2/types/keys.go b/modules/apps/transfer/v2/types/keys.go new file mode 100644 index 00000000000..c590d2fc8fd --- /dev/null +++ b/modules/apps/transfer/v2/types/keys.go @@ -0,0 +1,23 @@ +package types + +import "fmt" + +const ( + // ModuleName defines the IBC transfer-v2 name + ModuleName = "transfer-v2" + + // StoreKey is the store key string for IBC transfer-v2 + StoreKey = ModuleName +) + +// ForwardedPacketSequenceKey returns the key used to store the sequence of a forwarded packet. +// TODO(bznein) make sure the string is correct +func ForwardedPacketSequenceKey(portID string, channelID string) []byte { + return []byte(fmt.Sprintf("forwarded/%s/%s/sequence", portID, channelID)) +} + +// ForwardedPacketDestinationChannelKey returns the key used to store the destinationChannel of a forwarded packet. +// TODO(bznein) make sure the string is correct +func ForwardedPacketDestinationChannelKey(portID string, channelID string) []byte { + return []byte(fmt.Sprintf("forwarded/%s/%s/edstinationchannel", portID, channelID)) +} diff --git a/modules/apps/transfer/v2/types/packet.pb.go b/modules/apps/transfer/v2/types/packet.pb.go new file mode 100644 index 00000000000..e673fc4682a --- /dev/null +++ b/modules/apps/transfer/v2/types/packet.pb.go @@ -0,0 +1,1216 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/transfer/v2/packet.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + 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/ibc/tree/master/spec/app/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"` + // optional memo + Memo string `protobuf:"bytes,5,opt,name=memo,proto3" json:"memo,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 (m *FungibleTokenPacketData) GetMemo() string { + if m != nil { + return m.Memo + } + return "" +} + +// FungibleTokenPacketDataV2 defines a struct for the packet payload +// See FungibleTokenPacketDataV2 spec: +// https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures +type FungibleTokenPacketDataV2 struct { + // the tokens to be transferred + Tokens []Token `protobuf:"bytes,1,rep,name=tokens,proto3" json:"tokens"` + // the sender address + Sender string `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"` + // the recipient address on the destination chain + Receiver string `protobuf:"bytes,3,opt,name=receiver,proto3" json:"receiver,omitempty"` + // optional memo + Memo string `protobuf:"bytes,4,opt,name=memo,proto3" json:"memo,omitempty"` + // optional forwarding information + Forwarding ForwardingPacketData `protobuf:"bytes,5,opt,name=forwarding,proto3" json:"forwarding"` +} + +func (m *FungibleTokenPacketDataV2) Reset() { *m = FungibleTokenPacketDataV2{} } +func (m *FungibleTokenPacketDataV2) String() string { return proto.CompactTextString(m) } +func (*FungibleTokenPacketDataV2) ProtoMessage() {} +func (*FungibleTokenPacketDataV2) Descriptor() ([]byte, []int) { + return fileDescriptor_653ca2ce9a5ca313, []int{1} +} +func (m *FungibleTokenPacketDataV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FungibleTokenPacketDataV2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FungibleTokenPacketDataV2.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 *FungibleTokenPacketDataV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_FungibleTokenPacketDataV2.Merge(m, src) +} +func (m *FungibleTokenPacketDataV2) XXX_Size() int { + return m.Size() +} +func (m *FungibleTokenPacketDataV2) XXX_DiscardUnknown() { + xxx_messageInfo_FungibleTokenPacketDataV2.DiscardUnknown(m) +} + +var xxx_messageInfo_FungibleTokenPacketDataV2 proto.InternalMessageInfo + +func (m *FungibleTokenPacketDataV2) GetTokens() []Token { + if m != nil { + return m.Tokens + } + return nil +} + +func (m *FungibleTokenPacketDataV2) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *FungibleTokenPacketDataV2) GetReceiver() string { + if m != nil { + return m.Receiver + } + return "" +} + +func (m *FungibleTokenPacketDataV2) GetMemo() string { + if m != nil { + return m.Memo + } + return "" +} + +func (m *FungibleTokenPacketDataV2) GetForwarding() ForwardingPacketData { + if m != nil { + return m.Forwarding + } + return ForwardingPacketData{} +} + +// ForwardingPacketData defines a list of port ID, channel ID pairs determining the path +// through which a packet must be forwarded, and the destination memo string to be used in the +// final destination of the tokens. +type ForwardingPacketData struct { + // optional memo consumed by final destination chain + DestinationMemo string `protobuf:"bytes,1,opt,name=destination_memo,json=destinationMemo,proto3" json:"destination_memo,omitempty"` + // optional intermediate path through which packet will be forwarded. + Hops []types.Hop `protobuf:"bytes,2,rep,name=hops,proto3" json:"hops"` + // timeout for the packet + TimeoutTimestamp uint64 `protobuf:"varint,3,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty"` +} + +func (m *ForwardingPacketData) Reset() { *m = ForwardingPacketData{} } +func (m *ForwardingPacketData) String() string { return proto.CompactTextString(m) } +func (*ForwardingPacketData) ProtoMessage() {} +func (*ForwardingPacketData) Descriptor() ([]byte, []int) { + return fileDescriptor_653ca2ce9a5ca313, []int{2} +} +func (m *ForwardingPacketData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ForwardingPacketData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ForwardingPacketData.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 *ForwardingPacketData) XXX_Merge(src proto.Message) { + xxx_messageInfo_ForwardingPacketData.Merge(m, src) +} +func (m *ForwardingPacketData) XXX_Size() int { + return m.Size() +} +func (m *ForwardingPacketData) XXX_DiscardUnknown() { + xxx_messageInfo_ForwardingPacketData.DiscardUnknown(m) +} + +var xxx_messageInfo_ForwardingPacketData proto.InternalMessageInfo + +func (m *ForwardingPacketData) GetDestinationMemo() string { + if m != nil { + return m.DestinationMemo + } + return "" +} + +func (m *ForwardingPacketData) GetHops() []types.Hop { + if m != nil { + return m.Hops + } + return nil +} + +func (m *ForwardingPacketData) GetTimeoutTimestamp() uint64 { + if m != nil { + return m.TimeoutTimestamp + } + return 0 +} + +func init() { + proto.RegisterType((*FungibleTokenPacketData)(nil), "ibc.applications.transfer.v2.FungibleTokenPacketData") + proto.RegisterType((*FungibleTokenPacketDataV2)(nil), "ibc.applications.transfer.v2.FungibleTokenPacketDataV2") + proto.RegisterType((*ForwardingPacketData)(nil), "ibc.applications.transfer.v2.ForwardingPacketData") +} + +func init() { + proto.RegisterFile("ibc/applications/transfer/v2/packet.proto", fileDescriptor_653ca2ce9a5ca313) +} + +var fileDescriptor_653ca2ce9a5ca313 = []byte{ + // 443 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0x9b, 0x36, 0xab, 0xc0, 0x3b, 0x30, 0xac, 0x0a, 0x42, 0x85, 0xc2, 0x28, 0x97, 0x4e, + 0x13, 0xb1, 0x16, 0x4e, 0xc0, 0x89, 0x09, 0x4d, 0x5c, 0x90, 0x50, 0x55, 0x21, 0xc4, 0x65, 0x72, + 0x1c, 0x2f, 0xb3, 0x56, 0xfb, 0x59, 0xb6, 0x53, 0xc4, 0x8d, 0x6f, 0x00, 0xdf, 0x83, 0x2f, 0xb2, + 0xe3, 0x8e, 0x9c, 0x10, 0x6a, 0xbf, 0x08, 0x8a, 0x93, 0xb5, 0x11, 0xa2, 0x39, 0xe5, 0xbd, 0xbf, + 0xff, 0xfe, 0xeb, 0xe7, 0x97, 0x87, 0x8e, 0x44, 0xc6, 0x08, 0xd5, 0x7a, 0x21, 0x18, 0x75, 0x02, + 0x94, 0x25, 0xce, 0x50, 0x65, 0x2f, 0xb8, 0x21, 0xcb, 0x94, 0x68, 0xca, 0xae, 0xb8, 0x4b, 0xb4, + 0x01, 0x07, 0xf8, 0xb1, 0xc8, 0x58, 0xd2, 0xb6, 0x26, 0xb7, 0xd6, 0x64, 0x99, 0x8e, 0xa7, 0x9d, + 0x41, 0x0e, 0xae, 0xb8, 0xaa, 0x73, 0xc6, 0xa3, 0x02, 0x0a, 0xf0, 0x25, 0xa9, 0xaa, 0x46, 0x3d, + 0xee, 0xb8, 0x7f, 0xb2, 0xa9, 0x6b, 0xf3, 0xe4, 0x7b, 0x80, 0x1e, 0x9e, 0x95, 0xaa, 0x10, 0xd9, + 0x82, 0xcf, 0xab, 0xe8, 0x0f, 0x1e, 0xf4, 0x2d, 0x75, 0x14, 0x8f, 0xd0, 0x5e, 0xce, 0x15, 0xc8, + 0x28, 0x38, 0x0c, 0xa6, 0x77, 0x67, 0x75, 0x83, 0x1f, 0xa0, 0x21, 0x95, 0x50, 0x2a, 0x17, 0xf5, + 0xbd, 0xdc, 0x74, 0x95, 0x6e, 0xb9, 0xca, 0xb9, 0x89, 0x06, 0xb5, 0x5e, 0x77, 0x78, 0x8c, 0xee, + 0x18, 0xce, 0xb8, 0x58, 0x72, 0x13, 0x85, 0xfe, 0x64, 0xd3, 0x63, 0x8c, 0x42, 0xc9, 0x25, 0x44, + 0x7b, 0x5e, 0xf7, 0xf5, 0xe4, 0x5b, 0x1f, 0x3d, 0xda, 0x41, 0xf4, 0x31, 0xc5, 0x6f, 0xd0, 0xd0, + 0x4f, 0xc0, 0x46, 0xc1, 0xe1, 0x60, 0xba, 0x9f, 0x3e, 0x4b, 0xba, 0x66, 0x99, 0xf8, 0x80, 0xd3, + 0xf0, 0xfa, 0xf7, 0x93, 0xde, 0xac, 0xb9, 0xd8, 0x02, 0xed, 0xef, 0x04, 0x1d, 0xec, 0x00, 0x0d, + 0xb7, 0xa0, 0xf8, 0x13, 0x42, 0x17, 0x60, 0xbe, 0x50, 0x93, 0x0b, 0x55, 0xf8, 0x27, 0xec, 0xa7, + 0x69, 0x37, 0xce, 0xd9, 0xc6, 0xbf, 0x7d, 0x54, 0x43, 0xd7, 0xca, 0x9a, 0xfc, 0x0c, 0xd0, 0xe8, + 0x7f, 0x56, 0x7c, 0x84, 0x0e, 0x72, 0x6e, 0x9d, 0x50, 0x3e, 0xfb, 0xdc, 0x23, 0xd5, 0x3f, 0xe7, + 0x5e, 0x4b, 0x7f, 0x5f, 0xd1, 0xbd, 0x46, 0xe1, 0x25, 0x68, 0x1b, 0xf5, 0xfd, 0x98, 0x9e, 0x76, + 0x71, 0x9d, 0x24, 0xef, 0x40, 0x37, 0x18, 0xfe, 0x12, 0x3e, 0x46, 0xf7, 0x9d, 0x90, 0x1c, 0x4a, + 0x77, 0x5e, 0x7d, 0xad, 0xa3, 0x52, 0xfb, 0x99, 0x84, 0xb3, 0x83, 0xe6, 0x60, 0x7e, 0xab, 0x9f, + 0xce, 0xaf, 0x57, 0x71, 0x70, 0xb3, 0x8a, 0x83, 0x3f, 0xab, 0x38, 0xf8, 0xb1, 0x8e, 0x7b, 0x37, + 0xeb, 0xb8, 0xf7, 0x6b, 0x1d, 0xf7, 0x3e, 0xbf, 0x2a, 0x84, 0xbb, 0x2c, 0xb3, 0x84, 0x81, 0x24, + 0x0c, 0xac, 0x04, 0x4b, 0x44, 0xc6, 0x9e, 0x17, 0x40, 0x96, 0x2f, 0x89, 0x84, 0xbc, 0x5c, 0x70, + 0x5b, 0x6d, 0xea, 0x3f, 0x1b, 0xfe, 0x55, 0x73, 0x9b, 0x0d, 0xfd, 0x7e, 0xbe, 0xf8, 0x1b, 0x00, + 0x00, 0xff, 0xff, 0x01, 0xe2, 0xa5, 0x86, 0x57, 0x03, 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.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x2a + } + 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 (m *FungibleTokenPacketDataV2) 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 *FungibleTokenPacketDataV2) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FungibleTokenPacketDataV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Forwarding.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPacket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x22 + } + 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] = 0x1a + } + 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] = 0x12 + } + if len(m.Tokens) > 0 { + for iNdEx := len(m.Tokens) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Tokens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPacket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ForwardingPacketData) 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 *ForwardingPacketData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ForwardingPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TimeoutTimestamp != 0 { + i = encodeVarintPacket(dAtA, i, uint64(m.TimeoutTimestamp)) + i-- + dAtA[i] = 0x18 + } + if len(m.Hops) > 0 { + for iNdEx := len(m.Hops) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Hops[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPacket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.DestinationMemo) > 0 { + i -= len(m.DestinationMemo) + copy(dAtA[i:], m.DestinationMemo) + i = encodeVarintPacket(dAtA, i, uint64(len(m.DestinationMemo))) + 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)) + } + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + return n +} + +func (m *FungibleTokenPacketDataV2) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Tokens) > 0 { + for _, e := range m.Tokens { + l = e.Size() + 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)) + } + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = m.Forwarding.Size() + n += 1 + l + sovPacket(uint64(l)) + return n +} + +func (m *ForwardingPacketData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DestinationMemo) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + if len(m.Hops) > 0 { + for _, e := range m.Hops { + l = e.Size() + n += 1 + l + sovPacket(uint64(l)) + } + } + if m.TimeoutTimestamp != 0 { + n += 1 + sovPacket(uint64(m.TimeoutTimestamp)) + } + 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 + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Memo", 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.Memo = 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 (m *FungibleTokenPacketDataV2) 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: FungibleTokenPacketDataV2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FungibleTokenPacketDataV2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tokens", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Tokens = append(m.Tokens, Token{}) + if err := m.Tokens[len(m.Tokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + 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 3: + 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 + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Memo", 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.Memo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Forwarding", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Forwarding.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 (m *ForwardingPacketData) 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: ForwardingPacketData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ForwardingPacketData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DestinationMemo", 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.DestinationMemo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hops", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hops = append(m.Hops, types.Hop{}) + if err := m.Hops[len(m.Hops)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutTimestamp", wireType) + } + m.TimeoutTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutTimestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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/v2/types/query.pb.go b/modules/apps/transfer/v2/types/query.pb.go new file mode 100644 index 00000000000..dfe0dfc82bc --- /dev/null +++ b/modules/apps/transfer/v2/types/query.pb.go @@ -0,0 +1,1769 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/transfer/v3/query.proto + +package types + +import ( + context "context" + fmt "fmt" + types1 "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// QueryParamsRequest is the request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params defines the parameters of the module. + Params *types.Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() *types.Params { + if m != nil { + return m.Params + } + return nil +} + +// QueryDenomHashRequest is the request type for the Query/DenomHash RPC +// method +type QueryDenomHashRequest struct { + // The denomination trace ([port_id]/[channel_id])+/[denom] + Trace string `protobuf:"bytes,1,opt,name=trace,proto3" json:"trace,omitempty"` +} + +func (m *QueryDenomHashRequest) Reset() { *m = QueryDenomHashRequest{} } +func (m *QueryDenomHashRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDenomHashRequest) ProtoMessage() {} +func (*QueryDenomHashRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{2} +} +func (m *QueryDenomHashRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDenomHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDenomHashRequest.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 *QueryDenomHashRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDenomHashRequest.Merge(m, src) +} +func (m *QueryDenomHashRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDenomHashRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDenomHashRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDenomHashRequest proto.InternalMessageInfo + +func (m *QueryDenomHashRequest) GetTrace() string { + if m != nil { + return m.Trace + } + return "" +} + +// QueryDenomHashResponse is the response type for the Query/DenomHash RPC +// method. +type QueryDenomHashResponse struct { + // hash (in hex format) of the denomination trace information. + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (m *QueryDenomHashResponse) Reset() { *m = QueryDenomHashResponse{} } +func (m *QueryDenomHashResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDenomHashResponse) ProtoMessage() {} +func (*QueryDenomHashResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{3} +} +func (m *QueryDenomHashResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDenomHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDenomHashResponse.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 *QueryDenomHashResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDenomHashResponse.Merge(m, src) +} +func (m *QueryDenomHashResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDenomHashResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDenomHashResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDenomHashResponse proto.InternalMessageInfo + +func (m *QueryDenomHashResponse) GetHash() string { + if m != nil { + return m.Hash + } + return "" +} + +// QueryEscrowAddressRequest is the request type for the EscrowAddress RPC method. +type QueryEscrowAddressRequest struct { + // unique port identifier + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + // unique channel identifier + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *QueryEscrowAddressRequest) Reset() { *m = QueryEscrowAddressRequest{} } +func (m *QueryEscrowAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryEscrowAddressRequest) ProtoMessage() {} +func (*QueryEscrowAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{4} +} +func (m *QueryEscrowAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryEscrowAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryEscrowAddressRequest.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 *QueryEscrowAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryEscrowAddressRequest.Merge(m, src) +} +func (m *QueryEscrowAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryEscrowAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryEscrowAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryEscrowAddressRequest proto.InternalMessageInfo + +func (m *QueryEscrowAddressRequest) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *QueryEscrowAddressRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +// QueryEscrowAddressResponse is the response type of the EscrowAddress RPC method. +type QueryEscrowAddressResponse struct { + // the escrow account address + EscrowAddress string `protobuf:"bytes,1,opt,name=escrow_address,json=escrowAddress,proto3" json:"escrow_address,omitempty"` +} + +func (m *QueryEscrowAddressResponse) Reset() { *m = QueryEscrowAddressResponse{} } +func (m *QueryEscrowAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryEscrowAddressResponse) ProtoMessage() {} +func (*QueryEscrowAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{5} +} +func (m *QueryEscrowAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryEscrowAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryEscrowAddressResponse.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 *QueryEscrowAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryEscrowAddressResponse.Merge(m, src) +} +func (m *QueryEscrowAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryEscrowAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryEscrowAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryEscrowAddressResponse proto.InternalMessageInfo + +func (m *QueryEscrowAddressResponse) GetEscrowAddress() string { + if m != nil { + return m.EscrowAddress + } + return "" +} + +// QueryTotalEscrowForDenomRequest is the request type for TotalEscrowForDenom RPC method. +type QueryTotalEscrowForDenomRequest struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *QueryTotalEscrowForDenomRequest) Reset() { *m = QueryTotalEscrowForDenomRequest{} } +func (m *QueryTotalEscrowForDenomRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTotalEscrowForDenomRequest) ProtoMessage() {} +func (*QueryTotalEscrowForDenomRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{6} +} +func (m *QueryTotalEscrowForDenomRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalEscrowForDenomRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalEscrowForDenomRequest.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 *QueryTotalEscrowForDenomRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalEscrowForDenomRequest.Merge(m, src) +} +func (m *QueryTotalEscrowForDenomRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalEscrowForDenomRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalEscrowForDenomRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalEscrowForDenomRequest proto.InternalMessageInfo + +func (m *QueryTotalEscrowForDenomRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +// QueryTotalEscrowForDenomResponse is the response type for TotalEscrowForDenom RPC method. +type QueryTotalEscrowForDenomResponse struct { + Amount types1.Coin `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount"` +} + +func (m *QueryTotalEscrowForDenomResponse) Reset() { *m = QueryTotalEscrowForDenomResponse{} } +func (m *QueryTotalEscrowForDenomResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTotalEscrowForDenomResponse) ProtoMessage() {} +func (*QueryTotalEscrowForDenomResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_67e995a711a4e262, []int{7} +} +func (m *QueryTotalEscrowForDenomResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalEscrowForDenomResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalEscrowForDenomResponse.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 *QueryTotalEscrowForDenomResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalEscrowForDenomResponse.Merge(m, src) +} +func (m *QueryTotalEscrowForDenomResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalEscrowForDenomResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalEscrowForDenomResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalEscrowForDenomResponse proto.InternalMessageInfo + +func (m *QueryTotalEscrowForDenomResponse) GetAmount() types1.Coin { + if m != nil { + return m.Amount + } + return types1.Coin{} +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "ibc.applications.transfer.v3.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "ibc.applications.transfer.v3.QueryParamsResponse") + proto.RegisterType((*QueryDenomHashRequest)(nil), "ibc.applications.transfer.v3.QueryDenomHashRequest") + proto.RegisterType((*QueryDenomHashResponse)(nil), "ibc.applications.transfer.v3.QueryDenomHashResponse") + proto.RegisterType((*QueryEscrowAddressRequest)(nil), "ibc.applications.transfer.v3.QueryEscrowAddressRequest") + proto.RegisterType((*QueryEscrowAddressResponse)(nil), "ibc.applications.transfer.v3.QueryEscrowAddressResponse") + proto.RegisterType((*QueryTotalEscrowForDenomRequest)(nil), "ibc.applications.transfer.v3.QueryTotalEscrowForDenomRequest") + proto.RegisterType((*QueryTotalEscrowForDenomResponse)(nil), "ibc.applications.transfer.v3.QueryTotalEscrowForDenomResponse") +} + +func init() { + proto.RegisterFile("ibc/applications/transfer/v3/query.proto", fileDescriptor_67e995a711a4e262) +} + +var fileDescriptor_67e995a711a4e262 = []byte{ + // 646 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0x8e, 0xab, 0x36, 0x3f, 0x75, 0x7f, 0x2a, 0x87, 0x6d, 0xf9, 0x53, 0xab, 0xb8, 0x95, 0x55, + 0xa4, 0xaa, 0xd0, 0x5d, 0x92, 0x14, 0x02, 0xa8, 0x45, 0xa2, 0x05, 0x44, 0x11, 0x07, 0x48, 0x7b, + 0x82, 0x43, 0xb4, 0xb6, 0x17, 0xc7, 0x52, 0xec, 0x75, 0xbd, 0x9b, 0xa0, 0x2a, 0xca, 0x85, 0x27, + 0x40, 0xea, 0x73, 0xf0, 0x1e, 0x3d, 0x56, 0x20, 0x21, 0x4e, 0x08, 0x25, 0xbc, 0x05, 0x17, 0xe4, + 0xf5, 0xa4, 0x24, 0x6d, 0x1a, 0x25, 0x9c, 0xbc, 0xb3, 0xf3, 0x7d, 0x33, 0xdf, 0x78, 0x3e, 0x1b, + 0xad, 0x05, 0x8e, 0x4b, 0x59, 0x1c, 0xd7, 0x03, 0x97, 0xa9, 0x40, 0x44, 0x92, 0xaa, 0x84, 0x45, + 0xf2, 0x3d, 0x4f, 0x68, 0xb3, 0x44, 0x0f, 0x1b, 0x3c, 0x39, 0x22, 0x71, 0x22, 0x94, 0xc0, 0x4b, + 0x81, 0xe3, 0x92, 0x7e, 0x24, 0xe9, 0x21, 0x49, 0xb3, 0x64, 0x2e, 0xf8, 0xc2, 0x17, 0x1a, 0x48, + 0xd3, 0x53, 0xc6, 0x31, 0x2d, 0x57, 0xc8, 0x50, 0x48, 0xea, 0x30, 0xc9, 0x69, 0xb3, 0xe0, 0x70, + 0xc5, 0x0a, 0xd4, 0x15, 0x41, 0x04, 0xf9, 0xdb, 0x23, 0xba, 0x17, 0xce, 0xce, 0x00, 0x5e, 0xf2, + 0x85, 0xf0, 0xeb, 0x9c, 0xb2, 0x38, 0xa0, 0x2c, 0x8a, 0x84, 0x02, 0x19, 0x3a, 0x6b, 0x2f, 0x20, + 0xfc, 0x26, 0x55, 0xfb, 0x9a, 0x25, 0x2c, 0x94, 0x15, 0x7e, 0xd8, 0xe0, 0x52, 0xd9, 0xfb, 0x68, + 0x7e, 0xe0, 0x56, 0xc6, 0x22, 0x92, 0x1c, 0x6f, 0xa1, 0x7c, 0xac, 0x6f, 0x6e, 0x18, 0x2b, 0xc6, + 0xda, 0xff, 0xc5, 0x55, 0x32, 0x62, 0xb8, 0x02, 0x01, 0x36, 0x70, 0xec, 0x0d, 0x74, 0x55, 0x17, + 0x7d, 0xca, 0x23, 0x11, 0xbe, 0x60, 0xb2, 0x06, 0xdd, 0xf0, 0x02, 0x9a, 0x51, 0x09, 0x73, 0xb9, + 0xae, 0x3a, 0x5b, 0xc9, 0x02, 0xfb, 0x0e, 0xba, 0x76, 0x1e, 0x0e, 0x32, 0x30, 0x9a, 0xae, 0x31, + 0x59, 0x03, 0xb8, 0x3e, 0xdb, 0xfb, 0x68, 0x51, 0xa3, 0x9f, 0x49, 0x37, 0x11, 0x1f, 0x9e, 0x78, + 0x5e, 0xc2, 0x65, 0x6f, 0x1c, 0x7c, 0x1d, 0xfd, 0x17, 0x8b, 0x44, 0x55, 0x03, 0x0f, 0x38, 0xf9, + 0x34, 0xdc, 0xf3, 0xf0, 0x4d, 0x84, 0xdc, 0x1a, 0x8b, 0x22, 0x5e, 0x4f, 0x73, 0x53, 0x3a, 0x37, + 0x0b, 0x37, 0x7b, 0x9e, 0xbd, 0x8b, 0xcc, 0x61, 0x45, 0x41, 0xc6, 0x2d, 0x74, 0x85, 0xeb, 0x44, + 0x95, 0x65, 0x19, 0x28, 0x3e, 0xc7, 0xfb, 0xe1, 0x76, 0x19, 0x2d, 0xeb, 0x22, 0x07, 0x42, 0xb1, + 0x7a, 0x56, 0xe9, 0xb9, 0x48, 0xf4, 0x54, 0x7d, 0x2f, 0xc0, 0x4b, 0xe3, 0xde, 0x0b, 0xd0, 0x81, + 0xfd, 0x0e, 0xad, 0x5c, 0x4e, 0x04, 0x0d, 0x65, 0x94, 0x67, 0xa1, 0x68, 0x44, 0x0a, 0x36, 0xb2, + 0x48, 0x32, 0xeb, 0x90, 0xd4, 0x3a, 0x04, 0xac, 0x43, 0x76, 0x45, 0x10, 0xed, 0x4c, 0x9f, 0xfc, + 0x58, 0xce, 0x55, 0x00, 0x5e, 0xfc, 0x3d, 0x83, 0x66, 0x74, 0x75, 0x7c, 0x6c, 0xa0, 0x7c, 0xb6, + 0x29, 0x7c, 0x77, 0xd4, 0x3e, 0x4b, 0xe4, 0xa2, 0x51, 0xcc, 0xc2, 0x04, 0x8c, 0x4c, 0xb2, 0xbd, + 0xfa, 0xf1, 0xeb, 0xaf, 0xe3, 0x29, 0x0b, 0x2f, 0x51, 0x70, 0x71, 0xbf, 0x7b, 0x8b, 0x34, 0x33, + 0x0b, 0xfe, 0x6c, 0xa0, 0xd9, 0xb3, 0xcd, 0xe3, 0xd2, 0x18, 0x6d, 0xce, 0xdb, 0xca, 0xdc, 0x9c, + 0x8c, 0x04, 0xf2, 0xee, 0x69, 0x79, 0x14, 0x6f, 0x0c, 0x97, 0xa7, 0x57, 0x53, 0x4d, 0x2d, 0xc7, + 0x25, 0x6d, 0x69, 0xa7, 0x6e, 0xaf, 0xaf, 0xb7, 0xf1, 0x37, 0x03, 0xcd, 0x0d, 0xd8, 0x04, 0x97, + 0xc7, 0x68, 0x3f, 0xcc, 0xad, 0xe6, 0x83, 0xc9, 0x89, 0xa0, 0xbd, 0xa2, 0xb5, 0xbf, 0xc2, 0x2f, + 0x87, 0x6b, 0x07, 0x63, 0x4b, 0xda, 0xfa, 0x6b, 0xfa, 0x36, 0x4d, 0x3f, 0x05, 0x49, 0x5b, 0xf0, + 0x81, 0xb4, 0xe9, 0xa0, 0xa7, 0xf1, 0x17, 0x03, 0xcd, 0x0f, 0x71, 0x20, 0xde, 0x1e, 0x43, 0xe5, + 0xe5, 0x96, 0x37, 0x1f, 0xff, 0x2b, 0x1d, 0x46, 0xdd, 0xd2, 0xa3, 0xde, 0xc7, 0x9b, 0x23, 0xd6, + 0x24, 0x69, 0x4b, 0x3f, 0xd3, 0x05, 0x51, 0x95, 0x16, 0xab, 0x66, 0xc3, 0xed, 0x1c, 0x9c, 0x74, + 0x2c, 0xe3, 0xb4, 0x63, 0x19, 0x3f, 0x3b, 0x96, 0xf1, 0xa9, 0x6b, 0xe5, 0x4e, 0xbb, 0x56, 0xee, + 0x7b, 0xd7, 0xca, 0xbd, 0x7d, 0xe4, 0x07, 0xaa, 0xd6, 0x70, 0x88, 0x2b, 0x42, 0x0a, 0x7f, 0xe1, + 0xc0, 0x71, 0x37, 0x7c, 0x41, 0x9b, 0x0f, 0x69, 0x28, 0xbc, 0x46, 0x9d, 0xcb, 0x8b, 0xed, 0xd4, + 0x51, 0xcc, 0xa5, 0x93, 0xd7, 0xbf, 0xd4, 0xd2, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 0xbc, + 0x5e, 0x39, 0x1d, 0x06, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Params queries all parameters of the ibc-transfer module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // DenomHash queries a denomination hash information. + DenomHash(ctx context.Context, in *QueryDenomHashRequest, opts ...grpc.CallOption) (*QueryDenomHashResponse, error) + // EscrowAddress returns the escrow address for a particular port and channel id. + EscrowAddress(ctx context.Context, in *QueryEscrowAddressRequest, opts ...grpc.CallOption) (*QueryEscrowAddressResponse, error) + // TotalEscrowForDenom returns the total amount of tokens in escrow based on the denom. + TotalEscrowForDenom(ctx context.Context, in *QueryTotalEscrowForDenomRequest, opts ...grpc.CallOption) (*QueryTotalEscrowForDenomResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v3.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) DenomHash(ctx context.Context, in *QueryDenomHashRequest, opts ...grpc.CallOption) (*QueryDenomHashResponse, error) { + out := new(QueryDenomHashResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v3.Query/DenomHash", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) EscrowAddress(ctx context.Context, in *QueryEscrowAddressRequest, opts ...grpc.CallOption) (*QueryEscrowAddressResponse, error) { + out := new(QueryEscrowAddressResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v3.Query/EscrowAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) TotalEscrowForDenom(ctx context.Context, in *QueryTotalEscrowForDenomRequest, opts ...grpc.CallOption) (*QueryTotalEscrowForDenomResponse, error) { + out := new(QueryTotalEscrowForDenomResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v3.Query/TotalEscrowForDenom", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params queries all parameters of the ibc-transfer module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // DenomHash queries a denomination hash information. + DenomHash(context.Context, *QueryDenomHashRequest) (*QueryDenomHashResponse, error) + // EscrowAddress returns the escrow address for a particular port and channel id. + EscrowAddress(context.Context, *QueryEscrowAddressRequest) (*QueryEscrowAddressResponse, error) + // TotalEscrowForDenom returns the total amount of tokens in escrow based on the denom. + TotalEscrowForDenom(context.Context, *QueryTotalEscrowForDenomRequest) (*QueryTotalEscrowForDenomResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) DenomHash(ctx context.Context, req *QueryDenomHashRequest) (*QueryDenomHashResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DenomHash not implemented") +} +func (*UnimplementedQueryServer) EscrowAddress(ctx context.Context, req *QueryEscrowAddressRequest) (*QueryEscrowAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EscrowAddress not implemented") +} +func (*UnimplementedQueryServer) TotalEscrowForDenom(ctx context.Context, req *QueryTotalEscrowForDenomRequest) (*QueryTotalEscrowForDenomResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TotalEscrowForDenom not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.transfer.v3.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_DenomHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDenomHashRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DenomHash(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.transfer.v3.Query/DenomHash", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DenomHash(ctx, req.(*QueryDenomHashRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_EscrowAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryEscrowAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).EscrowAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.transfer.v3.Query/EscrowAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).EscrowAddress(ctx, req.(*QueryEscrowAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_TotalEscrowForDenom_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTotalEscrowForDenomRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TotalEscrowForDenom(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.transfer.v3.Query/TotalEscrowForDenom", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TotalEscrowForDenom(ctx, req.(*QueryTotalEscrowForDenomRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ibc.applications.transfer.v3.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "DenomHash", + Handler: _Query_DenomHash_Handler, + }, + { + MethodName: "EscrowAddress", + Handler: _Query_EscrowAddress_Handler, + }, + { + MethodName: "TotalEscrowForDenom", + Handler: _Query_TotalEscrowForDenom_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/applications/transfer/v3/query.proto", +} + +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Params != nil { + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDenomHashRequest) 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 *QueryDenomHashRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDenomHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Trace) > 0 { + i -= len(m.Trace) + copy(dAtA[i:], m.Trace) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Trace))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryDenomHashResponse) 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 *QueryDenomHashResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDenomHashResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryEscrowAddressRequest) 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 *QueryEscrowAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryEscrowAddressRequest) 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 = encodeVarintQuery(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 = encodeVarintQuery(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryEscrowAddressResponse) 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 *QueryEscrowAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryEscrowAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EscrowAddress) > 0 { + i -= len(m.EscrowAddress) + copy(dAtA[i:], m.EscrowAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.EscrowAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryTotalEscrowForDenomRequest) 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 *QueryTotalEscrowForDenomRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalEscrowForDenomRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryTotalEscrowForDenomResponse) 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 *QueryTotalEscrowForDenomResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalEscrowForDenomResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Params != nil { + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDenomHashRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Trace) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryDenomHashResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryEscrowAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryEscrowAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.EscrowAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTotalEscrowForDenomRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTotalEscrowForDenomResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) 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 ErrIntOverflowQuery + } + 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) 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 ErrIntOverflowQuery + } + 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Params == nil { + m.Params = &types.Params{} + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDenomHashRequest) 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 ErrIntOverflowQuery + } + 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: QueryDenomHashRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDenomHashRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Trace", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Trace = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDenomHashResponse) 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 ErrIntOverflowQuery + } + 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: QueryDenomHashResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDenomHashResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryEscrowAddressRequest) 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 ErrIntOverflowQuery + } + 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: QueryEscrowAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryEscrowAddressRequest: 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryEscrowAddressResponse) 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 ErrIntOverflowQuery + } + 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: QueryEscrowAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryEscrowAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EscrowAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EscrowAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTotalEscrowForDenomRequest) 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 ErrIntOverflowQuery + } + 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: QueryTotalEscrowForDenomRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalEscrowForDenomRequest: 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTotalEscrowForDenomResponse) 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 ErrIntOverflowQuery + } + 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: QueryTotalEscrowForDenomResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalEscrowForDenomResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/apps/transfer/v2/types/query.pb.gw.go b/modules/apps/transfer/v2/types/query.pb.gw.go new file mode 100644 index 00000000000..9f273cafeac --- /dev/null +++ b/modules/apps/transfer/v2/types/query.pb.gw.go @@ -0,0 +1,478 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: ibc/applications/transfer/v3/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_DenomHash_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDenomHashRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["trace"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "trace") + } + + protoReq.Trace, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "trace", err) + } + + msg, err := client.DenomHash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DenomHash_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDenomHashRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["trace"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "trace") + } + + protoReq.Trace, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "trace", err) + } + + msg, err := server.DenomHash(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_EscrowAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryEscrowAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["port_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "port_id") + } + + protoReq.PortId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "port_id", err) + } + + msg, err := client.EscrowAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_EscrowAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryEscrowAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["port_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "port_id") + } + + protoReq.PortId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "port_id", err) + } + + msg, err := server.EscrowAddress(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_TotalEscrowForDenom_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalEscrowForDenomRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := client.TotalEscrowForDenom(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TotalEscrowForDenom_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalEscrowForDenomRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := server.TotalEscrowForDenom(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DenomHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_DenomHash_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DenomHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_EscrowAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_EscrowAddress_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_EscrowAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalEscrowForDenom_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_TotalEscrowForDenom_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TotalEscrowForDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DenomHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_DenomHash_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DenomHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_EscrowAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_EscrowAddress_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_EscrowAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalEscrowForDenom_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_TotalEscrowForDenom_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TotalEscrowForDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"ibc", "apps", "transfer", "v2", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_DenomHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 3, 0, 4, 1, 5, 5}, []string{"ibc", "apps", "transfer", "v2", "denom_hashes", "trace"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_EscrowAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6, 1, 0, 4, 1, 5, 7, 2, 8}, []string{"ibc", "apps", "transfer", "v2", "channels", "channel_id", "ports", "port_id", "escrow_address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_TotalEscrowForDenom_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 3, 0, 4, 1, 5, 5, 2, 6}, []string{"ibc", "apps", "transfer", "v2", "denoms", "denom", "total_escrow"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_DenomHash_0 = runtime.ForwardResponseMessage + + forward_Query_EscrowAddress_0 = runtime.ForwardResponseMessage + + forward_Query_TotalEscrowForDenom_0 = runtime.ForwardResponseMessage +) diff --git a/modules/apps/transfer/v2/types/token.pb.go b/modules/apps/transfer/v2/types/token.pb.go new file mode 100644 index 00000000000..693e7529ab0 --- /dev/null +++ b/modules/apps/transfer/v2/types/token.pb.go @@ -0,0 +1,617 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/transfer/v2/token.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + 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 + +// Token defines a struct which represents a token to be transferred. +type Token struct { + // the token denomination + Denom Denom `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom"` + // the token amount to be transferred + Amount string `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (m *Token) Reset() { *m = Token{} } +func (m *Token) String() string { return proto.CompactTextString(m) } +func (*Token) ProtoMessage() {} +func (*Token) Descriptor() ([]byte, []int) { + return fileDescriptor_732b93aa1330663e, []int{0} +} +func (m *Token) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Token) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Token.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 *Token) XXX_Merge(src proto.Message) { + xxx_messageInfo_Token.Merge(m, src) +} +func (m *Token) XXX_Size() int { + return m.Size() +} +func (m *Token) XXX_DiscardUnknown() { + xxx_messageInfo_Token.DiscardUnknown(m) +} + +var xxx_messageInfo_Token proto.InternalMessageInfo + +func (m *Token) GetDenom() Denom { + if m != nil { + return m.Denom + } + return Denom{} +} + +func (m *Token) GetAmount() string { + if m != nil { + return m.Amount + } + return "" +} + +// Denom holds the base denom of a Token and a trace of the chains it was sent through. +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 []types.Hop `protobuf:"bytes,3,rep,name=trace,proto3" json:"trace"` +} + +func (m *Denom) Reset() { *m = Denom{} } +func (m *Denom) String() string { return proto.CompactTextString(m) } +func (*Denom) ProtoMessage() {} +func (*Denom) Descriptor() ([]byte, []int) { + return fileDescriptor_732b93aa1330663e, []int{1} +} +func (m *Denom) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Denom) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Denom.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 *Denom) XXX_Merge(src proto.Message) { + xxx_messageInfo_Denom.Merge(m, src) +} +func (m *Denom) XXX_Size() int { + return m.Size() +} +func (m *Denom) XXX_DiscardUnknown() { + xxx_messageInfo_Denom.DiscardUnknown(m) +} + +var xxx_messageInfo_Denom proto.InternalMessageInfo + +func (m *Denom) GetBase() string { + if m != nil { + return m.Base + } + return "" +} + +func (m *Denom) GetTrace() []types.Hop { + if m != nil { + return m.Trace + } + return nil +} + +func init() { + proto.RegisterType((*Token)(nil), "ibc.applications.transfer.v2.Token") + proto.RegisterType((*Denom)(nil), "ibc.applications.transfer.v2.Denom") +} + +func init() { + proto.RegisterFile("ibc/applications/transfer/v2/token.proto", fileDescriptor_732b93aa1330663e) +} + +var fileDescriptor_732b93aa1330663e = []byte{ + // 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, 0x93, 0x82, 0x08, 0xc3, 0x83, 0xe7, 0xb1, 0xd3, 0x4e, 0x26, 0x59, 0xac, 0xc1, 0xb5, 0x5f, + 0x69, 0xb2, 0x81, 0xff, 0xc2, 0x9f, 0xb5, 0xe3, 0x8e, 0x9e, 0x44, 0xda, 0x3f, 0x22, 0x4d, 0x9d, + 0x88, 0x87, 0xde, 0xde, 0x84, 0xe7, 0x7b, 0x1f, 0x78, 0x71, 0x64, 0xa4, 0xe2, 0x22, 0xcf, 0xd7, + 0x46, 0x09, 0x67, 0x20, 0xb3, 0xdc, 0x15, 0x22, 0xb3, 0xcf, 0xba, 0xe0, 0xdb, 0x98, 0x3b, 0x78, + 0xd5, 0x19, 0xcb, 0x0b, 0x70, 0x40, 0x4e, 0x8d, 0x54, 0xec, 0x2f, 0xc9, 0x0e, 0x24, 0xdb, 0xc6, + 0xa3, 0xcb, 0x96, 0x9e, 0xe9, 0x6f, 0x6e, 0xaa, 0x46, 0xc7, 0x09, 0x24, 0xe0, 0x23, 0xaf, 0x53, + 0xf3, 0x3b, 0x79, 0xc2, 0xe1, 0xa2, 0xf6, 0x91, 0x7b, 0x1c, 0xae, 0x74, 0x06, 0xe9, 0x10, 0x8d, + 0x51, 0x34, 0x88, 0x2f, 0x58, 0x9b, 0x99, 0x3d, 0xd4, 0xe8, 0xac, 0xbb, 0xfb, 0x3c, 0x0b, 0xe6, + 0xcd, 0x1d, 0x39, 0xc1, 0x3d, 0x91, 0xc2, 0x26, 0x73, 0xc3, 0xa3, 0x31, 0x8a, 0xfa, 0xf3, 0x9f, + 0xd7, 0x64, 0x89, 0x43, 0x4f, 0x13, 0x82, 0xbb, 0x52, 0x58, 0xed, 0x05, 0xfd, 0xb9, 0xcf, 0xe4, + 0x0e, 0x87, 0xae, 0x10, 0x4a, 0x0f, 0x3b, 0xe3, 0x4e, 0x34, 0x88, 0xcf, 0xdb, 0xac, 0x53, 0xf6, + 0x08, 0xf9, 0xc1, 0xe9, 0xaf, 0x66, 0x8b, 0x5d, 0x49, 0xd1, 0xbe, 0xa4, 0xe8, 0xab, 0xa4, 0xe8, + 0xbd, 0xa2, 0xc1, 0xbe, 0xa2, 0xc1, 0x47, 0x45, 0x83, 0xe5, 0x6d, 0x62, 0xdc, 0xcb, 0x46, 0x32, + 0x05, 0x29, 0x57, 0x60, 0x53, 0xb0, 0xdc, 0x48, 0x75, 0x95, 0x00, 0xdf, 0xde, 0xf0, 0x14, 0x56, + 0x9b, 0xb5, 0xb6, 0xf5, 0x74, 0xff, 0xa6, 0x7f, 0xcb, 0xb5, 0x95, 0x3d, 0x3f, 0xcd, 0xf5, 0x77, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x65, 0x9e, 0xcf, 0x86, 0xa7, 0x01, 0x00, 0x00, +} + +func (m *Token) 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 *Token) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Token) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintToken(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Denom.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintToken(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *Denom) 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 *Denom) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Denom) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Trace) > 0 { + for iNdEx := len(m.Trace) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Trace[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintToken(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Base) > 0 { + i -= len(m.Base) + copy(dAtA[i:], m.Base) + i = encodeVarintToken(dAtA, i, uint64(len(m.Base))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintToken(dAtA []byte, offset int, v uint64) int { + offset -= sovToken(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Token) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Denom.Size() + n += 1 + l + sovToken(uint64(l)) + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovToken(uint64(l)) + } + return n +} + +func (m *Denom) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Base) + if l > 0 { + n += 1 + l + sovToken(uint64(l)) + } + if len(m.Trace) > 0 { + for _, e := range m.Trace { + l = e.Size() + n += 1 + l + sovToken(uint64(l)) + } + } + return n +} + +func sovToken(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozToken(x uint64) (n int) { + return sovToken(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Token) 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: Token: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Token: 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 msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowToken + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthToken + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthToken + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Denom.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 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.Amount = 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 (m *Denom) 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: Denom: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Denom: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Base", 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.Base = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Trace", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowToken + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthToken + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthToken + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Trace = append(m.Trace, types.Hop{}) + if err := m.Trace[len(m.Trace)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowToken + } + 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, ErrIntOverflowToken + } + 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, ErrIntOverflowToken + } + 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, ErrInvalidLengthToken + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupToken + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthToken + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthToken = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowToken = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupToken = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/apps/transfer/v2/types/transfer.pb.go b/modules/apps/transfer/v2/types/transfer.pb.go new file mode 100644 index 00000000000..6867c76718e --- /dev/null +++ b/modules/apps/transfer/v2/types/transfer.pb.go @@ -0,0 +1,604 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/transfer/v2/transfer.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/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 + +// Forwarding defines a list of port ID, channel ID pairs determining the path +// through which a packet must be forwarded, and an unwind boolean indicating if +// the coin should be unwinded to its native chain before forwarding. +type Forwarding struct { + // optional unwinding for the token transfered + Unwind bool `protobuf:"varint,1,opt,name=unwind,proto3" json:"unwind,omitempty"` + // optional intermediate path through which packet will be forwarded + Hops []Hop `protobuf:"bytes,2,rep,name=hops,proto3" json:"hops"` +} + +func (m *Forwarding) Reset() { *m = Forwarding{} } +func (m *Forwarding) String() string { return proto.CompactTextString(m) } +func (*Forwarding) ProtoMessage() {} +func (*Forwarding) Descriptor() ([]byte, []int) { + return fileDescriptor_661702322184c8d7, []int{0} +} +func (m *Forwarding) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Forwarding) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Forwarding.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 *Forwarding) XXX_Merge(src proto.Message) { + xxx_messageInfo_Forwarding.Merge(m, src) +} +func (m *Forwarding) XXX_Size() int { + return m.Size() +} +func (m *Forwarding) XXX_DiscardUnknown() { + xxx_messageInfo_Forwarding.DiscardUnknown(m) +} + +var xxx_messageInfo_Forwarding proto.InternalMessageInfo + +func (m *Forwarding) GetUnwind() bool { + if m != nil { + return m.Unwind + } + return false +} + +func (m *Forwarding) GetHops() []Hop { + if m != nil { + return m.Hops + } + return nil +} + +// Hop defines a port ID, channel ID pair specifying where tokens must be forwarded +// next in a multihop transfer. +type Hop 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 *Hop) Reset() { *m = Hop{} } +func (*Hop) ProtoMessage() {} +func (*Hop) Descriptor() ([]byte, []int) { + return fileDescriptor_661702322184c8d7, []int{1} +} +func (m *Hop) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Hop) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Hop.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 *Hop) XXX_Merge(src proto.Message) { + xxx_messageInfo_Hop.Merge(m, src) +} +func (m *Hop) XXX_Size() int { + return m.Size() +} +func (m *Hop) XXX_DiscardUnknown() { + xxx_messageInfo_Hop.DiscardUnknown(m) +} + +var xxx_messageInfo_Hop proto.InternalMessageInfo + +func (m *Hop) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *Hop) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func init() { + proto.RegisterType((*Forwarding)(nil), "ibc.applications.transfer.v2.Forwarding") + proto.RegisterType((*Hop)(nil), "ibc.applications.transfer.v2.Hop") +} + +func init() { + proto.RegisterFile("ibc/applications/transfer/v2/transfer.proto", fileDescriptor_661702322184c8d7) +} + +var fileDescriptor_661702322184c8d7 = []byte{ + // 284 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0x31, 0x4b, 0xc3, 0x40, + 0x1c, 0xc5, 0x93, 0x36, 0x44, 0x7b, 0x6e, 0x41, 0xb4, 0x88, 0x5e, 0x6b, 0xa7, 0x82, 0x78, 0x07, + 0x71, 0xb2, 0x6e, 0x15, 0xa4, 0x5d, 0x83, 0x93, 0x8b, 0x5c, 0x2e, 0x31, 0x39, 0x48, 0xee, 0x7f, + 0xdc, 0x25, 0x29, 0x7e, 0x0b, 0x47, 0x47, 0x3f, 0x4e, 0xc7, 0x8e, 0x4e, 0x22, 0xc9, 0x17, 0x91, + 0xa4, 0xa5, 0x88, 0x83, 0xdb, 0x7b, 0xf7, 0xde, 0xbb, 0x3f, 0xfc, 0xd0, 0x95, 0x08, 0x39, 0x65, + 0x4a, 0x65, 0x82, 0xb3, 0x42, 0x80, 0x34, 0xb4, 0xd0, 0x4c, 0x9a, 0x97, 0x58, 0xd3, 0xca, 0xdf, + 0x6b, 0xa2, 0x34, 0x14, 0xe0, 0x9d, 0x8b, 0x90, 0x93, 0xdf, 0x65, 0xb2, 0x2f, 0x54, 0xfe, 0xd9, + 0x71, 0x02, 0x09, 0x74, 0x45, 0xda, 0xaa, 0xed, 0x66, 0xc2, 0x10, 0x7a, 0x00, 0xbd, 0x62, 0x3a, + 0x12, 0x32, 0xf1, 0x4e, 0x90, 0x5b, 0xca, 0x95, 0x90, 0xd1, 0xd0, 0x1e, 0xdb, 0xd3, 0xc3, 0x60, + 0xe7, 0xbc, 0x3b, 0xe4, 0xa4, 0xa0, 0xcc, 0xb0, 0x37, 0xee, 0x4f, 0x8f, 0xfc, 0x4b, 0xf2, 0xdf, + 0x21, 0xb2, 0x00, 0x35, 0x77, 0xd6, 0x5f, 0x23, 0x2b, 0xe8, 0x46, 0x93, 0x7b, 0xd4, 0x5f, 0x80, + 0xf2, 0x4e, 0xd1, 0x81, 0x02, 0x5d, 0x3c, 0x8b, 0xed, 0xe7, 0x83, 0xc0, 0x6d, 0xed, 0x32, 0xf2, + 0x2e, 0x10, 0xe2, 0x29, 0x93, 0x32, 0xce, 0xda, 0xac, 0xd7, 0x65, 0x83, 0xdd, 0xcb, 0x32, 0x9a, + 0x39, 0xef, 0x1f, 0x23, 0x6b, 0xfe, 0xb8, 0xae, 0xb1, 0xbd, 0xa9, 0xb1, 0xfd, 0x5d, 0x63, 0xfb, + 0xad, 0xc1, 0xd6, 0xa6, 0xc1, 0xd6, 0x67, 0x83, 0xad, 0xa7, 0x59, 0x22, 0x8a, 0xb4, 0x0c, 0x09, + 0x87, 0x9c, 0x72, 0x30, 0x39, 0x18, 0x2a, 0x42, 0x7e, 0x9d, 0x00, 0xad, 0x6e, 0x69, 0x0e, 0x51, + 0x99, 0xc5, 0xa6, 0x45, 0xf8, 0x07, 0xdd, 0xab, 0x8a, 0x4d, 0xe8, 0x76, 0x10, 0x6e, 0x7e, 0x02, + 0x00, 0x00, 0xff, 0xff, 0xdd, 0xe0, 0x66, 0xfe, 0x67, 0x01, 0x00, 0x00, +} + +func (m *Forwarding) 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 *Forwarding) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Forwarding) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Hops) > 0 { + for iNdEx := len(m.Hops) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Hops[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTransfer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.Unwind { + i-- + if m.Unwind { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Hop) 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 *Hop) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Hop) 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 = encodeVarintTransfer(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 = encodeVarintTransfer(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTransfer(dAtA []byte, offset int, v uint64) int { + offset -= sovTransfer(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Forwarding) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Unwind { + n += 2 + } + if len(m.Hops) > 0 { + for _, e := range m.Hops { + l = e.Size() + n += 1 + l + sovTransfer(uint64(l)) + } + } + return n +} + +func (m *Hop) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovTransfer(uint64(l)) + } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovTransfer(uint64(l)) + } + return n +} + +func sovTransfer(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTransfer(x uint64) (n int) { + return sovTransfer(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Forwarding) 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: Forwarding: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Forwarding: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Unwind", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Unwind = bool(v != 0) + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hops", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTransfer + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTransfer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hops = append(m.Hops, Hop{}) + if err := m.Hops[len(m.Hops)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 *Hop) 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: Hop: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Hop: 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 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.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 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.ChannelId = 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 skipTransfer(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, ErrIntOverflowTransfer + } + 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, ErrIntOverflowTransfer + } + 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, ErrIntOverflowTransfer + } + 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, ErrInvalidLengthTransfer + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTransfer + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTransfer + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTransfer = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTransfer = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTransfer = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/apps/transfer/v2/types/tx.pb.go b/modules/apps/transfer/v2/types/tx.pb.go new file mode 100644 index 00000000000..a7a27c02137 --- /dev/null +++ b/modules/apps/transfer/v2/types/tx.pb.go @@ -0,0 +1,1035 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/transfer/v3/tx.proto + +// TODO(bznein) ugly: find a better package name? + +package types + +import ( + context "context" + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + types1 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between +// ICS20 enabled chains. See ICS Spec here: +// https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures +type MsgTransfer struct { + // the channel by which the packet will be sent + SourceChannel string `protobuf:"bytes,1,opt,name=source_channel,json=sourceChannel,proto3" json:"source_channel,omitempty"` + // the source port for the packet + SourcePort string `protobuf:"bytes,2,opt,name=source_port,json=sourcePort,proto3" json:"source_port,omitempty"` + // the destination port for the packet + DestinationPort string `protobuf:"bytes,3,opt,name=destination_port,json=destinationPort,proto3" json:"destination_port,omitempty"` + // TODO comment + Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"` + // TODO comment + Encoding string `protobuf:"bytes,5,opt,name=encoding,proto3" json:"encoding,omitempty"` + // the sender address + Sender string `protobuf:"bytes,6,opt,name=sender,proto3" json:"sender,omitempty"` + // the recipient address on the destination chain + Receiver string `protobuf:"bytes,7,opt,name=receiver,proto3" json:"receiver,omitempty"` + // Timeout timestamp in absolute nanoseconds since unix epoch. + TimeoutTimestamp uint64 `protobuf:"varint,8,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty"` + // optional memo + Memo string `protobuf:"bytes,9,opt,name=memo,proto3" json:"memo,omitempty"` + // tokens to be transferred + Tokens []types.Coin `protobuf:"bytes,10,rep,name=tokens,proto3" json:"tokens"` + // optional forwarding information + Forwarding *types1.Forwarding `protobuf:"bytes,11,opt,name=forwarding,proto3" json:"forwarding,omitempty"` +} + +func (m *MsgTransfer) Reset() { *m = MsgTransfer{} } +func (m *MsgTransfer) String() string { return proto.CompactTextString(m) } +func (*MsgTransfer) ProtoMessage() {} +func (*MsgTransfer) Descriptor() ([]byte, []int) { + return fileDescriptor_e0fd8912df40617f, []int{0} +} +func (m *MsgTransfer) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgTransfer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgTransfer.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 *MsgTransfer) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgTransfer.Merge(m, src) +} +func (m *MsgTransfer) XXX_Size() int { + return m.Size() +} +func (m *MsgTransfer) XXX_DiscardUnknown() { + xxx_messageInfo_MsgTransfer.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgTransfer proto.InternalMessageInfo + +// MsgTransferResponse defines the Msg/Transfer response type. +type MsgTransferResponse struct { + // sequence number of the transfer packet sent + Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *MsgTransferResponse) Reset() { *m = MsgTransferResponse{} } +func (m *MsgTransferResponse) String() string { return proto.CompactTextString(m) } +func (*MsgTransferResponse) ProtoMessage() {} +func (*MsgTransferResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e0fd8912df40617f, []int{1} +} +func (m *MsgTransferResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgTransferResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgTransferResponse.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 *MsgTransferResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgTransferResponse.Merge(m, src) +} +func (m *MsgTransferResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgTransferResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgTransferResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgTransferResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgTransfer)(nil), "ibc.applications.transfer.v3.MsgTransfer") + proto.RegisterType((*MsgTransferResponse)(nil), "ibc.applications.transfer.v3.MsgTransferResponse") +} + +func init() { + proto.RegisterFile("ibc/applications/transfer/v3/tx.proto", fileDescriptor_e0fd8912df40617f) +} + +var fileDescriptor_e0fd8912df40617f = []byte{ + // 550 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0x1b, 0x9a, 0x75, 0x9b, 0x2b, 0x60, 0x33, 0x68, 0x84, 0x0a, 0xa5, 0xd5, 0xa4, 0x49, + 0x5d, 0xa7, 0xd9, 0x4a, 0x7b, 0x98, 0xe8, 0x71, 0x93, 0x10, 0x97, 0x49, 0x28, 0xea, 0x89, 0xcb, + 0x94, 0xb8, 0x5e, 0x6a, 0xad, 0xb1, 0x83, 0xed, 0x06, 0xb8, 0x21, 0x4e, 0x88, 0x13, 0x1f, 0x81, + 0x8f, 0xd0, 0x8f, 0xb1, 0xe3, 0x8e, 0x88, 0x03, 0x42, 0xed, 0xa1, 0x5f, 0x03, 0xc5, 0x71, 0xab, + 0x9c, 0x2a, 0x2e, 0xf5, 0x7b, 0xff, 0xf7, 0x7b, 0xee, 0x73, 0xde, 0x1f, 0x9c, 0xb0, 0x98, 0xe0, + 0x28, 0xcb, 0xa6, 0x8c, 0x44, 0x9a, 0x09, 0xae, 0xb0, 0x96, 0x11, 0x57, 0xb7, 0x54, 0xe2, 0x7c, + 0x80, 0xf5, 0x27, 0x94, 0x49, 0xa1, 0x05, 0x7c, 0xc5, 0x62, 0x82, 0xaa, 0x18, 0x5a, 0x63, 0x28, + 0x1f, 0xb4, 0x0e, 0xa3, 0x94, 0x71, 0x81, 0xcd, 0x6f, 0xd9, 0xd0, 0x7a, 0x9e, 0x88, 0x44, 0x98, + 0x10, 0x17, 0x91, 0x55, 0x5f, 0x10, 0xa1, 0x52, 0xa1, 0x70, 0xaa, 0x12, 0x9c, 0x07, 0xc5, 0x61, + 0x0b, 0xbe, 0x2d, 0xc4, 0x91, 0xa2, 0x38, 0x0f, 0x62, 0xaa, 0xa3, 0x00, 0x13, 0xc1, 0xb8, 0xad, + 0x9f, 0x6d, 0x19, 0x33, 0xd8, 0xc4, 0x25, 0x7c, 0xfc, 0xbb, 0x0e, 0x9a, 0xd7, 0x2a, 0x19, 0x59, + 0x15, 0x9e, 0x80, 0x27, 0x4a, 0xcc, 0x24, 0xa1, 0x37, 0x64, 0x12, 0x71, 0x4e, 0xa7, 0x9e, 0xd3, + 0x71, 0xba, 0xfb, 0xe1, 0xe3, 0x52, 0xbd, 0x2a, 0x45, 0xd8, 0x06, 0x4d, 0x8b, 0x65, 0x42, 0x6a, + 0xef, 0x91, 0x61, 0x40, 0x29, 0xbd, 0x13, 0x52, 0xc3, 0x53, 0x70, 0x30, 0xa6, 0x4a, 0x33, 0x6e, + 0x46, 0x28, 0xa9, 0xba, 0xa1, 0x9e, 0x56, 0x74, 0x83, 0x7a, 0x60, 0x37, 0xa7, 0x52, 0x31, 0xc1, + 0x3d, 0xd7, 0x10, 0xeb, 0x14, 0xb6, 0xc0, 0x1e, 0xe5, 0x44, 0x8c, 0x19, 0x4f, 0xbc, 0x1d, 0x53, + 0xda, 0xe4, 0xf0, 0x08, 0x34, 0x14, 0xe5, 0x63, 0x2a, 0xbd, 0x86, 0xa9, 0xd8, 0xac, 0xe8, 0x91, + 0x94, 0x50, 0x96, 0x53, 0xe9, 0xed, 0x96, 0x3d, 0xeb, 0x1c, 0x9e, 0x81, 0x43, 0xcd, 0x52, 0x2a, + 0x66, 0xfa, 0xa6, 0x38, 0x95, 0x8e, 0xd2, 0xcc, 0xdb, 0xeb, 0x38, 0x5d, 0x37, 0x3c, 0xb0, 0x85, + 0xd1, 0x5a, 0x87, 0x10, 0xb8, 0x29, 0x4d, 0x85, 0xb7, 0x6f, 0x2e, 0x31, 0x31, 0xbc, 0x00, 0x0d, + 0x2d, 0xee, 0x28, 0x57, 0x1e, 0xe8, 0xd4, 0xbb, 0xcd, 0xfe, 0x4b, 0x54, 0xee, 0x02, 0x15, 0xbb, + 0x40, 0x76, 0x17, 0xe8, 0x4a, 0x30, 0x7e, 0xe9, 0xde, 0xff, 0x69, 0xd7, 0x42, 0x8b, 0xc3, 0xb7, + 0x00, 0xdc, 0x0a, 0xf9, 0x31, 0x92, 0xe6, 0x2d, 0xcd, 0x8e, 0xd3, 0x6d, 0xf6, 0xbb, 0x68, 0x8b, + 0x51, 0x02, 0xf4, 0x66, 0xc3, 0x87, 0x95, 0xde, 0x61, 0xef, 0xdb, 0xcf, 0x76, 0xed, 0xeb, 0x6a, + 0xde, 0xb3, 0x0f, 0xfe, 0xbe, 0x9a, 0xf7, 0x8e, 0xca, 0x29, 0xce, 0xd5, 0xf8, 0x0e, 0x57, 0x96, + 0x79, 0x7c, 0x01, 0x9e, 0x55, 0xd2, 0x90, 0xaa, 0x4c, 0x70, 0x45, 0x8b, 0x4f, 0xa4, 0xe8, 0x87, + 0x19, 0xe5, 0x84, 0x9a, 0xed, 0xba, 0xe1, 0x26, 0x1f, 0xba, 0xc5, 0xf5, 0xfd, 0x1c, 0xd4, 0xaf, + 0x55, 0x02, 0x27, 0x60, 0x6f, 0x63, 0x8c, 0xd3, 0x6d, 0xd3, 0x0e, 0x50, 0xe5, 0x7f, 0x5a, 0xc1, + 0x7f, 0xa3, 0xeb, 0x91, 0x5a, 0x3b, 0x5f, 0x56, 0xf3, 0x9e, 0x73, 0x39, 0xba, 0x5f, 0xf8, 0xce, + 0xc3, 0xc2, 0x77, 0xfe, 0x2e, 0x7c, 0xe7, 0xc7, 0xd2, 0xaf, 0x3d, 0x2c, 0xfd, 0xda, 0xaf, 0xa5, + 0x5f, 0x7b, 0x3f, 0x4c, 0x98, 0x9e, 0xcc, 0x62, 0x44, 0x44, 0x8a, 0xad, 0xff, 0x59, 0x4c, 0xce, + 0x13, 0x81, 0xf3, 0xd7, 0x38, 0x15, 0xe3, 0xd9, 0x94, 0xaa, 0xc2, 0xf4, 0x55, 0xb3, 0xf7, 0xb1, + 0xfe, 0x9c, 0x51, 0x15, 0x37, 0x8c, 0xd5, 0x07, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x29, 0xdf, + 0x61, 0x67, 0xc0, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // Transfer defines a rpc handler method for MsgTransfer. + Transfer(ctx context.Context, in *MsgTransfer, opts ...grpc.CallOption) (*MsgTransferResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Transfer(ctx context.Context, in *MsgTransfer, opts ...grpc.CallOption) (*MsgTransferResponse, error) { + out := new(MsgTransferResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.transfer.v3.Msg/Transfer", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // Transfer defines a rpc handler method for MsgTransfer. + Transfer(context.Context, *MsgTransfer) (*MsgTransferResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) Transfer(ctx context.Context, req *MsgTransfer) (*MsgTransferResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Transfer not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_Transfer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgTransfer) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Transfer(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.transfer.v3.Msg/Transfer", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Transfer(ctx, req.(*MsgTransfer)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ibc.applications.transfer.v3.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Transfer", + Handler: _Msg_Transfer_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/applications/transfer/v3/tx.proto", +} + +func (m *MsgTransfer) 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 *MsgTransfer) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgTransfer) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Forwarding != nil { + { + size, err := m.Forwarding.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x5a + } + if len(m.Tokens) > 0 { + for iNdEx := len(m.Tokens) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Tokens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + } + } + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintTx(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x4a + } + if m.TimeoutTimestamp != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.TimeoutTimestamp)) + i-- + dAtA[i] = 0x40 + } + if len(m.Receiver) > 0 { + i -= len(m.Receiver) + copy(dAtA[i:], m.Receiver) + i = encodeVarintTx(dAtA, i, uint64(len(m.Receiver))) + i-- + dAtA[i] = 0x3a + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0x32 + } + if len(m.Encoding) > 0 { + i -= len(m.Encoding) + copy(dAtA[i:], m.Encoding) + i = encodeVarintTx(dAtA, i, uint64(len(m.Encoding))) + i-- + dAtA[i] = 0x2a + } + if len(m.Version) > 0 { + i -= len(m.Version) + copy(dAtA[i:], m.Version) + i = encodeVarintTx(dAtA, i, uint64(len(m.Version))) + i-- + dAtA[i] = 0x22 + } + if len(m.DestinationPort) > 0 { + i -= len(m.DestinationPort) + copy(dAtA[i:], m.DestinationPort) + i = encodeVarintTx(dAtA, i, uint64(len(m.DestinationPort))) + i-- + dAtA[i] = 0x1a + } + if len(m.SourcePort) > 0 { + i -= len(m.SourcePort) + copy(dAtA[i:], m.SourcePort) + i = encodeVarintTx(dAtA, i, uint64(len(m.SourcePort))) + i-- + dAtA[i] = 0x12 + } + if len(m.SourceChannel) > 0 { + i -= len(m.SourceChannel) + copy(dAtA[i:], m.SourceChannel) + i = encodeVarintTx(dAtA, i, uint64(len(m.SourceChannel))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgTransferResponse) 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 *MsgTransferResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgTransferResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgTransfer) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SourceChannel) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SourcePort) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.DestinationPort) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Version) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Encoding) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Receiver) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.TimeoutTimestamp != 0 { + n += 1 + sovTx(uint64(m.TimeoutTimestamp)) + } + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Tokens) > 0 { + for _, e := range m.Tokens { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if m.Forwarding != nil { + l = m.Forwarding.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgTransferResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sequence != 0 { + n += 1 + sovTx(uint64(m.Sequence)) + } + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgTransfer) 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 ErrIntOverflowTx + } + 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: MsgTransfer: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgTransfer: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourceChannel", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SourceChannel = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourcePort", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SourcePort = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DestinationPort", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DestinationPort = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Version = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Encoding", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Encoding = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + 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 ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + 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 ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Receiver = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutTimestamp", wireType) + } + m.TimeoutTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutTimestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Memo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tokens", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Tokens = append(m.Tokens, types.Coin{}) + if err := m.Tokens[len(m.Tokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Forwarding", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Forwarding == nil { + m.Forwarding = &types1.Forwarding{} + } + if err := m.Forwarding.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgTransferResponse) 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 ErrIntOverflowTx + } + 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: MsgTransferResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgTransferResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 87bb1041ffc..27bd89e12a1 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -320,6 +320,10 @@ func (k *Keeper) VerifyMembership(ctx context.Context, clientID string, height e return err } + if status := clientModule.Status(ctx, clientID); status != exported.Active { + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot call verify membership on client (%s) with status %s", clientID, status) + } + return clientModule.VerifyMembership(ctx, clientID, height, delayTimePeriod, delayBlockPeriod, proof, path, value) } @@ -330,6 +334,10 @@ func (k *Keeper) VerifyNonMembership(ctx context.Context, clientID string, heigh return err } + if status := clientModule.Status(ctx, clientID); status != exported.Active { + return errorsmod.Wrapf(types.ErrClientNotActive, "cannot call verify non membership on client (%s) with status %s", clientID, status) + } + return clientModule.VerifyNonMembership(ctx, clientID, height, delayTimePeriod, delayBlockPeriod, proof, path) } diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index 7e4005bda45..1db1949bbee 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -465,6 +465,134 @@ func (suite *KeeperTestSuite) TestGetTimestampAtHeight() { } } +func (suite *KeeperTestSuite) TestVerifyMembership() { + var path *ibctesting.Path + + cases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "invalid client id", + func() { + path.EndpointA.ClientID = "" + }, + host.ErrInvalidID, + }, + { + "failure: client is frozen", + func() { + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) + clientState.FrozenHeight = types.NewHeight(0, 1) + path.EndpointA.SetClientState(clientState) + }, + types.ErrClientNotActive, + }, + } + + for _, tc := range cases { + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.Setup() + + // create default proof, merklePath, and value which passes + key := host.FullClientStateKey(path.EndpointB.ClientID) + merklePath := commitmenttypes.NewMerklePath(key) + merklePrefixPath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) + suite.Require().NoError(err) + + proof, proofHeight := suite.chainB.QueryProof(key) + + clientState, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) + value, err := suite.chainB.Codec.MarshalInterface(clientState) + suite.Require().NoError(err) + + tc.malleate() + + err = suite.chainA.App.GetIBCKeeper().ClientKeeper.VerifyMembership(suite.chainA.GetContext(), path.EndpointA.ClientID, proofHeight, 0, 0, proof, merklePrefixPath, value) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + } else { + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} + +func (suite *KeeperTestSuite) TestVerifyNonMembership() { + var path *ibctesting.Path + + cases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "invalid client id", + func() { + path.EndpointA.ClientID = "" + }, + host.ErrInvalidID, + }, + { + "failure: client is frozen", + func() { + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) + clientState.FrozenHeight = types.NewHeight(0, 1) + path.EndpointA.SetClientState(clientState) + }, + types.ErrClientNotActive, + }, + } + + for _, tc := range cases { + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.Setup() + + // create default proof, merklePath, and value which passes + key := host.FullClientStateKey("invalid-client-id") + + merklePath := commitmenttypes.NewMerklePath(key) + merklePrefixPath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) + suite.Require().NoError(err) + + proof, proofHeight := suite.chainB.QueryProof(key) + + tc.malleate() + + err = suite.chainA.App.GetIBCKeeper().ClientKeeper.VerifyNonMembership(suite.chainA.GetContext(), path.EndpointA.ClientID, proofHeight, 0, 0, proof, merklePrefixPath) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + } else { + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} + // TestDefaultSetParams tests the default params set are what is expected func (suite *KeeperTestSuite) TestDefaultSetParams() { expParams := types.DefaultParams() diff --git a/modules/core/02-client/types/msgs_test.go b/modules/core/02-client/types/msgs_test.go index 6440ddabc8a..4dc9acb4dfd 100644 --- a/modules/core/02-client/types/msgs_test.go +++ b/modules/core/02-client/types/msgs_test.go @@ -681,7 +681,6 @@ func (suite *TypesTestSuite) TestMsgRecoverClientValidateBasic() { if expPass { suite.Require().NoError(err, "valid case %s failed", tc.name) } else { - suite.Require().Error(err, "invalid case %s passed", tc.name) suite.Require().ErrorIs(err, tc.expError, "invalid case %s passed", tc.name) } } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 5dd4969edd2..1cdc8193d2e 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" @@ -27,10 +26,6 @@ func (k *Keeper) VerifyConnectionState( counterpartyConnection types.ConnectionEnd, // opposite connection ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - merklePath := commitmenttypes.NewMerklePath(host.ConnectionKey(connectionID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -65,10 +60,6 @@ func (k *Keeper) VerifyChannelState( channel channeltypes.Channel, ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - merklePath := commitmenttypes.NewMerklePath(host.ChannelKey(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -104,10 +95,6 @@ func (k *Keeper) VerifyPacketCommitment( commitmentBytes []byte, ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) @@ -140,10 +127,6 @@ func (k *Keeper) VerifyPacketAcknowledgement( acknowledgement []byte, ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) @@ -177,10 +160,6 @@ func (k *Keeper) VerifyPacketReceiptAbsence( sequence uint64, ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) @@ -212,10 +191,6 @@ func (k *Keeper) VerifyNextSequenceRecv( nextSequenceRecv uint64, ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - // get time and block delays timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) @@ -248,10 +223,6 @@ func (k *Keeper) VerifyChannelUpgradeError( errorReceipt channeltypes.ErrorReceipt, ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorKey(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { @@ -285,10 +256,6 @@ func (k *Keeper) VerifyChannelUpgrade( upgrade channeltypes.Upgrade, ) error { clientID := connection.ClientId - if status := k.clientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeKey(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { diff --git a/modules/core/03-connection/keeper/verify_test.go b/modules/core/03-connection/keeper/verify_test.go index 4177aebbbce..163df7ba4f6 100644 --- a/modules/core/03-connection/keeper/verify_test.go +++ b/modules/core/03-connection/keeper/verify_test.go @@ -214,7 +214,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { suite.chainB.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(timePerBlock)) } - commitment := channeltypes.CommitPacket(suite.chainB.App.GetIBCKeeper().Codec(), packet) + commitment := channeltypes.CommitPacket(packet) err = suite.chainB.App.GetIBCKeeper().ConnectionKeeper.VerifyPacketCommitment( suite.chainB.GetContext(), connection, malleateHeight(proofHeight, heightDiff), proof, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), commitment, diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index fad33c9808b..b83af2a7c16 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -128,8 +128,10 @@ func emitChannelCloseConfirmEvent(ctx context.Context, portID string, channelID // emitSendPacketEvent emits an event with packet data along with other packet information for relayer // to pick up and relay to other chain -func emitSendPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel, timeoutHeight exported.Height) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitSendPacketEvent(ctx context.Context, packet types.Packet, channel types.Channel, timeoutHeight exported.Height) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeSendPacket, sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())), @@ -155,8 +157,10 @@ func emitSendPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Cha // emitRecvPacketEvent emits a receive packet event. It will be emitted both the first time a packet // is received for a certain sequence and for all duplicate receives. -func emitRecvPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitRecvPacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRecvPacket, sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())), @@ -181,8 +185,10 @@ func emitRecvPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Cha } // emitWriteAcknowledgementEvent emits an event that the relayer can query for -func emitWriteAcknowledgementEvent(ctx sdk.Context, packet types.Packet, channel types.Channel, acknowledgement []byte) { - ctx.EventManager().EmitEvents(sdk.Events{ +func emitWriteAcknowledgementEvent(ctx context.Context, packet types.Packet, channel types.Channel, acknowledgement []byte) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeWriteAck, sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())), @@ -211,6 +217,7 @@ func emitWriteAcknowledgementEvent(ctx sdk.Context, packet types.Packet, channel // a packet is acknowledged for a certain sequence and for all duplicate acknowledgements. func emitAcknowledgePacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) { sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeAcknowledgePacket, @@ -238,6 +245,7 @@ func emitAcknowledgePacketEvent(ctx context.Context, packet types.Packet, channe // is timed out for a certain sequence and for all duplicate timeouts. func emitTimeoutPacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) { sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeTimeoutPacket, @@ -248,8 +256,11 @@ func emitTimeoutPacketEvent(ctx context.Context, packet types.Packet, channel ty sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()), sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()), sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()), + // we only support 1-hop packets now, and that is the most important hop for a relayer + // (is it going to a chain I am connected to) + sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), // DEPRECATED + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), ), sdk.NewEvent( sdk.EventTypeMessage, @@ -279,8 +290,9 @@ func emitChannelClosedEvent(ctx context.Context, packet types.Packet, channel ty } // EmitChannelUpgradeInitEvent emits a channel upgrade init event -func EmitChannelUpgradeInitEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitChannelUpgradeInitEvent(ctx context.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeInit, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -297,8 +309,9 @@ func EmitChannelUpgradeInitEvent(ctx sdk.Context, portID string, channelID strin } // EmitChannelUpgradeTryEvent emits a channel upgrade try event -func EmitChannelUpgradeTryEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitChannelUpgradeTryEvent(ctx context.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeTry, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -315,8 +328,9 @@ func EmitChannelUpgradeTryEvent(ctx sdk.Context, portID string, channelID string } // EmitChannelUpgradeAckEvent emits a channel upgrade ack event -func EmitChannelUpgradeAckEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitChannelUpgradeAckEvent(ctx context.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeAck, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -333,8 +347,9 @@ func EmitChannelUpgradeAckEvent(ctx sdk.Context, portID string, channelID string } // EmitChannelUpgradeConfirmEvent emits a channel upgrade confirm event -func EmitChannelUpgradeConfirmEvent(ctx sdk.Context, portID, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitChannelUpgradeConfirmEvent(ctx context.Context, portID, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeConfirm, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -352,8 +367,9 @@ func EmitChannelUpgradeConfirmEvent(ctx sdk.Context, portID, channelID string, c } // EmitChannelUpgradeOpenEvent emits a channel upgrade open event -func EmitChannelUpgradeOpenEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitChannelUpgradeOpenEvent(ctx context.Context, portID string, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeOpen, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -371,8 +387,9 @@ func EmitChannelUpgradeOpenEvent(ctx sdk.Context, portID string, channelID strin } // EmitChannelUpgradeTimeoutEvent emits an upgrade timeout event. -func EmitChannelUpgradeTimeoutEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitChannelUpgradeTimeoutEvent(ctx context.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeTimeout, sdk.NewAttribute(types.AttributeKeyPortID, portID), @@ -411,8 +428,9 @@ func EmitErrorReceiptEvent(ctx context.Context, portID string, channelID string, } // EmitChannelUpgradeCancelEvent emits an upgraded cancelled event. -func EmitChannelUpgradeCancelEvent(ctx sdk.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { - ctx.EventManager().EmitEvents(sdk.Events{ +func EmitChannelUpgradeCancelEvent(ctx context.Context, portID string, channelID string, channel types.Channel, upgrade types.Upgrade) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelUpgradeCancel, sdk.NewAttribute(types.AttributeKeyPortID, portID), diff --git a/modules/core/04-channel/keeper/export_test.go b/modules/core/04-channel/keeper/export_test.go index bbe084b15c5..fce2e6487b4 100644 --- a/modules/core/04-channel/keeper/export_test.go +++ b/modules/core/04-channel/keeper/export_test.go @@ -34,3 +34,8 @@ func (k *Keeper) SetUpgradeErrorReceipt(ctx sdk.Context, portID, channelID strin func (k *Keeper) SetRecvStartSequence(ctx sdk.Context, portID, channelID string, sequence uint64) { k.setRecvStartSequence(ctx, portID, channelID, sequence) } + +// TimeoutExecuted is a wrapper around timeoutExecuted to allow the function to be directly called in tests. +func (k *Keeper) TimeoutExecuted(ctx sdk.Context, channel types.Channel, packet types.Packet) error { + return k.timeoutExecuted(ctx, channel, packet) +} diff --git a/modules/core/04-channel/keeper/keeper_test.go b/modules/core/04-channel/keeper/keeper_test.go index c6014805af6..ff343faa1e8 100644 --- a/modules/core/04-channel/keeper/keeper_test.go +++ b/modules/core/04-channel/keeper/keeper_test.go @@ -26,6 +26,7 @@ type KeeperTestSuite struct { // testing chains used for convenience and readability chainA *ibctesting.TestChain chainB *ibctesting.TestChain + chainC *ibctesting.TestChain } // TestKeeperTestSuite runs all the tests within this package. @@ -35,12 +36,14 @@ func TestKeeperTestSuite(t *testing.T) { // SetupTest creates a coordinator with 2 test chains. func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3)) // commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1) suite.coordinator.CommitNBlocks(suite.chainA, 2) suite.coordinator.CommitNBlocks(suite.chainB, 2) + suite.coordinator.CommitNBlocks(suite.chainC, 2) } // TestSetChannel create clients and connections on both chains. It tests for the non-existence diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 65410bcd11b..4be14bbf330 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -80,7 +80,7 @@ func (k *Keeper) SendPacket( return 0, errorsmod.Wrap(timeout.ErrTimeoutElapsed(latestHeight, latestTimestamp), "invalid packet timeout") } - commitment := types.CommitPacket(k.cdc, packet) + commitment := types.CommitPacket(packet) k.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1) k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) @@ -164,7 +164,7 @@ func (k *Keeper) RecvPacket( return "", errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "packet timeout elapsed") } - commitment := types.CommitPacket(k.cdc, packet) + commitment := types.CommitPacket(packet) // verify that the counterparty did commit to sending this packet if err := k.connectionKeeper.VerifyPacketCommitment( @@ -400,7 +400,7 @@ func (k *Keeper) AcknowledgePacket( return "", types.ErrNoOpMsg } - packetCommitment := types.CommitPacket(k.cdc, packet) + packetCommitment := types.CommitPacket(packet) // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 8025eaca3b6..5eb2d43062d 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -535,7 +535,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // manually set packet commitment - suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, packet.GetSequence(), types.CommitPacket(suite.chainA.App.AppCodec(), packet)) + suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, packet.GetSequence(), types.CommitPacket(packet)) err := path.EndpointA.UpdateClient() suite.Require().NoError(err) diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 5b548605700..b7d39b843c4 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -78,7 +78,7 @@ func (k *Keeper) TimeoutPacket( return "", types.ErrNoOpMsg } - packetCommitment := types.CommitPacket(k.cdc, packet) + packetCommitment := types.CommitPacket(packet) // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { @@ -113,26 +113,25 @@ func (k *Keeper) TimeoutPacket( return "", err } - // NOTE: the remaining code is located in the TimeoutExecuted function + if err = k.timeoutExecuted(ctx, channel, packet); err != nil { + return "", err + } + return channel.Version, nil } -// TimeoutExecuted deletes the commitment send from this chain after it verifies timeout. +// timeoutExecuted deletes the commitment send from this chain after it verifies timeout. // If the timed-out packet came from an ORDERED channel then this channel will be closed. // If the channel is in the FLUSHING state and there is a counterparty upgrade, then the // upgrade will be aborted if the upgrade has timed out. Otherwise, if there are no more inflight packets, // then the channel will be set to the FLUSHCOMPLETE state. // // CONTRACT: this function must be called in the IBC handler -func (k *Keeper) TimeoutExecuted( +func (k *Keeper) timeoutExecuted( ctx context.Context, + channel types.Channel, packet types.Packet, ) error { - channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) - if !found { - return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) - } - k.deletePacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) // if an upgrade is in progress, handling packet flushing and update channel state appropriately @@ -220,7 +219,7 @@ func (k *Keeper) TimeoutOnClose( return "", types.ErrNoOpMsg } - packetCommitment := types.CommitPacket(k.cdc, packet) + packetCommitment := types.CommitPacket(packet) // verify we sent the packet and haven't cleared it out yet if !bytes.Equal(commitment, packetCommitment) { @@ -274,6 +273,9 @@ func (k *Keeper) TimeoutOnClose( return "", err } - // NOTE: the remaining code is located in the TimeoutExecuted function + if err = k.timeoutExecuted(ctx, channel, packet); err != nil { + return "", err + } + return channel.Version, nil } diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index 163d626e763..0748e6efbd7 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -143,6 +143,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().UnixNano()) sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, timeoutTimestamp, ibctesting.MockPacketData) + suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, timeoutTimestamp) err = path.EndpointA.UpdateClient() @@ -275,22 +276,6 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { }, nil, }, - { - "channel not found", - func() { - // use wrong channel naming - path.Setup() - packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - }, - func(packetCommitment []byte, err error) { - suite.Require().Error(err) - suite.Require().ErrorIs(err, types.ErrChannelNotFound) - - // packet never sent. - suite.Require().Nil(packetCommitment) - }, - nil, - }, { "set to flush complete with no inflight packets", func() { @@ -490,7 +475,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { tc.malleate() - err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutExecuted(ctx, packet) + err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutExecuted(ctx, path.EndpointA.GetChannel(), packet) pc := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) tc.expResult(pc, err) diff --git a/modules/core/04-channel/types/packet.go b/modules/core/04-channel/types/packet.go index 0660a8f91c2..b585f093e50 100644 --- a/modules/core/04-channel/types/packet.go +++ b/modules/core/04-channel/types/packet.go @@ -5,7 +5,6 @@ import ( errorsmod "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" @@ -16,8 +15,10 @@ import ( // CommitPacket returns the packet commitment bytes. The commitment consists of: // sha256_hash(timeout_timestamp + timeout_height.RevisionNumber + timeout_height.RevisionHeight + sha256_hash(data)) // from a given packet. This results in a fixed length preimage. +// NOTE: A fixed length preimage is ESSENTIAL to prevent relayers from being able +// to malleate the packet fields and create a commitment hash that matches the original packet. // NOTE: sdk.Uint64ToBigEndian sets the uint64 to a slice of length 8. -func CommitPacket(cdc codec.BinaryCodec, packet Packet) []byte { +func CommitPacket(packet Packet) []byte { timeoutHeight := packet.GetTimeoutHeight() buf := sdk.Uint64ToBigEndian(packet.GetTimeoutTimestamp()) @@ -108,6 +109,7 @@ func (p Packet) ValidateBasic() error { if len(p.Data) == 0 { return errorsmod.Wrap(ErrInvalidPacket, "packet data bytes cannot be empty") } + return nil } diff --git a/modules/core/04-channel/types/packet_test.go b/modules/core/04-channel/types/packet_test.go index fca1d9a357d..f26192b8712 100644 --- a/modules/core/04-channel/types/packet_test.go +++ b/modules/core/04-channel/types/packet_test.go @@ -5,22 +5,13 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" ) func TestCommitPacket(t *testing.T) { - registry := codectypes.NewInterfaceRegistry() - clienttypes.RegisterInterfaces(registry) - types.RegisterInterfaces(registry) - - cdc := codec.NewProtoCodec(registry) - packet := types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) - commitment := types.CommitPacket(cdc, packet) + commitment := types.CommitPacket(packet) require.NotNil(t, commitment) testCases := []struct { @@ -46,7 +37,7 @@ func TestCommitPacket(t *testing.T) { } for _, tc := range testCases { - testCommitment := types.CommitPacket(cdc, tc.packet) + testCommitment := types.CommitPacket(tc.packet) require.NotNil(t, testCommitment) require.NotEqual(t, commitment, testCommitment) @@ -60,6 +51,7 @@ func TestPacketValidateBasic(t *testing.T) { errMsg string }{ {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""}, + {types.NewPacket(unknownPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""}, {types.NewPacket(validPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid sequence"}, {types.NewPacket(validPacketData, 1, invalidPort, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source port"}, {types.NewPacket(validPacketData, 1, portid, invalidChannel, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source channel"}, @@ -68,7 +60,6 @@ func TestPacketValidateBasic(t *testing.T) { {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, 0), false, "disabled both timeout height and timestamp"}, {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, timeoutTimestamp), true, "disabled timeout height, valid timeout timestamp"}, {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, 0), true, "disabled timeout timestamp, valid timeout height"}, - {types.NewPacket(unknownPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""}, } for i, tc := range testCases { diff --git a/modules/core/04-channel/types/timeout.go b/modules/core/04-channel/types/timeout.go index 47265d5b3a9..ca1e70ca8e6 100644 --- a/modules/core/04-channel/types/timeout.go +++ b/modules/core/04-channel/types/timeout.go @@ -14,6 +14,14 @@ func NewTimeout(height clienttypes.Height, timestamp uint64) Timeout { } } +// NewTimeoutWithTimestamp creates a new Timeout with only the timestamp set. +func NewTimeoutWithTimestamp(timestamp uint64) Timeout { + return Timeout{ + Height: clienttypes.ZeroHeight(), + Timestamp: timestamp, + } +} + // IsValid returns true if either the height or timestamp is non-zero. func (t Timeout) IsValid() bool { return !t.Height.IsZero() || t.Timestamp != 0 @@ -25,6 +33,11 @@ func (t Timeout) Elapsed(height clienttypes.Height, timestamp uint64) bool { return t.heightElapsed(height) || t.timestampElapsed(timestamp) } +// TimestampElapsed returns true if the provided timestamp is past the timeout timestamp. +func (t Timeout) TimestampElapsed(timestamp uint64) bool { + return t.timestampElapsed(timestamp) +} + // ErrTimeoutElapsed returns a timeout elapsed error indicating which timeout value // has elapsed. func (t Timeout) ErrTimeoutElapsed(height clienttypes.Height, timestamp uint64) error { diff --git a/modules/core/04-channel/v2/client/cli/abci.go b/modules/core/04-channel/v2/client/cli/abci.go new file mode 100644 index 00000000000..d341e35b4e2 --- /dev/null +++ b/modules/core/04-channel/v2/client/cli/abci.go @@ -0,0 +1,71 @@ +package cli + +import ( + "encoding/binary" + + errorsmod "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" + ibcclient "github.com/cosmos/ibc-go/v9/modules/core/client" +) + +func queryNextSequenceSendABCI(clientCtx client.Context, channelID string) (*types.QueryNextSequenceSendResponse, error) { + key := hostv2.NextSequenceSendKey(channelID) + value, proofBz, proofHeight, err := ibcclient.QueryTendermintProof(clientCtx, key) + if err != nil { + return nil, err + } + + // check if next sequence send exists + if len(value) == 0 { + return nil, errorsmod.Wrapf(types.ErrSequenceSendNotFound, "channelID (%s)", channelID) + } + + sequence := binary.BigEndian.Uint64(value) + + return types.NewQueryNextSequenceSendResponse(sequence, proofBz, proofHeight), nil +} + +func queryPacketCommitmentABCI(clientCtx client.Context, channelID string, sequence uint64) (*types.QueryPacketCommitmentResponse, error) { + key := hostv2.PacketCommitmentKey(channelID, sequence) + value, proofBz, proofHeight, err := ibcclient.QueryTendermintProof(clientCtx, key) + if err != nil { + return nil, err + } + + // check if packet commitment exists + if len(value) == 0 { + return nil, errorsmod.Wrapf(types.ErrPacketCommitmentNotFound, "channelID (%s), sequence (%d)", channelID, sequence) + } + + return types.NewQueryPacketCommitmentResponse(value, proofBz, proofHeight), nil +} + +func queryPacketAcknowledgementABCI(clientCtx client.Context, channelID string, sequence uint64) (*types.QueryPacketAcknowledgementResponse, error) { + key := hostv2.PacketAcknowledgementKey(channelID, sequence) + value, proofBz, proofHeight, err := ibcclient.QueryTendermintProof(clientCtx, key) + if err != nil { + return nil, err + } + + // check if packet commitment exists + if len(value) == 0 { + return nil, errorsmod.Wrapf(types.ErrAcknowledgementNotFound, "channelID (%s), sequence (%d)", channelID, sequence) + } + + return types.NewQueryPacketAcknowledgementResponse(value, proofBz, proofHeight), nil +} + +func queryPacketReceiptABCI(clientCtx client.Context, channelID string, sequence uint64) (*types.QueryPacketReceiptResponse, error) { + key := hostv2.PacketReceiptKey(channelID, sequence) + + value, proofBz, proofHeight, err := ibcclient.QueryTendermintProof(clientCtx, key) + if err != nil { + return nil, err + } + + return types.NewQueryPacketReceiptResponse(value != nil, proofBz, proofHeight), nil +} diff --git a/modules/core/04-channel/v2/client/cli/cli.go b/modules/core/04-channel/v2/client/cli/cli.go new file mode 100644 index 00000000000..c9a0d954287 --- /dev/null +++ b/modules/core/04-channel/v2/client/cli/cli.go @@ -0,0 +1,51 @@ +package cli + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// GetQueryCmd returns the query commands for the IBC channel/v2. +func GetQueryCmd() *cobra.Command { + queryCmd := &cobra.Command{ + Use: types.SubModuleName, + Short: "IBC channel/v2 query subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + queryCmd.AddCommand( + getCmdQueryChannel(), + getCmdQueryNextSequenceSend(), + getCmdQueryPacketCommitment(), + getCmdQueryPacketCommitments(), + getCmdQueryPacketAcknowledgement(), + getCmdQueryPacketReceipt(), + getCmdQueryUnreceivedPackets(), + getCmdQueryUnreceivedAcks(), + ) + + return queryCmd +} + +// NewTxCmd returns the command to submit transactions defined for IBC channel/v2. +func NewTxCmd() *cobra.Command { + txCmd := &cobra.Command{ + Use: types.SubModuleName, + Short: "IBC channel/v2 transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + txCmd.AddCommand( + newCreateChannelTxCmd(), + newRegisterCounterpartyTxCmd(), + ) + + return txCmd +} diff --git a/modules/core/04-channel/v2/client/cli/query.go b/modules/core/04-channel/v2/client/cli/query.go new file mode 100644 index 00000000000..2be1a004d3e --- /dev/null +++ b/modules/core/04-channel/v2/client/cli/query.go @@ -0,0 +1,381 @@ +package cli + +import ( + "fmt" + "strconv" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +const ( + flagSequences = "sequences" +) + +// getCmdQueryChannel defines the command to query the channel information (creator and channel) for the given channel ID. +func getCmdQueryChannel() *cobra.Command { + cmd := &cobra.Command{ + Use: "channel [channel-id]", + Short: "Query the information of a channel.", + Long: "Query the channel information for the provided channel ID.", + Example: fmt.Sprintf("%s query %s %s channel [channel-id]", version.AppName, exported.ModuleName, types.SubModuleName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + channelID := args[0] + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.Channel(cmd.Context(), types.NewQueryChannelRequest(channelID)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// getCmdQueryNextSequenceSend defines the command to query a next send sequence for a given channel +func getCmdQueryNextSequenceSend() *cobra.Command { + cmd := &cobra.Command{ + Use: "next-sequence-send [channel-id]", + Short: "Query a next send sequence", + Long: "Query the next sequence send for a given channel", + Example: fmt.Sprintf( + "%s query %s %s next-sequence-send [channel-id]", version.AppName, exported.ModuleName, types.SubModuleName, + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + channelID := args[0] + prove, err := cmd.Flags().GetBool(flags.FlagProve) + if err != nil { + return err + } + + if prove { + res, err := queryNextSequenceSendABCI(clientCtx, channelID) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.NextSequenceSend(cmd.Context(), types.NewQueryNextSequenceSendRequest(channelID)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func getCmdQueryPacketCommitment() *cobra.Command { + cmd := &cobra.Command{ + Use: "packet-commitment [channel-id] [sequence]", + Short: "Query a channel/v2 packet commitment", + Long: "Query a channel/v2 packet commitment by channel-id and sequence", + Example: fmt.Sprintf( + "%s query %s %s packet-commitment [channel-id] [sequence]", version.AppName, exported.ModuleName, types.SubModuleName, + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + channelID := args[0] + seq, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + prove, err := cmd.Flags().GetBool(flags.FlagProve) + if err != nil { + return err + } + + if prove { + res, err := queryPacketCommitmentABCI(clientCtx, channelID, seq) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.PacketCommitment(cmd.Context(), types.NewQueryPacketCommitmentRequest(channelID, seq)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func getCmdQueryPacketCommitments() *cobra.Command { + cmd := &cobra.Command{ + Use: "packet-commitments [channel-id]", + Short: "Query all packet commitments associated with a channel", + Long: "Query all packet commitments associated with a channel", + Example: fmt.Sprintf("%s query %s %s packet-commitments [channel-id]", version.AppName, exported.ModuleName, types.SubModuleName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + req := &types.QueryPacketCommitmentsRequest{ + ChannelId: args[0], + Pagination: pageReq, + } + + res, err := queryClient.PacketCommitments(cmd.Context(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "packet commitments associated with a channel") + + return cmd +} + +func getCmdQueryPacketAcknowledgement() *cobra.Command { + cmd := &cobra.Command{ + Use: "packet-acknowledgement [channel-id] [sequence]", + Short: "Query a channel/v2 packet acknowledgement", + Long: "Query a channel/v2 packet acknowledgement by channel-id and sequence", + Example: fmt.Sprintf( + "%s query %s %s packet-acknowledgement [channel-id] [sequence]", version.AppName, exported.ModuleName, types.SubModuleName, + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + channelID := args[0] + seq, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + prove, err := cmd.Flags().GetBool(flags.FlagProve) + if err != nil { + return err + } + + if prove { + res, err := queryPacketAcknowledgementABCI(clientCtx, channelID, seq) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.PacketAcknowledgement(cmd.Context(), types.NewQueryPacketAcknowledgementRequest(channelID, seq)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func getCmdQueryPacketReceipt() *cobra.Command { + cmd := &cobra.Command{ + Use: "packet-receipt [channel-id] [sequence]", + Short: "Query a channel/v2 packet receipt", + Long: "Query a channel/v2 packet receipt by channel-id and sequence", + Example: fmt.Sprintf( + "%s query %s %s packet-receipt [channel-id] [sequence]", version.AppName, exported.ModuleName, types.SubModuleName, + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + channelID := args[0] + seq, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + prove, err := cmd.Flags().GetBool(flags.FlagProve) + if err != nil { + return err + } + + if prove { + res, err := queryPacketReceiptABCI(clientCtx, channelID, seq) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.PacketReceipt(cmd.Context(), types.NewQueryPacketReceiptRequest(channelID, seq)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// getCmdQueryUnreceivedPackets defines the command to query all the unreceived +// packets on the receiving chain +func getCmdQueryUnreceivedPackets() *cobra.Command { + cmd := &cobra.Command{ + Use: "unreceived-packets [channel-id]", + Short: "Query a channel/v2 unreceived-packets", + Long: "Query a channel/v2 unreceived-packets by channel-id and sequences", + Example: fmt.Sprintf( + "%s query %s %s unreceived-packet [channel-id] --sequences=1,2,3", version.AppName, exported.ModuleName, types.SubModuleName, + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + channelID := args[0] + seqSlice, err := cmd.Flags().GetInt64Slice(flagSequences) + if err != nil { + return err + } + + seqs := make([]uint64, len(seqSlice)) + for i := range seqSlice { + seqs[i] = uint64(seqSlice[i]) + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.UnreceivedPackets(cmd.Context(), types.NewQueryUnreceivedPacketsRequest(channelID, seqs)) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + cmd.Flags().Int64Slice(flagSequences, []int64{}, "comma separated list of packet sequence numbers") + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// getCmdQueryUnreceivedAcks defines the command to query all the unreceived acks on the original sending chain +func getCmdQueryUnreceivedAcks() *cobra.Command { + cmd := &cobra.Command{ + Use: "unreceived-acks [channel-id]", + Short: "Query all the unreceived acks associated with a channel", + Long: `Given a list of acknowledgement sequences from counterparty, determine if an ack on the counterparty chain has been received on the executing chain. + +The return value represents: +- Unreceived packet acknowledgement: packet commitment exists on original sending (executing) chain and ack exists on receiving chain. +`, + Example: fmt.Sprintf("%s query %s %s unreceived-acks [channel-id] --sequences=1,2,3", version.AppName, exported.ModuleName, types.SubModuleName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + seqSlice, err := cmd.Flags().GetInt64Slice(flagSequences) + if err != nil { + return err + } + + seqs := make([]uint64, len(seqSlice)) + for i := range seqSlice { + seqs[i] = uint64(seqSlice[i]) + } + + req := &types.QueryUnreceivedAcksRequest{ + ChannelId: args[0], + PacketAckSequences: seqs, + } + + res, err := queryClient.UnreceivedAcks(cmd.Context(), req) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + cmd.Flags().Int64Slice(flagSequences, []int64{}, "comma separated list of packet sequence numbers") + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/modules/core/04-channel/v2/client/cli/tx.go b/modules/core/04-channel/v2/client/cli/tx.go new file mode 100644 index 00000000000..6849a1476a9 --- /dev/null +++ b/modules/core/04-channel/v2/client/cli/tx.go @@ -0,0 +1,93 @@ +package cli + +import ( + "encoding/hex" + "fmt" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +// newCreateChannelTxCmd defines the command to create an IBC channel/v2. +func newCreateChannelTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-channel [client-identifier] [merkle-path-prefix]", + Args: cobra.ExactArgs(2), + Short: "create an IBC channel/v2", + Long: `Creates an IBC channel/v2 using the client identifier representing the counterparty chain and the hex-encoded merkle path prefix under which the counterparty stores packet flow information.`, + Example: fmt.Sprintf("%s tx %s %s create-channel 07-tendermint-0 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + clientID := args[0] + merklePathPrefix, err := parseMerklePathPrefix(args[2]) + if err != nil { + return err + } + + msg := types.NewMsgCreateChannel(clientID, merklePathPrefix, clientCtx.GetFromAddress().String()) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +// newRegisterCounterpartyCmd defines the command to provide the counterparty channel identifier to an IBC channel. +func newRegisterCounterpartyTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "register-counterparty [channel-identifier] [counterparty-channel-identifier]", + Args: cobra.ExactArgs(2), + Short: "Register the counterparty channel identifier for an IBC channel", + Long: `Register the counterparty channel identifier for an IBC channel specified by its channel ID.`, + Example: fmt.Sprintf("%s tx %s %s register-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + channelID := args[0] + counterpartyChannelID := args[1] + + msg := types.MsgRegisterCounterparty{ + ChannelId: channelID, + CounterpartyChannelId: counterpartyChannelID, + Signer: clientCtx.GetFromAddress().String(), + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +// parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath. +func parseMerklePathPrefix(merklePathPrefixString string) (commitmenttypesv2.MerklePath, error) { + var keyPath [][]byte + hexPrefixes := strings.Split(merklePathPrefixString, ",") + for _, hexPrefix := range hexPrefixes { + prefix, err := hex.DecodeString(hexPrefix) + if err != nil { + return commitmenttypesv2.MerklePath{}, fmt.Errorf("invalid hex merkle path prefix: %w", err) + } + keyPath = append(keyPath, prefix) + } + + return commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil +} diff --git a/modules/core/04-channel/v2/keeper/events.go b/modules/core/04-channel/v2/keeper/events.go new file mode 100644 index 00000000000..75a9ff0efb8 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/events.go @@ -0,0 +1,145 @@ +package keeper + +import ( + "context" + "encoding/hex" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// emitSendPacketEvents emits events for the SendPacket handler. +func emitSendPacketEvents(ctx context.Context, packet types.Packet) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeSendPacket, + sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), + sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), + sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.TimeoutTimestamp)), + sdk.NewAttribute(types.AttributeKeyPayloadLength, fmt.Sprintf("%d", len(packet.Payloads))), + sdk.NewAttribute(types.AttributeKeyVersion, packet.Payloads[0].Version), + sdk.NewAttribute(types.AttributeKeyEncoding, packet.Payloads[0].Encoding), + sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(packet.Payloads[0].Value)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + + for i, payload := range packet.Payloads { + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeSendPayload, + sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), + sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), + sdk.NewAttribute(types.AttributeKeyPayloadSequence, fmt.Sprintf("%d", i)), + sdk.NewAttribute(types.AttributeKeyVersion, payload.Version), + sdk.NewAttribute(types.AttributeKeyEncoding, payload.Encoding), + sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(payload.Value)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + } +} + +// emitRecvPacketEvents emits events for the RecvPacket handler. +func emitRecvPacketEvents(ctx context.Context, packet types.Packet) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeRecvPacket, + sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), + sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), + sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.TimeoutTimestamp)), + sdk.NewAttribute(types.AttributeKeyPayloadLength, fmt.Sprintf("%d", len(packet.Payloads))), + sdk.NewAttribute(types.AttributeKeyVersion, packet.Payloads[0].Version), + sdk.NewAttribute(types.AttributeKeyEncoding, packet.Payloads[0].Encoding), + sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(packet.Payloads[0].Value)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + + for i, payload := range packet.Payloads { + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeRecvPayload, + sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), + sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), + sdk.NewAttribute(types.AttributeKeyPayloadSequence, fmt.Sprintf("%d", i)), + sdk.NewAttribute(types.AttributeKeyVersion, payload.Version), + sdk.NewAttribute(types.AttributeKeyEncoding, payload.Encoding), + sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(payload.Value)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + } +} + +// EmitWriteAcknowledgementEvents emits events for WriteAcknowledgement. +func EmitWriteAcknowledgementEvents(ctx context.Context, packet types.Packet, ack types.Acknowledgement) { + // TODO: https://github.com/cosmos/ibc-go/issues/7386 +} + +// EmitAcknowledgePacketEvents emits events for the AcknowledgePacket handler. +func EmitAcknowledgePacketEvents(ctx context.Context, packet types.Packet) { + // TODO: https://github.com/cosmos/ibc-go/issues/7386 +} + +// EmitTimeoutPacketEvents emits events for the TimeoutPacket handler. +func EmitTimeoutPacketEvents(ctx context.Context, packet types.Packet) { + // TODO: https://github.com/cosmos/ibc-go/issues/7386 +} + +// emitCreateChannelEvent emits a channel create event. +func (*Keeper) emitCreateChannelEvent(ctx context.Context, channelID, clientID string) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeCreateChannel, + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeKeyClientID, clientID), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} + +// emitRegisterCounterpartyEvent emits a register counterparty event. +func (*Keeper) emitRegisterCounterpartyEvent(ctx context.Context, channelID string, channel types.Channel) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeRegisterCounterparty, + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeKeyClientID, channel.ClientId), + sdk.NewAttribute(types.AttributeKeyCounterpartyChannelID, channel.CounterpartyChannelId), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} diff --git a/modules/core/04-channel/v2/keeper/export_test.go b/modules/core/04-channel/v2/keeper/export_test.go new file mode 100644 index 00000000000..6da7c89c873 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/export_test.go @@ -0,0 +1,75 @@ +package keeper + +/* + This file is to allow for unexported functions to be accessible to the testing package. +*/ + +import ( + "context" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +func (k *Keeper) SendPacketTest( + ctx context.Context, + sourceChannel string, + timeoutTimestamp uint64, + payloads []types.Payload, +) (uint64, string, error) { + return k.sendPacket( + ctx, + sourceChannel, + timeoutTimestamp, + payloads, + ) +} + +func (k *Keeper) RecvPacketTest( + ctx context.Context, + packet types.Packet, + proof []byte, + proofHeight exported.Height, +) error { + return k.recvPacket( + ctx, + packet, + proof, + proofHeight, + ) +} + +func (k *Keeper) AcknowledgePacketTest( + ctx context.Context, + packet types.Packet, + acknowledgement types.Acknowledgement, + proof []byte, + proofHeight exported.Height, +) error { + return k.acknowledgePacket( + ctx, + packet, + acknowledgement, + proof, + proofHeight, + ) +} + +func (k *Keeper) TimeoutPacketTest( + ctx context.Context, + packet types.Packet, + proof []byte, + proofHeight exported.Height, +) error { + return k.timeoutPacket( + ctx, + packet, + proof, + proofHeight, + ) +} + +// AliasV1Channel is a wrapper around aliasV1Channel to allow its usage in tests. +func (k *Keeper) AliasV1Channel(ctx context.Context, portID, channelID string) (types.Channel, bool) { + return k.aliasV1Channel(ctx, portID, channelID) +} diff --git a/modules/core/04-channel/v2/keeper/grpc_query.go b/modules/core/04-channel/v2/keeper/grpc_query.go new file mode 100644 index 00000000000..644fa315fb5 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/grpc_query.go @@ -0,0 +1,290 @@ +package keeper + +import ( + "context" + "strings" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/store/prefix" + + "github.com/cosmos/cosmos-sdk/runtime" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" +) + +var _ types.QueryServer = (*queryServer)(nil) + +// queryServer implements the channel/v2 types.QueryServer interface. +type queryServer struct { + *Keeper +} + +// NewQueryServer returns a new types.QueryServer implementation. +func NewQueryServer(k *Keeper) types.QueryServer { + return &queryServer{ + Keeper: k, + } +} + +// Channel implements the Query/Channel gRPC method +func (q *queryServer) Channel(ctx context.Context, req *types.QueryChannelRequest) (*types.QueryChannelResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + channel, found := q.GetChannel(ctx, req.ChannelId) + if !found { + return nil, status.Error(codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "channel-id: %s", req.ChannelId).Error()) + } + + return types.NewQueryChannelResponse(channel), nil +} + +// NextSequenceSend implements the Query/NextSequenceSend gRPC method +func (q *queryServer) NextSequenceSend(ctx context.Context, req *types.QueryNextSequenceSendRequest) (*types.QueryNextSequenceSendResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + sequence, found := q.GetNextSequenceSend(ctx, req.ChannelId) + if !found { + return nil, status.Error( + codes.NotFound, + errorsmod.Wrapf(types.ErrSequenceSendNotFound, "channel-id %s", req.ChannelId).Error(), + ) + } + return types.NewQueryNextSequenceSendResponse(sequence, nil, clienttypes.GetSelfHeight(ctx)), nil +} + +// PacketCommitment implements the Query/PacketCommitment gRPC method. +func (q *queryServer) PacketCommitment(ctx context.Context, req *types.QueryPacketCommitmentRequest) (*types.QueryPacketCommitmentResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + if req.Sequence == 0 { + return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0") + } + + if !q.HasChannel(ctx, req.ChannelId) { + return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrChannelNotFound, req.ChannelId).Error()) + } + + commitment := q.GetPacketCommitment(ctx, req.ChannelId, req.Sequence) + if len(commitment) == 0 { + return nil, status.Error(codes.NotFound, "packet commitment hash not found") + } + + return types.NewQueryPacketCommitmentResponse(commitment, nil, clienttypes.GetSelfHeight(ctx)), nil +} + +// PacketCommitments implements the Query/PacketCommitments gRPC method +func (q *queryServer) PacketCommitments(ctx context.Context, req *types.QueryPacketCommitmentsRequest) (*types.QueryPacketCommitmentsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + if !q.HasChannel(ctx, req.ChannelId) { + return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrChannelNotFound, req.ChannelId).Error()) + } + + var commitments []*types.PacketState + store := prefix.NewStore(runtime.KVStoreAdapter(q.storeService.OpenKVStore(ctx)), hostv2.PacketCommitmentPrefixKey(req.ChannelId)) + + pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { + keySplit := strings.Split(string(key), "/") + + sequence := sdk.BigEndianToUint64([]byte(keySplit[len(keySplit)-1])) + if sequence == 0 { + return types.ErrInvalidPacket + } + + commitment := types.NewPacketState(req.ChannelId, sequence, value) + commitments = append(commitments, &commitment) + return nil + }) + if err != nil { + return nil, err + } + + selfHeight := clienttypes.GetSelfHeight(ctx) + return &types.QueryPacketCommitmentsResponse{ + Commitments: commitments, + Pagination: pageRes, + Height: selfHeight, + }, nil +} + +// PacketAcknowledgement implements the Query/PacketAcknowledgement gRPC method. +func (q *queryServer) PacketAcknowledgement(ctx context.Context, req *types.QueryPacketAcknowledgementRequest) (*types.QueryPacketAcknowledgementResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + if req.Sequence == 0 { + return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0") + } + + if !q.HasChannel(ctx, req.ChannelId) { + return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrChannelNotFound, req.ChannelId).Error()) + } + + acknowledgement := q.GetPacketAcknowledgement(ctx, req.ChannelId, req.Sequence) + if len(acknowledgement) == 0 { + return nil, status.Error(codes.NotFound, "packet acknowledgement hash not found") + } + + return types.NewQueryPacketAcknowledgementResponse(acknowledgement, nil, clienttypes.GetSelfHeight(ctx)), nil +} + +// PacketReceipt implements the Query/PacketReceipt gRPC method. +func (q *queryServer) PacketReceipt(ctx context.Context, req *types.QueryPacketReceiptRequest) (*types.QueryPacketReceiptResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + if req.Sequence == 0 { + return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0") + } + + if !q.HasChannel(ctx, req.ChannelId) { + return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrChannelNotFound, req.ChannelId).Error()) + } + + hasReceipt := q.HasPacketReceipt(ctx, req.ChannelId, req.Sequence) + + return types.NewQueryPacketReceiptResponse(hasReceipt, nil, clienttypes.GetSelfHeight(ctx)), nil +} + +// UnreceivedPackets implements the Query/UnreceivedPackets gRPC method. Given +// a list of counterparty packet commitments, the querier checks if the packet +// has already been received by checking if a receipt exists on this +// chain for the packet sequence. All packets that haven't been received yet +// are returned in the response +// Usage: To use this method correctly, first query all packet commitments on +// the sending chain using the Query/PacketCommitments gRPC method. +// Then input the returned sequences into the QueryUnreceivedPacketsRequest +// and send the request to this Query/UnreceivedPackets on the **receiving** +// chain. This gRPC method will then return the list of packet sequences that +// are yet to be received on the receiving chain. +// +// NOTE: The querier makes the assumption that the provided list of packet +// commitments is correct and will not function properly if the list +// is not up to date. Ideally the query height should equal the latest height +// on the counterparty's client which represents this chain. +func (q *queryServer) UnreceivedPackets(ctx context.Context, req *types.QueryUnreceivedPacketsRequest) (*types.QueryUnreceivedPacketsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + if !q.HasChannel(ctx, req.ChannelId) { + return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrChannelNotFound, req.ChannelId).Error()) + } + + var unreceivedSequences []uint64 + for i, seq := range req.Sequences { + // filter for invalid sequences to ensure they are not included in the response value. + if seq == 0 { + return nil, status.Errorf(codes.InvalidArgument, "packet sequence %d cannot be 0", i) + } + + // if the packet receipt does not exist, then it is unreceived + if !q.HasPacketReceipt(ctx, req.ChannelId, seq) { + unreceivedSequences = append(unreceivedSequences, seq) + } + } + + selfHeight := clienttypes.GetSelfHeight(ctx) + return &types.QueryUnreceivedPacketsResponse{ + Sequences: unreceivedSequences, + Height: selfHeight, + }, nil +} + +// UnreceivedAcks implements the Query/UnreceivedAcks gRPC method. Given +// a list of counterparty packet acknowledgements, the querier checks if the packet +// has already been received by checking if the packet commitment still exists on this +// chain (original sender) for the packet sequence. +// All acknowledgmeents that haven't been received yet are returned in the response. +// Usage: To use this method correctly, first query all packet acknowledgements on +// the original receiving chain (ie the chain that wrote the acks) using the Query/PacketAcknowledgements gRPC method. +// Then input the returned sequences into the QueryUnreceivedAcksRequest +// and send the request to this Query/UnreceivedAcks on the **original sending** +// chain. This gRPC method will then return the list of packet sequences whose +// acknowledgements are already written on the receiving chain but haven't yet +// been received back to the sending chain. +// +// NOTE: The querier makes the assumption that the provided list of packet +// acknowledgements is correct and will not function properly if the list +// is not up to date. Ideally the query height should equal the latest height +// on the counterparty's client which represents this chain. +func (q *queryServer) UnreceivedAcks(ctx context.Context, req *types.QueryUnreceivedAcksRequest) (*types.QueryUnreceivedAcksResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := host.ChannelIdentifierValidator(req.ChannelId); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + if !q.HasChannel(ctx, req.ChannelId) { + return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrChannelNotFound, req.ChannelId).Error()) + } + + var unreceivedSequences []uint64 + + for _, seq := range req.PacketAckSequences { + if seq == 0 { + return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0") + } + + // if packet commitment still exists on the original sending chain, then packet ack has not been received + // since processing the ack will delete the packet commitment + if commitment := q.GetPacketCommitment(ctx, req.ChannelId, seq); len(commitment) != 0 { + unreceivedSequences = append(unreceivedSequences, seq) + } + + } + + selfHeight := clienttypes.GetSelfHeight(ctx) + return &types.QueryUnreceivedAcksResponse{ + Sequences: unreceivedSequences, + Height: selfHeight, + }, nil +} diff --git a/modules/core/04-channel/v2/keeper/grpc_query_test.go b/modules/core/04-channel/v2/keeper/grpc_query_test.go new file mode 100644 index 00000000000..b0e107328d3 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/grpc_query_test.go @@ -0,0 +1,860 @@ +package keeper_test + +import ( + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func (suite *KeeperTestSuite) TestQueryChannel() { + var ( + req *types.QueryChannelRequest + expChannel types.Channel + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "success", + func() { + ctx := suite.chainA.GetContext() + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(ctx, ibctesting.FirstChannelID, expChannel) + + req = &types.QueryChannelRequest{ + ChannelId: ibctesting.FirstChannelID, + } + }, + nil, + }, + { + "req is nil", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channelID", + func() { + req = &types.QueryChannelRequest{} + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "channel not found", + func() { + req = &types.QueryChannelRequest{ + ChannelId: ibctesting.FirstChannelID, + } + }, + status.Error(codes.NotFound, fmt.Sprintf("channel-id: %s: channel not found", ibctesting.FirstChannelID)), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + merklePathPrefix := commitmenttypes.NewMerklePath([]byte("prefix")) + expChannel = types.Channel{ClientId: ibctesting.SecondClientID, CounterpartyChannelId: ibctesting.SecondChannelID, MerklePathPrefix: merklePathPrefix} + + tc.malleate() + + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeperV2) + res, err := queryServer.Channel(suite.chainA.GetContext(), req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expChannel, res.Channel) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Nil(res) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryPacketCommitment() { + var ( + expCommitment []byte + path *ibctesting.Path + req *types.QueryPacketCommitmentRequest + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "success", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + expCommitment = []byte("commitmentHash") + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelID, 1, expCommitment) + + req = &types.QueryPacketCommitmentRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequence: 1, + } + }, + nil, + }, + { + "empty request", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channel ID", + func() { + req = &types.QueryPacketCommitmentRequest{ + ChannelId: "", + Sequence: 1, + } + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "invalid sequence", + func() { + req = &types.QueryPacketCommitmentRequest{ + ChannelId: ibctesting.FirstChannelID, + Sequence: 0, + } + }, + status.Error(codes.InvalidArgument, "packet sequence cannot be 0"), + }, + { + "channel not found", + func() { + req = &types.QueryPacketCommitmentRequest{ + ChannelId: "channel-141", + Sequence: 1, + } + }, + status.Error(codes.NotFound, fmt.Sprintf("%s: channel not found", "channel-141")), + }, + { + "commitment not found", + func() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + req = &types.QueryPacketCommitmentRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequence: 1, + } + }, + status.Error(codes.NotFound, "packet commitment hash not found"), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.malleate() + + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeperV2) + res, err := queryServer.PacketCommitment(suite.chainA.GetContext(), req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expCommitment, res.Commitment) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Nil(res) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryPacketCommitments() { + var ( + req *types.QueryPacketCommitmentsRequest + expCommitments = []*types.PacketState{} + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "success", + func() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + expCommitments = make([]*types.PacketState, 0, 10) // reset expected commitments + for i := uint64(1); i <= 10; i++ { + pktStateCommitment := types.NewPacketState(path.EndpointA.ChannelID, i, []byte(fmt.Sprintf("hash_%d", i))) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), pktStateCommitment.ChannelId, pktStateCommitment.Sequence, pktStateCommitment.Data) + expCommitments = append(expCommitments, &pktStateCommitment) + } + + req = &types.QueryPacketCommitmentsRequest{ + ChannelId: path.EndpointA.ChannelID, + Pagination: &query.PageRequest{ + Key: nil, + Limit: 11, + CountTotal: true, + }, + } + }, + nil, + }, + { + "success: with pagination", + func() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + expCommitments = make([]*types.PacketState, 0, 10) // reset expected commitments + for i := uint64(1); i <= 10; i++ { + pktStateCommitment := types.NewPacketState(path.EndpointA.ChannelID, i, []byte(fmt.Sprintf("hash_%d", i))) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), pktStateCommitment.ChannelId, pktStateCommitment.Sequence, pktStateCommitment.Data) + expCommitments = append(expCommitments, &pktStateCommitment) + } + + limit := uint64(5) + expCommitments = expCommitments[:limit] + + req = &types.QueryPacketCommitmentsRequest{ + ChannelId: path.EndpointA.ChannelID, + Pagination: &query.PageRequest{ + Key: nil, + Limit: limit, + CountTotal: true, + }, + } + }, + nil, + }, + { + "empty request", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channel ID", + func() { + req = &types.QueryPacketCommitmentsRequest{ + ChannelId: "", + } + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "channel not found", + func() { + req = &types.QueryPacketCommitmentsRequest{ + ChannelId: "channel-141", + } + }, + status.Error(codes.NotFound, fmt.Sprintf("%s: channel not found", "channel-141")), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.malleate() + ctx := suite.chainA.GetContext() + + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeperV2) + res, err := queryServer.PacketCommitments(ctx, req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expCommitments, res.Commitments) + } else { + suite.Require().Error(err) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryPacketAcknowledgement() { + var ( + expAcknowledgement []byte + path *ibctesting.Path + req *types.QueryPacketAcknowledgementRequest + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "success", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + expAcknowledgement = []byte("acknowledgementHash") + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketAcknowledgement(suite.chainA.GetContext(), path.EndpointA.ChannelID, 1, expAcknowledgement) + + req = &types.QueryPacketAcknowledgementRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequence: 1, + } + }, + nil, + }, + { + "empty request", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channel ID", + func() { + req = &types.QueryPacketAcknowledgementRequest{ + ChannelId: "", + Sequence: 1, + } + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "invalid sequence", + func() { + req = &types.QueryPacketAcknowledgementRequest{ + ChannelId: ibctesting.FirstChannelID, + Sequence: 0, + } + }, + status.Error(codes.InvalidArgument, "packet sequence cannot be 0"), + }, + { + "channel not found", + func() { + req = &types.QueryPacketAcknowledgementRequest{ + ChannelId: "channel-141", + Sequence: 1, + } + }, + status.Error(codes.NotFound, fmt.Sprintf("%s: channel not found", "channel-141")), + }, + { + "acknowledgement not found", + func() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + req = &types.QueryPacketAcknowledgementRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequence: 1, + } + }, + status.Error(codes.NotFound, "packet acknowledgement hash not found"), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.malleate() + + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeperV2) + res, err := queryServer.PacketAcknowledgement(suite.chainA.GetContext(), req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expAcknowledgement, res.Acknowledgement) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Nil(res) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryPacketReceipt() { + var ( + expReceipt bool + path *ibctesting.Path + req *types.QueryPacketReceiptRequest + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "success with receipt", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainA.GetContext(), path.EndpointA.ChannelID, 1) + + expReceipt = true + req = &types.QueryPacketReceiptRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequence: 1, + } + }, + nil, + }, + { + "success with no receipt", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + expReceipt = false + req = &types.QueryPacketReceiptRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequence: 1, + } + }, + nil, + }, + { + "empty request", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channel ID", + func() { + req = &types.QueryPacketReceiptRequest{ + ChannelId: "", + Sequence: 1, + } + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "invalid sequence", + func() { + req = &types.QueryPacketReceiptRequest{ + ChannelId: ibctesting.FirstChannelID, + Sequence: 0, + } + }, + status.Error(codes.InvalidArgument, "packet sequence cannot be 0"), + }, + { + "channel not found", + func() { + req = &types.QueryPacketReceiptRequest{ + ChannelId: "channel-141", + Sequence: 1, + } + }, + status.Error(codes.NotFound, fmt.Sprintf("%s: channel not found", "channel-141")), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.malleate() + + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeperV2) + res, err := queryServer.PacketReceipt(suite.chainA.GetContext(), req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expReceipt, res.Received) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Nil(res) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { + var ( + req *types.QueryNextSequenceSendRequest + expSeq uint64 + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "success", + func() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.Setup() + + expSeq = 42 + seq := uint64(42) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelID, seq) + req = types.NewQueryNextSequenceSendRequest(path.EndpointA.ChannelID) + }, + nil, + }, + { + "req is nil", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channel ID", + func() { + req = types.NewQueryNextSequenceSendRequest("") + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "sequence send not found", + func() { + req = types.NewQueryNextSequenceSendRequest(ibctesting.FirstChannelID) + }, + status.Error(codes.NotFound, fmt.Sprintf("channel-id %s: sequence send not found", ibctesting.FirstChannelID)), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.malleate() + ctx := suite.chainA.GetContext() + + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeperV2) + res, err := queryServer.NextSequenceSend(ctx, req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expSeq, res.NextSequenceSend) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Nil(res) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryUnreceivedPackets() { + var ( + expSeq []uint64 + path *ibctesting.Path + req *types.QueryUnreceivedPacketsRequest + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "empty request", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channel ID", + func() { + req = &types.QueryUnreceivedPacketsRequest{ + ChannelId: "", + } + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "invalid seq", + func() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + req = &types.QueryUnreceivedPacketsRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequences: []uint64{0}, + } + }, + status.Error(codes.InvalidArgument, "packet sequence 0 cannot be 0"), + }, + { + "channel not found", + func() { + req = &types.QueryUnreceivedPacketsRequest{ + ChannelId: "invalid-channel-id", + } + }, + status.Error(codes.NotFound, fmt.Sprintf("%s: channel not found", "invalid-channel-id")), + }, + { + "basic success empty packet commitments", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + expSeq = []uint64(nil) + req = &types.QueryUnreceivedPacketsRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequences: []uint64{}, + } + }, + nil, + }, + { + "basic success unreceived packet commitments", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + // no ack exists + + expSeq = []uint64{1} + req = &types.QueryUnreceivedPacketsRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequences: []uint64{1}, + } + }, + nil, + }, + { + "basic success unreceived packet commitments, nothing to relay", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainA.GetContext(), path.EndpointA.ChannelID, 1) + + expSeq = []uint64(nil) + req = &types.QueryUnreceivedPacketsRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequences: []uint64{1}, + } + }, + nil, + }, + { + "success multiple unreceived packet commitments", + func() { + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + expSeq = []uint64(nil) // reset + packetCommitments := []uint64{} + + // set packet receipt for every other sequence + for seq := uint64(1); seq < 10; seq++ { + packetCommitments = append(packetCommitments, seq) + + if seq%2 == 0 { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainA.GetContext(), path.EndpointA.ChannelID, seq) + } else { + expSeq = append(expSeq, seq) + } + } + + req = &types.QueryUnreceivedPacketsRequest{ + ChannelId: path.EndpointA.ChannelID, + Sequences: packetCommitments, + } + }, + nil, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + + tc.malleate() + ctx := suite.chainA.GetContext() + + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeperV2) + res, err := queryServer.UnreceivedPackets(ctx, req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expSeq, res.Sequences) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Error(err) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryUnreceivedAcks() { + var ( + path *ibctesting.Path + req *types.QueryUnreceivedAcksRequest + expSeq = []uint64{} + ) + + testCases := []struct { + msg string + malleate func() + expError error + }{ + { + "success", + func() { + expSeq = []uint64(nil) + req = &types.QueryUnreceivedAcksRequest{ + ChannelId: path.EndpointA.ChannelID, + PacketAckSequences: []uint64{1}, + } + }, + nil, + }, + { + "success: single unreceived packet ack", + func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelID, 1, []byte("commitment")) + + expSeq = []uint64{1} + req = &types.QueryUnreceivedAcksRequest{ + ChannelId: path.EndpointA.ChannelID, + PacketAckSequences: []uint64{1}, + } + }, + nil, + }, + { + "success: multiple unreceived packet acknowledgements", + func() { + expSeq = []uint64{} // reset + packetAcks := []uint64{} + + // set packet commitment for every other sequence + for seq := uint64(1); seq < 10; seq++ { + packetAcks = append(packetAcks, seq) + + if seq%2 == 0 { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelID, seq, []byte("commitement")) + expSeq = append(expSeq, seq) + } + } + + req = &types.QueryUnreceivedAcksRequest{ + ChannelId: path.EndpointA.ChannelID, + PacketAckSequences: packetAcks, + } + }, + nil, + }, + { + "empty request", + func() { + req = nil + }, + status.Error(codes.InvalidArgument, "empty request"), + }, + { + "invalid channel ID", + func() { + req = &types.QueryUnreceivedAcksRequest{ + ChannelId: "", + } + }, + status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"), + }, + { + "channel not found", + func() { + req = &types.QueryUnreceivedAcksRequest{ + ChannelId: "test-channel-id", + } + }, + status.Error(codes.NotFound, fmt.Sprintf("%s: channel not found", "test-channel-id")), + }, + { + "invalid seq", + func() { + req = &types.QueryUnreceivedAcksRequest{ + ChannelId: path.EndpointA.ChannelID, + PacketAckSequences: []uint64{0}, + } + }, + status.Error(codes.InvalidArgument, "packet sequence cannot be 0"), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { + suite.SetupTest() // reset + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + tc.malleate() + ctx := suite.chainA.GetContext() + + queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ChannelKeeperV2) + res, err := queryServer.UnreceivedAcks(ctx, req) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(expSeq, res.Sequences) + } else { + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Nil(res) + } + }) + } +} diff --git a/modules/core/04-channel/v2/keeper/keeper.go b/modules/core/04-channel/v2/keeper/keeper.go new file mode 100644 index 00000000000..2eb1a7120a1 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/keeper.go @@ -0,0 +1,267 @@ +package keeper + +import ( + "context" + "fmt" + + corestore "cosmossdk.io/core/store" + "cosmossdk.io/log" + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" + sdk "github.com/cosmos/cosmos-sdk/types" + + connectionkeeper "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" + channelkeeperv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" + channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" + "github.com/cosmos/ibc-go/v9/modules/core/api" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +// Keeper defines the channel keeper v2. +type Keeper struct { + cdc codec.BinaryCodec + storeService corestore.KVStoreService + ClientKeeper types.ClientKeeper + // channelKeeperV1 is used for channel aliasing only. + channelKeeperV1 *channelkeeperv1.Keeper + connectionKeeper *connectionkeeper.Keeper + + // Router is used to route messages to the appropriate module callbacks + // NOTE: it must be explicitly set before usage. + Router *api.Router +} + +// NewKeeper creates a new channel v2 keeper +func NewKeeper(cdc codec.BinaryCodec, storeService corestore.KVStoreService, clientKeeper types.ClientKeeper, channelKeeperV1 *channelkeeperv1.Keeper, connectionKeeper *connectionkeeper.Keeper) *Keeper { + return &Keeper{ + cdc: cdc, + storeService: storeService, + channelKeeperV1: channelKeeperV1, + connectionKeeper: connectionKeeper, + ClientKeeper: clientKeeper, + } +} + +// Logger returns a module-specific logger. +func (Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) +} + +func (k Keeper) ChannelStore(ctx context.Context, channelID string) storetypes.KVStore { + channelPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyChannelPrefix, channelID)) + return prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), channelPrefix) +} + +// SetChannel sets the Channel for a given channel identifier. +func (k *Keeper) SetChannel(ctx context.Context, channelID string, channel types.Channel) { + bz := k.cdc.MustMarshal(&channel) + k.ChannelStore(ctx, channelID).Set([]byte(types.ChannelKey), bz) +} + +// GetChannel gets the Channel for a given channel identifier. +func (k *Keeper) GetChannel(ctx context.Context, channelID string) (types.Channel, bool) { + store := k.ChannelStore(ctx, channelID) + bz := store.Get([]byte(types.ChannelKey)) + if len(bz) == 0 { + return types.Channel{}, false + } + + var channel types.Channel + k.cdc.MustUnmarshal(bz, &channel) + return channel, true +} + +// HasChannel returns true if a Channel exists for a given channel identifier, otherwise false. +func (k *Keeper) HasChannel(ctx context.Context, channelID string) bool { + store := k.ChannelStore(ctx, channelID) + return store.Has([]byte(types.ChannelKey)) +} + +// GetCreator returns the creator of the channel. +func (k *Keeper) GetCreator(ctx context.Context, channelID string) (string, bool) { + bz := k.ChannelStore(ctx, channelID).Get([]byte(types.CreatorKey)) + if len(bz) == 0 { + return "", false + } + + return string(bz), true +} + +// SetCreator sets the creator of the channel. +func (k *Keeper) SetCreator(ctx context.Context, channelID, creator string) { + k.ChannelStore(ctx, channelID).Set([]byte(types.CreatorKey), []byte(creator)) +} + +// DeleteCreator deletes the creator associated with the channel. +func (k *Keeper) DeleteCreator(ctx context.Context, channelID string) { + k.ChannelStore(ctx, channelID).Delete([]byte(types.CreatorKey)) +} + +// GetPacketReceipt returns the packet receipt from the packet receipt path based on the channelID and sequence. +func (k *Keeper) GetPacketReceipt(ctx context.Context, channelID string, sequence uint64) ([]byte, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(hostv2.PacketReceiptKey(channelID, sequence)) + if err != nil { + panic(err) + } + if len(bz) == 0 { + return nil, false + } + return bz, true +} + +// HasPacketRceipt returns true if the packet receipt exists, otherwise false. +func (k *Keeper) HasPacketReceipt(ctx context.Context, channelID string, sequence uint64) bool { + store := k.storeService.OpenKVStore(ctx) + has, err := store.Has(hostv2.PacketReceiptKey(channelID, sequence)) + if err != nil { + panic(err) + } + + return has +} + +// SetPacketReceipt writes the packet receipt under the receipt path +// This is a public path that is standardized by the IBC V2 specification. +func (k *Keeper) SetPacketReceipt(ctx context.Context, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(hostv2.PacketReceiptKey(channelID, sequence), []byte{byte(2)}); err != nil { + panic(err) + } +} + +// GetPacketAcknowledgement fetches the packet acknowledgement from the store. +func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64) []byte { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(hostv2.PacketAcknowledgementKey(channelID, sequence)) + if err != nil { + panic(err) + } + return bz +} + +// SetPacketAcknowledgement writes the acknowledgement hash under the acknowledgement path +// This is a public path that is standardized by the IBC V2 specification. +func (k *Keeper) SetPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64, ackHash []byte) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(hostv2.PacketAcknowledgementKey(channelID, sequence), ackHash); err != nil { + panic(err) + } +} + +// HasPacketAcknowledgement check if the packet ack hash is already on the store. +func (k *Keeper) HasPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64) bool { + return len(k.GetPacketAcknowledgement(ctx, channelID, sequence)) > 0 +} + +// GetPacketCommitment returns the packet commitment hash under the commitment path. +func (k *Keeper) GetPacketCommitment(ctx context.Context, channelID string, sequence uint64) []byte { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(hostv2.PacketCommitmentKey(channelID, sequence)) + if err != nil { + panic(err) + } + if len(bz) == 0 { + return nil + } + return bz +} + +// SetPacketCommitment writes the commitment hash under the commitment path. +func (k *Keeper) SetPacketCommitment(ctx context.Context, channelID string, sequence uint64, commitment []byte) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Set(hostv2.PacketCommitmentKey(channelID, sequence), commitment); err != nil { + panic(err) + } +} + +// DeletePacketCommitment deletes the packet commitment hash under the commitment path. +func (k *Keeper) DeletePacketCommitment(ctx context.Context, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Delete(hostv2.PacketCommitmentKey(channelID, sequence)); err != nil { + panic(err) + } +} + +// GetNextSequenceSend returns the next send sequence from the sequence path +func (k *Keeper) GetNextSequenceSend(ctx context.Context, channelID string) (uint64, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(hostv2.NextSequenceSendKey(channelID)) + if err != nil { + panic(err) + } + if len(bz) == 0 { + return 0, false + } + return sdk.BigEndianToUint64(bz), true +} + +// SetNextSequenceSend writes the next send sequence under the sequence path +func (k *Keeper) SetNextSequenceSend(ctx context.Context, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) + bigEndianBz := sdk.Uint64ToBigEndian(sequence) + if err := store.Set(hostv2.NextSequenceSendKey(channelID), bigEndianBz); err != nil { + panic(err) + } +} + +func (k *Keeper) SetPacket(ctx context.Context, channelID string, sequence uint64, packet types.Packet) { + store := k.storeService.OpenKVStore(ctx) + bz := k.cdc.MustMarshal(&packet) + if err := store.Set(types.PacketStoreKey(channelID, sequence), bz); err != nil { + panic(err) + } +} + +func (k *Keeper) DeletePacket(ctx context.Context, channelID string, sequence uint64) { + store := k.storeService.OpenKVStore(ctx) + if err := store.Delete(types.PacketStoreKey(channelID, sequence)); err != nil { + panic(err) + } +} + +// aliasV1Channel returns a version 2 channel for the given port and channel ID +// by converting the channel into a version 2 channel. +func (k *Keeper) aliasV1Channel(ctx context.Context, portID, channelID string) (types.Channel, bool) { + channel, ok := k.channelKeeperV1.GetChannel(ctx, portID, channelID) + if !ok { + return types.Channel{}, false + } + // Do not allow channel to be converted into a version 2 channel + // if the channel is not OPEN or if it is ORDERED + if channel.State != channeltypesv1.OPEN || channel.Ordering == channeltypesv1.ORDERED { + return types.Channel{}, false + } + connection, ok := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) + if !ok { + return types.Channel{}, false + } + merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte("")) + + channelv2 := types.Channel{ + CounterpartyChannelId: channel.Counterparty.ChannelId, + ClientId: connection.ClientId, + MerklePathPrefix: merklePathPrefix, + } + return channelv2, true +} + +// convertV1Channel attempts to retrieve a v1 channel from the channel keeper if it exists, then converts it +// to a v2 counterparty and stores it in the v2 channel keeper for future use +func (k *Keeper) convertV1Channel(ctx context.Context, port, id string) (types.Channel, bool) { + if channel, ok := k.aliasV1Channel(ctx, port, id); ok { + // we can key on just the channel here since channel ids are globally unique + k.SetChannel(ctx, id, channel) + return channel, true + } + + return types.Channel{}, false +} diff --git a/modules/core/04-channel/v2/keeper/keeper_test.go b/modules/core/04-channel/v2/keeper/keeper_test.go new file mode 100644 index 00000000000..3521e3c789f --- /dev/null +++ b/modules/core/04-channel/v2/keeper/keeper_test.go @@ -0,0 +1,153 @@ +package keeper_test + +import ( + "testing" + + testifysuite "github.com/stretchr/testify/suite" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channeltypes2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func TestKeeperTestSuite(t *testing.T) { + testifysuite.Run(t, new(KeeperTestSuite)) +} + +type KeeperTestSuite struct { + testifysuite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + chainC *ibctesting.TestChain +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3)) +} + +func (suite *KeeperTestSuite) TestAliasV1Channel() { + var path *ibctesting.Path + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", + func() {}, + true, + }, + { + "failure: channel not found", + func() { + path.EndpointA.ChannelID = "" + }, + false, + }, + { + "failure: channel not OPEN", + func() { + path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.TRYOPEN }) + }, + false, + }, + { + "failure: channel is ORDERED", + func() { + path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.Ordering = types.ORDERED }) + }, + false, + }, + { + "failure: connection not found", + func() { + path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.ConnectionHops = []string{ibctesting.InvalidID} }) + }, + false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + // create a previously existing path on chainA to change the identifiers + // between the path between chainA and chainB + path1 := ibctesting.NewPath(suite.chainA, suite.chainC) + path1.Setup() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.Setup() + + tc.malleate() + + channel, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeperV2.AliasV1Channel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + + if tc.expPass { + suite.Require().True(found) + + merklePath := commitmentv2types.NewMerklePath([]byte("ibc"), []byte("")) + expChannel := channeltypes2.NewChannel(path.EndpointA.ClientID, path.EndpointB.ChannelID, merklePath) + suite.Require().Equal(channel, expChannel) + } else { + suite.Require().False(found) + suite.Require().Equal(channel, channeltypes2.Channel{}) + } + }) + } +} + +func (suite *KeeperTestSuite) TestSetChannel() { + merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) + channel := channeltypes2.Channel{ + ClientId: ibctesting.FirstClientID, + MerklePathPrefix: merklePathPrefix, + } + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(suite.chainA.GetContext(), ibctesting.FirstChannelID, channel) + + retrievedChannel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), ibctesting.FirstChannelID) + suite.Require().True(found, "GetChannel does not return channel") + suite.Require().Equal(channel, retrievedChannel, "Channel retrieved not equal") + + // No channel stored under other channel identifier. + retrievedChannel, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), ibctesting.SecondChannelID) + suite.Require().False(found, "GetChannel unexpectedly returned a channel") + suite.Require().Equal(channeltypes2.Channel{}, retrievedChannel, "Channel retrieved not empty") +} + +func (suite *KeeperTestSuite) TestSetCreator() { + expectedCreator := "test-creator" + + // Set the creator for the client + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID, expectedCreator) + + // Retrieve the creator from the store + retrievedCreator, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID) + + // Verify that the retrieved creator matches the expected creator + suite.Require().True(found, "GetCreator did not return stored creator") + suite.Require().Equal(expectedCreator, retrievedCreator, "Creator is not retrieved correctly") + + // Verify that the creator is deleted from the store + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID) + retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID) + suite.Require().False(found, "GetCreator unexpectedly returned a creator") + suite.Require().Empty(retrievedCreator, "Creator is not empty") + + // Verify non stored creator is not found + retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.SecondChannelID) + suite.Require().False(found, "GetCreator unexpectedly returned a creator") + suite.Require().Empty(retrievedCreator, "Creator is not empty") +} diff --git a/modules/core/04-channel/v2/keeper/msg_server.go b/modules/core/04-channel/v2/keeper/msg_server.go new file mode 100644 index 00000000000..79a83a13756 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/msg_server.go @@ -0,0 +1,264 @@ +package keeper + +import ( + "context" + "time" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" + "github.com/cosmos/ibc-go/v9/modules/core/internal/v2/telemetry" +) + +var _ types.MsgServer = &Keeper{} + +// CreateChannel defines a rpc handler method for MsgCreateChannel. +func (k *Keeper) CreateChannel(goCtx context.Context, msg *types.MsgCreateChannel) (*types.MsgCreateChannelResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + channelID := k.channelKeeperV1.GenerateChannelIdentifier(ctx) + + // Initialize channel with empty counterparty channel identifier. + channel := types.NewChannel(msg.ClientId, "", msg.MerklePathPrefix) + k.SetChannel(ctx, channelID, channel) + k.SetCreator(ctx, channelID, msg.Signer) + k.SetNextSequenceSend(ctx, channelID, 1) + + k.emitCreateChannelEvent(goCtx, channelID, msg.ClientId) + + return &types.MsgCreateChannelResponse{ChannelId: channelID}, nil +} + +// RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. +func (k *Keeper) RegisterCounterparty(goCtx context.Context, msg *types.MsgRegisterCounterparty) (*types.MsgRegisterCounterpartyResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + channel, ok := k.GetChannel(ctx, msg.ChannelId) + if !ok { + return nil, errorsmod.Wrapf(types.ErrChannelNotFound, "channel must exist for channel id %s", msg.ChannelId) + } + + creator, found := k.GetCreator(ctx, msg.ChannelId) + if !found { + return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "channel creator must be set") + } + + if creator != msg.Signer { + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "channel creator (%s) must match signer (%s)", creator, msg.Signer) + } + + channel.CounterpartyChannelId = msg.CounterpartyChannelId + k.SetChannel(ctx, msg.ChannelId, channel) + // Delete client creator from state as it is not needed after this point. + k.DeleteCreator(ctx, msg.ChannelId) + + k.emitRegisterCounterpartyEvent(goCtx, msg.ChannelId, channel) + + return &types.MsgRegisterCounterpartyResponse{}, nil +} + +// SendPacket implements the PacketMsgServer SendPacket method. +func (k *Keeper) SendPacket(ctx context.Context, msg *types.MsgSendPacket) (*types.MsgSendPacketResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + sequence, destChannel, err := k.sendPacket(ctx, msg.SourceChannel, msg.TimeoutTimestamp, msg.Payloads) + if err != nil { + sdkCtx.Logger().Error("send packet failed", "source-channel", msg.SourceChannel, "error", errorsmod.Wrap(err, "send packet failed")) + return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s", msg.SourceChannel) + } + + // Note, the validate basic function in sendPacket does the timeoutTimestamp != 0 check and other stateless checks on the packet. + // timeoutTimestamp must be greater than current block time + timeout := time.Unix(int64(msg.TimeoutTimestamp), 0) + if timeout.Before(sdkCtx.BlockTime()) { + return nil, errorsmod.Wrap(types.ErrTimeoutElapsed, "timeout is less than the current block timestamp") + } + + // timeoutTimestamp must be less than current block time + MaxTimeoutDelta + if timeout.After(sdkCtx.BlockTime().Add(types.MaxTimeoutDelta)) { + return nil, errorsmod.Wrap(types.ErrInvalidTimeout, "timeout exceeds the maximum expected value") + } + + signer, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + sdkCtx.Logger().Error("send packet failed", "error", errorsmod.Wrap(err, "invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "invalid address for msg Signer") + } + + for _, pd := range msg.Payloads { + cbs := k.Router.Route(pd.SourcePort) + err := cbs.OnSendPacket(ctx, msg.SourceChannel, destChannel, sequence, pd, signer) + if err != nil { + return nil, err + } + } + + return &types.MsgSendPacketResponse{Sequence: sequence}, nil +} + +// RecvPacket implements the PacketMsgServer RecvPacket method. + +func (k *Keeper) RecvPacket(ctx context.Context, msg *types.MsgRecvPacket) (*types.MsgRecvPacketResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + signer, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + sdkCtx.Logger().Error("receive packet failed", "error", errorsmod.Wrap(err, "invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "invalid address for msg Signer") + } + + // Perform TAO verification + // + // If the packet was already received, perform a no-op + // Use a cached context to prevent accidental state changes + cacheCtx, writeFn := sdkCtx.CacheContext() + err = k.recvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight) + + switch err { + case nil: + writeFn() + case types.ErrNoOpMsg: + // no-ops do not need event emission as they will be ignored + sdkCtx.Logger().Debug("no-op on redundant relay", "source-channel", msg.Packet.SourceChannel) + return &types.MsgRecvPacketResponse{Result: types.NOOP}, nil + default: + sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "receive packet verification failed")) + return nil, errorsmod.Wrap(err, "receive packet verification failed") + } + + // build up the recv results for each application callback. + ack := types.Acknowledgement{ + AppAcknowledgements: [][]byte{}, + } + + var isAsync bool + for _, pd := range msg.Packet.Payloads { + // Cache context so that we may discard state changes from callback if the acknowledgement is unsuccessful. + cacheCtx, writeFn = sdkCtx.CacheContext() + cb := k.Router.Route(pd.DestinationPort) + res := cb.OnRecvPacket(cacheCtx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, msg.Packet.Sequence, pd, signer) + + if res.Status != types.PacketStatus_Failure { + // write application state changes for asynchronous and successful acknowledgements + writeFn() + } else { + // Modify events in cached context to reflect unsuccessful acknowledgement + sdkCtx.EventManager().EmitEvents(internalerrors.ConvertToErrorEvents(cacheCtx.EventManager().Events())) + } + + if res.Status == types.PacketStatus_Async { + // Set packet acknowledgement to async if any of the acknowledgements are async. + isAsync = true + // Return error if there is more than 1 payload + // TODO: Handle case where there are multiple payloads + if len(msg.Packet.Payloads) > 1 { + return nil, errorsmod.Wrapf(types.ErrInvalidPacket, "packet with multiple payloads cannot have async acknowledgement") + } + } + + // append app acknowledgement to the overall acknowledgement + ack.AppAcknowledgements = append(ack.AppAcknowledgements, res.Acknowledgement) + } + + // note this should never happen as the payload would have had to be empty. + if len(ack.AppAcknowledgements) == 0 { + sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results")) + return &types.MsgRecvPacketResponse{Result: types.FAILURE}, errorsmod.Wrapf(err, "receive packet failed source-channel %s invalid acknowledgement results", msg.Packet.SourceChannel) + } + + if isAsync { + k.SetPacket(ctx, msg.Packet.DestinationChannel, msg.Packet.Sequence, msg.Packet) + } else { + if len(ack.AppAcknowledgements) != len(msg.Packet.Payloads) { + return nil, errorsmod.Wrapf(types.ErrInvalidAcknowledgement, "length of acknowledgement results %d does not match length of payload %d", len(ack.AppAcknowledgements), len(msg.Packet.Payloads)) + } + // Set packet acknowledgement only if the acknowledgement is not async. + // NOTE: IBC applications modules may call the WriteAcknowledgement asynchronously if the + // acknowledgement is async. + if err := k.WriteAcknowledgement(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, msg.Packet.Sequence, ack); err != nil { + return nil, err + } + } + defer telemetry.ReportRecvPacket(msg.Packet) + + sdkCtx.Logger().Info("receive packet callback succeeded", "source-channel", msg.Packet.SourceChannel, "dest-channel", msg.Packet.DestinationChannel, "result", types.SUCCESS.String()) + return &types.MsgRecvPacketResponse{Result: types.SUCCESS}, nil +} + +// Acknowledgement defines an rpc handler method for MsgAcknowledgement. +func (k *Keeper) Acknowledgement(ctx context.Context, msg *types.MsgAcknowledgement) (*types.MsgAcknowledgementResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + relayer, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + sdkCtx.Logger().Error("acknowledgement failed", "error", errorsmod.Wrap(err, "Invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") + } + + cacheCtx, writeFn := sdkCtx.CacheContext() + err = k.acknowledgePacket(cacheCtx, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) + + switch err { + case nil: + writeFn() + case types.ErrNoOpMsg: + // no-ops do not need event emission as they will be ignored + sdkCtx.Logger().Debug("no-op on redundant relay", "source-channel", msg.Packet.SourceChannel) + return &types.MsgAcknowledgementResponse{Result: types.NOOP}, nil + default: + sdkCtx.Logger().Error("acknowledgement failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "acknowledge packet verification failed")) + return nil, errorsmod.Wrap(err, "acknowledge packet verification failed") + } + + for i, pd := range msg.Packet.Payloads { + cbs := k.Router.Route(pd.SourcePort) + ack := msg.Acknowledgement.AppAcknowledgements[i] + err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, msg.Packet.Sequence, ack, pd, relayer) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed OnAcknowledgementPacket for source port %s, source channel %s, destination channel %s", pd.SourcePort, msg.Packet.SourceChannel, msg.Packet.DestinationChannel) + } + } + + return &types.MsgAcknowledgementResponse{Result: types.SUCCESS}, nil +} + +// Timeout implements the PacketMsgServer Timeout method. +func (k *Keeper) Timeout(ctx context.Context, timeout *types.MsgTimeout) (*types.MsgTimeoutResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + signer, err := sdk.AccAddressFromBech32(timeout.Signer) + if err != nil { + sdkCtx.Logger().Error("timeout packet failed", "error", errorsmod.Wrap(err, "invalid address for msg Signer")) + return nil, errorsmod.Wrap(err, "invalid address for msg Signer") + } + + cacheCtx, writeFn := sdkCtx.CacheContext() + if err := k.timeoutPacket(cacheCtx, timeout.Packet, timeout.ProofUnreceived, timeout.ProofHeight); err != nil { + sdkCtx.Logger().Error("Timeout packet failed", "source-channel", timeout.Packet.SourceChannel, "destination-channel", timeout.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "timeout packet failed")) + return nil, errorsmod.Wrapf(err, "timeout packet failed for source id: %s and destination id: %s", timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel) + } + + switch err { + case nil: + writeFn() + case types.ErrNoOpMsg: + // no-ops do not need event emission as they will be ignored + sdkCtx.Logger().Debug("no-op on redundant relay", "source-channel", timeout.Packet.SourceChannel) + return &types.MsgTimeoutResponse{Result: types.NOOP}, nil + default: + sdkCtx.Logger().Error("timeout failed", "source-channel", timeout.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet verification failed")) + return nil, errorsmod.Wrap(err, "timeout packet verification failed") + } + + for _, pd := range timeout.Packet.Payloads { + cbs := k.Router.Route(pd.SourcePort) + err := cbs.OnTimeoutPacket(ctx, timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel, timeout.Packet.Sequence, pd, signer) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed OnTimeoutPacket for source port %s, source channel %s, destination channel %s", pd.SourcePort, timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel) + } + } + + return &types.MsgTimeoutResponse{Result: types.SUCCESS}, nil +} diff --git a/modules/core/04-channel/v2/keeper/msg_server_test.go b/modules/core/04-channel/v2/keeper/msg_server_test.go new file mode 100644 index 00000000000..072de3e77fb --- /dev/null +++ b/modules/core/04-channel/v2/keeper/msg_server_test.go @@ -0,0 +1,543 @@ +package keeper_test + +import ( + "context" + "errors" + "fmt" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + "github.com/cosmos/ibc-go/v9/testing/mock" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" +) + +func (suite *KeeperTestSuite) TestRegisterCounterparty() { + var ( + path *ibctesting.Path + msg *types.MsgRegisterCounterparty + ) + cases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() { + // set it before handler + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(suite.chainA.GetContext(), msg.ChannelId, types.NewChannel(path.EndpointA.ClientID, "", ibctesting.MerklePath)) + }, + nil, + }, + { + "failure: creator not set", + func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID) + }, + ibcerrors.ErrUnauthorized, + }, + { + "failure: signer does not match creator", + func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID, ibctesting.TestAccAddress) + }, + ibcerrors.ErrUnauthorized, + }, + { + "failure: channel must already exist", + func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(types.ChannelKey)) + }, + types.ErrChannelNotFound, + }, + } + + for _, tc := range cases { + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupClients() + + suite.Require().NoError(path.EndpointA.CreateChannel()) + suite.Require().NoError(path.EndpointB.CreateChannel()) + + signer := path.EndpointA.Chain.SenderAccount.GetAddress().String() + msg = types.NewMsgRegisterCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer) + + tc.malleate() + + res, err := path.EndpointA.Chain.SendMsgs(msg) + + expPass := tc.expError == nil + if expPass { + suite.Require().NotNil(res) + suite.Require().Nil(err) + + // Assert counterparty channel id filled in and creator deleted + channel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID) + suite.Require().True(found) + suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID) + + _, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID) + suite.Require().False(found) + + seq, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelID) + suite.Require().True(found) + suite.Require().Equal(seq, uint64(1)) + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q, got %q instead", tc.expError, err) + } + }) + } +} + +func (suite *KeeperTestSuite) TestMsgSendPacket() { + var ( + path *ibctesting.Path + expectedPacket types.Packet + timeoutTimestamp uint64 + payload types.Payload + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + expError: nil, + }, + { + name: "success: valid timeout timestamp", + malleate: func() { + // ensure a message timeout. + timeoutTimestamp = uint64(suite.chainA.GetContext().BlockTime().Add(types.MaxTimeoutDelta - 10*time.Second).Unix()) + expectedPacket = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, timeoutTimestamp, payload) + }, + expError: nil, + }, + { + name: "failure: timeout elapsed", + malleate: func() { + // ensure a message timeout. + timeoutTimestamp = uint64(1) + }, + expError: types.ErrTimeoutElapsed, + }, + { + name: "failure: timeout timestamp exceeds max allowed input", + malleate: func() { + // ensure message timeout exceeds max allowed input. + timeoutTimestamp = uint64(suite.chainA.GetContext().BlockTime().Add(types.MaxTimeoutDelta + 10*time.Second).Unix()) + }, + expError: types.ErrInvalidTimeout, + }, + { + name: "failure: timeout timestamp less than current block timestamp", + malleate: func() { + // ensure message timeout exceeds max allowed input. + timeoutTimestamp = uint64(suite.chainA.GetContext().BlockTime().Unix()) - 1 + }, + expError: types.ErrTimeoutElapsed, + }, + { + name: "failure: inactive client", + malleate: func() { + path.EndpointA.FreezeClient() + }, + expError: clienttypes.ErrClientNotActive, + }, + { + name: "failure: application callback error", + malleate: func() { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnSendPacket = func(ctx context.Context, sourceID string, destinationID string, sequence uint64, data types.Payload, signer sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + expError: mock.MockApplicationCallbackError, + }, + { + name: "failure: channel not found", + malleate: func() { + path.EndpointA.ChannelID = ibctesting.InvalidID + }, + expError: types.ErrChannelNotFound, + }, + { + name: "failure: route to non existing app", + malleate: func() { + payload.SourcePort = "foo" + }, + expError: fmt.Errorf("no route for foo"), + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + timeoutTimestamp = suite.chainA.GetTimeoutTimestampSecs() + payload = mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB) + + expectedPacket = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, timeoutTimestamp, payload) + + tc.malleate() + + packet, err := path.EndpointA.MsgSendPacket(timeoutTimestamp, payload) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + suite.Require().NotEmpty(packet) + + ck := path.EndpointA.Chain.GetSimApp().IBCKeeper.ChannelKeeperV2 + + packetCommitment := ck.GetPacketCommitment(path.EndpointA.Chain.GetContext(), path.EndpointA.ChannelID, 1) + suite.Require().NotNil(packetCommitment) + suite.Require().Equal(types.CommitPacket(expectedPacket), packetCommitment, "packet commitment is not stored correctly") + + nextSequenceSend, ok := ck.GetNextSequenceSend(path.EndpointA.Chain.GetContext(), path.EndpointA.ChannelID) + suite.Require().True(ok) + suite.Require().Equal(uint64(2), nextSequenceSend, "next sequence send was not incremented correctly") + + suite.Require().Equal(expectedPacket, packet) + + } else { + suite.Require().Error(err) + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError) + } + }) + } +} + +func (suite *KeeperTestSuite) TestMsgRecvPacket() { + var ( + path *ibctesting.Path + packet types.Packet + expRecvRes types.RecvPacketResult + ) + + testCases := []struct { + name string + malleate func() + expError error + expAckWritten bool + }{ + { + name: "success", + malleate: func() {}, + expError: nil, + expAckWritten: true, + }, + { + name: "success: failed recv result", + malleate: func() { + expRecvRes = types.RecvPacketResult{ + Status: types.PacketStatus_Failure, + Acknowledgement: mock.MockFailPacketData, + } + }, + expError: nil, + expAckWritten: true, + }, + { + name: "success: async recv result", + malleate: func() { + expRecvRes = types.RecvPacketResult{ + Status: types.PacketStatus_Async, + Acknowledgement: nil, + } + }, + expError: nil, + expAckWritten: false, + }, + { + name: "success: NoOp", + malleate: func() { + suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence) + }, + expError: nil, + expAckWritten: false, + }, + { + name: "failure: counterparty not found", + malleate: func() { + // change the destination id to a non-existent channel. + packet.DestinationChannel = ibctesting.InvalidID + }, + expError: types.ErrChannelNotFound, + }, + { + name: "failure: invalid proof", + malleate: func() { + // proof verification fails because the packet commitment is different due to a different sequence. + packet.Sequence = 10 + }, + expError: commitmenttypes.ErrInvalidProof, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + timeoutTimestamp := suite.chainA.GetTimeoutTimestampSecs() + + var err error + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)) + suite.Require().NoError(err) + + // default expected receive result is a single successful recv result for moduleB. + expRecvRes = mockv2.MockRecvPacketResult + + tc.malleate() + + // expectedAck is derived from the expected recv result. + expectedAck := types.Acknowledgement{AppAcknowledgements: [][]byte{expRecvRes.Acknowledgement}} + + // modify the callback to return the expected recv result. + path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, data types.Payload, relayer sdk.AccAddress) types.RecvPacketResult { + return expRecvRes + } + + err = path.EndpointB.MsgRecvPacket(packet) + + ck := path.EndpointB.Chain.GetSimApp().IBCKeeper.ChannelKeeperV2 + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + // packet receipt should be written + _, ok := ck.GetPacketReceipt(path.EndpointB.Chain.GetContext(), packet.DestinationChannel, packet.Sequence) + suite.Require().True(ok) + + ackWritten := ck.HasPacketAcknowledgement(path.EndpointB.Chain.GetContext(), packet.DestinationChannel, packet.Sequence) + + if !tc.expAckWritten { + // ack should not be written for async app or if the packet receipt was already present. + suite.Require().False(ackWritten) + } else { // successful or failed acknowledgement + // ack should be written for synchronous app (default mock application behaviour). + suite.Require().True(ackWritten) + expectedBz := types.CommitAcknowledgement(expectedAck) + + actualAckBz := ck.GetPacketAcknowledgement(path.EndpointB.Chain.GetContext(), packet.DestinationChannel, packet.Sequence) + suite.Require().Equal(expectedBz, actualAckBz) + } + + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError) + _, ok := ck.GetPacketReceipt(path.EndpointB.Chain.GetContext(), packet.SourceChannel, packet.Sequence) + suite.Require().False(ok) + } + }) + } +} + +func (suite *KeeperTestSuite) TestMsgAcknowledgement() { + var ( + path *ibctesting.Path + packet types.Packet + ack types.Acknowledgement + ) + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "success: NoOp", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeletePacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence) + + // Modify the callback to return an error. + // This way, we can verify that the callback is not executed in a No-op case. + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, uint64, types.Payload, []byte, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + }, + { + name: "failure: callback fails", + malleate: func() { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, uint64, types.Payload, []byte, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + expError: mock.MockApplicationCallbackError, + }, + { + name: "failure: counterparty not found", + malleate: func() { + // change the source id to a non-existent channel. + packet.SourceChannel = "not-existent-channel" + }, + expError: types.ErrChannelNotFound, + }, + { + name: "failure: invalid commitment", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence, []byte("foo")) + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: failed membership verification", + malleate: func() { + ack.AppAcknowledgements[0] = mock.MockFailPacketData + }, + expError: errors.New("failed packet acknowledgement verification"), + }, + } + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + timeoutTimestamp := suite.chainA.GetTimeoutTimestampSecs() + + var err error + // Send packet from A to B + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)) + suite.Require().NoError(err) + + err = path.EndpointB.MsgRecvPacket(packet) + suite.Require().NoError(err) + + // Construct expected acknowledgement + ack = types.Acknowledgement{AppAcknowledgements: [][]byte{mockv2.MockRecvPacketResult.Acknowledgement}} + + tc.malleate() + + // Finally, acknowledge the packet on A + err = path.EndpointA.MsgAcknowledgePacket(packet, ack) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q, got %q instead", tc.expError, err) + } + }) + } +} + +func (suite *KeeperTestSuite) TestMsgTimeout() { + var ( + path *ibctesting.Path + packet types.Packet + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: no-op", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeletePacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence) + + // Modify the callback to return a different error. + // This way, we can verify that the callback is not executed in a No-op case. + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, uint64, types.Payload, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + expError: types.ErrNoOpMsg, + }, + { + name: "failure: callback fails", + malleate: func() { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, uint64, types.Payload, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + expError: mock.MockApplicationCallbackError, + }, + { + name: "failure: channel not found", + malleate: func() { + // change the source id to a non-existent channel. + packet.SourceChannel = "not-existent-channel" + }, + expError: types.ErrChannelNotFound, + }, + { + name: "failure: invalid commitment", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence, []byte("foo")) + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: unable to timeout if packet has been received", + malleate: func() { + suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.SourceChannel, packet.Sequence) + suite.Require().NoError(path.EndpointB.UpdateClient()) + }, + expError: commitmenttypes.ErrInvalidProof, + }, + } + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + // Send packet from A to B + timeoutTimestamp := uint64(suite.chainA.GetContext().BlockTime().Unix()) + mockData := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB) + + var err error + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockData) + suite.Require().NoError(err) + suite.Require().NotEmpty(packet) + + tc.malleate() + + suite.Require().NoError(path.EndpointA.UpdateClient()) + + err = path.EndpointA.MsgTimeoutPacket(packet) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q, got %q instead", tc.expError, err) + } + }) + } +} diff --git a/modules/core/04-channel/v2/keeper/packet.go b/modules/core/04-channel/v2/keeper/packet.go new file mode 100644 index 00000000000..e3397fd5de7 --- /dev/null +++ b/modules/core/04-channel/v2/keeper/packet.go @@ -0,0 +1,347 @@ +package keeper + +import ( + "bytes" + "context" + "strconv" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +// sendPacket constructs a packet from the input arguments, writes a packet commitment to state +// in order for the packet to be sent to the counterparty. +func (k *Keeper) sendPacket( + ctx context.Context, + sourceChannel string, + timeoutTimestamp uint64, + payloads []types.Payload, +) (uint64, string, error) { + // Lookup channel associated with our source channel to retrieve the destination channel + channel, ok := k.GetChannel(ctx, sourceChannel) + if !ok { + // TODO: figure out how aliasing will work when more than one payload is sent. + channel, ok = k.convertV1Channel(ctx, payloads[0].SourcePort, sourceChannel) + if !ok { + return 0, "", errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel) + } + } + + destChannel := channel.CounterpartyChannelId + clientID := channel.ClientId + + sequence, found := k.GetNextSequenceSend(ctx, sourceChannel) + if !found { + return 0, "", errorsmod.Wrapf( + types.ErrSequenceSendNotFound, + "source channel: %s", sourceChannel, + ) + } + + // construct packet from given fields and channel state + packet := types.NewPacket(sequence, sourceChannel, destChannel, timeoutTimestamp, payloads...) + + if err := packet.ValidateBasic(); err != nil { + return 0, "", errorsmod.Wrapf(types.ErrInvalidPacket, "constructed packet failed basic validation: %v", err) + } + + // check that the client of counterparty chain is still active + if status := k.ClientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { + return 0, "", errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) + } + + // retrieve latest height and timestamp of the client of counterparty chain + latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, clientID) + if latestHeight.IsZero() { + return 0, "", errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "cannot send packet using client (%s) with zero height", clientID) + } + + latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, clientID, latestHeight) + if err != nil { + return 0, "", err + } + + // client timestamps are in nanoseconds while packet timeouts are in seconds + // thus to compare them, we convert the packet timeout to nanoseconds + timeoutTimestamp = types.TimeoutTimestampToNanos(packet.TimeoutTimestamp) + if latestTimestamp >= timeoutTimestamp { + return 0, "", errorsmod.Wrapf(types.ErrTimeoutElapsed, "latest timestamp: %d, timeout timestamp: %d", latestTimestamp, timeoutTimestamp) + } + + commitment := types.CommitPacket(packet) + + // bump the sequence and set the packet commitment, so it is provable by the counterparty + k.SetNextSequenceSend(ctx, sourceChannel, sequence+1) + k.SetPacketCommitment(ctx, sourceChannel, packet.GetSequence(), commitment) + + k.Logger(ctx).Info("packet sent", "sequence", strconv.FormatUint(packet.Sequence, 10), "dest_channel_id", packet.DestinationChannel, "src_channel_id", packet.SourceChannel) + + emitSendPacketEvents(ctx, packet) + + return sequence, destChannel, nil +} + +// recvPacket implements the packet receiving logic required by a packet handler. +// The packet is checked for correctness including asserting that the packet was +// sent and received on clients which are counterparties for one another. +// If the packet has already been received a no-op error is returned. +// The packet handler will verify that the packet has not timed out and that the +// counterparty stored a packet commitment. If successful, a packet receipt is stored +// to indicate to the counterparty successful delivery. +func (k *Keeper) recvPacket( + ctx context.Context, + packet types.Packet, + proof []byte, + proofHeight exported.Height, +) error { + channel, ok := k.GetChannel(ctx, packet.DestinationChannel) + if !ok { + // TODO: figure out how aliasing will work when more than one payload is sent. + channel, ok = k.convertV1Channel(ctx, packet.Payloads[0].DestinationPort, packet.DestinationChannel) + if !ok { + return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel) + } + } + + if channel.CounterpartyChannelId != packet.SourceChannel { + return errorsmod.Wrapf(types.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet source channel id (%s)", channel.CounterpartyChannelId, packet.SourceChannel) + } + + clientID := channel.ClientId + + // check if packet timed out by comparing it with the latest height of the chain + sdkCtx := sdk.UnwrapSDKContext(ctx) + currentTimestamp := uint64(sdkCtx.BlockTime().Unix()) + if currentTimestamp >= packet.TimeoutTimestamp { + return errorsmod.Wrapf(types.ErrTimeoutElapsed, "current timestamp: %d, timeout timestamp: %d", currentTimestamp, packet.TimeoutTimestamp) + } + + // REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received + // on unordered channels. Packet receipts must not be pruned, unless it has been marked stale + // by the increase of the recvStartSequence. + if k.HasPacketReceipt(ctx, packet.DestinationChannel, packet.Sequence) { + emitRecvPacketEvents(ctx, packet) + // This error indicates that the packet has already been relayed. Core IBC will + // treat this error as a no-op in order to prevent an entire relay transaction + // from failing and consuming unnecessary fees. + return types.ErrNoOpMsg + } + + path := hostv2.PacketCommitmentKey(packet.SourceChannel, packet.Sequence) + merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + + commitment := types.CommitPacket(packet) + + if err := k.ClientKeeper.VerifyMembership( + ctx, + clientID, + proofHeight, + 0, 0, + proof, + merklePath, + commitment, + ); err != nil { + return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) + } + + // Set Packet Receipt to prevent timeout from occurring on counterparty + k.SetPacketReceipt(ctx, packet.DestinationChannel, packet.Sequence) + + k.Logger(ctx).Info("packet received", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_id", packet.SourceChannel, "dst_id", packet.DestinationChannel) + + emitRecvPacketEvents(ctx, packet) + + return nil +} + +// WriteAcknowledgement writes the acknowledgement to the store. +// TODO: change this function to accept destPort, destChannel, sequence, ack +func (k Keeper) WriteAcknowledgement( + ctx context.Context, + sourceChannel string, + destinationChannel string, + sequence uint64, + ack types.Acknowledgement, +) error { + // Lookup channel associated with destination channel ID and ensure + // that the packet was indeed sent by our counterparty by verifying + // packet sender is our channel's counterparty channel id. + channel, ok := k.GetChannel(ctx, destinationChannel) + if !ok { + return errorsmod.Wrapf(types.ErrChannelNotFound, "channel (%s) not found", destinationChannel) + } + + if channel.CounterpartyChannelId != sourceChannel { + return errorsmod.Wrapf(types.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet source channel id (%s)", channel.CounterpartyChannelId, sourceChannel) + } + + // NOTE: IBC app modules might have written the acknowledgement synchronously on + // the OnRecvPacket callback so we need to check if the acknowledgement is already + // set on the store and return an error if so. + if k.HasPacketAcknowledgement(ctx, destinationChannel, sequence) { + return errorsmod.Wrapf(types.ErrAcknowledgementExists, "acknowledgement for channel %s, sequence %d already exists", destinationChannel, sequence) + } + + if _, found := k.GetPacketReceipt(ctx, destinationChannel, sequence); !found { + return errorsmod.Wrap(types.ErrInvalidPacket, "receipt not found for packet") + } + + // TODO: Validate Acknowledgment more thoroughly here after Issue #7472: https://github.com/cosmos/ibc-go/issues/7472 + + // set the acknowledgement so that it can be verified on the other side + k.SetPacketAcknowledgement( + ctx, destinationChannel, sequence, + types.CommitAcknowledgement(ack), + ) + + k.Logger(ctx).Info("acknowledgement written", "sequence", strconv.FormatUint(sequence, 10), "dest-channel", destinationChannel) + + // TODO: decide how relayers will reconstruct the packet as it is not being passed. + // EmitWriteAcknowledgementEvents(ctx, packet, ack) + + k.DeletePacket(ctx, destinationChannel, sequence) + // TODO: decide how relayers will reconstruct the packet as it is not being passed. + // EmitWriteAcknowledgementEvents(ctx, packet, ack) + + return nil +} + +func (k *Keeper) acknowledgePacket(ctx context.Context, packet types.Packet, acknowledgement types.Acknowledgement, proof []byte, proofHeight exported.Height) error { + // Lookup counterparty associated with our channel and ensure + // that the packet was indeed sent by our counterparty. + channel, ok := k.GetChannel(ctx, packet.SourceChannel) + if !ok { + return errorsmod.Wrap(types.ErrChannelNotFound, packet.SourceChannel) + } + + if channel.CounterpartyChannelId != packet.DestinationChannel { + return errorsmod.Wrapf(types.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) + } + + clientID := channel.ClientId + + commitment := k.GetPacketCommitment(ctx, packet.SourceChannel, packet.Sequence) + if len(commitment) == 0 { + // TODO: signal noop in events? + EmitAcknowledgePacketEvents(ctx, packet) + + // This error indicates that the acknowledgement has already been relayed + // or there is a misconfigured relayer attempting to prove an acknowledgement + // for a packet never sent. Core IBC will treat this error as a no-op in order to + // prevent an entire relay transaction from failing and consuming unnecessary fees. + return types.ErrNoOpMsg + } + + packetCommitment := types.CommitPacket(packet) + + // verify we sent the packet and haven't cleared it out yet + if !bytes.Equal(commitment, packetCommitment) { + return errorsmod.Wrapf(types.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) + } + + path := hostv2.PacketAcknowledgementKey(packet.DestinationChannel, packet.Sequence) + merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + + if err := k.ClientKeeper.VerifyMembership( + ctx, + clientID, + proofHeight, + 0, 0, + proof, + merklePath, + types.CommitAcknowledgement(acknowledgement), + ); err != nil { + return errorsmod.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID) + } + + k.DeletePacketCommitment(ctx, packet.SourceChannel, packet.Sequence) + + k.Logger(ctx).Info("packet acknowledged", "sequence", strconv.FormatUint(packet.GetSequence(), 10), "source_channel_id", packet.GetSourceChannel(), "destination_channel_id", packet.GetDestinationChannel()) + + EmitAcknowledgePacketEvents(ctx, packet) + + return nil +} + +// timeoutPacket implements the timeout logic required by a packet handler. +// The packet is checked for correctness including asserting that the packet was +// sent and received on clients which are counterparties for one another. +// If no packet commitment exists, a no-op error is returned, otherwise +// an absence proof of the packet receipt is performed to ensure that the packet +// was never delivered to the counterparty. If successful, the packet commitment +// is deleted and the packet has completed its lifecycle. +func (k *Keeper) timeoutPacket( + ctx context.Context, + packet types.Packet, + proof []byte, + proofHeight exported.Height, +) error { + channel, ok := k.GetChannel(ctx, packet.SourceChannel) + if !ok { + return errorsmod.Wrap(types.ErrChannelNotFound, packet.SourceChannel) + } + + if channel.CounterpartyChannelId != packet.DestinationChannel { + return errorsmod.Wrapf(types.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) + } + + clientID := channel.ClientId + + // check that timeout height or timeout timestamp has passed on the other end + proofTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, clientID, proofHeight) + if err != nil { + return err + } + + timeoutTimestamp := types.TimeoutTimestampToNanos(packet.TimeoutTimestamp) + if proofTimestamp < timeoutTimestamp { + return errorsmod.Wrapf(types.ErrTimeoutNotReached, "proof timestamp: %d, timeout timestamp: %d", proofTimestamp, timeoutTimestamp) + } + + // check that the commitment has not been cleared and that it matches the packet sent by relayer + commitment := k.GetPacketCommitment(ctx, packet.SourceChannel, packet.Sequence) + if len(commitment) == 0 { + EmitTimeoutPacketEvents(ctx, packet) + // This error indicates that the timeout has already been relayed + // or there is a misconfigured relayer attempting to prove a timeout + // for a packet never sent. Core IBC will treat this error as a no-op in order to + // prevent an entire relay transaction from failing and consuming unnecessary fees. + return types.ErrNoOpMsg + } + + packetCommitment := types.CommitPacket(packet) + // verify we sent the packet and haven't cleared it out yet + if !bytes.Equal(commitment, packetCommitment) { + return errorsmod.Wrapf(types.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) + } + + // verify packet receipt absence + path := hostv2.PacketReceiptKey(packet.SourceChannel, packet.Sequence) + merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + + if err := k.ClientKeeper.VerifyNonMembership( + ctx, + clientID, + proofHeight, + 0, 0, + proof, + merklePath, + ); err != nil { + return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) + } + + // delete packet commitment to prevent replay + k.DeletePacketCommitment(ctx, packet.SourceChannel, packet.Sequence) + + k.Logger(ctx).Info("packet timed out", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_channel_id", packet.SourceChannel, "dst_channel_id", packet.DestinationChannel) + + EmitTimeoutPacketEvents(ctx, packet) + + return nil +} diff --git a/modules/core/04-channel/v2/keeper/packet_test.go b/modules/core/04-channel/v2/keeper/packet_test.go new file mode 100644 index 00000000000..2aa8f2aaf6e --- /dev/null +++ b/modules/core/04-channel/v2/keeper/packet_test.go @@ -0,0 +1,597 @@ +package keeper_test + +import ( + "fmt" + "time" + + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" + ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" +) + +var unusedChannel = "channel-5" + +func (suite *KeeperTestSuite) TestSendPacket() { + var ( + path *ibctesting.Path + packet types.Packet + expSequence uint64 + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "success with later packet", + func() { + // send the same packet earlier so next packet send should be sequence 2 + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err) + expSequence = 2 + }, + nil, + }, + { + "channel not found", + func() { + packet.SourceChannel = ibctesting.InvalidID + }, + types.ErrChannelNotFound, + }, + { + "packet failed basic validation", + func() { + // invalid data + packet.Payloads = nil + }, + types.ErrInvalidPacket, + }, + { + "client status invalid", + func() { + path.EndpointA.FreezeClient() + }, + clienttypes.ErrClientNotActive, + }, + { + "client state zero height", func() { + clientState := path.EndpointA.GetClientState() + cs, ok := clientState.(*ibctm.ClientState) + suite.Require().True(ok) + + // force a consensus state into the store at height zero to allow client status check to pass. + consensusState := path.EndpointA.GetConsensusState(cs.LatestHeight) + path.EndpointA.SetConsensusState(consensusState, clienttypes.ZeroHeight()) + + cs.LatestHeight = clienttypes.ZeroHeight() + suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID, cs) + }, + clienttypes.ErrInvalidHeight, + }, + { + "timeout elapsed", func() { + packet.TimeoutTimestamp = 1 + }, + types.ErrTimeoutElapsed, + }, + } + + for i, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tc.name, i, len(testCases)), func() { + suite.SetupTest() // reset + + // create clients and set counterparties on both chains + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB) + + timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix()) + + // create standard packet that can be malleated + packet = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, + timeoutTimestamp, payload) + expSequence = 1 + + // malleate the test case + tc.malleate() + + // send packet + seq, destChannel, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, packet.TimeoutTimestamp, packet.Payloads) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + // verify send packet method instantiated packet with correct sequence and destination channel + suite.Require().Equal(expSequence, seq) + suite.Require().Equal(path.EndpointB.ChannelID, destChannel) + // verify send packet stored the packet commitment correctly + expCommitment := types.CommitPacket(packet) + suite.Require().Equal(expCommitment, suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, seq)) + } else { + suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expError) + suite.Require().Equal(uint64(0), seq) + suite.Require().Nil(suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, seq)) + + } + }) + } +} + +func (suite *KeeperTestSuite) TestRecvPacket() { + var ( + path *ibctesting.Path + err error + packet types.Packet + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: channel not found", + func() { + packet.DestinationChannel = ibctesting.InvalidID + }, + types.ErrChannelNotFound, + }, + { + "failure: client is not active", + func() { + path.EndpointB.FreezeClient() + }, + clienttypes.ErrClientNotActive, + }, + { + "failure: counterparty channel identifier different than source channel", + func() { + packet.SourceChannel = unusedChannel + }, + types.ErrInvalidChannelIdentifier, + }, + { + "failure: packet has timed out", + func() { + suite.coordinator.IncrementTimeBy(time.Hour * 20) + }, + types.ErrTimeoutElapsed, + }, + { + "failure: packet already received", + func() { + suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence) + }, + types.ErrNoOpMsg, + }, + { + "failure: verify membership failed", + func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence, []byte("")) + suite.coordinator.CommitBlock(path.EndpointA.Chain) + suite.Require().NoError(path.EndpointB.UpdateClient()) + }, + commitmenttypes.ErrInvalidProof, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB) + + timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix()) + + // send packet + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, payload) + suite.Require().NoError(err) + + tc.malleate() + + // get proof of v2 packet commitment from chainA + packetKey := hostv2.PacketCommitmentKey(packet.GetSourceChannel(), packet.GetSequence()) + proof, proofHeight := path.EndpointA.QueryProof(packetKey) + + err = suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.RecvPacketTest(suite.chainB.GetContext(), packet, proof, proofHeight) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + _, found := suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.GetPacketReceipt(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence) + suite.Require().True(found) + } else { + suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} + +func (suite *KeeperTestSuite) TestWriteAcknowledgement() { + var ( + packet types.Packet + ack types.Acknowledgement + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: channel not found", + func() { + packet.DestinationChannel = ibctesting.InvalidID + }, + types.ErrChannelNotFound, + }, + { + "failure: counterparty channel identifier different than source channel", + func() { + packet.SourceChannel = unusedChannel + }, + types.ErrInvalidChannelIdentifier, + }, + { + "failure: ack already exists", + func() { + ackBz := types.CommitAcknowledgement(ack) + suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence, ackBz) + }, + types.ErrAcknowledgementExists, + }, + // TODO: Move somewhere else as the check has been moved. + // { + // "failure: empty ack", + // func() { + // ack = types.Acknowledgement{ + // AppAcknowledgements: [][]byte{}, + // } + // }, + // types.ErrInvalidAcknowledgement, + // }, + { + "failure: receipt not found for packet", + func() { + packet.Sequence = 2 + }, + types.ErrInvalidPacket, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB) + + timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix()) + + // create standard packet that can be malleated + packet = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, + timeoutTimestamp, payload) + + // create standard ack that can be malleated + ack = types.Acknowledgement{ + AppAcknowledgements: [][]byte{mockv2.MockRecvPacketResult.Acknowledgement}, + } + + suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence) + + tc.malleate() + + err := suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.WriteAcknowledgement(suite.chainB.GetContext(), packet.SourceChannel, packet.DestinationChannel, packet.Sequence, ack) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + ackCommitment := suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence) + suite.Require().Equal(types.CommitAcknowledgement(ack), ackCommitment) + } else { + suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} + +func (suite *KeeperTestSuite) TestAcknowledgePacket() { + var ( + packet types.Packet + err error + ack = types.Acknowledgement{ + AppAcknowledgements: [][]byte{mockv2.MockRecvPacketResult.Acknowledgement}, + } + freezeClient bool + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: channel not found", + func() { + packet.SourceChannel = ibctesting.InvalidID + }, + types.ErrChannelNotFound, + }, + { + "failure: counterparty channel identifier different than source channel", + func() { + packet.DestinationChannel = unusedChannel + }, + types.ErrInvalidChannelIdentifier, + }, + { + "failure: packet commitment doesn't exist.", + func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeletePacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence) + }, + types.ErrNoOpMsg, + }, + { + "failure: client status invalid", + func() { + freezeClient = true + }, + clienttypes.ErrClientNotActive, + }, + { + "failure: packet commitment bytes differ", + func() { + // change payload after send to acknowledge different packet + packet.Payloads[0].Value = []byte("different value") + }, + types.ErrInvalidPacket, + }, + { + "failure: verify membership fails", + func() { + ack.AppAcknowledgements[0] = mockv2.MockFailRecvPacketResult.Acknowledgement + }, + commitmenttypes.ErrInvalidProof, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path := ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + freezeClient = false + + payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB) + + timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix()) + + // send packet + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, payload) + suite.Require().NoError(err) + + err = path.EndpointB.MsgRecvPacket(packet) + suite.Require().NoError(err) + + tc.malleate() + + packetKey := hostv2.PacketAcknowledgementKey(packet.DestinationChannel, packet.Sequence) + proof, proofHeight := path.EndpointB.QueryProof(packetKey) + + if freezeClient { + path.EndpointA.FreezeClient() + } + + err = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.AcknowledgePacketTest(suite.chainA.GetContext(), packet, ack, proof, proofHeight) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + commitment := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence) + suite.Require().Empty(commitment) + } else { + suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} + +func (suite *KeeperTestSuite) TestTimeoutPacket() { + var ( + path *ibctesting.Path + packet types.Packet + freezeClient bool + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() { + // send packet + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, + packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err, "send packet failed") + }, + nil, + }, + { + "failure: channel not found", + func() { + // send packet + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, + packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err, "send packet failed") + + packet.SourceChannel = ibctesting.InvalidID + }, + types.ErrChannelNotFound, + }, + { + "failure: counterparty channel identifier different than source channel", + func() { + // send packet + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, + packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err, "send packet failed") + + packet.DestinationChannel = unusedChannel + }, + types.ErrInvalidChannelIdentifier, + }, + { + "failure: packet has not timed out yet", + func() { + packet.TimeoutTimestamp = uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix()) + + // send packet + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, + packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err, "send packet failed") + }, + types.ErrTimeoutNotReached, + }, + { + "failure: packet already timed out", + func() {}, // equivalent to not sending packet at all + types.ErrNoOpMsg, + }, + { + "failure: packet does not match commitment", + func() { + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, + packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err, "send packet failed") + + // try to timeout packet with different data + packet.Payloads[0].Value = []byte("different value") + }, + types.ErrInvalidPacket, + }, + { + "failure: client status invalid", + func() { + // send packet + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, + packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err, "send packet failed") + + freezeClient = true + }, + clienttypes.ErrClientNotActive, + }, + { + "failure: verify non-membership failed", + func() { + // send packet + _, _, err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SendPacketTest(suite.chainA.GetContext(), packet.SourceChannel, + packet.TimeoutTimestamp, packet.Payloads) + suite.Require().NoError(err, "send packet failed") + + // set packet receipt to mock a valid past receive + suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.DestinationChannel, packet.Sequence) + }, + commitmenttypes.ErrInvalidProof, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + // initialize freezeClient to false + freezeClient = false + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + // create default packet with a timed out timestamp + payload := mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB) + + timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Unix()) + + // test cases may mutate timeout values + packet = types.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, + timeoutTimestamp, payload) + + tc.malleate() + + // need to update chainA's client representing chainB to prove missing ack + // commit the changes and update the clients + suite.coordinator.CommitBlock(path.EndpointA.Chain) + suite.Require().NoError(path.EndpointB.UpdateClient()) + suite.Require().NoError(path.EndpointA.UpdateClient()) + + // get proof of packet receipt absence from chainB + receiptKey := hostv2.PacketReceiptKey(packet.DestinationChannel, packet.Sequence) + proof, proofHeight := path.EndpointB.QueryProof(receiptKey) + + if freezeClient { + path.EndpointA.FreezeClient() + } + + err := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.TimeoutPacketTest(suite.chainA.GetContext(), packet, proof, proofHeight) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + commitment := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetPacketCommitment(suite.chainA.GetContext(), packet.DestinationChannel, packet.Sequence) + suite.Require().Nil(commitment, "packet commitment not deleted") + } else { + suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expError) + } + }) + } +} diff --git a/modules/core/04-channel/v2/module.go b/modules/core/04-channel/v2/module.go new file mode 100644 index 00000000000..9f6fbf8f7d6 --- /dev/null +++ b/modules/core/04-channel/v2/module.go @@ -0,0 +1,23 @@ +package client + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/client/cli" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// Name returns the IBC channel/v2 name +func Name() string { + return types.SubModuleName +} + +// GetQueryCmd returns the root query command for IBC channels v2. +func GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// GetTxCmd returns the root tx command for IBC channels v2. +func GetTxCmd() *cobra.Command { + return cli.NewTxCmd() +} diff --git a/modules/core/04-channel/v2/types/channel.go b/modules/core/04-channel/v2/types/channel.go new file mode 100644 index 00000000000..f4ab5b2afe4 --- /dev/null +++ b/modules/core/04-channel/v2/types/channel.go @@ -0,0 +1,51 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" +) + +// NewChannel creates a new Channel instance +func NewChannel(clientID, counterpartyChannelID string, merklePathPrefix commitmenttypes.MerklePath) Channel { + return Channel{ + ClientId: clientID, + CounterpartyChannelId: counterpartyChannelID, + MerklePathPrefix: merklePathPrefix, + } +} + +// Validate validates the Channel +func (c Channel) Validate() error { + if err := host.ClientIdentifierValidator(c.ClientId); err != nil { + return err + } + + if err := host.ChannelIdentifierValidator(c.CounterpartyChannelId); err != nil { + return err + } + + if err := c.MerklePathPrefix.ValidateAsPrefix(); err != nil { + return errorsmod.Wrap(ErrInvalidChannel, err.Error()) + } + + return nil +} + +// NewIdentifiedChannel creates a new IdentifiedChannel instance +func NewIdentifiedChannel(channelID string, channel Channel) IdentifiedChannel { + return IdentifiedChannel{ + Channel: channel, + ChannelId: channelID, + } +} + +// ValidateBasic performs a basic validation of the identifiers and channel fields. +func (ic IdentifiedChannel) ValidateBasic() error { + if err := host.ChannelIdentifierValidator(ic.ChannelId); err != nil { + return errorsmod.Wrap(err, "invalid channel ID") + } + + return ic.Channel.Validate() +} diff --git a/modules/core/04-channel/v2/types/channel.pb.go b/modules/core/04-channel/v2/types/channel.pb.go new file mode 100644 index 00000000000..8d3dafb35ae --- /dev/null +++ b/modules/core/04-channel/v2/types/channel.pb.go @@ -0,0 +1,658 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/channel/v2/channel.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + 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 + +// Channel defines the channel end on a chain that is implementing the version 2 IBC protocol +// Each side will maintain its own Channel to create an IBC channel +// The channel will be referenced by a channelID which will be used to send packets +// to the counterparty +// The channel will contain the client identifier that will provide proof verification for the channel +// and the counterparty channel identifier that the other channel end will be using +// to send packets to our channel end. +type Channel struct { + // the client identifier of the light client representing the counterparty chain + ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + // the counterparty identifier that must be used by packets sent by counterparty + // to our channel end. + CounterpartyChannelId string `protobuf:"bytes,2,opt,name=counterparty_channel_id,json=counterpartyChannelId,proto3" json:"counterparty_channel_id,omitempty"` + // the key path used to store packet flow messages that the counterparty + // will use to send to us. In backwards compatible cases, we will append the channelID and sequence in order to create + // the final path. + MerklePathPrefix v2.MerklePath `protobuf:"bytes,3,opt,name=merkle_path_prefix,json=merklePathPrefix,proto3" json:"merkle_path_prefix"` +} + +func (m *Channel) Reset() { *m = Channel{} } +func (m *Channel) String() string { return proto.CompactTextString(m) } +func (*Channel) ProtoMessage() {} +func (*Channel) Descriptor() ([]byte, []int) { + return fileDescriptor_7e9b57d8f218397d, []int{0} +} +func (m *Channel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Channel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Channel.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 *Channel) XXX_Merge(src proto.Message) { + xxx_messageInfo_Channel.Merge(m, src) +} +func (m *Channel) XXX_Size() int { + return m.Size() +} +func (m *Channel) XXX_DiscardUnknown() { + xxx_messageInfo_Channel.DiscardUnknown(m) +} + +var xxx_messageInfo_Channel proto.InternalMessageInfo + +func (m *Channel) GetClientId() string { + if m != nil { + return m.ClientId + } + return "" +} + +func (m *Channel) GetCounterpartyChannelId() string { + if m != nil { + return m.CounterpartyChannelId + } + return "" +} + +func (m *Channel) GetMerklePathPrefix() v2.MerklePath { + if m != nil { + return m.MerklePathPrefix + } + return v2.MerklePath{} +} + +// IdentifiedChannel defines a channel with an additional channel identifier field. +type IdentifiedChannel struct { + // channel identified. + Channel Channel `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel"` + // channel identifier + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *IdentifiedChannel) Reset() { *m = IdentifiedChannel{} } +func (m *IdentifiedChannel) String() string { return proto.CompactTextString(m) } +func (*IdentifiedChannel) ProtoMessage() {} +func (*IdentifiedChannel) Descriptor() ([]byte, []int) { + return fileDescriptor_7e9b57d8f218397d, []int{1} +} +func (m *IdentifiedChannel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IdentifiedChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IdentifiedChannel.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 *IdentifiedChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_IdentifiedChannel.Merge(m, src) +} +func (m *IdentifiedChannel) XXX_Size() int { + return m.Size() +} +func (m *IdentifiedChannel) XXX_DiscardUnknown() { + xxx_messageInfo_IdentifiedChannel.DiscardUnknown(m) +} + +var xxx_messageInfo_IdentifiedChannel proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Channel)(nil), "ibc.core.channel.v2.Channel") + proto.RegisterType((*IdentifiedChannel)(nil), "ibc.core.channel.v2.IdentifiedChannel") +} + +func init() { proto.RegisterFile("ibc/core/channel/v2/channel.proto", fileDescriptor_7e9b57d8f218397d) } + +var fileDescriptor_7e9b57d8f218397d = []byte{ + // 356 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4e, 0xea, 0x40, + 0x14, 0x86, 0x3b, 0xf7, 0x92, 0xcb, 0x65, 0xd8, 0x68, 0xd5, 0x48, 0x50, 0x0b, 0xb2, 0x91, 0x0d, + 0x33, 0xa6, 0x1a, 0x13, 0x0d, 0x2b, 0x5c, 0xb1, 0x30, 0x21, 0x2c, 0x58, 0xb8, 0x69, 0xda, 0xe9, + 0xd0, 0x4e, 0xec, 0x74, 0x9a, 0x76, 0x68, 0xe4, 0x0d, 0x5c, 0xfa, 0x08, 0x3e, 0x85, 0xcf, 0xc0, + 0x92, 0xa5, 0x2b, 0x63, 0xe0, 0x45, 0x4c, 0xa7, 0x2d, 0x90, 0xe8, 0xee, 0xcc, 0x39, 0xff, 0xf9, + 0xf2, 0xff, 0x73, 0xe0, 0x39, 0x73, 0x08, 0x26, 0x22, 0xa6, 0x98, 0xf8, 0x76, 0x18, 0xd2, 0x00, + 0xa7, 0x66, 0x59, 0xa2, 0x28, 0x16, 0x52, 0xe8, 0x07, 0xcc, 0x21, 0x28, 0x93, 0xa0, 0xb2, 0x9f, + 0x9a, 0xcd, 0x43, 0x4f, 0x78, 0x42, 0xcd, 0x71, 0x56, 0xe5, 0xd2, 0xe6, 0xc5, 0x96, 0x26, 0x38, + 0x67, 0x92, 0xd3, 0x50, 0x2a, 0xe0, 0xe6, 0x95, 0x0b, 0x3b, 0xef, 0x00, 0x56, 0xef, 0x73, 0x9a, + 0x7e, 0x02, 0x6b, 0x24, 0x60, 0x34, 0x94, 0x16, 0x73, 0x1b, 0xa0, 0x0d, 0xba, 0xb5, 0xf1, 0xff, + 0xbc, 0x31, 0x74, 0xf5, 0x1b, 0x78, 0x4c, 0xc4, 0x2c, 0x94, 0x34, 0x8e, 0xec, 0x58, 0xce, 0xad, + 0xc2, 0x42, 0x26, 0xfd, 0xa3, 0xa4, 0x47, 0xbb, 0xe3, 0x02, 0x39, 0x74, 0xf5, 0x09, 0xd4, 0x39, + 0x8d, 0x9f, 0x02, 0x6a, 0x45, 0xb6, 0xf4, 0xad, 0x28, 0xa6, 0x53, 0xf6, 0xdc, 0xf8, 0xdb, 0x06, + 0xdd, 0xba, 0xd9, 0x41, 0xdb, 0x44, 0x5b, 0x63, 0xa9, 0x89, 0x1e, 0xd4, 0xc6, 0xc8, 0x96, 0xfe, + 0xa0, 0xb2, 0xf8, 0x6c, 0x69, 0xe3, 0x3d, 0xbe, 0xe9, 0x8c, 0x14, 0xa1, 0x93, 0xc2, 0xfd, 0xa1, + 0x4b, 0x43, 0xc9, 0xa6, 0x8c, 0xba, 0x65, 0x82, 0x3e, 0xac, 0x16, 0xbe, 0x94, 0xff, 0xba, 0x79, + 0x8a, 0x7e, 0xf9, 0x33, 0x54, 0xc8, 0x0b, 0x76, 0xb9, 0xa2, 0x9f, 0x41, 0xf8, 0x23, 0x55, 0x8d, + 0x94, 0x49, 0xee, 0x2a, 0x2f, 0x6f, 0x2d, 0x6d, 0x30, 0x59, 0xac, 0x0c, 0xb0, 0x5c, 0x19, 0xe0, + 0x6b, 0x65, 0x80, 0xd7, 0xb5, 0xa1, 0x2d, 0xd7, 0x86, 0xf6, 0xb1, 0x36, 0xb4, 0xc7, 0xbe, 0xc7, + 0xa4, 0x3f, 0x73, 0xb2, 0x28, 0x98, 0x88, 0x84, 0x8b, 0x04, 0x33, 0x87, 0xf4, 0x3c, 0x81, 0xd3, + 0x5b, 0xcc, 0x85, 0x3b, 0x0b, 0x68, 0x92, 0xdf, 0xe4, 0xf2, 0xba, 0xb7, 0x73, 0x64, 0x39, 0x8f, + 0x68, 0xe2, 0xfc, 0x53, 0xf7, 0xb8, 0xfa, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xc2, 0xc9, 0x7e, 0x8b, + 0x08, 0x02, 0x00, 0x00, +} + +func (m *Channel) 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 *Channel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Channel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.MerklePathPrefix.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintChannel(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.CounterpartyChannelId) > 0 { + i -= len(m.CounterpartyChannelId) + copy(dAtA[i:], m.CounterpartyChannelId) + i = encodeVarintChannel(dAtA, i, uint64(len(m.CounterpartyChannelId))) + i-- + dAtA[i] = 0x12 + } + if len(m.ClientId) > 0 { + i -= len(m.ClientId) + copy(dAtA[i:], m.ClientId) + i = encodeVarintChannel(dAtA, i, uint64(len(m.ClientId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *IdentifiedChannel) 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 *IdentifiedChannel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IdentifiedChannel) 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 = encodeVarintChannel(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Channel.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintChannel(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintChannel(dAtA []byte, offset int, v uint64) int { + offset -= sovChannel(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Channel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovChannel(uint64(l)) + } + l = len(m.CounterpartyChannelId) + if l > 0 { + n += 1 + l + sovChannel(uint64(l)) + } + l = m.MerklePathPrefix.Size() + n += 1 + l + sovChannel(uint64(l)) + return n +} + +func (m *IdentifiedChannel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Channel.Size() + n += 1 + l + sovChannel(uint64(l)) + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovChannel(uint64(l)) + } + return n +} + +func sovChannel(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozChannel(x uint64) (n int) { + return sovChannel(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Channel) 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 ErrIntOverflowChannel + } + 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: Channel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Channel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowChannel + } + 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 ErrInvalidLengthChannel + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthChannel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowChannel + } + 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 ErrInvalidLengthChannel + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthChannel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CounterpartyChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MerklePathPrefix", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowChannel + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthChannel + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthChannel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MerklePathPrefix.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipChannel(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthChannel + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IdentifiedChannel) 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 ErrIntOverflowChannel + } + 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: IdentifiedChannel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IdentifiedChannel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channel", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowChannel + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthChannel + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthChannel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Channel.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 ErrIntOverflowChannel + } + 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 ErrInvalidLengthChannel + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthChannel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipChannel(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthChannel + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipChannel(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, ErrIntOverflowChannel + } + 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, ErrIntOverflowChannel + } + 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, ErrIntOverflowChannel + } + 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, ErrInvalidLengthChannel + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupChannel + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthChannel + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthChannel = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowChannel = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupChannel = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/04-channel/v2/types/channel_test.go b/modules/core/04-channel/v2/types/channel_test.go new file mode 100644 index 00000000000..c6c71d9a157 --- /dev/null +++ b/modules/core/04-channel/v2/types/channel_test.go @@ -0,0 +1,58 @@ +package types_test + +import ( + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func (s *TypesTestSuite) TestValidateChannel() { + var c types.Channel + testCases := []struct { + name string + malleate func() + expErr error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: invalid ClientID", + malleate: func() { + c.ClientId = "" + }, + expErr: host.ErrInvalidID, + }, + { + name: "failure: invalid counterparty channel id", + malleate: func() { + c.CounterpartyChannelId = "" + }, + expErr: host.ErrInvalidID, + }, + { + name: "failure: invalid Merkle Path Prefix", + malleate: func() { + c.MerklePathPrefix.KeyPath = [][]byte{} + }, + expErr: types.ErrInvalidChannel, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + c = types.NewChannel(ibctesting.FirstClientID, ibctesting.SecondClientID, ibctesting.MerklePath) + + tc.malleate() + + err := c.Validate() + + expPass := tc.expErr == nil + if expPass { + s.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expErr) + } + }) + } +} diff --git a/modules/core/04-channel/v2/types/codec.go b/modules/core/04-channel/v2/types/codec.go new file mode 100644 index 00000000000..788cdb30732 --- /dev/null +++ b/modules/core/04-channel/v2/types/codec.go @@ -0,0 +1,20 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterInterfaces register the ibc channel submodule interfaces to protobuf +// Any. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgCreateChannel{}, + &MsgRegisterCounterparty{}, + &MsgSendPacket{}, + &MsgRecvPacket{}, + &MsgTimeout{}, + &MsgAcknowledgement{}, + ) +} diff --git a/modules/core/04-channel/v2/types/commitment.go b/modules/core/04-channel/v2/types/commitment.go new file mode 100644 index 00000000000..3f79cc3fad1 --- /dev/null +++ b/modules/core/04-channel/v2/types/commitment.go @@ -0,0 +1,66 @@ +package types + +import ( + "crypto/sha256" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// CommitPacket returns the V2 packet commitment bytes. The commitment consists of: +// ha256_hash(0x02 + sha256_hash(destinationChannel) + sha256_hash(timeout) + sha256_hash(payload)) from a given packet. +// This results in a fixed length preimage of 32 bytes. +// NOTE: A fixed length preimage is ESSENTIAL to prevent relayers from being able +// to malleate the packet fields and create a commitment hash that matches the original packet. +func CommitPacket(packet Packet) []byte { + var buf []byte + destIDHash := sha256.Sum256([]byte(packet.DestinationChannel)) + buf = append(buf, destIDHash[:]...) + + timeoutBytes := sdk.Uint64ToBigEndian(packet.GetTimeoutTimestamp()) + timeoutHash := sha256.Sum256(timeoutBytes) + buf = append(buf, timeoutHash[:]...) + + var appBytes []byte + for _, payload := range packet.Payloads { + appBytes = append(appBytes, hashPayload(payload)...) + } + appHash := sha256.Sum256(appBytes) + buf = append(buf, appHash[:]...) + + buf = append([]byte{byte(2)}, buf...) + + hash := sha256.Sum256(buf) + return hash[:] +} + +// hashPayload returns the hash of the payload. +func hashPayload(data Payload) []byte { + var buf []byte + sourceHash := sha256.Sum256([]byte(data.SourcePort)) + buf = append(buf, sourceHash[:]...) + destHash := sha256.Sum256([]byte(data.DestinationPort)) + buf = append(buf, destHash[:]...) + payloadVersionHash := sha256.Sum256([]byte(data.Version)) + buf = append(buf, payloadVersionHash[:]...) + payloadEncodingHash := sha256.Sum256([]byte(data.Encoding)) + buf = append(buf, payloadEncodingHash[:]...) + payloadValueHash := sha256.Sum256(data.Value) + buf = append(buf, payloadValueHash[:]...) + hash := sha256.Sum256(buf) + return hash[:] +} + +// CommitAcknowledgement returns the V2 acknowledgement commitment bytes. The commitment consists of: +// sha256_hash(0x02 + sha256_hash(ack1) + sha256_hash(ack2) + ...) from a given acknowledgement. +func CommitAcknowledgement(acknowledgement Acknowledgement) []byte { + var buf []byte + for _, ack := range acknowledgement.GetAppAcknowledgements() { + hash := sha256.Sum256(ack) + buf = append(buf, hash[:]...) + } + + buf = append([]byte{byte(2)}, buf...) + + hash := sha256.Sum256(buf) + return hash[:] +} diff --git a/modules/core/04-channel/v2/types/commitment_test.go b/modules/core/04-channel/v2/types/commitment_test.go new file mode 100644 index 00000000000..a77f93f451f --- /dev/null +++ b/modules/core/04-channel/v2/types/commitment_test.go @@ -0,0 +1,58 @@ +package types_test + +import ( + "encoding/hex" + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// TestCommitPacket is primarily used to document the expected commitment output +// so that other implementations (such as the IBC Solidity) can replicate the +// same commitment output. But it is also useful to catch any changes in the commitment. +func TestCommitPacket(t *testing.T) { + transferData, err := json.Marshal(transfertypes.FungibleTokenPacketData{ + Denom: "uatom", + Amount: "1000000", + Sender: "sender", + Receiver: "receiver", + Memo: "memo", + }) + require.NoError(t, err) + packet := types.Packet{ + Sequence: 1, + SourceChannel: "channel-0", + DestinationChannel: "channel-1", + TimeoutTimestamp: 100, + Payloads: []types.Payload{ + { + SourcePort: transfertypes.PortID, + DestinationPort: transfertypes.PortID, + Version: transfertypes.V1, + Encoding: "application/json", + Value: transferData, + }, + }, + } + commitment := types.CommitPacket(packet) + require.Equal(t, "450194f2ce25b12487f65593e106d91367a1e5c90b2efc03ed78265a54cfcebe", hex.EncodeToString(commitment)) + require.Len(t, commitment, 32) +} + +// TestCommitAcknowledgement is primarily used to document the expected commitment output +// so that other implementations (such as the IBC Solidity) can replicate the +// same commitment output. But it is also useful to catch any changes in the commitment. +func TestCommitAcknowledgement(t *testing.T) { + ack := types.Acknowledgement{ + AppAcknowledgements: [][]byte{ + []byte("some bytes"), + }, + } + + commitment := types.CommitAcknowledgement(ack) + require.Equal(t, "f03b4667413e56aaf086663267913e525c442b56fa1af4fa3f3dab9f37044c5b", hex.EncodeToString(commitment)) +} diff --git a/modules/core/04-channel/v2/types/errors.go b/modules/core/04-channel/v2/types/errors.go new file mode 100644 index 00000000000..eb64f47e5ce --- /dev/null +++ b/modules/core/04-channel/v2/types/errors.go @@ -0,0 +1,22 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" +) + +var ( + ErrInvalidChannel = errorsmod.Register(SubModuleName, 2, "invalid channel") + ErrChannelNotFound = errorsmod.Register(SubModuleName, 3, "channel not found") + ErrInvalidPacket = errorsmod.Register(SubModuleName, 4, "invalid packet") + ErrInvalidPayload = errorsmod.Register(SubModuleName, 5, "invalid payload") + ErrSequenceSendNotFound = errorsmod.Register(SubModuleName, 6, "sequence send not found") + ErrInvalidAcknowledgement = errorsmod.Register(SubModuleName, 7, "invalid acknowledgement") + ErrPacketCommitmentNotFound = errorsmod.Register(SubModuleName, 8, "packet commitment not found") + ErrAcknowledgementNotFound = errorsmod.Register(SubModuleName, 9, "packet acknowledgement not found") + ErrInvalidTimeout = errorsmod.Register(SubModuleName, 10, "invalid packet timeout") + ErrTimeoutElapsed = errorsmod.Register(SubModuleName, 11, "timeout elapsed") + ErrTimeoutNotReached = errorsmod.Register(SubModuleName, 12, "timeout not reached") + ErrInvalidChannelIdentifier = errorsmod.Register(SubModuleName, 13, "invalid channel identifier") + ErrAcknowledgementExists = errorsmod.Register(SubModuleName, 14, "acknowledgement for packet already exists") + ErrNoOpMsg = errorsmod.Register(SubModuleName, 15, "message is redundant, no-op will be performed") +) diff --git a/modules/core/04-channel/v2/types/events.go b/modules/core/04-channel/v2/types/events.go new file mode 100644 index 00000000000..da7f25dd586 --- /dev/null +++ b/modules/core/04-channel/v2/types/events.go @@ -0,0 +1,36 @@ +package types + +import ( + "fmt" + + ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +// IBC channel events +const ( + EventTypeCreateChannel = "create_channel" + EventTypeRegisterCounterparty = "register_counterparty" + EventTypeSendPacket = "send_packet" + EventTypeRecvPacket = "recv_packet" + + EventTypeSendPayload = "send_payload" + EventTypeRecvPayload = "recv_payload" + + AttributeKeyChannelID = "channel_id" + AttributeKeyClientID = "client_id" + AttributeKeyCounterpartyChannelID = "counterparty_channel_id" + AttributeKeySrcChannel = "packet_source_channel" + AttributeKeyDstChannel = "packet_dest_channel" + AttributeKeySequence = "packet_sequence" + AttributeKeyTimeoutTimestamp = "packet_timeout_timestamp" + AttributeKeyPayloadLength = "packet_payload_length" + AttributeKeyPayloadSequence = "payload_sequence" + AttributeKeyVersion = "payload_version" + AttributeKeyEncoding = "payload_encoding" + AttributeKeyData = "payload_data" +) + +// IBC channel events vars +var ( + AttributeValueCategory = fmt.Sprintf("%s_%s", ibcexported.ModuleName, SubModuleName) +) diff --git a/modules/core/04-channel/v2/types/expected_keepers.go b/modules/core/04-channel/v2/types/expected_keepers.go new file mode 100644 index 00000000000..5a1a0a5d058 --- /dev/null +++ b/modules/core/04-channel/v2/types/expected_keepers.go @@ -0,0 +1,22 @@ +package types + +import ( + "context" + + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +type ClientKeeper interface { + // VerifyMembership retrieves the light client module for the clientID and verifies the proof of the existence of a key-value pair at a specified height. + VerifyMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error + // VerifyNonMembership retrieves the light client module for the clientID and verifies the absence of a given key at a specified height. + VerifyNonMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error + // GetClientStatus returns the status of a client given the client ID + GetClientStatus(ctx context.Context, clientID string) exported.Status + // GetClientLatestHeight returns the latest height of a client given the client ID + GetClientLatestHeight(ctx context.Context, clientID string) clienttypes.Height + // GetClientTimestampAtHeight returns the timestamp for a given height on the client + // given its client ID and height + GetClientTimestampAtHeight(ctx context.Context, clientID string, height exported.Height) (uint64, error) +} diff --git a/modules/core/04-channel/v2/types/genesis.go b/modules/core/04-channel/v2/types/genesis.go new file mode 100644 index 00000000000..3b567f97c87 --- /dev/null +++ b/modules/core/04-channel/v2/types/genesis.go @@ -0,0 +1,134 @@ +package types + +import ( + "errors" + "fmt" + + channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" +) + +// NewPacketState creates a new PacketState instance. +func NewPacketState(channelID string, sequence uint64, data []byte) PacketState { + return PacketState{ + ChannelId: channelID, + Sequence: sequence, + Data: data, + } +} + +// Validate performs basic validation of fields returning an error upon any failure. +func (ps PacketState) Validate() error { + if ps.Data == nil { + return errors.New("data bytes cannot be nil") + } + return validateGenFields(ps.ChannelId, ps.Sequence) +} + +// NewPacketSequence creates a new PacketSequences instance. +func NewPacketSequence(channelID string, sequence uint64) PacketSequence { + return PacketSequence{ + ChannelId: channelID, + Sequence: sequence, + } +} + +// Validate performs basic validation of fields returning an error upon any failure. +func (ps PacketSequence) Validate() error { + return validateGenFields(ps.ChannelId, ps.Sequence) +} + +// NewGenesisState creates a GenesisState instance. +func NewGenesisState( + channels []IdentifiedChannel, acks, receipts, commitments []PacketState, + sendSeqs []PacketSequence, nextChannelSequence uint64, +) GenesisState { + return GenesisState{ + Channels: channels, + Acknowledgements: acks, + Receipts: receipts, + Commitments: commitments, + SendSequences: sendSeqs, + NextChannelSequence: nextChannelSequence, + } +} + +// DefaultGenesisState returns the ibc channel v2 submodule's default genesis state. +func DefaultGenesisState() GenesisState { + return GenesisState{ + Channels: []IdentifiedChannel{}, + Acknowledgements: []PacketState{}, + Receipts: []PacketState{}, + Commitments: []PacketState{}, + SendSequences: []PacketSequence{}, + NextChannelSequence: 0, + } +} + +// Validate performs basic genesis state validation returning an error upon any failure. +func (gs GenesisState) Validate() error { + // keep track of the max sequence to ensure it is less than + // the next sequence used in creating channel identifiers. + var maxSequence uint64 + + for i, channel := range gs.Channels { + sequence, err := channeltypesv1.ParseChannelSequence(channel.ChannelId) + if err != nil { + return err + } + + if sequence > maxSequence { + maxSequence = sequence + } + + if err := channel.ValidateBasic(); err != nil { + return fmt.Errorf("invalid channel %v channel index %d: %w", channel, i, err) + } + } + + if maxSequence != 0 && maxSequence >= gs.NextChannelSequence { + return fmt.Errorf("next channel sequence %d must be greater than maximum sequence used in channel identifier %d", gs.NextChannelSequence, maxSequence) + } + + for i, ack := range gs.Acknowledgements { + if err := ack.Validate(); err != nil { + return fmt.Errorf("invalid acknowledgement %v ack index %d: %w", ack, i, err) + } + if len(ack.Data) == 0 { + return fmt.Errorf("invalid acknowledgement %v ack index %d: data bytes cannot be empty", ack, i) + } + } + + for i, receipt := range gs.Receipts { + if err := receipt.Validate(); err != nil { + return fmt.Errorf("invalid acknowledgement %v ack index %d: %w", receipt, i, err) + } + } + + for i, commitment := range gs.Commitments { + if err := commitment.Validate(); err != nil { + return fmt.Errorf("invalid commitment %v index %d: %w", commitment, i, err) + } + if len(commitment.Data) == 0 { + return fmt.Errorf("invalid acknowledgement %v ack index %d: data bytes cannot be empty", commitment, i) + } + } + + for i, ss := range gs.SendSequences { + if err := ss.Validate(); err != nil { + return fmt.Errorf("invalid send sequence %v index %d: %w", ss, i, err) + } + } + + return nil +} + +func validateGenFields(channelID string, sequence uint64) error { + if err := host.ChannelIdentifierValidator(channelID); err != nil { + return fmt.Errorf("invalid channel Id: %w", err) + } + if sequence == 0 { + return errors.New("sequence cannot be 0") + } + return nil +} diff --git a/modules/core/04-channel/v2/types/genesis.pb.go b/modules/core/04-channel/v2/types/genesis.pb.go new file mode 100644 index 00000000000..ea9c321819f --- /dev/null +++ b/modules/core/04-channel/v2/types/genesis.pb.go @@ -0,0 +1,1081 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/channel/v2/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/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 + +// GenesisState defines the ibc channel/v2 submodule's genesis state. +type GenesisState struct { + Channels []IdentifiedChannel `protobuf:"bytes,1,rep,name=channels,proto3,casttype=IdentifiedChannel" json:"channels"` + Acknowledgements []PacketState `protobuf:"bytes,2,rep,name=acknowledgements,proto3" json:"acknowledgements"` + Commitments []PacketState `protobuf:"bytes,3,rep,name=commitments,proto3" json:"commitments"` + Receipts []PacketState `protobuf:"bytes,4,rep,name=receipts,proto3" json:"receipts"` + SendSequences []PacketSequence `protobuf:"bytes,5,rep,name=send_sequences,json=sendSequences,proto3" json:"send_sequences"` + // the sequence for the next generated channel identifier + NextChannelSequence uint64 `protobuf:"varint,6,opt,name=next_channel_sequence,json=nextChannelSequence,proto3" json:"next_channel_sequence,omitempty"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_b5d374f126f051c3, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetChannels() []IdentifiedChannel { + if m != nil { + return m.Channels + } + return nil +} + +func (m *GenesisState) GetAcknowledgements() []PacketState { + if m != nil { + return m.Acknowledgements + } + return nil +} + +func (m *GenesisState) GetCommitments() []PacketState { + if m != nil { + return m.Commitments + } + return nil +} + +func (m *GenesisState) GetReceipts() []PacketState { + if m != nil { + return m.Receipts + } + return nil +} + +func (m *GenesisState) GetSendSequences() []PacketSequence { + if m != nil { + return m.SendSequences + } + return nil +} + +func (m *GenesisState) GetNextChannelSequence() uint64 { + if m != nil { + return m.NextChannelSequence + } + return 0 +} + +// PacketState defines the generic type necessary to retrieve and store +// packet commitments, acknowledgements, and receipts. +// Caller is responsible for knowing the context necessary to interpret this +// state as a commitment, acknowledgement, or a receipt. +type PacketState struct { + // channel unique identifier. + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // packet sequence. + Sequence uint64 `protobuf:"varint,2,opt,name=sequence,proto3" json:"sequence,omitempty"` + // embedded data that represents packet state. + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *PacketState) Reset() { *m = PacketState{} } +func (m *PacketState) String() string { return proto.CompactTextString(m) } +func (*PacketState) ProtoMessage() {} +func (*PacketState) Descriptor() ([]byte, []int) { + return fileDescriptor_b5d374f126f051c3, []int{1} +} +func (m *PacketState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketState.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 *PacketState) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketState.Merge(m, src) +} +func (m *PacketState) XXX_Size() int { + return m.Size() +} +func (m *PacketState) XXX_DiscardUnknown() { + xxx_messageInfo_PacketState.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketState proto.InternalMessageInfo + +// PacketSequence defines the genesis type necessary to retrieve and store next send sequences. +type PacketSequence struct { + // channel unique identifier. + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // packet sequence + Sequence uint64 `protobuf:"varint,2,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *PacketSequence) Reset() { *m = PacketSequence{} } +func (m *PacketSequence) String() string { return proto.CompactTextString(m) } +func (*PacketSequence) ProtoMessage() {} +func (*PacketSequence) Descriptor() ([]byte, []int) { + return fileDescriptor_b5d374f126f051c3, []int{2} +} +func (m *PacketSequence) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketSequence) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketSequence.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 *PacketSequence) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketSequence.Merge(m, src) +} +func (m *PacketSequence) XXX_Size() int { + return m.Size() +} +func (m *PacketSequence) XXX_DiscardUnknown() { + xxx_messageInfo_PacketSequence.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketSequence proto.InternalMessageInfo + +func (m *PacketSequence) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *PacketSequence) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "ibc.core.channel.v2.GenesisState") + proto.RegisterType((*PacketState)(nil), "ibc.core.channel.v2.PacketState") + proto.RegisterType((*PacketSequence)(nil), "ibc.core.channel.v2.PacketSequence") +} + +func init() { proto.RegisterFile("ibc/core/channel/v2/genesis.proto", fileDescriptor_b5d374f126f051c3) } + +var fileDescriptor_b5d374f126f051c3 = []byte{ + // 436 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x4f, 0x6b, 0xd4, 0x40, + 0x18, 0xc6, 0x33, 0xdd, 0x58, 0xb6, 0xb3, 0xb5, 0xe8, 0x54, 0x21, 0x2e, 0x98, 0x8d, 0x2b, 0x48, + 0x2e, 0xcd, 0x48, 0xf4, 0xa2, 0x78, 0x8a, 0x07, 0x2d, 0x5e, 0x4a, 0x04, 0x0f, 0x82, 0x94, 0x64, + 0xe6, 0x35, 0x1d, 0xba, 0x99, 0x59, 0x77, 0x66, 0x57, 0xfd, 0x06, 0x1e, 0xfd, 0x08, 0x7e, 0x9c, + 0x1e, 0x7b, 0x11, 0x3c, 0x15, 0xd9, 0xfd, 0x16, 0x9e, 0x24, 0x93, 0x3f, 0xac, 0x74, 0x11, 0x4a, + 0x6f, 0xef, 0xbc, 0xef, 0xf3, 0xfc, 0x9e, 0x97, 0xe1, 0xc5, 0x0f, 0x44, 0xce, 0x28, 0x53, 0x33, + 0xa0, 0xec, 0x24, 0x93, 0x12, 0x26, 0x74, 0x11, 0xd3, 0x02, 0x24, 0x68, 0xa1, 0xa3, 0xe9, 0x4c, + 0x19, 0x45, 0xf6, 0x45, 0xce, 0xa2, 0x4a, 0x12, 0x35, 0x92, 0x68, 0x11, 0x0f, 0xef, 0x14, 0xaa, + 0x50, 0x76, 0x4e, 0xab, 0xaa, 0x96, 0x0e, 0x37, 0xd2, 0x5a, 0x97, 0x95, 0x8c, 0x7f, 0xf6, 0xf0, + 0xee, 0xab, 0x9a, 0xff, 0xd6, 0x64, 0x06, 0xc8, 0x07, 0xdc, 0x6f, 0x14, 0xda, 0x43, 0x41, 0x2f, + 0x1c, 0xc4, 0x8f, 0xa2, 0x0d, 0x89, 0xd1, 0x21, 0x07, 0x69, 0xc4, 0x47, 0x01, 0xfc, 0x65, 0xdd, + 0x4c, 0xee, 0x9d, 0x5d, 0x8c, 0x9c, 0x3f, 0x17, 0xa3, 0xdb, 0x97, 0x46, 0x69, 0x87, 0x24, 0x29, + 0xbe, 0x95, 0xb1, 0x53, 0xa9, 0x3e, 0x4f, 0x80, 0x17, 0x50, 0x82, 0x34, 0xda, 0xdb, 0xb2, 0x31, + 0xc1, 0xc6, 0x98, 0xa3, 0x8c, 0x9d, 0x82, 0xb1, 0xab, 0x25, 0x6e, 0x15, 0x90, 0x5e, 0xf2, 0x93, + 0xd7, 0x78, 0xc0, 0x54, 0x59, 0x0a, 0x53, 0xe3, 0x7a, 0x57, 0xc2, 0xad, 0x5b, 0x49, 0x82, 0xfb, + 0x33, 0x60, 0x20, 0xa6, 0x46, 0x7b, 0xee, 0x95, 0x30, 0x9d, 0x8f, 0x1c, 0xe1, 0x3d, 0x0d, 0x92, + 0x1f, 0x6b, 0xf8, 0x34, 0x07, 0xc9, 0x40, 0x7b, 0x37, 0x2c, 0xe9, 0xe1, 0xff, 0x48, 0x8d, 0xb6, + 0x81, 0xdd, 0xac, 0x00, 0x6d, 0x4f, 0x93, 0x18, 0xdf, 0x95, 0xf0, 0xc5, 0x1c, 0x37, 0xb6, 0x8e, + 0xec, 0x6d, 0x07, 0x28, 0x74, 0xd3, 0xfd, 0x6a, 0xd8, 0xfc, 0x74, 0x6b, 0x1a, 0xe7, 0x78, 0xb0, + 0xb6, 0x24, 0xb9, 0x8f, 0x71, 0xeb, 0x16, 0xdc, 0x43, 0x01, 0x0a, 0x77, 0xd2, 0x9d, 0xa6, 0x73, + 0xc8, 0xc9, 0x10, 0xf7, 0x3b, 0xe8, 0x96, 0x85, 0x76, 0x6f, 0x42, 0xb0, 0xcb, 0x33, 0x93, 0x79, + 0xbd, 0x00, 0x85, 0xbb, 0xa9, 0xad, 0x9f, 0xbb, 0xdf, 0x7e, 0x8c, 0x9c, 0xf1, 0x1b, 0xbc, 0xf7, + 0xef, 0xfa, 0xd7, 0x88, 0x49, 0xde, 0x9d, 0x2d, 0x7d, 0x74, 0xbe, 0xf4, 0xd1, 0xef, 0xa5, 0x8f, + 0xbe, 0xaf, 0x7c, 0xe7, 0x7c, 0xe5, 0x3b, 0xbf, 0x56, 0xbe, 0xf3, 0xfe, 0x45, 0x21, 0xcc, 0xc9, + 0x3c, 0x8f, 0x98, 0x2a, 0x29, 0x53, 0xba, 0x54, 0x9a, 0x8a, 0x9c, 0x1d, 0x14, 0x8a, 0x2e, 0x9e, + 0xd1, 0x52, 0xf1, 0xf9, 0x04, 0x74, 0x7d, 0xe5, 0x8f, 0x9f, 0x1e, 0xac, 0x1d, 0xba, 0xf9, 0x3a, + 0x05, 0x9d, 0x6f, 0xdb, 0x3b, 0x7f, 0xf2, 0x37, 0x00, 0x00, 0xff, 0xff, 0x28, 0x88, 0xce, 0xb6, + 0x5a, 0x03, 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.NextChannelSequence != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextChannelSequence)) + i-- + dAtA[i] = 0x30 + } + if len(m.SendSequences) > 0 { + for iNdEx := len(m.SendSequences) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.SendSequences[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.Receipts) > 0 { + for iNdEx := len(m.Receipts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Receipts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.Commitments) > 0 { + for iNdEx := len(m.Commitments) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Commitments[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Acknowledgements) > 0 { + for iNdEx := len(m.Acknowledgements) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Acknowledgements[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Channels) > 0 { + for iNdEx := len(m.Channels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Channels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *PacketState) 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 *PacketState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x1a + } + if m.Sequence != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x10 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *PacketSequence) 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 *PacketSequence) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketSequence) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x10 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Channels) > 0 { + for _, e := range m.Channels { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Acknowledgements) > 0 { + for _, e := range m.Acknowledgements { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Commitments) > 0 { + for _, e := range m.Commitments { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Receipts) > 0 { + for _, e := range m.Receipts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.SendSequences) > 0 { + for _, e := range m.SendSequences { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if m.NextChannelSequence != 0 { + n += 1 + sovGenesis(uint64(m.NextChannelSequence)) + } + return n +} + +func (m *PacketState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovGenesis(uint64(m.Sequence)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *PacketSequence) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovGenesis(uint64(m.Sequence)) + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Channels = append(m.Channels, IdentifiedChannel{}) + if err := m.Channels[len(m.Channels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Acknowledgements", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Acknowledgements = append(m.Acknowledgements, PacketState{}) + if err := m.Acknowledgements[len(m.Acknowledgements)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commitments", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Commitments = append(m.Commitments, PacketState{}) + if err := m.Commitments[len(m.Commitments)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receipts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Receipts = append(m.Receipts, PacketState{}) + if err := m.Receipts[len(m.Receipts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SendSequences", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SendSequences = append(m.SendSequences, PacketSequence{}) + if err := m.SendSequences[len(m.SendSequences)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextChannelSequence", wireType) + } + m.NextChannelSequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextChannelSequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PacketState) 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 ErrIntOverflowGenesis + } + 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: PacketState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PacketSequence) 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 ErrIntOverflowGenesis + } + 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: PacketSequence: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketSequence: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/04-channel/v2/types/genesis_test.go b/modules/core/04-channel/v2/types/genesis_test.go new file mode 100644 index 00000000000..e70290d54b1 --- /dev/null +++ b/modules/core/04-channel/v2/types/genesis_test.go @@ -0,0 +1,102 @@ +package types_test + +import ( + "errors" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func TestValidateGenesis(t *testing.T) { + testCases := []struct { + name string + genState types.GenesisState + expError error + }{ + { + "default", + types.DefaultGenesisState(), + nil, + }, + { + "valid genesis", + types.NewGenesisState( + []types.IdentifiedChannel{ + types.NewIdentifiedChannel( + ibctesting.FirstChannelID, types.NewChannel(ibctesting.FirstClientID, ibctesting.SecondChannelID, ibctesting.MerklePath), + ), + types.NewIdentifiedChannel( + ibctesting.SecondChannelID, types.NewChannel(ibctesting.SecondClientID, ibctesting.FirstChannelID, ibctesting.MerklePath), + ), + }, + []types.PacketState{types.NewPacketState(ibctesting.FirstChannelID, 1, []byte("ack"))}, + []types.PacketState{types.NewPacketState(ibctesting.SecondChannelID, 1, []byte(""))}, + []types.PacketState{types.NewPacketState(ibctesting.FirstChannelID, 1, []byte("commit_hash"))}, + []types.PacketSequence{types.NewPacketSequence(ibctesting.SecondChannelID, 1)}, + 2, + ), + nil, + }, + { + "invalid channel identifier", + types.GenesisState{ + Channels: []types.IdentifiedChannel{types.NewIdentifiedChannel(ibctesting.InvalidID, types.NewChannel(ibctesting.FirstClientID, ibctesting.SecondChannelID, ibctesting.MerklePath))}, + }, + host.ErrInvalidID, + }, + { + "invalid ack", + types.GenesisState{ + Acknowledgements: []types.PacketState{ + types.NewPacketState(ibctesting.SecondChannelID, 1, nil), + }, + }, + errors.New("data bytes cannot be nil"), + }, + { + "invalid commitment", + types.GenesisState{ + Commitments: []types.PacketState{ + types.NewPacketState(ibctesting.FirstChannelID, 1, nil), + }, + }, + errors.New("data bytes cannot be nil"), + }, + { + "invalid send seq", + types.GenesisState{ + SendSequences: []types.PacketSequence{ + types.NewPacketSequence(ibctesting.FirstChannelID, 0), + }, + }, + errors.New("sequence cannot be 0"), + }, + { + "next channel sequence is less than maximum channel identifier sequence used", + types.GenesisState{ + Channels: []types.IdentifiedChannel{ + types.NewIdentifiedChannel("channel-10", types.NewChannel(ibctesting.FirstClientID, ibctesting.SecondChannelID, ibctesting.MerklePath)), + }, + NextChannelSequence: 0, + }, + fmt.Errorf("next channel sequence 0 must be greater than maximum sequence used in channel identifier 10"), + }, + } + + for _, tc := range testCases { + + err := tc.genState.Validate() + + expPass := tc.expError == nil + if expPass { + require.NoError(t, err) + } else { + ibctesting.RequireErrorIsOrContains(t, err, tc.expError) + } + } +} diff --git a/modules/core/04-channel/v2/types/keys.go b/modules/core/04-channel/v2/types/keys.go new file mode 100644 index 00000000000..103393f1c13 --- /dev/null +++ b/modules/core/04-channel/v2/types/keys.go @@ -0,0 +1,29 @@ +package types + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // SubModuleName defines the channelv2 module name. + SubModuleName = "channelv2" + + // ChannelKey is the key used to store channels in the channel store. + // the channel key is imported from types instead of host because + // the channel key is not a part of the ics-24 host specification + ChannelKey = "channel" + + // CreatorKey is the key used to store the channel creator in the channel store + // the creator key is imported from types instead of host because + // the creator key is not a part of the ics-24 host specification + CreatorKey = "creator" + + // TODO + PacketKey = "packet" +) + +func PacketStoreKey(channelID string, sequence uint64) []byte { + return []byte(fmt.Sprintf("%s/%s/%s", PacketKey, channelID, sdk.Uint64ToBigEndian(sequence))) +} diff --git a/modules/core/04-channel/v2/types/merkle.go b/modules/core/04-channel/v2/types/merkle.go new file mode 100644 index 00000000000..59be153c960 --- /dev/null +++ b/modules/core/04-channel/v2/types/merkle.go @@ -0,0 +1,31 @@ +package types + +import ( + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" +) + +// BuildMerklePath takes the merkle path prefix and an ICS24 path +// and builds a new path by appending the ICS24 path to the last element of the merkle path prefix. +func BuildMerklePath(prefix commitmenttypesv2.MerklePath, path []byte) commitmenttypesv2.MerklePath { + if prefix.Empty() { + return commitmenttypes.NewMerklePath(path) + } + + // avoid mutating the provided prefix + prefixKeys := make([][]byte, len(prefix.KeyPath)) + copy(prefixKeys, prefix.KeyPath) + + lastElement := prefixKeys[len(prefixKeys)-1] + // append path to last element + newLastElement := cloneAppend(lastElement, path) + prefixKeys[len(prefixKeys)-1] = newLastElement + return commitmenttypes.NewMerklePath(prefixKeys...) +} + +func cloneAppend(bz []byte, tail []byte) []byte { + res := make([]byte, len(bz)+len(tail)) + copy(res, bz) + copy(res[len(bz):], tail) + return res +} diff --git a/modules/core/04-channel/v2/types/merkle_test.go b/modules/core/04-channel/v2/types/merkle_test.go new file mode 100644 index 00000000000..df239bc17d7 --- /dev/null +++ b/modules/core/04-channel/v2/types/merkle_test.go @@ -0,0 +1,64 @@ +package types_test + +import ( + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibctesting "github.com/cosmos/ibc-go/v9/testing" +) + +func (s *TypesTestSuite) TestBuildMerklePath() { + path := ibctesting.NewPath(s.chainA, s.chainB) + path.SetupV2() + + prefixPath := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) + packetCommitmentKey := host.PacketCommitmentKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, 1) + + testCases := []struct { + name string + prefix commitmenttypesv2.MerklePath + path []byte + expPath commitmenttypesv2.MerklePath + }{ + { + name: "standard ibc path", + prefix: prefixPath, + path: packetCommitmentKey, + expPath: commitmenttypesv2.NewMerklePath([]byte("ibc"), packetCommitmentKey), + }, + { + name: "non-empty last element prefix path", + prefix: commitmenttypes.NewMerklePath([]byte("ibc"), []byte("abc")), + path: packetCommitmentKey, + expPath: commitmenttypesv2.NewMerklePath([]byte("ibc"), append([]byte("abc"), packetCommitmentKey...)), + }, + { + name: "many elements in prefix path", + prefix: commitmenttypes.NewMerklePath([]byte("ibc"), []byte("a"), []byte("b"), []byte("c"), []byte("d")), + path: packetCommitmentKey, + expPath: commitmenttypesv2.NewMerklePath([]byte("ibc"), []byte("a"), []byte("b"), []byte("c"), append([]byte("d"), packetCommitmentKey...)), + }, + { + name: "empty prefix", + prefix: commitmenttypesv2.MerklePath{}, + path: packetCommitmentKey, + expPath: commitmenttypesv2.NewMerklePath(packetCommitmentKey), + }, + { + name: "empty path", + prefix: prefixPath, + path: []byte{}, + expPath: commitmenttypesv2.NewMerklePath([]byte("ibc"), []byte("")), + }, + } + + for _, tc := range testCases { + tc := tc + + s.Run(tc.name, func() { + merklePath := types.BuildMerklePath(tc.prefix, tc.path) + s.Require().Equal(tc.expPath, merklePath) + }) + } +} diff --git a/modules/core/04-channel/v2/types/msgs.go b/modules/core/04-channel/v2/types/msgs.go new file mode 100644 index 00000000000..b0a8d9cd9de --- /dev/null +++ b/modules/core/04-channel/v2/types/msgs.go @@ -0,0 +1,202 @@ +package types + +import ( + "time" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + commitmenttypesv1 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" +) + +const MaxTimeoutDelta time.Duration = 24 * time.Hour + +var ( + _ sdk.Msg = (*MsgCreateChannel)(nil) + _ sdk.HasValidateBasic = (*MsgCreateChannel)(nil) + + _ sdk.Msg = (*MsgRegisterCounterparty)(nil) + _ sdk.HasValidateBasic = (*MsgRegisterCounterparty)(nil) + + _ sdk.Msg = (*MsgSendPacket)(nil) + _ sdk.HasValidateBasic = (*MsgSendPacket)(nil) + + _ sdk.Msg = (*MsgRecvPacket)(nil) + _ sdk.HasValidateBasic = (*MsgRecvPacket)(nil) + + _ sdk.Msg = (*MsgTimeout)(nil) + _ sdk.HasValidateBasic = (*MsgTimeout)(nil) + + _ sdk.Msg = (*MsgAcknowledgement)(nil) + _ sdk.HasValidateBasic = (*MsgAcknowledgement)(nil) +) + +// NewMsgCreateChannel creates a new MsgCreateChannel instance +func NewMsgCreateChannel(clientID string, merklePathPrefix commitmenttypesv2.MerklePath, signer string) *MsgCreateChannel { + return &MsgCreateChannel{ + Signer: signer, + ClientId: clientID, + MerklePathPrefix: merklePathPrefix, + } +} + +// ValidateBasic performs basic checks on a MsgCreateChannel. +func (msg *MsgCreateChannel) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { + return err + } + + if err := msg.MerklePathPrefix.ValidateAsPrefix(); err != nil { + return err + } + + return nil +} + +// NewMsgRegisterCounterparty creates a new MsgRegisterCounterparty instance +func NewMsgRegisterCounterparty(channelID, counterpartyChannelID string, signer string) *MsgRegisterCounterparty { + return &MsgRegisterCounterparty{ + Signer: signer, + ChannelId: channelID, + CounterpartyChannelId: counterpartyChannelID, + } +} + +// ValidateBasic performs basic checks on a MsgRegisterCounterparty. +func (msg *MsgRegisterCounterparty) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil { + return err + } + + if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil { + return err + } + + return nil +} + +// NewMsgSendPacket creates a new MsgSendPacket instance. +func NewMsgSendPacket(sourceChannel string, timeoutTimestamp uint64, signer string, payloads ...Payload) *MsgSendPacket { + return &MsgSendPacket{ + SourceChannel: sourceChannel, + TimeoutTimestamp: timeoutTimestamp, + Payloads: payloads, + Signer: signer, + } +} + +// ValidateBasic performs basic checks on a MsgSendPacket. +func (msg *MsgSendPacket) ValidateBasic() error { + if err := host.ChannelIdentifierValidator(msg.SourceChannel); err != nil { + return err + } + + if msg.TimeoutTimestamp == 0 { + return errorsmod.Wrap(ErrInvalidTimeout, "timeout must not be 0") + } + + if len(msg.Payloads) != 1 { + return errorsmod.Wrapf(ErrInvalidPayload, "payloads must be of length 1, got %d instead", len(msg.Payloads)) + } + + for _, pd := range msg.Payloads { + if err := pd.ValidateBasic(); err != nil { + return err + } + } + + _, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + return nil +} + +// NewMsgRecvPacket creates a new MsgRecvPacket instance. +func NewMsgRecvPacket(packet Packet, proofCommitment []byte, proofHeight clienttypes.Height, signer string) *MsgRecvPacket { + return &MsgRecvPacket{ + Packet: packet, + ProofCommitment: proofCommitment, + ProofHeight: proofHeight, + Signer: signer, + } +} + +// ValidateBasic performs basic checks on a MsgRecvPacket. +func (msg *MsgRecvPacket) ValidateBasic() error { + if len(msg.ProofCommitment) == 0 { + return errorsmod.Wrap(commitmenttypesv1.ErrInvalidProof, "proof commitment can not be empty") + } + + _, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + return msg.Packet.ValidateBasic() +} + +// NewMsgAcknowledgement creates a new MsgAcknowledgement instance +func NewMsgAcknowledgement(packet Packet, acknowledgement Acknowledgement, proofAcked []byte, proofHeight clienttypes.Height, signer string) *MsgAcknowledgement { + return &MsgAcknowledgement{ + Packet: packet, + Acknowledgement: acknowledgement, + ProofAcked: proofAcked, + ProofHeight: proofHeight, + Signer: signer, + } +} + +// ValidateBasic performs basic checks on a MsgAcknowledgement. +func (msg *MsgAcknowledgement) ValidateBasic() error { + if len(msg.ProofAcked) == 0 { + return errorsmod.Wrap(commitmenttypesv1.ErrInvalidProof, "cannot submit an empty acknowledgement proof") + } + + // TODO: Add validation for ack object https://github.com/cosmos/ibc-go/issues/7472 + + _, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + return msg.Packet.ValidateBasic() +} + +// NewMsgTimeout creates a new MsgTimeout instance +func NewMsgTimeout(packet Packet, proofUnreceived []byte, proofHeight clienttypes.Height, signer string) *MsgTimeout { + return &MsgTimeout{ + Packet: packet, + ProofUnreceived: proofUnreceived, + ProofHeight: proofHeight, + Signer: signer, + } +} + +// ValidateBasic performs basic checks on a MsgTimeout +func (msg *MsgTimeout) ValidateBasic() error { + if len(msg.ProofUnreceived) == 0 { + return errorsmod.Wrap(commitmenttypesv1.ErrInvalidProof, "proof unreceived can not be empty") + } + + _, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + return msg.Packet.ValidateBasic() +} diff --git a/modules/core/04-channel/v2/types/msgs_test.go b/modules/core/04-channel/v2/types/msgs_test.go new file mode 100644 index 00000000000..35165f0d72e --- /dev/null +++ b/modules/core/04-channel/v2/types/msgs_test.go @@ -0,0 +1,410 @@ +package types_test + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/suite" + + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" +) + +var testProof = []byte("test") + +type TypesTestSuite struct { + suite.Suite + + coordinator *ibctesting.Coordinator + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain +} + +func (s *TypesTestSuite) SetupTest() { + s.coordinator = ibctesting.NewCoordinator(s.T(), 2) + s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) + s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) +} + +func TestTypesTestSuite(t *testing.T) { + suite.Run(t, new(TypesTestSuite)) +} + +func (s *TypesTestSuite) TestMsgRegisterCounterpartyValidateBasic() { + var msg *types.MsgRegisterCounterparty + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: invalid signer address", + func() { + msg.Signer = "invalid" + }, + ibcerrors.ErrInvalidAddress, + }, + { + "failure: invalid channel ID", + func() { + msg.ChannelId = "" + }, + host.ErrInvalidID, + }, + { + "failure: invalid counterparty channel ID", + func() { + msg.CounterpartyChannelId = "" + }, + host.ErrInvalidID, + }, + } + + for _, tc := range testCases { + msg = types.NewMsgRegisterCounterparty( + ibctesting.FirstChannelID, + ibctesting.SecondChannelID, + ibctesting.TestAccAddress, + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err, "valid case %s failed", tc.name) + } else { + s.Require().ErrorIs(err, tc.expError, "invalid case %s passed", tc.name) + } + } +} + +// TestMsgCreateChannelValidateBasic tests ValidateBasic for MsgCreateChannel +func (s *TypesTestSuite) TestMsgCreateChannelValidateBasic() { + var msg *types.MsgCreateChannel + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: invalid signer address", + func() { + msg.Signer = "invalid" + }, + ibcerrors.ErrInvalidAddress, + }, + { + "failure: invalid client ID", + func() { + msg.ClientId = "" + }, + host.ErrInvalidID, + }, + { + "failure: empty key path", + func() { + msg.MerklePathPrefix.KeyPath = nil + }, + errors.New("path cannot have length 0"), + }, + } + + for _, tc := range testCases { + msg = types.NewMsgCreateChannel( + ibctesting.FirstClientID, + commitmenttypes.NewMerklePath([]byte("key")), + ibctesting.TestAccAddress, + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err, "valid case %s failed", tc.name) + } else { + s.Require().ErrorContains(err, tc.expError.Error(), "invalid case %s passed", tc.name) + } + } +} + +func (s *TypesTestSuite) TestMsgSendPacketValidateBasic() { + var msg *types.MsgSendPacket + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: invalid source channel", + malleate: func() { + msg.SourceChannel = "" + }, + expError: host.ErrInvalidID, + }, + { + name: "failure: invalid timestamp", + malleate: func() { + msg.TimeoutTimestamp = 0 + }, + expError: types.ErrInvalidTimeout, + }, + { + name: "failure: invalid length for payload", + malleate: func() { + msg.Payloads = []types.Payload{{}, {}} + }, + expError: types.ErrInvalidPayload, + }, + { + name: "failure: invalid packetdata", + malleate: func() { + msg.Payloads = []types.Payload{} + }, + expError: types.ErrInvalidPayload, + }, + { + name: "failure: invalid payload", + malleate: func() { + msg.Payloads[0].DestinationPort = "" + }, + expError: host.ErrInvalidID, + }, + { + name: "failure: invalid signer", + malleate: func() { + msg.Signer = "" + }, + expError: ibcerrors.ErrInvalidAddress, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + msg = types.NewMsgSendPacket( + ibctesting.FirstChannelID, s.chainA.GetTimeoutTimestamp(), + s.chainA.SenderAccount.GetAddress().String(), + types.Payload{SourcePort: ibctesting.MockPort, DestinationPort: ibctesting.MockPort, Version: "ics20-1", Encoding: transfertypes.EncodingJSON, Value: ibctesting.MockPacketData}, + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expError) + } + }) + } +} + +func (s *TypesTestSuite) TestMsgRecvPacketValidateBasic() { + var msg *types.MsgRecvPacket + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: invalid packet", + malleate: func() { + msg.Packet.Payloads = []types.Payload{} + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: invalid proof commitment", + malleate: func() { + msg.ProofCommitment = []byte{} + }, + expError: commitmenttypes.ErrInvalidProof, + }, + { + name: "failure: invalid length for packet payloads", + malleate: func() { + msg.Packet.Payloads = []types.Payload{{}, {}} + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: invalid signer", + malleate: func() { + msg.Signer = "" + }, + expError: ibcerrors.ErrInvalidAddress, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + packet := types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)) + + msg = types.NewMsgRecvPacket(packet, testProof, s.chainA.GetTimeoutHeight(), s.chainA.SenderAccount.GetAddress().String()) + + tc.malleate() + + err := msg.ValidateBasic() + + expPass := tc.expError == nil + + if expPass { + s.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expError) + } + }) + } +} + +func (s *TypesTestSuite) TestMsgAcknowledge_ValidateBasic() { + var msg *types.MsgAcknowledgement + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: invalid proof of acknowledgement", + malleate: func() { + msg.ProofAcked = []byte{} + }, + expError: commitmenttypes.ErrInvalidProof, + }, + { + name: "failure: invalid length for packet payloads", + malleate: func() { + msg.Packet.Payloads = []types.Payload{{}, {}} + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: invalid signer", + malleate: func() { + msg.Signer = "" + }, + expError: ibcerrors.ErrInvalidAddress, + }, + { + name: "failure: invalid packet", + malleate: func() { + msg.Packet.Sequence = 0 + }, + expError: types.ErrInvalidPacket, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + msg = types.NewMsgAcknowledgement( + types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)), + types.Acknowledgement{}, + testProof, + clienttypes.ZeroHeight(), + s.chainA.SenderAccount.GetAddress().String(), + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expError) + } + }) + } +} + +func (s *TypesTestSuite) TestMsgTimeoutValidateBasic() { + var msg *types.MsgTimeout + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: invalid signer", + malleate: func() { + msg.Signer = "" + }, + expError: ibcerrors.ErrInvalidAddress, + }, + { + name: "failure: invalid length for packet payloads", + malleate: func() { + msg.Packet.Payloads = []types.Payload{{}, {}} + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: invalid packet", + malleate: func() { + msg.Packet.Sequence = 0 + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: invalid proof unreceived", + malleate: func() { + msg.ProofUnreceived = []byte{} + }, + expError: commitmenttypes.ErrInvalidProof, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + msg = types.NewMsgTimeout( + types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPayload(mockv2.ModuleNameA, mockv2.ModuleNameB)), + testProof, + clienttypes.ZeroHeight(), + s.chainA.SenderAccount.GetAddress().String(), + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expError) + } + }) + } +} diff --git a/modules/core/04-channel/v2/types/packet.go b/modules/core/04-channel/v2/types/packet.go new file mode 100644 index 00000000000..1ba7722b925 --- /dev/null +++ b/modules/core/04-channel/v2/types/packet.go @@ -0,0 +1,86 @@ +package types + +import ( + "strings" + "time" + + errorsmod "cosmossdk.io/errors" + + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" +) + +// NewPacket constructs a new packet. +func NewPacket(sequence uint64, sourceChannel, destinationChannel string, timeoutTimestamp uint64, payloads ...Payload) Packet { + return Packet{ + Sequence: sequence, + SourceChannel: sourceChannel, + DestinationChannel: destinationChannel, + TimeoutTimestamp: timeoutTimestamp, + Payloads: payloads, + } +} + +// NewPayload constructs a new Payload +func NewPayload(sourcePort, destPort, version, encoding string, value []byte) Payload { + return Payload{ + SourcePort: sourcePort, + DestinationPort: destPort, + Version: version, + Encoding: encoding, + Value: value, + } +} + +// ValidateBasic validates that a Packet satisfies the basic requirements. +func (p Packet) ValidateBasic() error { + if len(p.Payloads) != 1 { + return errorsmod.Wrap(ErrInvalidPacket, "payloads must not be empty") + } + + for _, pd := range p.Payloads { + if err := pd.ValidateBasic(); err != nil { + return errorsmod.Wrap(err, "invalid Payload") + } + } + + if err := host.ChannelIdentifierValidator(p.SourceChannel); err != nil { + return errorsmod.Wrap(err, "invalid source channel ID") + } + if err := host.ChannelIdentifierValidator(p.DestinationChannel); err != nil { + return errorsmod.Wrap(err, "invalid destination channel ID") + } + + if p.Sequence == 0 { + return errorsmod.Wrap(ErrInvalidPacket, "packet sequence cannot be 0") + } + if p.TimeoutTimestamp == 0 { + return errorsmod.Wrap(ErrInvalidPacket, "packet timeout timestamp cannot be 0") + } + + return nil +} + +// ValidateBasic validates a Payload. +func (p Payload) ValidateBasic() error { + if err := host.PortIdentifierValidator(p.SourcePort); err != nil { + return errorsmod.Wrap(err, "invalid source port ID") + } + if err := host.PortIdentifierValidator(p.DestinationPort); err != nil { + return errorsmod.Wrap(err, "invalid destination port ID") + } + if strings.TrimSpace(p.Version) == "" { + return errorsmod.Wrap(ErrInvalidPayload, "payload version cannot be empty") + } + if strings.TrimSpace(p.Encoding) == "" { + return errorsmod.Wrap(ErrInvalidPayload, "payload encoding cannot be empty") + } + if len(p.Value) == 0 { + return errorsmod.Wrap(ErrInvalidPayload, "payload value cannot be empty") + } + return nil +} + +// TimeoutTimestampToNanos takes seconds as a uint64 and returns Unix nanoseconds as uint64. +func TimeoutTimestampToNanos(seconds uint64) uint64 { + return uint64(time.Unix(int64(seconds), 0).UnixNano()) +} diff --git a/modules/core/04-channel/v2/types/packet.pb.go b/modules/core/04-channel/v2/types/packet.pb.go new file mode 100644 index 00000000000..cb14c1e8880 --- /dev/null +++ b/modules/core/04-channel/v2/types/packet.pb.go @@ -0,0 +1,1337 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/channel/v2/packet.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/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 + +// PacketStatus specifies the status of a RecvPacketResult. +type PacketStatus int32 + +const ( + // PACKET_STATUS_UNSPECIFIED indicates an unknown packet status. + PacketStatus_NONE PacketStatus = 0 + // PACKET_STATUS_SUCCESS indicates a successful packet receipt. + PacketStatus_Success PacketStatus = 1 + // PACKET_STATUS_FAILURE indicates a failed packet receipt. + PacketStatus_Failure PacketStatus = 2 + // PACKET_STATUS_ASYNC indicates an async packet receipt. + PacketStatus_Async PacketStatus = 3 +) + +var PacketStatus_name = map[int32]string{ + 0: "PACKET_STATUS_UNSPECIFIED", + 1: "PACKET_STATUS_SUCCESS", + 2: "PACKET_STATUS_FAILURE", + 3: "PACKET_STATUS_ASYNC", +} + +var PacketStatus_value = map[string]int32{ + "PACKET_STATUS_UNSPECIFIED": 0, + "PACKET_STATUS_SUCCESS": 1, + "PACKET_STATUS_FAILURE": 2, + "PACKET_STATUS_ASYNC": 3, +} + +func (x PacketStatus) String() string { + return proto.EnumName(PacketStatus_name, int32(x)) +} + +func (PacketStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_2f814aba9ca97169, []int{0} +} + +// Packet defines a type that carries data across different chains through IBC +type Packet struct { + // number corresponds to the order of sends and receives, where a Packet + // with an earlier sequence number must be sent and received before a Packet + // with a later sequence number. + Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` + // identifies the sending chain. + SourceChannel string `protobuf:"bytes,2,opt,name=source_channel,json=sourceChannel,proto3" json:"source_channel,omitempty"` + // identifies the receiving chain. + DestinationChannel string `protobuf:"bytes,3,opt,name=destination_channel,json=destinationChannel,proto3" json:"destination_channel,omitempty"` + // timeout timestamp in seconds after which the packet times out. + TimeoutTimestamp uint64 `protobuf:"varint,4,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty"` + // a list of payloads, each one for a specific application. + Payloads []Payload `protobuf:"bytes,5,rep,name=payloads,proto3" json:"payloads"` +} + +func (m *Packet) Reset() { *m = Packet{} } +func (m *Packet) String() string { return proto.CompactTextString(m) } +func (*Packet) ProtoMessage() {} +func (*Packet) Descriptor() ([]byte, []int) { + return fileDescriptor_2f814aba9ca97169, []int{0} +} +func (m *Packet) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Packet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Packet.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 *Packet) XXX_Merge(src proto.Message) { + xxx_messageInfo_Packet.Merge(m, src) +} +func (m *Packet) XXX_Size() int { + return m.Size() +} +func (m *Packet) XXX_DiscardUnknown() { + xxx_messageInfo_Packet.DiscardUnknown(m) +} + +var xxx_messageInfo_Packet proto.InternalMessageInfo + +func (m *Packet) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +func (m *Packet) GetSourceChannel() string { + if m != nil { + return m.SourceChannel + } + return "" +} + +func (m *Packet) GetDestinationChannel() string { + if m != nil { + return m.DestinationChannel + } + return "" +} + +func (m *Packet) GetTimeoutTimestamp() uint64 { + if m != nil { + return m.TimeoutTimestamp + } + return 0 +} + +func (m *Packet) GetPayloads() []Payload { + if m != nil { + return m.Payloads + } + return nil +} + +// Payload contains the source and destination ports and payload for the application (version, encoding, raw bytes) +type Payload struct { + // specifies the source port of the packet. + SourcePort string `protobuf:"bytes,1,opt,name=source_port,json=sourcePort,proto3" json:"source_port,omitempty"` + // specifies the destination port of the packet. + DestinationPort string `protobuf:"bytes,2,opt,name=destination_port,json=destinationPort,proto3" json:"destination_port,omitempty"` + // version of the specified application. + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + // the encoding used for the provided value. + Encoding string `protobuf:"bytes,4,opt,name=encoding,proto3" json:"encoding,omitempty"` + // the raw bytes for the payload. + Value []byte `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *Payload) Reset() { *m = Payload{} } +func (m *Payload) String() string { return proto.CompactTextString(m) } +func (*Payload) ProtoMessage() {} +func (*Payload) Descriptor() ([]byte, []int) { + return fileDescriptor_2f814aba9ca97169, []int{1} +} +func (m *Payload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Payload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Payload.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 *Payload) XXX_Merge(src proto.Message) { + xxx_messageInfo_Payload.Merge(m, src) +} +func (m *Payload) XXX_Size() int { + return m.Size() +} +func (m *Payload) XXX_DiscardUnknown() { + xxx_messageInfo_Payload.DiscardUnknown(m) +} + +var xxx_messageInfo_Payload proto.InternalMessageInfo + +func (m *Payload) GetSourcePort() string { + if m != nil { + return m.SourcePort + } + return "" +} + +func (m *Payload) GetDestinationPort() string { + if m != nil { + return m.DestinationPort + } + return "" +} + +func (m *Payload) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +func (m *Payload) GetEncoding() string { + if m != nil { + return m.Encoding + } + return "" +} + +func (m *Payload) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +// Acknowledgement contains a list of all ack results associated with a single packet. +type Acknowledgement struct { + AppAcknowledgements [][]byte `protobuf:"bytes,1,rep,name=app_acknowledgements,json=appAcknowledgements,proto3" json:"app_acknowledgements,omitempty"` +} + +func (m *Acknowledgement) Reset() { *m = Acknowledgement{} } +func (m *Acknowledgement) String() string { return proto.CompactTextString(m) } +func (*Acknowledgement) ProtoMessage() {} +func (*Acknowledgement) Descriptor() ([]byte, []int) { + return fileDescriptor_2f814aba9ca97169, []int{2} +} +func (m *Acknowledgement) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Acknowledgement) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Acknowledgement.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 *Acknowledgement) XXX_Merge(src proto.Message) { + xxx_messageInfo_Acknowledgement.Merge(m, src) +} +func (m *Acknowledgement) XXX_Size() int { + return m.Size() +} +func (m *Acknowledgement) XXX_DiscardUnknown() { + xxx_messageInfo_Acknowledgement.DiscardUnknown(m) +} + +var xxx_messageInfo_Acknowledgement proto.InternalMessageInfo + +func (m *Acknowledgement) GetAppAcknowledgements() [][]byte { + if m != nil { + return m.AppAcknowledgements + } + return nil +} + +// RecvPacketResult speecifies the status of a packet as well as the acknowledgement bytes. +type RecvPacketResult struct { + // status of the packet + Status PacketStatus `protobuf:"varint,1,opt,name=status,proto3,enum=ibc.core.channel.v2.PacketStatus" json:"status,omitempty"` + // acknowledgement of the packet + Acknowledgement []byte `protobuf:"bytes,2,opt,name=acknowledgement,proto3" json:"acknowledgement,omitempty"` +} + +func (m *RecvPacketResult) Reset() { *m = RecvPacketResult{} } +func (m *RecvPacketResult) String() string { return proto.CompactTextString(m) } +func (*RecvPacketResult) ProtoMessage() {} +func (*RecvPacketResult) Descriptor() ([]byte, []int) { + return fileDescriptor_2f814aba9ca97169, []int{3} +} +func (m *RecvPacketResult) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RecvPacketResult) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RecvPacketResult.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 *RecvPacketResult) XXX_Merge(src proto.Message) { + xxx_messageInfo_RecvPacketResult.Merge(m, src) +} +func (m *RecvPacketResult) XXX_Size() int { + return m.Size() +} +func (m *RecvPacketResult) XXX_DiscardUnknown() { + xxx_messageInfo_RecvPacketResult.DiscardUnknown(m) +} + +var xxx_messageInfo_RecvPacketResult proto.InternalMessageInfo + +func (m *RecvPacketResult) GetStatus() PacketStatus { + if m != nil { + return m.Status + } + return PacketStatus_NONE +} + +func (m *RecvPacketResult) GetAcknowledgement() []byte { + if m != nil { + return m.Acknowledgement + } + return nil +} + +func init() { + proto.RegisterEnum("ibc.core.channel.v2.PacketStatus", PacketStatus_name, PacketStatus_value) + proto.RegisterType((*Packet)(nil), "ibc.core.channel.v2.Packet") + proto.RegisterType((*Payload)(nil), "ibc.core.channel.v2.Payload") + proto.RegisterType((*Acknowledgement)(nil), "ibc.core.channel.v2.Acknowledgement") + proto.RegisterType((*RecvPacketResult)(nil), "ibc.core.channel.v2.RecvPacketResult") +} + +func init() { proto.RegisterFile("ibc/core/channel/v2/packet.proto", fileDescriptor_2f814aba9ca97169) } + +var fileDescriptor_2f814aba9ca97169 = []byte{ + // 587 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0xc7, 0xeb, 0xb5, 0xdd, 0x56, 0xaf, 0x6c, 0xc1, 0x1d, 0x52, 0xa8, 0x50, 0x17, 0x2a, 0x01, + 0x05, 0xb4, 0x04, 0x0a, 0x97, 0x49, 0x08, 0xa9, 0xcb, 0x32, 0x69, 0x02, 0x95, 0xca, 0x69, 0x91, + 0xe0, 0x52, 0xb9, 0xae, 0x95, 0x45, 0x4b, 0xe2, 0x10, 0x3b, 0x99, 0xf6, 0x0a, 0x3b, 0xf1, 0x02, + 0x3b, 0x70, 0xe6, 0x45, 0x76, 0xdc, 0x91, 0x13, 0x42, 0xdb, 0x89, 0xb7, 0x40, 0x75, 0xb2, 0xaa, + 0x1b, 0x70, 0x4a, 0xbe, 0xff, 0xf7, 0xfb, 0xdb, 0xfa, 0x7f, 0xd6, 0x07, 0x0d, 0x7f, 0x42, 0x2d, + 0xca, 0x13, 0x66, 0xd1, 0x43, 0x12, 0x45, 0x2c, 0xb0, 0xb2, 0xae, 0x15, 0x13, 0x7a, 0xc4, 0xa4, + 0x19, 0x27, 0x5c, 0x72, 0xd4, 0xf0, 0x27, 0xd4, 0x9c, 0x11, 0x66, 0x41, 0x98, 0x59, 0xb7, 0xb9, + 0xe9, 0x71, 0x8f, 0xab, 0xbe, 0x35, 0xfb, 0xcb, 0xd1, 0xf6, 0x6f, 0x00, 0x97, 0x07, 0xca, 0x8b, + 0x9a, 0x70, 0x55, 0xb0, 0x2f, 0x29, 0x8b, 0x28, 0xd3, 0x81, 0x01, 0x3a, 0x15, 0x3c, 0xaf, 0xd1, + 0x23, 0xb8, 0x2e, 0x78, 0x9a, 0x50, 0x36, 0x2e, 0x4e, 0xd4, 0x97, 0x0c, 0xd0, 0xa9, 0xe1, 0x3b, + 0xb9, 0x6a, 0xe7, 0x22, 0xb2, 0x60, 0x63, 0xca, 0x84, 0xf4, 0x23, 0x22, 0x7d, 0x1e, 0xcd, 0xd9, + 0xb2, 0x62, 0xd1, 0x42, 0xeb, 0xda, 0xf0, 0x1c, 0xde, 0x95, 0x7e, 0xc8, 0x78, 0x2a, 0xc7, 0xb3, + 0xaf, 0x90, 0x24, 0x8c, 0xf5, 0x8a, 0xba, 0x5c, 0x2b, 0x1a, 0xc3, 0x6b, 0x1d, 0xbd, 0x85, 0xab, + 0x31, 0x39, 0x09, 0x38, 0x99, 0x0a, 0xbd, 0x6a, 0x94, 0x3b, 0x6b, 0xdd, 0x07, 0xe6, 0x3f, 0x92, + 0x9a, 0x83, 0x1c, 0xda, 0xad, 0x9c, 0xff, 0xdc, 0x2a, 0xe1, 0xb9, 0xa7, 0xfd, 0x0d, 0xc0, 0x95, + 0xa2, 0x87, 0xb6, 0xe0, 0x5a, 0x11, 0x28, 0xe6, 0x89, 0x54, 0x79, 0x6b, 0x18, 0xe6, 0xd2, 0x80, + 0x27, 0x12, 0x3d, 0x85, 0xda, 0x62, 0x14, 0x45, 0xe5, 0x99, 0x37, 0x16, 0x74, 0x85, 0xea, 0x70, + 0x25, 0x63, 0x89, 0xf0, 0x79, 0x54, 0x24, 0xbd, 0x2e, 0x67, 0x23, 0x65, 0x11, 0xe5, 0x53, 0x3f, + 0xf2, 0x54, 0xaa, 0x1a, 0x9e, 0xd7, 0x68, 0x13, 0x56, 0x33, 0x12, 0xa4, 0x4c, 0xaf, 0x1a, 0xa0, + 0x53, 0xc7, 0x79, 0xd1, 0xde, 0x83, 0x1b, 0x3d, 0x7a, 0x14, 0xf1, 0xe3, 0x80, 0x4d, 0x3d, 0x16, + 0xb2, 0x48, 0xa2, 0x97, 0x70, 0x93, 0xc4, 0xf1, 0x98, 0xdc, 0x94, 0x85, 0x0e, 0x8c, 0x72, 0xa7, + 0x8e, 0x1b, 0x24, 0x8e, 0x6f, 0x39, 0x44, 0xfb, 0x18, 0x6a, 0x98, 0xd1, 0x2c, 0x7f, 0x58, 0xcc, + 0x44, 0x1a, 0x48, 0xb4, 0x03, 0x97, 0x85, 0x24, 0x32, 0x15, 0x2a, 0xec, 0x7a, 0xf7, 0xe1, 0x7f, + 0x66, 0x37, 0xb3, 0xb8, 0x0a, 0xc4, 0x85, 0x01, 0x75, 0xe0, 0xc6, 0xad, 0xdb, 0xd5, 0x28, 0xea, + 0xf8, 0xb6, 0xfc, 0xec, 0x3b, 0x80, 0xf5, 0xc5, 0x23, 0xd0, 0x13, 0x78, 0x7f, 0xd0, 0xb3, 0xdf, + 0x39, 0xc3, 0xb1, 0x3b, 0xec, 0x0d, 0x47, 0xee, 0x78, 0xd4, 0x77, 0x07, 0x8e, 0x7d, 0xb0, 0x7f, + 0xe0, 0xec, 0x69, 0xa5, 0xe6, 0xea, 0xe9, 0x99, 0x51, 0xe9, 0x7f, 0xe8, 0x3b, 0xe8, 0x31, 0xbc, + 0x77, 0x13, 0x74, 0x47, 0xb6, 0xed, 0xb8, 0xae, 0x06, 0x9a, 0x6b, 0xa7, 0x67, 0xc6, 0x8a, 0x9b, + 0x52, 0xca, 0x84, 0xf8, 0x9b, 0xdb, 0xef, 0x1d, 0xbc, 0x1f, 0x61, 0x47, 0x5b, 0xca, 0xb9, 0x7d, + 0xe2, 0x07, 0x69, 0xc2, 0x50, 0x1b, 0x36, 0x6e, 0x72, 0x3d, 0xf7, 0x53, 0xdf, 0xd6, 0xca, 0xcd, + 0xda, 0xe9, 0x99, 0x51, 0xed, 0x89, 0x93, 0x88, 0xee, 0x7e, 0x3c, 0xbf, 0x6c, 0x81, 0x8b, 0xcb, + 0x16, 0xf8, 0x75, 0xd9, 0x02, 0x5f, 0xaf, 0x5a, 0xa5, 0x8b, 0xab, 0x56, 0xe9, 0xc7, 0x55, 0xab, + 0xf4, 0xf9, 0x8d, 0xe7, 0xcb, 0xc3, 0x74, 0x62, 0x52, 0x1e, 0x5a, 0x94, 0x8b, 0x90, 0x0b, 0xcb, + 0x9f, 0xd0, 0x6d, 0x8f, 0x5b, 0xd9, 0x8e, 0x15, 0xf2, 0x69, 0x1a, 0x30, 0x91, 0xef, 0xe0, 0x8b, + 0xd7, 0xdb, 0x0b, 0x6b, 0x28, 0x4f, 0x62, 0x26, 0x26, 0xcb, 0x6a, 0xb7, 0x5e, 0xfd, 0x09, 0x00, + 0x00, 0xff, 0xff, 0x23, 0xd8, 0x40, 0xe5, 0xaa, 0x03, 0x00, 0x00, +} + +func (m *Packet) 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 *Packet) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Packet) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Payloads) > 0 { + for iNdEx := len(m.Payloads) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Payloads[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPacket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if m.TimeoutTimestamp != 0 { + i = encodeVarintPacket(dAtA, i, uint64(m.TimeoutTimestamp)) + i-- + dAtA[i] = 0x20 + } + if len(m.DestinationChannel) > 0 { + i -= len(m.DestinationChannel) + copy(dAtA[i:], m.DestinationChannel) + i = encodeVarintPacket(dAtA, i, uint64(len(m.DestinationChannel))) + i-- + dAtA[i] = 0x1a + } + if len(m.SourceChannel) > 0 { + i -= len(m.SourceChannel) + copy(dAtA[i:], m.SourceChannel) + i = encodeVarintPacket(dAtA, i, uint64(len(m.SourceChannel))) + i-- + dAtA[i] = 0x12 + } + if m.Sequence != 0 { + i = encodeVarintPacket(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Payload) 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 *Payload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Payload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x2a + } + if len(m.Encoding) > 0 { + i -= len(m.Encoding) + copy(dAtA[i:], m.Encoding) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Encoding))) + i-- + dAtA[i] = 0x22 + } + if len(m.Version) > 0 { + i -= len(m.Version) + copy(dAtA[i:], m.Version) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Version))) + i-- + dAtA[i] = 0x1a + } + if len(m.DestinationPort) > 0 { + i -= len(m.DestinationPort) + copy(dAtA[i:], m.DestinationPort) + i = encodeVarintPacket(dAtA, i, uint64(len(m.DestinationPort))) + i-- + dAtA[i] = 0x12 + } + if len(m.SourcePort) > 0 { + i -= len(m.SourcePort) + copy(dAtA[i:], m.SourcePort) + i = encodeVarintPacket(dAtA, i, uint64(len(m.SourcePort))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Acknowledgement) 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 *Acknowledgement) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Acknowledgement) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AppAcknowledgements) > 0 { + for iNdEx := len(m.AppAcknowledgements) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AppAcknowledgements[iNdEx]) + copy(dAtA[i:], m.AppAcknowledgements[iNdEx]) + i = encodeVarintPacket(dAtA, i, uint64(len(m.AppAcknowledgements[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *RecvPacketResult) 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 *RecvPacketResult) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RecvPacketResult) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Acknowledgement) > 0 { + i -= len(m.Acknowledgement) + copy(dAtA[i:], m.Acknowledgement) + i = encodeVarintPacket(dAtA, i, uint64(len(m.Acknowledgement))) + i-- + dAtA[i] = 0x12 + } + if m.Status != 0 { + i = encodeVarintPacket(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x8 + } + 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 *Packet) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sequence != 0 { + n += 1 + sovPacket(uint64(m.Sequence)) + } + l = len(m.SourceChannel) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.DestinationChannel) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + if m.TimeoutTimestamp != 0 { + n += 1 + sovPacket(uint64(m.TimeoutTimestamp)) + } + if len(m.Payloads) > 0 { + for _, e := range m.Payloads { + l = e.Size() + n += 1 + l + sovPacket(uint64(l)) + } + } + return n +} + +func (m *Payload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SourcePort) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.DestinationPort) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.Version) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.Encoding) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovPacket(uint64(l)) + } + return n +} + +func (m *Acknowledgement) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.AppAcknowledgements) > 0 { + for _, b := range m.AppAcknowledgements { + l = len(b) + n += 1 + l + sovPacket(uint64(l)) + } + } + return n +} + +func (m *RecvPacketResult) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Status != 0 { + n += 1 + sovPacket(uint64(m.Status)) + } + l = len(m.Acknowledgement) + 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 *Packet) 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: Packet: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Packet: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourceChannel", 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.SourceChannel = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DestinationChannel", 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.DestinationChannel = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutTimestamp", wireType) + } + m.TimeoutTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutTimestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payloads", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payloads = append(m.Payloads, Payload{}) + if err := m.Payloads[len(m.Payloads)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 (m *Payload) 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: Payload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Payload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourcePort", 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.SourcePort = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DestinationPort", 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.DestinationPort = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", 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.Version = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Encoding", 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.Encoding = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) + if m.Value == nil { + m.Value = []byte{} + } + 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 (m *Acknowledgement) 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: Acknowledgement: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Acknowledgement: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AppAcknowledgements", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AppAcknowledgements = append(m.AppAcknowledgements, make([]byte, postIndex-iNdEx)) + copy(m.AppAcknowledgements[len(m.AppAcknowledgements)-1], 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 (m *RecvPacketResult) 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: RecvPacketResult: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RecvPacketResult: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= PacketStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Acknowledgement", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPacket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPacket + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPacket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Acknowledgement = append(m.Acknowledgement[:0], dAtA[iNdEx:postIndex]...) + if m.Acknowledgement == nil { + m.Acknowledgement = []byte{} + } + 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/core/04-channel/v2/types/packet_test.go b/modules/core/04-channel/v2/types/packet_test.go new file mode 100644 index 00000000000..4952e03671d --- /dev/null +++ b/modules/core/04-channel/v2/types/packet_test.go @@ -0,0 +1,127 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + "github.com/cosmos/ibc-go/v9/testing/mock" +) + +// TestValidateBasic tests the ValidateBasic function of Packet +func TestValidateBasic(t *testing.T) { + var packet types.Packet + testCases := []struct { + name string + malleate func() + expErr error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: payloads is nil", + func() { + packet.Payloads = nil + }, + types.ErrInvalidPacket, + }, + { + "failure: empty payload", + func() { + packet.Payloads = []types.Payload{} + }, + types.ErrInvalidPacket, + }, + { + "failure: invalid payload source port ID", + func() { + packet.Payloads[0].SourcePort = "" + }, + host.ErrInvalidID, + }, + { + "failure: invalid payload dest port ID", + func() { + packet.Payloads[0].DestinationPort = "" + }, + host.ErrInvalidID, + }, + { + "failure: invalid source channel ID", + func() { + packet.SourceChannel = "" + }, + host.ErrInvalidID, + }, + { + "failure: invalid dest channel ID", + func() { + packet.DestinationChannel = "" + }, + host.ErrInvalidID, + }, + { + "failure: invalid sequence", + func() { + packet.Sequence = 0 + }, + types.ErrInvalidPacket, + }, + { + "failure: invalid timestamp", + func() { + packet.TimeoutTimestamp = 0 + }, + types.ErrInvalidPacket, + }, + { + "failure: empty version", + func() { + packet.Payloads[0].Version = "" + }, + types.ErrInvalidPayload, + }, + { + "failure: empty encoding", + func() { + packet.Payloads[0].Encoding = "" + }, + types.ErrInvalidPayload, + }, + { + "failure: empty value", + func() { + packet.Payloads[0].Value = []byte{} + }, + types.ErrInvalidPayload, + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + packet = types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, uint64(time.Now().Unix()), types.Payload{ + SourcePort: ibctesting.MockPort, + DestinationPort: ibctesting.MockPort, + Version: "ics20-v2", + Encoding: transfertypes.EncodingProtobuf, + Value: mock.MockPacketData, + }) + + tc.malleate() + + err := packet.ValidateBasic() + if tc.expErr == nil { + require.NoError(t, err) + } else { + require.ErrorIs(t, err, tc.expErr) + } + }) + } +} diff --git a/modules/core/04-channel/v2/types/query.go b/modules/core/04-channel/v2/types/query.go new file mode 100644 index 00000000000..b02d0275537 --- /dev/null +++ b/modules/core/04-channel/v2/types/query.go @@ -0,0 +1,94 @@ +package types + +import clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + +// NewQueryChannelRequest creates and returns a new channel query request. +func NewQueryChannelRequest(channelID string) *QueryChannelRequest { + return &QueryChannelRequest{ + ChannelId: channelID, + } +} + +// NewQueryChannelResponse creates and returns a new channel query response. +func NewQueryChannelResponse(channel Channel) *QueryChannelResponse { + return &QueryChannelResponse{ + Channel: channel, + } +} + +// NewQueryNextSequenceSendRequest creates a new next sequence send query. +func NewQueryNextSequenceSendRequest(channelID string) *QueryNextSequenceSendRequest { + return &QueryNextSequenceSendRequest{ + ChannelId: channelID, + } +} + +// NewQueryNextSequenceSendResponse creates a new QueryNextSequenceSendResponse instance +func NewQueryNextSequenceSendResponse( + sequence uint64, proof []byte, height clienttypes.Height, +) *QueryNextSequenceSendResponse { + return &QueryNextSequenceSendResponse{ + NextSequenceSend: sequence, + Proof: proof, + ProofHeight: height, + } +} + +// NewQueryPacketCommitmentRequest creates and returns a new packet commitment query request. +func NewQueryPacketCommitmentRequest(channelID string, sequence uint64) *QueryPacketCommitmentRequest { + return &QueryPacketCommitmentRequest{ + ChannelId: channelID, + Sequence: sequence, + } +} + +// NewQueryPacketCommitmentResponse creates and returns a new packet commitment query response. +func NewQueryPacketCommitmentResponse(commitmentHash []byte, proof []byte, proofHeight clienttypes.Height) *QueryPacketCommitmentResponse { + return &QueryPacketCommitmentResponse{ + Commitment: commitmentHash, + Proof: proof, + ProofHeight: proofHeight, + } +} + +// NewQueryPacketAcknowledgementRequest creates and returns a new packet acknowledgement query request. +func NewQueryPacketAcknowledgementRequest(channelID string, sequence uint64) *QueryPacketAcknowledgementRequest { + return &QueryPacketAcknowledgementRequest{ + ChannelId: channelID, + Sequence: sequence, + } +} + +// NewQueryPacketAcknowledgementResponse creates and returns a new packet acknowledgement query response. +func NewQueryPacketAcknowledgementResponse(acknowledgementHash []byte, proof []byte, proofHeight clienttypes.Height) *QueryPacketAcknowledgementResponse { + return &QueryPacketAcknowledgementResponse{ + Acknowledgement: acknowledgementHash, + Proof: proof, + ProofHeight: proofHeight, + } +} + +// NewQueryPacketReceiptRequest creates and returns a new packet receipt query request. +func NewQueryPacketReceiptRequest(channelID string, sequence uint64) *QueryPacketReceiptRequest { + return &QueryPacketReceiptRequest{ + ChannelId: channelID, + Sequence: sequence, + } +} + +// NewQueryPacketReceiptResponse creates and returns a new packet receipt query response. +func NewQueryPacketReceiptResponse(exists bool, proof []byte, height clienttypes.Height) *QueryPacketReceiptResponse { + return &QueryPacketReceiptResponse{ + Received: exists, + Proof: proof, + ProofHeight: height, + } +} + +// NewQueryPacketReceiptRequest creates and returns a new packet receipt query request. +func NewQueryUnreceivedPacketsRequest(channelID string, sequences []uint64) *QueryUnreceivedPacketsRequest { + return &QueryUnreceivedPacketsRequest{ + ChannelId: channelID, + Sequences: sequences, + } +} diff --git a/modules/core/04-channel/v2/types/query.pb.go b/modules/core/04-channel/v2/types/query.pb.go new file mode 100644 index 00000000000..4fbbf60c8f7 --- /dev/null +++ b/modules/core/04-channel/v2/types/query.pb.go @@ -0,0 +1,4512 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/channel/v2/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// QueryChannelRequest is the request type for the Query/Channel RPC method +type QueryChannelRequest struct { + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *QueryChannelRequest) Reset() { *m = QueryChannelRequest{} } +func (m *QueryChannelRequest) String() string { return proto.CompactTextString(m) } +func (*QueryChannelRequest) ProtoMessage() {} +func (*QueryChannelRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{0} +} +func (m *QueryChannelRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryChannelRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryChannelRequest.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 *QueryChannelRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryChannelRequest.Merge(m, src) +} +func (m *QueryChannelRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryChannelRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryChannelRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryChannelRequest proto.InternalMessageInfo + +func (m *QueryChannelRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +// QueryChannelRequest is the response type for the Query/Channel RPC method +type QueryChannelResponse struct { + // the channel associated with the provided channel id + Channel Channel `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel"` +} + +func (m *QueryChannelResponse) Reset() { *m = QueryChannelResponse{} } +func (m *QueryChannelResponse) String() string { return proto.CompactTextString(m) } +func (*QueryChannelResponse) ProtoMessage() {} +func (*QueryChannelResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{1} +} +func (m *QueryChannelResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryChannelResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryChannelResponse.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 *QueryChannelResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryChannelResponse.Merge(m, src) +} +func (m *QueryChannelResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryChannelResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryChannelResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryChannelResponse proto.InternalMessageInfo + +func (m *QueryChannelResponse) GetChannel() Channel { + if m != nil { + return m.Channel + } + return Channel{} +} + +// QueryNextSequenceSendRequest is the request type for the Query/QueryNextSequenceSend RPC method +type QueryNextSequenceSendRequest struct { + // channel unique identifier + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *QueryNextSequenceSendRequest) Reset() { *m = QueryNextSequenceSendRequest{} } +func (m *QueryNextSequenceSendRequest) String() string { return proto.CompactTextString(m) } +func (*QueryNextSequenceSendRequest) ProtoMessage() {} +func (*QueryNextSequenceSendRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{2} +} +func (m *QueryNextSequenceSendRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryNextSequenceSendRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryNextSequenceSendRequest.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 *QueryNextSequenceSendRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryNextSequenceSendRequest.Merge(m, src) +} +func (m *QueryNextSequenceSendRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryNextSequenceSendRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryNextSequenceSendRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryNextSequenceSendRequest proto.InternalMessageInfo + +func (m *QueryNextSequenceSendRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +// QueryNextSequenceSendResponse is the response type for the Query/QueryNextSequenceSend RPC method +type QueryNextSequenceSendResponse struct { + // next sequence send number + NextSequenceSend uint64 `protobuf:"varint,1,opt,name=next_sequence_send,json=nextSequenceSend,proto3" json:"next_sequence_send,omitempty"` + // merkle proof of existence + Proof []byte `protobuf:"bytes,2,opt,name=proof,proto3" json:"proof,omitempty"` + // height at which the proof was retrieved + ProofHeight types.Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` +} + +func (m *QueryNextSequenceSendResponse) Reset() { *m = QueryNextSequenceSendResponse{} } +func (m *QueryNextSequenceSendResponse) String() string { return proto.CompactTextString(m) } +func (*QueryNextSequenceSendResponse) ProtoMessage() {} +func (*QueryNextSequenceSendResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{3} +} +func (m *QueryNextSequenceSendResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryNextSequenceSendResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryNextSequenceSendResponse.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 *QueryNextSequenceSendResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryNextSequenceSendResponse.Merge(m, src) +} +func (m *QueryNextSequenceSendResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryNextSequenceSendResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryNextSequenceSendResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryNextSequenceSendResponse proto.InternalMessageInfo + +func (m *QueryNextSequenceSendResponse) GetNextSequenceSend() uint64 { + if m != nil { + return m.NextSequenceSend + } + return 0 +} + +func (m *QueryNextSequenceSendResponse) GetProof() []byte { + if m != nil { + return m.Proof + } + return nil +} + +func (m *QueryNextSequenceSendResponse) GetProofHeight() types.Height { + if m != nil { + return m.ProofHeight + } + return types.Height{} +} + +// QueryPacketCommitmentRequest is the request type for the Query/PacketCommitment RPC method. +type QueryPacketCommitmentRequest struct { + // channel unique identifier + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // packet sequence + Sequence uint64 `protobuf:"varint,2,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *QueryPacketCommitmentRequest) Reset() { *m = QueryPacketCommitmentRequest{} } +func (m *QueryPacketCommitmentRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPacketCommitmentRequest) ProtoMessage() {} +func (*QueryPacketCommitmentRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{4} +} +func (m *QueryPacketCommitmentRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketCommitmentRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketCommitmentRequest.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 *QueryPacketCommitmentRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketCommitmentRequest.Merge(m, src) +} +func (m *QueryPacketCommitmentRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketCommitmentRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketCommitmentRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketCommitmentRequest proto.InternalMessageInfo + +func (m *QueryPacketCommitmentRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *QueryPacketCommitmentRequest) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +// QueryPacketCommitmentResponse is the response type for the Query/PacketCommitment RPC method. +type QueryPacketCommitmentResponse struct { + // packet associated with the request fields + Commitment []byte `protobuf:"bytes,1,opt,name=commitment,proto3" json:"commitment,omitempty"` + // merkle proof of existence + Proof []byte `protobuf:"bytes,2,opt,name=proof,proto3" json:"proof,omitempty"` + // height at which the proof was retrieved + ProofHeight types.Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` +} + +func (m *QueryPacketCommitmentResponse) Reset() { *m = QueryPacketCommitmentResponse{} } +func (m *QueryPacketCommitmentResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPacketCommitmentResponse) ProtoMessage() {} +func (*QueryPacketCommitmentResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{5} +} +func (m *QueryPacketCommitmentResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketCommitmentResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketCommitmentResponse.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 *QueryPacketCommitmentResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketCommitmentResponse.Merge(m, src) +} +func (m *QueryPacketCommitmentResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketCommitmentResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketCommitmentResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketCommitmentResponse proto.InternalMessageInfo + +func (m *QueryPacketCommitmentResponse) GetCommitment() []byte { + if m != nil { + return m.Commitment + } + return nil +} + +func (m *QueryPacketCommitmentResponse) GetProof() []byte { + if m != nil { + return m.Proof + } + return nil +} + +func (m *QueryPacketCommitmentResponse) GetProofHeight() types.Height { + if m != nil { + return m.ProofHeight + } + return types.Height{} +} + +// QueryPacketCommitmentsRequest is the request type for the Query/PacketCommitments RPC method. +type QueryPacketCommitmentsRequest struct { + // channel unique identifier + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // pagination request + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPacketCommitmentsRequest) Reset() { *m = QueryPacketCommitmentsRequest{} } +func (m *QueryPacketCommitmentsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPacketCommitmentsRequest) ProtoMessage() {} +func (*QueryPacketCommitmentsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{6} +} +func (m *QueryPacketCommitmentsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketCommitmentsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketCommitmentsRequest.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 *QueryPacketCommitmentsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketCommitmentsRequest.Merge(m, src) +} +func (m *QueryPacketCommitmentsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketCommitmentsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketCommitmentsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketCommitmentsRequest proto.InternalMessageInfo + +func (m *QueryPacketCommitmentsRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *QueryPacketCommitmentsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryPacketCommitmentResponse is the response type for the Query/PacketCommitment RPC method. +type QueryPacketCommitmentsResponse struct { + // collection of packet commitments for the requested channel identifier. + Commitments []*PacketState `protobuf:"bytes,1,rep,name=commitments,proto3" json:"commitments,omitempty"` + // pagination response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` + // query block height. + Height types.Height `protobuf:"bytes,3,opt,name=height,proto3" json:"height"` +} + +func (m *QueryPacketCommitmentsResponse) Reset() { *m = QueryPacketCommitmentsResponse{} } +func (m *QueryPacketCommitmentsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPacketCommitmentsResponse) ProtoMessage() {} +func (*QueryPacketCommitmentsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{7} +} +func (m *QueryPacketCommitmentsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketCommitmentsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketCommitmentsResponse.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 *QueryPacketCommitmentsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketCommitmentsResponse.Merge(m, src) +} +func (m *QueryPacketCommitmentsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketCommitmentsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketCommitmentsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketCommitmentsResponse proto.InternalMessageInfo + +func (m *QueryPacketCommitmentsResponse) GetCommitments() []*PacketState { + if m != nil { + return m.Commitments + } + return nil +} + +func (m *QueryPacketCommitmentsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func (m *QueryPacketCommitmentsResponse) GetHeight() types.Height { + if m != nil { + return m.Height + } + return types.Height{} +} + +// QueryPacketAcknowledgementRequest is the request type for the Query/PacketAcknowledgement RPC method. +type QueryPacketAcknowledgementRequest struct { + // channel unique identifier + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // packet sequence + Sequence uint64 `protobuf:"varint,2,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *QueryPacketAcknowledgementRequest) Reset() { *m = QueryPacketAcknowledgementRequest{} } +func (m *QueryPacketAcknowledgementRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPacketAcknowledgementRequest) ProtoMessage() {} +func (*QueryPacketAcknowledgementRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{8} +} +func (m *QueryPacketAcknowledgementRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketAcknowledgementRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketAcknowledgementRequest.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 *QueryPacketAcknowledgementRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketAcknowledgementRequest.Merge(m, src) +} +func (m *QueryPacketAcknowledgementRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketAcknowledgementRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketAcknowledgementRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketAcknowledgementRequest proto.InternalMessageInfo + +func (m *QueryPacketAcknowledgementRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *QueryPacketAcknowledgementRequest) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +// QueryPacketAcknowledgementResponse is the response type for the Query/PacketAcknowledgement RPC method. +type QueryPacketAcknowledgementResponse struct { + // acknowledgement associated with the request fields + Acknowledgement []byte `protobuf:"bytes,1,opt,name=acknowledgement,proto3" json:"acknowledgement,omitempty"` + // merkle proof of existence + Proof []byte `protobuf:"bytes,2,opt,name=proof,proto3" json:"proof,omitempty"` + // height at which the proof was retrieved + ProofHeight types.Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` +} + +func (m *QueryPacketAcknowledgementResponse) Reset() { *m = QueryPacketAcknowledgementResponse{} } +func (m *QueryPacketAcknowledgementResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPacketAcknowledgementResponse) ProtoMessage() {} +func (*QueryPacketAcknowledgementResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{9} +} +func (m *QueryPacketAcknowledgementResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketAcknowledgementResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketAcknowledgementResponse.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 *QueryPacketAcknowledgementResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketAcknowledgementResponse.Merge(m, src) +} +func (m *QueryPacketAcknowledgementResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketAcknowledgementResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketAcknowledgementResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketAcknowledgementResponse proto.InternalMessageInfo + +func (m *QueryPacketAcknowledgementResponse) GetAcknowledgement() []byte { + if m != nil { + return m.Acknowledgement + } + return nil +} + +func (m *QueryPacketAcknowledgementResponse) GetProof() []byte { + if m != nil { + return m.Proof + } + return nil +} + +func (m *QueryPacketAcknowledgementResponse) GetProofHeight() types.Height { + if m != nil { + return m.ProofHeight + } + return types.Height{} +} + +// QueryPacketReceiptRequest is the request type for the Query/PacketReceipt RPC method. +type QueryPacketReceiptRequest struct { + // port unique identifier + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + // channel unique identifier + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // packet sequence + Sequence uint64 `protobuf:"varint,3,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *QueryPacketReceiptRequest) Reset() { *m = QueryPacketReceiptRequest{} } +func (m *QueryPacketReceiptRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPacketReceiptRequest) ProtoMessage() {} +func (*QueryPacketReceiptRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{10} +} +func (m *QueryPacketReceiptRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketReceiptRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketReceiptRequest.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 *QueryPacketReceiptRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketReceiptRequest.Merge(m, src) +} +func (m *QueryPacketReceiptRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketReceiptRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketReceiptRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketReceiptRequest proto.InternalMessageInfo + +func (m *QueryPacketReceiptRequest) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *QueryPacketReceiptRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *QueryPacketReceiptRequest) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +// QueryPacketReceiptResponse is the response type for the Query/PacketReceipt RPC method. +type QueryPacketReceiptResponse struct { + // success flag for if receipt exists + Received bool `protobuf:"varint,2,opt,name=received,proto3" json:"received,omitempty"` + // merkle proof of existence or absence + Proof []byte `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` + // height at which the proof was retrieved + ProofHeight types.Height `protobuf:"bytes,4,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` +} + +func (m *QueryPacketReceiptResponse) Reset() { *m = QueryPacketReceiptResponse{} } +func (m *QueryPacketReceiptResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPacketReceiptResponse) ProtoMessage() {} +func (*QueryPacketReceiptResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{11} +} +func (m *QueryPacketReceiptResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPacketReceiptResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPacketReceiptResponse.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 *QueryPacketReceiptResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPacketReceiptResponse.Merge(m, src) +} +func (m *QueryPacketReceiptResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPacketReceiptResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPacketReceiptResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPacketReceiptResponse proto.InternalMessageInfo + +func (m *QueryPacketReceiptResponse) GetReceived() bool { + if m != nil { + return m.Received + } + return false +} + +func (m *QueryPacketReceiptResponse) GetProof() []byte { + if m != nil { + return m.Proof + } + return nil +} + +func (m *QueryPacketReceiptResponse) GetProofHeight() types.Height { + if m != nil { + return m.ProofHeight + } + return types.Height{} +} + +// QueryUnreceivedPacketsRequest is the request type for the Query/UnreceivedPackets RPC method +type QueryUnreceivedPacketsRequest struct { + // channel unique identifier + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // list of packet sequences + Sequences []uint64 `protobuf:"varint,2,rep,packed,name=sequences,proto3" json:"sequences,omitempty"` +} + +func (m *QueryUnreceivedPacketsRequest) Reset() { *m = QueryUnreceivedPacketsRequest{} } +func (m *QueryUnreceivedPacketsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryUnreceivedPacketsRequest) ProtoMessage() {} +func (*QueryUnreceivedPacketsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{12} +} +func (m *QueryUnreceivedPacketsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUnreceivedPacketsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUnreceivedPacketsRequest.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 *QueryUnreceivedPacketsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUnreceivedPacketsRequest.Merge(m, src) +} +func (m *QueryUnreceivedPacketsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryUnreceivedPacketsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUnreceivedPacketsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUnreceivedPacketsRequest proto.InternalMessageInfo + +func (m *QueryUnreceivedPacketsRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *QueryUnreceivedPacketsRequest) GetSequences() []uint64 { + if m != nil { + return m.Sequences + } + return nil +} + +// QueryUnreceivedPacketsResponse is the response type for the Query/UnreceivedPacketCommitments RPC method +type QueryUnreceivedPacketsResponse struct { + // list of unreceived packet sequences + Sequences []uint64 `protobuf:"varint,1,rep,packed,name=sequences,proto3" json:"sequences,omitempty"` + // query block height + Height types.Height `protobuf:"bytes,2,opt,name=height,proto3" json:"height"` +} + +func (m *QueryUnreceivedPacketsResponse) Reset() { *m = QueryUnreceivedPacketsResponse{} } +func (m *QueryUnreceivedPacketsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryUnreceivedPacketsResponse) ProtoMessage() {} +func (*QueryUnreceivedPacketsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{13} +} +func (m *QueryUnreceivedPacketsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUnreceivedPacketsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUnreceivedPacketsResponse.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 *QueryUnreceivedPacketsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUnreceivedPacketsResponse.Merge(m, src) +} +func (m *QueryUnreceivedPacketsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryUnreceivedPacketsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUnreceivedPacketsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUnreceivedPacketsResponse proto.InternalMessageInfo + +func (m *QueryUnreceivedPacketsResponse) GetSequences() []uint64 { + if m != nil { + return m.Sequences + } + return nil +} + +func (m *QueryUnreceivedPacketsResponse) GetHeight() types.Height { + if m != nil { + return m.Height + } + return types.Height{} +} + +// QueryUnreceivedAcks is the request type for the +// Query/UnreceivedAcks RPC method +type QueryUnreceivedAcksRequest struct { + // channel unique identifier + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // list of acknowledgement sequences + PacketAckSequences []uint64 `protobuf:"varint,2,rep,packed,name=packet_ack_sequences,json=packetAckSequences,proto3" json:"packet_ack_sequences,omitempty"` +} + +func (m *QueryUnreceivedAcksRequest) Reset() { *m = QueryUnreceivedAcksRequest{} } +func (m *QueryUnreceivedAcksRequest) String() string { return proto.CompactTextString(m) } +func (*QueryUnreceivedAcksRequest) ProtoMessage() {} +func (*QueryUnreceivedAcksRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{14} +} +func (m *QueryUnreceivedAcksRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUnreceivedAcksRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUnreceivedAcksRequest.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 *QueryUnreceivedAcksRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUnreceivedAcksRequest.Merge(m, src) +} +func (m *QueryUnreceivedAcksRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryUnreceivedAcksRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUnreceivedAcksRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUnreceivedAcksRequest proto.InternalMessageInfo + +func (m *QueryUnreceivedAcksRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *QueryUnreceivedAcksRequest) GetPacketAckSequences() []uint64 { + if m != nil { + return m.PacketAckSequences + } + return nil +} + +// QueryUnreceivedAcksResponse is the response type for the +// Query/UnreceivedAcks RPC method +type QueryUnreceivedAcksResponse struct { + // list of unreceived acknowledgement sequences + Sequences []uint64 `protobuf:"varint,1,rep,packed,name=sequences,proto3" json:"sequences,omitempty"` + // query block height + Height types.Height `protobuf:"bytes,2,opt,name=height,proto3" json:"height"` +} + +func (m *QueryUnreceivedAcksResponse) Reset() { *m = QueryUnreceivedAcksResponse{} } +func (m *QueryUnreceivedAcksResponse) String() string { return proto.CompactTextString(m) } +func (*QueryUnreceivedAcksResponse) ProtoMessage() {} +func (*QueryUnreceivedAcksResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a328cba4986edcab, []int{15} +} +func (m *QueryUnreceivedAcksResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUnreceivedAcksResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUnreceivedAcksResponse.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 *QueryUnreceivedAcksResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUnreceivedAcksResponse.Merge(m, src) +} +func (m *QueryUnreceivedAcksResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryUnreceivedAcksResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUnreceivedAcksResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUnreceivedAcksResponse proto.InternalMessageInfo + +func (m *QueryUnreceivedAcksResponse) GetSequences() []uint64 { + if m != nil { + return m.Sequences + } + return nil +} + +func (m *QueryUnreceivedAcksResponse) GetHeight() types.Height { + if m != nil { + return m.Height + } + return types.Height{} +} + +func init() { + proto.RegisterType((*QueryChannelRequest)(nil), "ibc.core.channel.v2.QueryChannelRequest") + proto.RegisterType((*QueryChannelResponse)(nil), "ibc.core.channel.v2.QueryChannelResponse") + proto.RegisterType((*QueryNextSequenceSendRequest)(nil), "ibc.core.channel.v2.QueryNextSequenceSendRequest") + proto.RegisterType((*QueryNextSequenceSendResponse)(nil), "ibc.core.channel.v2.QueryNextSequenceSendResponse") + proto.RegisterType((*QueryPacketCommitmentRequest)(nil), "ibc.core.channel.v2.QueryPacketCommitmentRequest") + proto.RegisterType((*QueryPacketCommitmentResponse)(nil), "ibc.core.channel.v2.QueryPacketCommitmentResponse") + proto.RegisterType((*QueryPacketCommitmentsRequest)(nil), "ibc.core.channel.v2.QueryPacketCommitmentsRequest") + proto.RegisterType((*QueryPacketCommitmentsResponse)(nil), "ibc.core.channel.v2.QueryPacketCommitmentsResponse") + proto.RegisterType((*QueryPacketAcknowledgementRequest)(nil), "ibc.core.channel.v2.QueryPacketAcknowledgementRequest") + proto.RegisterType((*QueryPacketAcknowledgementResponse)(nil), "ibc.core.channel.v2.QueryPacketAcknowledgementResponse") + proto.RegisterType((*QueryPacketReceiptRequest)(nil), "ibc.core.channel.v2.QueryPacketReceiptRequest") + proto.RegisterType((*QueryPacketReceiptResponse)(nil), "ibc.core.channel.v2.QueryPacketReceiptResponse") + proto.RegisterType((*QueryUnreceivedPacketsRequest)(nil), "ibc.core.channel.v2.QueryUnreceivedPacketsRequest") + proto.RegisterType((*QueryUnreceivedPacketsResponse)(nil), "ibc.core.channel.v2.QueryUnreceivedPacketsResponse") + proto.RegisterType((*QueryUnreceivedAcksRequest)(nil), "ibc.core.channel.v2.QueryUnreceivedAcksRequest") + proto.RegisterType((*QueryUnreceivedAcksResponse)(nil), "ibc.core.channel.v2.QueryUnreceivedAcksResponse") +} + +func init() { proto.RegisterFile("ibc/core/channel/v2/query.proto", fileDescriptor_a328cba4986edcab) } + +var fileDescriptor_a328cba4986edcab = []byte{ + // 1028 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x5d, 0x6f, 0xdb, 0x54, + 0x18, 0xee, 0x49, 0xb2, 0xb5, 0x7d, 0x53, 0xa0, 0x3b, 0x2b, 0x22, 0x98, 0x2e, 0xcb, 0x7c, 0x01, + 0x61, 0xda, 0x7c, 0x9a, 0x6c, 0xe2, 0x43, 0xda, 0x84, 0xda, 0x6a, 0x6c, 0x45, 0x02, 0x15, 0x17, + 0x90, 0x40, 0xd3, 0x22, 0xc7, 0x39, 0x73, 0xad, 0x24, 0x3e, 0x5e, 0xec, 0x84, 0x4e, 0x53, 0x6f, + 0xb8, 0xe0, 0x1a, 0xb1, 0x3b, 0x7e, 0x01, 0xfc, 0x0a, 0x90, 0xb8, 0x99, 0xc4, 0xcd, 0xa4, 0x71, + 0xc1, 0x15, 0x82, 0x16, 0x89, 0xbf, 0x81, 0x72, 0xce, 0x71, 0x62, 0x27, 0xb6, 0x6b, 0xb3, 0xf5, + 0xce, 0x3e, 0x79, 0x3f, 0x9e, 0xe7, 0xf1, 0xfb, 0xfa, 0x89, 0xe1, 0xa2, 0xdd, 0x36, 0x89, 0xc9, + 0x06, 0x94, 0x98, 0xfb, 0x86, 0xe3, 0xd0, 0x1e, 0x19, 0x35, 0xc9, 0x83, 0x21, 0x1d, 0x3c, 0xd4, + 0xdc, 0x01, 0xf3, 0x19, 0x3e, 0x6f, 0xb7, 0x4d, 0x6d, 0x1c, 0xa0, 0xc9, 0x00, 0x6d, 0xd4, 0x54, + 0x2e, 0x9b, 0xcc, 0xeb, 0x33, 0x8f, 0xb4, 0x0d, 0x8f, 0x8a, 0x68, 0x32, 0x6a, 0xb4, 0xa9, 0x6f, + 0x34, 0x88, 0x6b, 0x58, 0xb6, 0x63, 0xf8, 0x36, 0x73, 0x44, 0x01, 0xe5, 0x52, 0x5c, 0x87, 0xa0, + 0x56, 0x4a, 0x88, 0x45, 0x1d, 0xea, 0xd9, 0x9e, 0x0c, 0x09, 0xe1, 0xec, 0xd9, 0xd4, 0xf1, 0xc9, + 0xa8, 0x21, 0xaf, 0x64, 0xc0, 0xba, 0xc5, 0x98, 0xd5, 0xa3, 0xc4, 0x70, 0x6d, 0x62, 0x38, 0x0e, + 0xf3, 0x39, 0x86, 0x20, 0x7d, 0xcd, 0x62, 0x16, 0xe3, 0x97, 0x64, 0x7c, 0x25, 0x4e, 0xd5, 0xeb, + 0x70, 0xfe, 0xd3, 0x31, 0xf8, 0x6d, 0xd1, 0x55, 0xa7, 0x0f, 0x86, 0xd4, 0xf3, 0xf1, 0x05, 0x00, + 0x89, 0xa3, 0x65, 0x77, 0x2a, 0xa8, 0x86, 0xea, 0xcb, 0xfa, 0xb2, 0x3c, 0xd9, 0xe9, 0xa8, 0x9f, + 0xc1, 0x5a, 0x34, 0xcb, 0x73, 0x99, 0xe3, 0x51, 0x7c, 0x03, 0x16, 0x65, 0x10, 0xcf, 0x29, 0x37, + 0xd7, 0xb5, 0x18, 0xed, 0x34, 0x99, 0xb6, 0x55, 0x7a, 0xf2, 0xe7, 0xc5, 0x05, 0x3d, 0x48, 0x51, + 0x6f, 0xc2, 0x3a, 0xaf, 0xfa, 0x09, 0x3d, 0xf0, 0xf7, 0xc6, 0x40, 0x1c, 0x93, 0xee, 0x51, 0xa7, + 0x93, 0x11, 0xd4, 0x8f, 0x08, 0x2e, 0x24, 0xe4, 0x4b, 0x78, 0x57, 0x00, 0x3b, 0xf4, 0xc0, 0x6f, + 0x79, 0xf2, 0xc7, 0x96, 0x47, 0x1d, 0x51, 0xa8, 0xa4, 0xaf, 0x3a, 0x33, 0x59, 0x78, 0x0d, 0xce, + 0xb8, 0x03, 0xc6, 0xee, 0x57, 0x0a, 0x35, 0x54, 0x5f, 0xd1, 0xc5, 0x0d, 0xde, 0x86, 0x15, 0x7e, + 0xd1, 0xda, 0xa7, 0xb6, 0xb5, 0xef, 0x57, 0x8a, 0x9c, 0xa7, 0x12, 0xe2, 0x29, 0x1e, 0xc9, 0xa8, + 0xa1, 0xdd, 0xe1, 0x11, 0x92, 0x65, 0x99, 0x67, 0x89, 0x23, 0xf5, 0x4b, 0xc9, 0x74, 0xd7, 0x30, + 0xbb, 0xd4, 0xdf, 0x66, 0xfd, 0xbe, 0xed, 0xf7, 0xa9, 0xe3, 0x67, 0x63, 0x8a, 0x15, 0x58, 0x0a, + 0x28, 0x70, 0x70, 0x25, 0x7d, 0x72, 0xaf, 0xfe, 0x10, 0xa8, 0x30, 0x5f, 0x5b, 0xaa, 0x50, 0x05, + 0x30, 0x27, 0xa7, 0xbc, 0xf8, 0x8a, 0x1e, 0x3a, 0x39, 0x4d, 0xde, 0xdf, 0x26, 0x81, 0xf3, 0x32, + 0x32, 0xff, 0x10, 0x60, 0xba, 0x5d, 0x1c, 0x60, 0xb9, 0xf9, 0xa6, 0x26, 0x56, 0x51, 0x1b, 0xaf, + 0xa2, 0x26, 0x16, 0x57, 0xae, 0xa2, 0xb6, 0x6b, 0x58, 0x54, 0x96, 0xd6, 0x43, 0x99, 0xea, 0xbf, + 0x08, 0xaa, 0x49, 0x40, 0xa4, 0x4c, 0x5b, 0x50, 0x9e, 0x8a, 0xe2, 0x55, 0x50, 0xad, 0x58, 0x2f, + 0x37, 0x6b, 0xb1, 0xf3, 0x2c, 0x8a, 0xec, 0xf9, 0x86, 0x4f, 0xf5, 0x70, 0x12, 0xbe, 0x1d, 0x03, + 0xf7, 0xad, 0x13, 0xe1, 0x0a, 0x00, 0x61, 0xbc, 0xf8, 0x3d, 0x38, 0x9b, 0x53, 0x77, 0x19, 0xaf, + 0xde, 0x83, 0x4b, 0x21, 0xa2, 0x9b, 0x66, 0xd7, 0x61, 0x5f, 0xf7, 0x68, 0xc7, 0xa2, 0x2f, 0x68, + 0xde, 0x7e, 0x42, 0xa0, 0xa6, 0x35, 0x90, 0x6a, 0xd6, 0xe1, 0x15, 0x23, 0xfa, 0x93, 0x9c, 0xbc, + 0xd9, 0xe3, 0xd3, 0x1c, 0x3f, 0x06, 0xaf, 0x87, 0xa0, 0xea, 0xd4, 0xa4, 0xb6, 0x3b, 0xd1, 0xe0, + 0x35, 0x58, 0x74, 0xd9, 0xc0, 0x9f, 0x0a, 0x70, 0x76, 0x7c, 0xbb, 0xd3, 0x99, 0x11, 0xa7, 0x90, + 0x26, 0x4e, 0x71, 0x46, 0x9c, 0xc7, 0x08, 0x94, 0xb8, 0x8e, 0x52, 0x14, 0x05, 0x96, 0x06, 0xe3, + 0xa3, 0x11, 0x15, 0x75, 0x97, 0xf4, 0xc9, 0xfd, 0x54, 0x86, 0x62, 0x9a, 0x0c, 0xa5, 0xff, 0x23, + 0xc3, 0x5d, 0xb9, 0x84, 0x9f, 0x3b, 0x41, 0x37, 0x01, 0x2f, 0xeb, 0x12, 0xae, 0xc3, 0x72, 0xc0, + 0xd0, 0xab, 0x14, 0x6a, 0xc5, 0x7a, 0x49, 0x9f, 0x1e, 0xa8, 0x07, 0x72, 0xb3, 0x62, 0xaa, 0x4b, + 0xda, 0x91, 0x7c, 0x34, 0x93, 0x1f, 0x1a, 0xf5, 0x42, 0xce, 0x51, 0xef, 0x4b, 0xb1, 0xa7, 0x9d, + 0x37, 0xcd, 0x6e, 0x56, 0x52, 0x1b, 0xb0, 0xe6, 0x72, 0x9c, 0x2d, 0xc3, 0xec, 0xb6, 0x66, 0xf9, + 0x61, 0x37, 0x98, 0xee, 0xbd, 0x09, 0xd1, 0x21, 0xbc, 0x11, 0xdb, 0xee, 0x74, 0x59, 0x36, 0x7f, + 0x5f, 0x81, 0x33, 0xbc, 0x2f, 0xfe, 0x1e, 0xc1, 0xa2, 0xb4, 0x52, 0x5c, 0x8f, 0x7d, 0x31, 0xc5, + 0x58, 0xbb, 0xf2, 0x76, 0x86, 0x48, 0x41, 0x41, 0x6d, 0x7e, 0xf3, 0xec, 0x9f, 0xc7, 0x85, 0x2b, + 0xf8, 0x32, 0x49, 0xf9, 0x03, 0xe3, 0x91, 0x47, 0x53, 0x5d, 0x0f, 0xf1, 0x2f, 0x08, 0x56, 0x67, + 0x0d, 0x18, 0x37, 0x92, 0x7b, 0x26, 0x98, 0xbd, 0xd2, 0xcc, 0x93, 0x22, 0xf1, 0xde, 0xe2, 0x78, + 0x3f, 0xc0, 0x37, 0xb3, 0xe3, 0x25, 0xf3, 0x7f, 0x08, 0xf0, 0x6f, 0x08, 0x56, 0x67, 0x7d, 0x21, + 0x8d, 0x42, 0x82, 0x8b, 0xa7, 0x51, 0x48, 0x32, 0x67, 0x75, 0x97, 0x53, 0xf8, 0x08, 0xdf, 0xc9, + 0x41, 0x41, 0xce, 0x6d, 0xc8, 0x78, 0xc8, 0xa3, 0x80, 0xd1, 0x21, 0xfe, 0x15, 0xc1, 0xb9, 0x39, + 0x97, 0xc3, 0x39, 0xb0, 0x05, 0x1b, 0xa4, 0x5c, 0xcb, 0x95, 0xf3, 0x1c, 0xcf, 0x64, 0x9e, 0x10, + 0x7e, 0x86, 0xe0, 0xd5, 0x58, 0x87, 0xc1, 0xef, 0x9c, 0x84, 0x2a, 0xde, 0xf3, 0x94, 0x77, 0x73, + 0xe7, 0x49, 0x46, 0x3b, 0x9c, 0xd1, 0x36, 0xde, 0xcc, 0xcf, 0xc8, 0x30, 0xbb, 0x91, 0x67, 0xf3, + 0x33, 0x82, 0x97, 0x22, 0xd6, 0x80, 0xb5, 0x93, 0x50, 0x45, 0x5d, 0x4b, 0x21, 0x99, 0xe3, 0x25, + 0xfa, 0x8f, 0x39, 0xfa, 0xdb, 0xf8, 0x56, 0x7e, 0xf4, 0x03, 0x51, 0x2a, 0xc2, 0xe0, 0x08, 0xc1, + 0xb9, 0xb9, 0x37, 0x7d, 0xda, 0x74, 0x25, 0x99, 0x4e, 0xda, 0x74, 0x25, 0x5a, 0x89, 0xda, 0xe1, + 0x6c, 0xee, 0xe1, 0xbb, 0x2f, 0x68, 0x5d, 0xbc, 0x43, 0x32, 0x9c, 0x34, 0x6b, 0xb9, 0x92, 0xce, + 0xdf, 0x08, 0x5e, 0x8e, 0xbe, 0xe5, 0x31, 0xc9, 0x82, 0x36, 0x64, 0x3f, 0xca, 0x46, 0xf6, 0x04, + 0xc9, 0xad, 0xc7, 0xb9, 0xdd, 0xc7, 0x9d, 0xe7, 0xe4, 0x16, 0x67, 0x6b, 0x11, 0x9a, 0xe3, 0xa9, + 0xdc, 0xfa, 0xe2, 0xc9, 0x51, 0x15, 0x3d, 0x3d, 0xaa, 0xa2, 0xbf, 0x8e, 0xaa, 0xe8, 0xbb, 0xe3, + 0xea, 0xc2, 0xd3, 0xe3, 0xea, 0xc2, 0x1f, 0xc7, 0xd5, 0x85, 0xaf, 0x6e, 0x58, 0xb6, 0xbf, 0x3f, + 0x6c, 0x6b, 0x26, 0xeb, 0x13, 0xf9, 0xd1, 0x6b, 0xb7, 0xcd, 0xab, 0x16, 0x23, 0xa3, 0xf7, 0x49, + 0x9f, 0x75, 0x86, 0x3d, 0xea, 0x09, 0x78, 0x1b, 0xd7, 0xaf, 0x86, 0x10, 0xfa, 0x0f, 0x5d, 0xea, + 0xb5, 0xcf, 0xf2, 0xef, 0xcc, 0x6b, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x9c, 0x92, 0x15, 0x18, + 0x66, 0x0f, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Channel queries the counterparty of an IBC client. + Channel(ctx context.Context, in *QueryChannelRequest, opts ...grpc.CallOption) (*QueryChannelResponse, error) + // NextSequenceSend returns the next send sequence for a given channel. + NextSequenceSend(ctx context.Context, in *QueryNextSequenceSendRequest, opts ...grpc.CallOption) (*QueryNextSequenceSendResponse, error) + // PacketCommitment queries a stored packet commitment hash. + PacketCommitment(ctx context.Context, in *QueryPacketCommitmentRequest, opts ...grpc.CallOption) (*QueryPacketCommitmentResponse, error) + // PacketCommitments queries a stored packet commitment hash. + PacketCommitments(ctx context.Context, in *QueryPacketCommitmentsRequest, opts ...grpc.CallOption) (*QueryPacketCommitmentsResponse, error) + // PacketAcknowledgement queries a stored acknowledgement commitment hash. + PacketAcknowledgement(ctx context.Context, in *QueryPacketAcknowledgementRequest, opts ...grpc.CallOption) (*QueryPacketAcknowledgementResponse, error) + // PacketReceipt queries a stored packet receipt. + PacketReceipt(ctx context.Context, in *QueryPacketReceiptRequest, opts ...grpc.CallOption) (*QueryPacketReceiptResponse, error) + // UnreceivedPakcets returns all unreceived packets. + UnreceivedPackets(ctx context.Context, in *QueryUnreceivedPacketsRequest, opts ...grpc.CallOption) (*QueryUnreceivedPacketsResponse, error) + // UnreceivedAcks returns all the unreceived IBC acknowledgements associated with a channel and sequences. + UnreceivedAcks(ctx context.Context, in *QueryUnreceivedAcksRequest, opts ...grpc.CallOption) (*QueryUnreceivedAcksResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Channel(ctx context.Context, in *QueryChannelRequest, opts ...grpc.CallOption) (*QueryChannelResponse, error) { + out := new(QueryChannelResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/Channel", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) NextSequenceSend(ctx context.Context, in *QueryNextSequenceSendRequest, opts ...grpc.CallOption) (*QueryNextSequenceSendResponse, error) { + out := new(QueryNextSequenceSendResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/NextSequenceSend", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PacketCommitment(ctx context.Context, in *QueryPacketCommitmentRequest, opts ...grpc.CallOption) (*QueryPacketCommitmentResponse, error) { + out := new(QueryPacketCommitmentResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/PacketCommitment", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PacketCommitments(ctx context.Context, in *QueryPacketCommitmentsRequest, opts ...grpc.CallOption) (*QueryPacketCommitmentsResponse, error) { + out := new(QueryPacketCommitmentsResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/PacketCommitments", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PacketAcknowledgement(ctx context.Context, in *QueryPacketAcknowledgementRequest, opts ...grpc.CallOption) (*QueryPacketAcknowledgementResponse, error) { + out := new(QueryPacketAcknowledgementResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/PacketAcknowledgement", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) PacketReceipt(ctx context.Context, in *QueryPacketReceiptRequest, opts ...grpc.CallOption) (*QueryPacketReceiptResponse, error) { + out := new(QueryPacketReceiptResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/PacketReceipt", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) UnreceivedPackets(ctx context.Context, in *QueryUnreceivedPacketsRequest, opts ...grpc.CallOption) (*QueryUnreceivedPacketsResponse, error) { + out := new(QueryUnreceivedPacketsResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/UnreceivedPackets", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) UnreceivedAcks(ctx context.Context, in *QueryUnreceivedAcksRequest, opts ...grpc.CallOption) (*QueryUnreceivedAcksResponse, error) { + out := new(QueryUnreceivedAcksResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/UnreceivedAcks", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Channel queries the counterparty of an IBC client. + Channel(context.Context, *QueryChannelRequest) (*QueryChannelResponse, error) + // NextSequenceSend returns the next send sequence for a given channel. + NextSequenceSend(context.Context, *QueryNextSequenceSendRequest) (*QueryNextSequenceSendResponse, error) + // PacketCommitment queries a stored packet commitment hash. + PacketCommitment(context.Context, *QueryPacketCommitmentRequest) (*QueryPacketCommitmentResponse, error) + // PacketCommitments queries a stored packet commitment hash. + PacketCommitments(context.Context, *QueryPacketCommitmentsRequest) (*QueryPacketCommitmentsResponse, error) + // PacketAcknowledgement queries a stored acknowledgement commitment hash. + PacketAcknowledgement(context.Context, *QueryPacketAcknowledgementRequest) (*QueryPacketAcknowledgementResponse, error) + // PacketReceipt queries a stored packet receipt. + PacketReceipt(context.Context, *QueryPacketReceiptRequest) (*QueryPacketReceiptResponse, error) + // UnreceivedPakcets returns all unreceived packets. + UnreceivedPackets(context.Context, *QueryUnreceivedPacketsRequest) (*QueryUnreceivedPacketsResponse, error) + // UnreceivedAcks returns all the unreceived IBC acknowledgements associated with a channel and sequences. + UnreceivedAcks(context.Context, *QueryUnreceivedAcksRequest) (*QueryUnreceivedAcksResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Channel(ctx context.Context, req *QueryChannelRequest) (*QueryChannelResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Channel not implemented") +} +func (*UnimplementedQueryServer) NextSequenceSend(ctx context.Context, req *QueryNextSequenceSendRequest) (*QueryNextSequenceSendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method NextSequenceSend not implemented") +} +func (*UnimplementedQueryServer) PacketCommitment(ctx context.Context, req *QueryPacketCommitmentRequest) (*QueryPacketCommitmentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PacketCommitment not implemented") +} +func (*UnimplementedQueryServer) PacketCommitments(ctx context.Context, req *QueryPacketCommitmentsRequest) (*QueryPacketCommitmentsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PacketCommitments not implemented") +} +func (*UnimplementedQueryServer) PacketAcknowledgement(ctx context.Context, req *QueryPacketAcknowledgementRequest) (*QueryPacketAcknowledgementResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PacketAcknowledgement not implemented") +} +func (*UnimplementedQueryServer) PacketReceipt(ctx context.Context, req *QueryPacketReceiptRequest) (*QueryPacketReceiptResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PacketReceipt not implemented") +} +func (*UnimplementedQueryServer) UnreceivedPackets(ctx context.Context, req *QueryUnreceivedPacketsRequest) (*QueryUnreceivedPacketsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UnreceivedPackets not implemented") +} +func (*UnimplementedQueryServer) UnreceivedAcks(ctx context.Context, req *QueryUnreceivedAcksRequest) (*QueryUnreceivedAcksResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UnreceivedAcks not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Channel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryChannelRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Channel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/Channel", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Channel(ctx, req.(*QueryChannelRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_NextSequenceSend_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryNextSequenceSendRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).NextSequenceSend(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/NextSequenceSend", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).NextSequenceSend(ctx, req.(*QueryNextSequenceSendRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PacketCommitment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPacketCommitmentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PacketCommitment(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/PacketCommitment", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PacketCommitment(ctx, req.(*QueryPacketCommitmentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PacketCommitments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPacketCommitmentsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PacketCommitments(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/PacketCommitments", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PacketCommitments(ctx, req.(*QueryPacketCommitmentsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PacketAcknowledgement_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPacketAcknowledgementRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PacketAcknowledgement(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/PacketAcknowledgement", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PacketAcknowledgement(ctx, req.(*QueryPacketAcknowledgementRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_PacketReceipt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPacketReceiptRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PacketReceipt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/PacketReceipt", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PacketReceipt(ctx, req.(*QueryPacketReceiptRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_UnreceivedPackets_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryUnreceivedPacketsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).UnreceivedPackets(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/UnreceivedPackets", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).UnreceivedPackets(ctx, req.(*QueryUnreceivedPacketsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_UnreceivedAcks_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryUnreceivedAcksRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).UnreceivedAcks(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Query/UnreceivedAcks", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).UnreceivedAcks(ctx, req.(*QueryUnreceivedAcksRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ibc.core.channel.v2.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Channel", + Handler: _Query_Channel_Handler, + }, + { + MethodName: "NextSequenceSend", + Handler: _Query_NextSequenceSend_Handler, + }, + { + MethodName: "PacketCommitment", + Handler: _Query_PacketCommitment_Handler, + }, + { + MethodName: "PacketCommitments", + Handler: _Query_PacketCommitments_Handler, + }, + { + MethodName: "PacketAcknowledgement", + Handler: _Query_PacketAcknowledgement_Handler, + }, + { + MethodName: "PacketReceipt", + Handler: _Query_PacketReceipt_Handler, + }, + { + MethodName: "UnreceivedPackets", + Handler: _Query_UnreceivedPackets_Handler, + }, + { + MethodName: "UnreceivedAcks", + Handler: _Query_UnreceivedAcks_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/core/channel/v2/query.proto", +} + +func (m *QueryChannelRequest) 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 *QueryChannelRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryChannelRequest) 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 = encodeVarintQuery(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryChannelResponse) 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 *QueryChannelResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryChannelResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Channel.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryNextSequenceSendRequest) 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 *QueryNextSequenceSendRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryNextSequenceSendRequest) 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 = encodeVarintQuery(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryNextSequenceSendResponse) 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 *QueryNextSequenceSendResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryNextSequenceSendResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Proof) > 0 { + i -= len(m.Proof) + copy(dAtA[i:], m.Proof) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Proof))) + i-- + dAtA[i] = 0x12 + } + if m.NextSequenceSend != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.NextSequenceSend)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketCommitmentRequest) 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 *QueryPacketCommitmentRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketCommitmentRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x10 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketCommitmentResponse) 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 *QueryPacketCommitmentResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketCommitmentResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Proof) > 0 { + i -= len(m.Proof) + copy(dAtA[i:], m.Proof) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Proof))) + i-- + dAtA[i] = 0x12 + } + if len(m.Commitment) > 0 { + i -= len(m.Commitment) + copy(dAtA[i:], m.Commitment) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Commitment))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketCommitmentsRequest) 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 *QueryPacketCommitmentsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketCommitmentsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketCommitmentsResponse) 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 *QueryPacketCommitmentsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketCommitmentsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Height.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Commitments) > 0 { + for iNdEx := len(m.Commitments) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Commitments[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketAcknowledgementRequest) 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 *QueryPacketAcknowledgementRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketAcknowledgementRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x10 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketAcknowledgementResponse) 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 *QueryPacketAcknowledgementResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketAcknowledgementResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Proof) > 0 { + i -= len(m.Proof) + copy(dAtA[i:], m.Proof) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Proof))) + i-- + dAtA[i] = 0x12 + } + if len(m.Acknowledgement) > 0 { + i -= len(m.Acknowledgement) + copy(dAtA[i:], m.Acknowledgement) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Acknowledgement))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketReceiptRequest) 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 *QueryPacketReceiptRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketReceiptRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x18 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintQuery(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 = encodeVarintQuery(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryPacketReceiptResponse) 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 *QueryPacketReceiptResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryPacketReceiptResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if len(m.Proof) > 0 { + i -= len(m.Proof) + copy(dAtA[i:], m.Proof) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Proof))) + i-- + dAtA[i] = 0x1a + } + if m.Received { + i-- + if m.Received { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + return len(dAtA) - i, nil +} + +func (m *QueryUnreceivedPacketsRequest) 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 *QueryUnreceivedPacketsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUnreceivedPacketsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Sequences) > 0 { + dAtA10 := make([]byte, len(m.Sequences)*10) + var j9 int + for _, num := range m.Sequences { + for num >= 1<<7 { + dAtA10[j9] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j9++ + } + dAtA10[j9] = uint8(num) + j9++ + } + i -= j9 + copy(dAtA[i:], dAtA10[:j9]) + i = encodeVarintQuery(dAtA, i, uint64(j9)) + i-- + dAtA[i] = 0x12 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryUnreceivedPacketsResponse) 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 *QueryUnreceivedPacketsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUnreceivedPacketsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Height.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Sequences) > 0 { + dAtA13 := make([]byte, len(m.Sequences)*10) + var j12 int + for _, num := range m.Sequences { + for num >= 1<<7 { + dAtA13[j12] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j12++ + } + dAtA13[j12] = uint8(num) + j12++ + } + i -= j12 + copy(dAtA[i:], dAtA13[:j12]) + i = encodeVarintQuery(dAtA, i, uint64(j12)) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryUnreceivedAcksRequest) 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 *QueryUnreceivedAcksRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUnreceivedAcksRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PacketAckSequences) > 0 { + dAtA15 := make([]byte, len(m.PacketAckSequences)*10) + var j14 int + for _, num := range m.PacketAckSequences { + for num >= 1<<7 { + dAtA15[j14] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j14++ + } + dAtA15[j14] = uint8(num) + j14++ + } + i -= j14 + copy(dAtA[i:], dAtA15[:j14]) + i = encodeVarintQuery(dAtA, i, uint64(j14)) + i-- + dAtA[i] = 0x12 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryUnreceivedAcksResponse) 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 *QueryUnreceivedAcksResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUnreceivedAcksResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Height.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Sequences) > 0 { + dAtA18 := make([]byte, len(m.Sequences)*10) + var j17 int + for _, num := range m.Sequences { + for num >= 1<<7 { + dAtA18[j17] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j17++ + } + dAtA18[j17] = uint8(num) + j17++ + } + i -= j17 + copy(dAtA[i:], dAtA18[:j17]) + i = encodeVarintQuery(dAtA, i, uint64(j17)) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryChannelRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryChannelResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Channel.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryNextSequenceSendRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryNextSequenceSendResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.NextSequenceSend != 0 { + n += 1 + sovQuery(uint64(m.NextSequenceSend)) + } + l = len(m.Proof) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.ProofHeight.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPacketCommitmentRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovQuery(uint64(m.Sequence)) + } + return n +} + +func (m *QueryPacketCommitmentResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Commitment) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Proof) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.ProofHeight.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPacketCommitmentsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPacketCommitmentsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Commitments) > 0 { + for _, e := range m.Commitments { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + l = m.Height.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPacketAcknowledgementRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovQuery(uint64(m.Sequence)) + } + return n +} + +func (m *QueryPacketAcknowledgementResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Acknowledgement) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Proof) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.ProofHeight.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPacketReceiptRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovQuery(uint64(m.Sequence)) + } + return n +} + +func (m *QueryPacketReceiptResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Received { + n += 2 + } + l = len(m.Proof) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.ProofHeight.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryUnreceivedPacketsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if len(m.Sequences) > 0 { + l = 0 + for _, e := range m.Sequences { + l += sovQuery(uint64(e)) + } + n += 1 + sovQuery(uint64(l)) + l + } + return n +} + +func (m *QueryUnreceivedPacketsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Sequences) > 0 { + l = 0 + for _, e := range m.Sequences { + l += sovQuery(uint64(e)) + } + n += 1 + sovQuery(uint64(l)) + l + } + l = m.Height.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryUnreceivedAcksRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if len(m.PacketAckSequences) > 0 { + l = 0 + for _, e := range m.PacketAckSequences { + l += sovQuery(uint64(e)) + } + n += 1 + sovQuery(uint64(l)) + l + } + return n +} + +func (m *QueryUnreceivedAcksResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Sequences) > 0 { + l = 0 + for _, e := range m.Sequences { + l += sovQuery(uint64(e)) + } + n += 1 + sovQuery(uint64(l)) + l + } + l = m.Height.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryChannelRequest) 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 ErrIntOverflowQuery + } + 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: QueryChannelRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryChannelRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryChannelResponse) 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 ErrIntOverflowQuery + } + 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: QueryChannelResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryChannelResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channel", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Channel.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryNextSequenceSendRequest) 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 ErrIntOverflowQuery + } + 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: QueryNextSequenceSendRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryNextSequenceSendRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryNextSequenceSendResponse) 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 ErrIntOverflowQuery + } + 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: QueryNextSequenceSendResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryNextSequenceSendResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextSequenceSend", wireType) + } + m.NextSequenceSend = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextSequenceSend |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proof = append(m.Proof[:0], dAtA[iNdEx:postIndex]...) + if m.Proof == nil { + m.Proof = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProofHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketCommitmentRequest) 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 ErrIntOverflowQuery + } + 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: QueryPacketCommitmentRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketCommitmentRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketCommitmentResponse) 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 ErrIntOverflowQuery + } + 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: QueryPacketCommitmentResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketCommitmentResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commitment", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Commitment = append(m.Commitment[:0], dAtA[iNdEx:postIndex]...) + if m.Commitment == nil { + m.Commitment = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proof = append(m.Proof[:0], dAtA[iNdEx:postIndex]...) + if m.Proof == nil { + m.Proof = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProofHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketCommitmentsRequest) 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 ErrIntOverflowQuery + } + 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: QueryPacketCommitmentsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketCommitmentsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketCommitmentsResponse) 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 ErrIntOverflowQuery + } + 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: QueryPacketCommitmentsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketCommitmentsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commitments", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Commitments = append(m.Commitments, &PacketState{}) + if err := m.Commitments[len(m.Commitments)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Height.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketAcknowledgementRequest) 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 ErrIntOverflowQuery + } + 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: QueryPacketAcknowledgementRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketAcknowledgementRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketAcknowledgementResponse) 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 ErrIntOverflowQuery + } + 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: QueryPacketAcknowledgementResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketAcknowledgementResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Acknowledgement", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Acknowledgement = append(m.Acknowledgement[:0], dAtA[iNdEx:postIndex]...) + if m.Acknowledgement == nil { + m.Acknowledgement = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proof = append(m.Proof[:0], dAtA[iNdEx:postIndex]...) + if m.Proof == nil { + m.Proof = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProofHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketReceiptRequest) 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 ErrIntOverflowQuery + } + 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: QueryPacketReceiptRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketReceiptRequest: 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPacketReceiptResponse) 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 ErrIntOverflowQuery + } + 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: QueryPacketReceiptResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPacketReceiptResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Received", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Received = bool(v != 0) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proof = append(m.Proof[:0], dAtA[iNdEx:postIndex]...) + if m.Proof == nil { + m.Proof = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProofHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryUnreceivedPacketsRequest) 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 ErrIntOverflowQuery + } + 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: QueryUnreceivedPacketsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUnreceivedPacketsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Sequences = append(m.Sequences, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.Sequences) == 0 { + m.Sequences = make([]uint64, 0, elementCount) + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Sequences = append(m.Sequences, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field Sequences", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryUnreceivedPacketsResponse) 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 ErrIntOverflowQuery + } + 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: QueryUnreceivedPacketsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUnreceivedPacketsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Sequences = append(m.Sequences, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.Sequences) == 0 { + m.Sequences = make([]uint64, 0, elementCount) + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Sequences = append(m.Sequences, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field Sequences", wireType) + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Height.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryUnreceivedAcksRequest) 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 ErrIntOverflowQuery + } + 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: QueryUnreceivedAcksRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUnreceivedAcksRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.PacketAckSequences = append(m.PacketAckSequences, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.PacketAckSequences) == 0 { + m.PacketAckSequences = make([]uint64, 0, elementCount) + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.PacketAckSequences = append(m.PacketAckSequences, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field PacketAckSequences", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryUnreceivedAcksResponse) 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 ErrIntOverflowQuery + } + 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: QueryUnreceivedAcksResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUnreceivedAcksResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Sequences = append(m.Sequences, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.Sequences) == 0 { + m.Sequences = make([]uint64, 0, elementCount) + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Sequences = append(m.Sequences, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field Sequences", wireType) + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Height.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/04-channel/v2/types/query.pb.gw.go b/modules/core/04-channel/v2/types/query.pb.gw.go new file mode 100644 index 00000000000..9454ddcb63a --- /dev/null +++ b/modules/core/04-channel/v2/types/query.pb.gw.go @@ -0,0 +1,1042 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: ibc/core/channel/v2/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Channel_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryChannelRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + msg, err := client.Channel(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Channel_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryChannelRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + msg, err := server.Channel(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_NextSequenceSend_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryNextSequenceSendRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + msg, err := client.NextSequenceSend(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_NextSequenceSend_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryNextSequenceSendRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + msg, err := server.NextSequenceSend(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_PacketCommitment_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketCommitmentRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequence"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequence") + } + + protoReq.Sequence, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequence", err) + } + + msg, err := client.PacketCommitment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PacketCommitment_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketCommitmentRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequence"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequence") + } + + protoReq.Sequence, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequence", err) + } + + msg, err := server.PacketCommitment(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_PacketCommitments_0 = &utilities.DoubleArray{Encoding: map[string]int{"channel_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_PacketCommitments_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketCommitmentsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PacketCommitments_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PacketCommitments(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PacketCommitments_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketCommitmentsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PacketCommitments_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PacketCommitments(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_PacketAcknowledgement_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketAcknowledgementRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequence"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequence") + } + + protoReq.Sequence, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequence", err) + } + + msg, err := client.PacketAcknowledgement(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PacketAcknowledgement_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketAcknowledgementRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequence"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequence") + } + + protoReq.Sequence, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequence", err) + } + + msg, err := server.PacketAcknowledgement(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_PacketReceipt_0 = &utilities.DoubleArray{Encoding: map[string]int{"channel_id": 0, "sequence": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} +) + +func request_Query_PacketReceipt_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketReceiptRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequence"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequence") + } + + protoReq.Sequence, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequence", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PacketReceipt_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PacketReceipt(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PacketReceipt_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPacketReceiptRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequence"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequence") + } + + protoReq.Sequence, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequence", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_PacketReceipt_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PacketReceipt(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_UnreceivedPackets_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUnreceivedPacketsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequences"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequences") + } + + protoReq.Sequences, err = runtime.Uint64Slice(val, ",") + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequences", err) + } + + msg, err := client.UnreceivedPackets(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_UnreceivedPackets_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUnreceivedPacketsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["sequences"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sequences") + } + + protoReq.Sequences, err = runtime.Uint64Slice(val, ",") + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sequences", err) + } + + msg, err := server.UnreceivedPackets(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_UnreceivedAcks_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUnreceivedAcksRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["packet_ack_sequences"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "packet_ack_sequences") + } + + protoReq.PacketAckSequences, err = runtime.Uint64Slice(val, ",") + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "packet_ack_sequences", err) + } + + msg, err := client.UnreceivedAcks(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_UnreceivedAcks_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUnreceivedAcksRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["channel_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "channel_id") + } + + protoReq.ChannelId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "channel_id", err) + } + + val, ok = pathParams["packet_ack_sequences"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "packet_ack_sequences") + } + + protoReq.PacketAckSequences, err = runtime.Uint64Slice(val, ",") + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "packet_ack_sequences", err) + } + + msg, err := server.UnreceivedAcks(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Channel_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Channel_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Channel_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_NextSequenceSend_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_NextSequenceSend_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_NextSequenceSend_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketCommitment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PacketCommitment_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketCommitment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketCommitments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PacketCommitments_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketCommitments_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketAcknowledgement_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PacketAcknowledgement_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketAcknowledgement_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketReceipt_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PacketReceipt_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketReceipt_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_UnreceivedPackets_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_UnreceivedPackets_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UnreceivedPackets_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_UnreceivedAcks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_UnreceivedAcks_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UnreceivedAcks_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Channel_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Channel_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Channel_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_NextSequenceSend_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_NextSequenceSend_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_NextSequenceSend_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketCommitment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PacketCommitment_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketCommitment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketCommitments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PacketCommitments_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketCommitments_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketAcknowledgement_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PacketAcknowledgement_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketAcknowledgement_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_PacketReceipt_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PacketReceipt_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PacketReceipt_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_UnreceivedPackets_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_UnreceivedPackets_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UnreceivedPackets_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_UnreceivedAcks_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_UnreceivedAcks_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UnreceivedAcks_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Channel_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_NextSequenceSend_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id", "next_sequence_send"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_PacketCommitment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6, 1, 0, 4, 1, 5, 7}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id", "packet_commitments", "sequence"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_PacketCommitments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id", "packet_commitments"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_PacketAcknowledgement_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6, 1, 0, 4, 1, 5, 7}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id", "packet_acks", "sequence"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_PacketReceipt_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6, 1, 0, 4, 1, 5, 7}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id", "packet_receipts", "sequence"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_UnreceivedPackets_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6, 1, 0, 4, 1, 5, 7, 2, 8}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id", "packet_commitments", "sequences", "unreceived_packets"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_UnreceivedAcks_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6, 1, 0, 4, 1, 5, 7, 2, 8}, []string{"ibc", "core", "channel", "v2", "channels", "channel_id", "packet_commitments", "packet_ack_sequences", "unreceived_acks"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Channel_0 = runtime.ForwardResponseMessage + + forward_Query_NextSequenceSend_0 = runtime.ForwardResponseMessage + + forward_Query_PacketCommitment_0 = runtime.ForwardResponseMessage + + forward_Query_PacketCommitments_0 = runtime.ForwardResponseMessage + + forward_Query_PacketAcknowledgement_0 = runtime.ForwardResponseMessage + + forward_Query_PacketReceipt_0 = runtime.ForwardResponseMessage + + forward_Query_UnreceivedPackets_0 = runtime.ForwardResponseMessage + + forward_Query_UnreceivedAcks_0 = runtime.ForwardResponseMessage +) diff --git a/modules/core/04-channel/v2/types/tx.pb.go b/modules/core/04-channel/v2/types/tx.pb.go new file mode 100644 index 00000000000..b40a86332a0 --- /dev/null +++ b/modules/core/04-channel/v2/types/tx.pb.go @@ -0,0 +1,3148 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/channel/v2/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// ResponseResultType defines the possible outcomes of the execution of a message +type ResponseResultType int32 + +const ( + // Default zero value enumeration + UNSPECIFIED ResponseResultType = 0 + // The message did not call the IBC application callbacks (because, for example, the packet had already been relayed) + NOOP ResponseResultType = 1 + // The message was executed successfully + SUCCESS ResponseResultType = 2 + // The message was executed unsuccessfully + FAILURE ResponseResultType = 3 +) + +var ResponseResultType_name = map[int32]string{ + 0: "RESPONSE_RESULT_TYPE_UNSPECIFIED", + 1: "RESPONSE_RESULT_TYPE_NOOP", + 2: "RESPONSE_RESULT_TYPE_SUCCESS", + 3: "RESPONSE_RESULT_TYPE_FAILURE", +} + +var ResponseResultType_value = map[string]int32{ + "RESPONSE_RESULT_TYPE_UNSPECIFIED": 0, + "RESPONSE_RESULT_TYPE_NOOP": 1, + "RESPONSE_RESULT_TYPE_SUCCESS": 2, + "RESPONSE_RESULT_TYPE_FAILURE": 3, +} + +func (x ResponseResultType) String() string { + return proto.EnumName(ResponseResultType_name, int32(x)) +} + +func (ResponseResultType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{0} +} + +// MsgCreateChannel defines the message used to create a v2 Channel. +type MsgCreateChannel struct { + // the client identifier of the light client representing the counterparty chain + ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + // the key path used to store packet flow messages that the counterparty + // will use to send to us. + MerklePathPrefix v2.MerklePath `protobuf:"bytes,2,opt,name=merkle_path_prefix,json=merklePathPrefix,proto3" json:"merkle_path_prefix"` + // signer address + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgCreateChannel) Reset() { *m = MsgCreateChannel{} } +func (m *MsgCreateChannel) String() string { return proto.CompactTextString(m) } +func (*MsgCreateChannel) ProtoMessage() {} +func (*MsgCreateChannel) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{0} +} +func (m *MsgCreateChannel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateChannel.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 *MsgCreateChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateChannel.Merge(m, src) +} +func (m *MsgCreateChannel) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateChannel) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateChannel.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateChannel proto.InternalMessageInfo + +// MsgCreateChannelResponse defines the Msg/CreateChannel response type. +type MsgCreateChannelResponse struct { + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *MsgCreateChannelResponse) Reset() { *m = MsgCreateChannelResponse{} } +func (m *MsgCreateChannelResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateChannelResponse) ProtoMessage() {} +func (*MsgCreateChannelResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{1} +} +func (m *MsgCreateChannelResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateChannelResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateChannelResponse.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 *MsgCreateChannelResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateChannelResponse.Merge(m, src) +} +func (m *MsgCreateChannelResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateChannelResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateChannelResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateChannelResponse proto.InternalMessageInfo + +// MsgRegisterCounterparty defines the message used to provide the counterparty channel +// identifier. +type MsgRegisterCounterparty struct { + // unique identifier we will use to write all packet messages sent to counterparty + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // counterparty channel identifier + CounterpartyChannelId string `protobuf:"bytes,2,opt,name=counterparty_channel_id,json=counterpartyChannelId,proto3" json:"counterparty_channel_id,omitempty"` + // signer address + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgRegisterCounterparty) Reset() { *m = MsgRegisterCounterparty{} } +func (m *MsgRegisterCounterparty) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterCounterparty) ProtoMessage() {} +func (*MsgRegisterCounterparty) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{2} +} +func (m *MsgRegisterCounterparty) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterCounterparty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterCounterparty.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 *MsgRegisterCounterparty) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterCounterparty.Merge(m, src) +} +func (m *MsgRegisterCounterparty) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterCounterparty) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterCounterparty.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterCounterparty proto.InternalMessageInfo + +// MsgRegisterCounterpartyResponse defines the Msg/RegisterCounterparty response type. +type MsgRegisterCounterpartyResponse struct { +} + +func (m *MsgRegisterCounterpartyResponse) Reset() { *m = MsgRegisterCounterpartyResponse{} } +func (m *MsgRegisterCounterpartyResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterCounterpartyResponse) ProtoMessage() {} +func (*MsgRegisterCounterpartyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{3} +} +func (m *MsgRegisterCounterpartyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterCounterpartyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterCounterpartyResponse.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 *MsgRegisterCounterpartyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterCounterpartyResponse.Merge(m, src) +} +func (m *MsgRegisterCounterpartyResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterCounterpartyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterCounterpartyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterCounterpartyResponse proto.InternalMessageInfo + +// MsgSendPacket sends an outgoing IBC packet. +type MsgSendPacket struct { + SourceChannel string `protobuf:"bytes,1,opt,name=source_channel,json=sourceChannel,proto3" json:"source_channel,omitempty"` + TimeoutTimestamp uint64 `protobuf:"varint,2,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty"` + Payloads []Payload `protobuf:"bytes,3,rep,name=payloads,proto3" json:"payloads"` + Signer string `protobuf:"bytes,4,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgSendPacket) Reset() { *m = MsgSendPacket{} } +func (m *MsgSendPacket) String() string { return proto.CompactTextString(m) } +func (*MsgSendPacket) ProtoMessage() {} +func (*MsgSendPacket) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{4} +} +func (m *MsgSendPacket) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSendPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSendPacket.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 *MsgSendPacket) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSendPacket.Merge(m, src) +} +func (m *MsgSendPacket) XXX_Size() int { + return m.Size() +} +func (m *MsgSendPacket) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSendPacket.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSendPacket proto.InternalMessageInfo + +// MsgSendPacketResponse defines the Msg/SendPacket response type. +type MsgSendPacketResponse struct { + Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *MsgSendPacketResponse) Reset() { *m = MsgSendPacketResponse{} } +func (m *MsgSendPacketResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSendPacketResponse) ProtoMessage() {} +func (*MsgSendPacketResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{5} +} +func (m *MsgSendPacketResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSendPacketResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSendPacketResponse.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 *MsgSendPacketResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSendPacketResponse.Merge(m, src) +} +func (m *MsgSendPacketResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSendPacketResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSendPacketResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSendPacketResponse proto.InternalMessageInfo + +// MsgRecvPacket receives an incoming IBC packet. +type MsgRecvPacket struct { + Packet Packet `protobuf:"bytes,1,opt,name=packet,proto3" json:"packet"` + ProofCommitment []byte `protobuf:"bytes,2,opt,name=proof_commitment,json=proofCommitment,proto3" json:"proof_commitment,omitempty"` + ProofHeight types.Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` + Signer string `protobuf:"bytes,4,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgRecvPacket) Reset() { *m = MsgRecvPacket{} } +func (m *MsgRecvPacket) String() string { return proto.CompactTextString(m) } +func (*MsgRecvPacket) ProtoMessage() {} +func (*MsgRecvPacket) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{6} +} +func (m *MsgRecvPacket) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRecvPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRecvPacket.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 *MsgRecvPacket) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRecvPacket.Merge(m, src) +} +func (m *MsgRecvPacket) XXX_Size() int { + return m.Size() +} +func (m *MsgRecvPacket) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRecvPacket.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRecvPacket proto.InternalMessageInfo + +// MsgRecvPacketResponse defines the Msg/RecvPacket response type. +type MsgRecvPacketResponse struct { + Result ResponseResultType `protobuf:"varint,1,opt,name=result,proto3,enum=ibc.core.channel.v2.ResponseResultType" json:"result,omitempty"` +} + +func (m *MsgRecvPacketResponse) Reset() { *m = MsgRecvPacketResponse{} } +func (m *MsgRecvPacketResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRecvPacketResponse) ProtoMessage() {} +func (*MsgRecvPacketResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{7} +} +func (m *MsgRecvPacketResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRecvPacketResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRecvPacketResponse.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 *MsgRecvPacketResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRecvPacketResponse.Merge(m, src) +} +func (m *MsgRecvPacketResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRecvPacketResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRecvPacketResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRecvPacketResponse proto.InternalMessageInfo + +// MsgTimeout receives timed-out packet +type MsgTimeout struct { + Packet Packet `protobuf:"bytes,1,opt,name=packet,proto3" json:"packet"` + ProofUnreceived []byte `protobuf:"bytes,2,opt,name=proof_unreceived,json=proofUnreceived,proto3" json:"proof_unreceived,omitempty"` + ProofHeight types.Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` + Signer string `protobuf:"bytes,5,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgTimeout) Reset() { *m = MsgTimeout{} } +func (m *MsgTimeout) String() string { return proto.CompactTextString(m) } +func (*MsgTimeout) ProtoMessage() {} +func (*MsgTimeout) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{8} +} +func (m *MsgTimeout) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgTimeout) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgTimeout.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 *MsgTimeout) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgTimeout.Merge(m, src) +} +func (m *MsgTimeout) XXX_Size() int { + return m.Size() +} +func (m *MsgTimeout) XXX_DiscardUnknown() { + xxx_messageInfo_MsgTimeout.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgTimeout proto.InternalMessageInfo + +// MsgTimeoutResponse defines the Msg/Timeout response type. +type MsgTimeoutResponse struct { + Result ResponseResultType `protobuf:"varint,1,opt,name=result,proto3,enum=ibc.core.channel.v2.ResponseResultType" json:"result,omitempty"` +} + +func (m *MsgTimeoutResponse) Reset() { *m = MsgTimeoutResponse{} } +func (m *MsgTimeoutResponse) String() string { return proto.CompactTextString(m) } +func (*MsgTimeoutResponse) ProtoMessage() {} +func (*MsgTimeoutResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{9} +} +func (m *MsgTimeoutResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgTimeoutResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgTimeoutResponse.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 *MsgTimeoutResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgTimeoutResponse.Merge(m, src) +} +func (m *MsgTimeoutResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgTimeoutResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgTimeoutResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgTimeoutResponse proto.InternalMessageInfo + +// MsgAcknowledgement receives incoming IBC acknowledgement. +type MsgAcknowledgement struct { + Packet Packet `protobuf:"bytes,1,opt,name=packet,proto3" json:"packet"` + Acknowledgement Acknowledgement `protobuf:"bytes,2,opt,name=acknowledgement,proto3" json:"acknowledgement"` + ProofAcked []byte `protobuf:"bytes,3,opt,name=proof_acked,json=proofAcked,proto3" json:"proof_acked,omitempty"` + ProofHeight types.Height `protobuf:"bytes,4,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` + Signer string `protobuf:"bytes,5,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgAcknowledgement) Reset() { *m = MsgAcknowledgement{} } +func (m *MsgAcknowledgement) String() string { return proto.CompactTextString(m) } +func (*MsgAcknowledgement) ProtoMessage() {} +func (*MsgAcknowledgement) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{10} +} +func (m *MsgAcknowledgement) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAcknowledgement) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAcknowledgement.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 *MsgAcknowledgement) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAcknowledgement.Merge(m, src) +} +func (m *MsgAcknowledgement) XXX_Size() int { + return m.Size() +} +func (m *MsgAcknowledgement) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAcknowledgement.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAcknowledgement proto.InternalMessageInfo + +// MsgAcknowledgementResponse defines the Msg/Acknowledgement response type. +type MsgAcknowledgementResponse struct { + Result ResponseResultType `protobuf:"varint,1,opt,name=result,proto3,enum=ibc.core.channel.v2.ResponseResultType" json:"result,omitempty"` +} + +func (m *MsgAcknowledgementResponse) Reset() { *m = MsgAcknowledgementResponse{} } +func (m *MsgAcknowledgementResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAcknowledgementResponse) ProtoMessage() {} +func (*MsgAcknowledgementResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{11} +} +func (m *MsgAcknowledgementResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAcknowledgementResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAcknowledgementResponse.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 *MsgAcknowledgementResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAcknowledgementResponse.Merge(m, src) +} +func (m *MsgAcknowledgementResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAcknowledgementResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAcknowledgementResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAcknowledgementResponse proto.InternalMessageInfo + +func init() { + proto.RegisterEnum("ibc.core.channel.v2.ResponseResultType", ResponseResultType_name, ResponseResultType_value) + proto.RegisterType((*MsgCreateChannel)(nil), "ibc.core.channel.v2.MsgCreateChannel") + proto.RegisterType((*MsgCreateChannelResponse)(nil), "ibc.core.channel.v2.MsgCreateChannelResponse") + proto.RegisterType((*MsgRegisterCounterparty)(nil), "ibc.core.channel.v2.MsgRegisterCounterparty") + proto.RegisterType((*MsgRegisterCounterpartyResponse)(nil), "ibc.core.channel.v2.MsgRegisterCounterpartyResponse") + proto.RegisterType((*MsgSendPacket)(nil), "ibc.core.channel.v2.MsgSendPacket") + proto.RegisterType((*MsgSendPacketResponse)(nil), "ibc.core.channel.v2.MsgSendPacketResponse") + proto.RegisterType((*MsgRecvPacket)(nil), "ibc.core.channel.v2.MsgRecvPacket") + proto.RegisterType((*MsgRecvPacketResponse)(nil), "ibc.core.channel.v2.MsgRecvPacketResponse") + proto.RegisterType((*MsgTimeout)(nil), "ibc.core.channel.v2.MsgTimeout") + proto.RegisterType((*MsgTimeoutResponse)(nil), "ibc.core.channel.v2.MsgTimeoutResponse") + proto.RegisterType((*MsgAcknowledgement)(nil), "ibc.core.channel.v2.MsgAcknowledgement") + proto.RegisterType((*MsgAcknowledgementResponse)(nil), "ibc.core.channel.v2.MsgAcknowledgementResponse") +} + +func init() { proto.RegisterFile("ibc/core/channel/v2/tx.proto", fileDescriptor_d421c7119e969b99) } + +var fileDescriptor_d421c7119e969b99 = []byte{ + // 993 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x96, 0x5d, 0x6f, 0xdb, 0x54, + 0x18, 0xc7, 0xe3, 0x26, 0xeb, 0xda, 0x27, 0xed, 0x12, 0xcc, 0x46, 0x83, 0x57, 0x92, 0x10, 0x31, + 0xb5, 0x14, 0x1a, 0x33, 0x33, 0x90, 0x3a, 0x21, 0xa6, 0x2e, 0x64, 0x22, 0xd2, 0xd2, 0x46, 0x4e, + 0x32, 0x89, 0x17, 0x61, 0x39, 0xce, 0x99, 0x63, 0x35, 0xf6, 0x31, 0x3e, 0x4e, 0x58, 0xb9, 0x42, + 0x5c, 0x4d, 0xbd, 0xe2, 0x96, 0x8b, 0x4a, 0x48, 0x7c, 0x81, 0x5e, 0xf0, 0x21, 0x76, 0xc1, 0xc5, + 0x2e, 0x77, 0x85, 0xa6, 0xf6, 0x62, 0x57, 0x7c, 0x07, 0xe4, 0x73, 0x4e, 0x1c, 0x37, 0xb5, 0xd7, + 0x22, 0xca, 0x55, 0xec, 0xe7, 0xfc, 0x9e, 0xb7, 0xff, 0x73, 0xe2, 0x73, 0x60, 0xd5, 0xea, 0x19, + 0xb2, 0x81, 0x3d, 0x24, 0x1b, 0x03, 0xdd, 0x71, 0xd0, 0x50, 0x1e, 0x2b, 0xb2, 0xff, 0xa4, 0xea, + 0x7a, 0xd8, 0xc7, 0xe2, 0x9b, 0x56, 0xcf, 0xa8, 0x06, 0xab, 0x55, 0xbe, 0x5a, 0x1d, 0x2b, 0xd2, + 0x75, 0x13, 0x9b, 0x98, 0xae, 0xcb, 0xc1, 0x13, 0x43, 0xa5, 0x15, 0x03, 0x13, 0x1b, 0x13, 0xd9, + 0x26, 0xa6, 0x3c, 0xbe, 0x1d, 0xfc, 0xf0, 0x85, 0x72, 0x5c, 0x06, 0x57, 0x37, 0xf6, 0x90, 0xcf, + 0x89, 0xd2, 0x94, 0x18, 0x5a, 0xc8, 0xf1, 0x03, 0x7f, 0xf6, 0xc4, 0x81, 0xb5, 0x29, 0x80, 0x6d, + 0xdb, 0xf2, 0x6d, 0x0a, 0x29, 0x91, 0x37, 0x06, 0x56, 0x8e, 0x04, 0xc8, 0x37, 0x89, 0x59, 0xf3, + 0x90, 0xee, 0xa3, 0x1a, 0x4b, 0x27, 0xde, 0x84, 0x45, 0x16, 0x4d, 0xb3, 0xfa, 0x05, 0xa1, 0x2c, + 0xac, 0x2f, 0xaa, 0x0b, 0xcc, 0xd0, 0xe8, 0x8b, 0x8f, 0x40, 0xb4, 0x91, 0xb7, 0x37, 0x44, 0x9a, + 0xab, 0xfb, 0x03, 0xcd, 0xf5, 0xd0, 0x63, 0xeb, 0x49, 0x61, 0xae, 0x2c, 0xac, 0x67, 0x95, 0x4a, + 0x75, 0xda, 0xfe, 0x34, 0xd3, 0x58, 0xa9, 0x36, 0xa9, 0x47, 0x4b, 0xf7, 0x07, 0xf7, 0x33, 0xcf, + 0xfe, 0x2a, 0xa5, 0xd4, 0xbc, 0x1d, 0x5a, 0x5a, 0x34, 0x82, 0xf8, 0x16, 0xcc, 0x13, 0xcb, 0x74, + 0x90, 0x57, 0x48, 0xd3, 0x8c, 0xfc, 0xed, 0x6e, 0xee, 0xe9, 0x6f, 0xa5, 0xd4, 0xcf, 0xaf, 0x8e, + 0x36, 0xb8, 0xa1, 0x72, 0x0f, 0x0a, 0xb3, 0x15, 0xab, 0x88, 0xb8, 0xd8, 0x21, 0x48, 0x7c, 0x07, + 0x80, 0x6b, 0x36, 0x2d, 0x7d, 0x91, 0x5b, 0x1a, 0xfd, 0xbb, 0x99, 0x20, 0x56, 0xe5, 0x57, 0x01, + 0x56, 0x9a, 0xc4, 0x54, 0x91, 0x69, 0x11, 0x1f, 0x79, 0x35, 0x3c, 0x72, 0x7c, 0xe4, 0xb9, 0xba, + 0xe7, 0xef, 0x9f, 0x13, 0x40, 0xfc, 0x14, 0x56, 0x8c, 0x08, 0xae, 0x45, 0xd8, 0x39, 0xca, 0xde, + 0x88, 0x2e, 0xd7, 0x42, 0xbf, 0x0b, 0x37, 0xf7, 0x2e, 0x94, 0x12, 0x4a, 0x9b, 0xf4, 0x58, 0xf9, + 0x53, 0x80, 0xe5, 0x26, 0x31, 0xdb, 0xc8, 0xe9, 0xb7, 0xe8, 0xa6, 0x10, 0x6f, 0xc1, 0x35, 0x82, + 0x47, 0x9e, 0x81, 0x26, 0xf5, 0xf0, 0xc2, 0x97, 0x99, 0x75, 0x32, 0xd6, 0x0f, 0xe0, 0x0d, 0xdf, + 0xb2, 0x11, 0x1e, 0xf9, 0x5a, 0xf0, 0x4b, 0x7c, 0xdd, 0x76, 0x69, 0xd9, 0x19, 0x35, 0xcf, 0x17, + 0x3a, 0x13, 0xbb, 0xf8, 0x39, 0x2c, 0xb8, 0xfa, 0xfe, 0x10, 0xeb, 0x7d, 0x52, 0x48, 0x97, 0xd3, + 0xeb, 0x59, 0x65, 0xb5, 0x1a, 0xb3, 0xb7, 0xab, 0x2d, 0x06, 0xf1, 0xb1, 0x86, 0x3e, 0x91, 0x8e, + 0x33, 0xaf, 0xef, 0x78, 0x0b, 0x6e, 0x9c, 0xea, 0x26, 0x9c, 0xa5, 0x04, 0x0b, 0x04, 0x7d, 0x3f, + 0x42, 0x8e, 0x81, 0x68, 0x3f, 0x19, 0x35, 0x7c, 0xe7, 0x83, 0x3c, 0x61, 0x4a, 0xa8, 0xc8, 0x18, + 0x73, 0x25, 0xb6, 0x60, 0x9e, 0xfd, 0x51, 0xa8, 0x47, 0x56, 0xb9, 0x99, 0x50, 0x73, 0x80, 0xf0, + 0x92, 0xb9, 0x83, 0xf8, 0x3e, 0xe4, 0x5d, 0x0f, 0xe3, 0xc7, 0xda, 0x74, 0xe7, 0x52, 0x71, 0x96, + 0xd4, 0x1c, 0xb5, 0xd7, 0x42, 0xb3, 0x58, 0x83, 0x25, 0x86, 0x0e, 0x90, 0x65, 0x0e, 0x7c, 0x3a, + 0xd3, 0xac, 0x22, 0x45, 0x72, 0xb1, 0xff, 0xe2, 0xf8, 0x76, 0xf5, 0x4b, 0x4a, 0xf0, 0x54, 0x59, + 0xea, 0xc5, 0x4c, 0x17, 0x17, 0xe8, 0x3b, 0x2a, 0xd0, 0xb4, 0xc9, 0x50, 0xa0, 0x7b, 0x30, 0xef, + 0x21, 0x32, 0x1a, 0xb2, 0x66, 0xaf, 0x29, 0x6b, 0xb1, 0xcd, 0x4e, 0x70, 0x95, 0xa2, 0x9d, 0x7d, + 0x17, 0xa9, 0xdc, 0x8d, 0xab, 0xf8, 0x52, 0x00, 0x68, 0x12, 0xb3, 0xc3, 0x76, 0xc0, 0xa5, 0x48, + 0x38, 0x72, 0x3c, 0x64, 0x20, 0x6b, 0x8c, 0xfa, 0xa7, 0x24, 0xec, 0x86, 0xe6, 0xcb, 0x96, 0xf0, + 0xca, 0xeb, 0x25, 0xfc, 0x06, 0xc4, 0x69, 0x87, 0x97, 0xad, 0xdf, 0x1f, 0x73, 0x34, 0xfa, 0xb6, + 0xb1, 0xe7, 0xe0, 0x1f, 0x86, 0xa8, 0x6f, 0x22, 0xba, 0x49, 0xfe, 0x83, 0x8e, 0x1d, 0xc8, 0xe9, + 0xa7, 0xa3, 0xf1, 0xef, 0xeb, 0x7b, 0xb1, 0x31, 0x66, 0x32, 0xf3, 0x60, 0xb3, 0x21, 0xc4, 0x12, + 0x30, 0xf1, 0xb4, 0x20, 0x49, 0x9f, 0x2a, 0xbe, 0xa4, 0x02, 0x35, 0x6d, 0x07, 0x96, 0x33, 0x33, + 0xc9, 0xfc, 0xaf, 0x33, 0x31, 0x40, 0x3a, 0xab, 0xda, 0x25, 0xcf, 0x66, 0xe3, 0x85, 0x00, 0xe2, + 0x59, 0x48, 0xfc, 0x04, 0xca, 0x6a, 0xbd, 0xdd, 0xda, 0xdd, 0x69, 0xd7, 0x35, 0xb5, 0xde, 0xee, + 0x3e, 0xec, 0x68, 0x9d, 0xaf, 0x5a, 0x75, 0xad, 0xbb, 0xd3, 0x6e, 0xd5, 0x6b, 0x8d, 0x07, 0x8d, + 0xfa, 0x17, 0xf9, 0x94, 0x94, 0x3b, 0x38, 0x2c, 0x67, 0x23, 0x26, 0x71, 0x0d, 0xde, 0x8e, 0x75, + 0xdb, 0xd9, 0xdd, 0x6d, 0xe5, 0x05, 0x69, 0xe1, 0xe0, 0xb0, 0x9c, 0x09, 0x9e, 0xc5, 0x4d, 0x58, + 0x8d, 0x05, 0xdb, 0xdd, 0x5a, 0xad, 0xde, 0x6e, 0xe7, 0xe7, 0xa4, 0xec, 0xc1, 0x61, 0xf9, 0x2a, + 0x7f, 0x4d, 0xc4, 0x1f, 0x6c, 0x37, 0x1e, 0x76, 0xd5, 0x7a, 0x3e, 0xcd, 0x70, 0xfe, 0x2a, 0x65, + 0x9e, 0xfe, 0x5e, 0x4c, 0x29, 0x7f, 0x67, 0x20, 0xdd, 0x24, 0xa6, 0x88, 0x60, 0xf9, 0xf4, 0xe9, + 0x7d, 0x2b, 0x56, 0xaa, 0xd9, 0x23, 0x53, 0xda, 0xbc, 0x10, 0x16, 0x0e, 0xe4, 0x47, 0xb8, 0x1e, + 0x7b, 0x60, 0x7e, 0x98, 0x14, 0x26, 0x8e, 0x96, 0xee, 0xfc, 0x1b, 0x3a, 0xcc, 0xfd, 0x2d, 0x40, + 0xe4, 0xb4, 0xab, 0x24, 0xc5, 0x98, 0x32, 0xd2, 0xc6, 0xf9, 0x4c, 0x34, 0x7a, 0xe4, 0x04, 0xa9, + 0x24, 0x57, 0x38, 0x61, 0x92, 0xa3, 0xc7, 0x7c, 0xa4, 0xdb, 0x70, 0x75, 0xf2, 0x65, 0x2d, 0x25, + 0xb9, 0x71, 0x40, 0x5a, 0x3b, 0x07, 0x08, 0x83, 0xee, 0x41, 0x6e, 0xf6, 0x73, 0x93, 0xe8, 0x3b, + 0x03, 0x4a, 0xf2, 0x05, 0xc1, 0x49, 0x32, 0xe9, 0xca, 0x4f, 0xaf, 0x8e, 0x36, 0x84, 0xfb, 0x8f, + 0x9e, 0x1d, 0x17, 0x85, 0xe7, 0xc7, 0x45, 0xe1, 0xe5, 0x71, 0x51, 0xf8, 0xe5, 0xa4, 0x98, 0x7a, + 0x7e, 0x52, 0x4c, 0xbd, 0x38, 0x29, 0xa6, 0xbe, 0xfe, 0xcc, 0xb4, 0xfc, 0xc1, 0xa8, 0x17, 0x5c, + 0xf9, 0x64, 0x7e, 0xa7, 0xb5, 0x7a, 0xc6, 0xa6, 0x89, 0xe5, 0xf1, 0x96, 0x6c, 0xe3, 0xfe, 0x68, + 0x88, 0x08, 0xbb, 0x8c, 0x7e, 0x74, 0x67, 0x33, 0x7a, 0x69, 0xde, 0x77, 0x11, 0xe9, 0xcd, 0xd3, + 0x8b, 0xe8, 0xc7, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x1d, 0x8d, 0xa1, 0xe9, 0x58, 0x0b, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // CreateChannel defines a rpc handler method for MsgCreateChannel + CreateChannel(ctx context.Context, in *MsgCreateChannel, opts ...grpc.CallOption) (*MsgCreateChannelResponse, error) + // RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. + RegisterCounterparty(ctx context.Context, in *MsgRegisterCounterparty, opts ...grpc.CallOption) (*MsgRegisterCounterpartyResponse, error) + // SendPacket defines a rpc handler method for MsgSendPacket. + SendPacket(ctx context.Context, in *MsgSendPacket, opts ...grpc.CallOption) (*MsgSendPacketResponse, error) + // RecvPacket defines a rpc handler method for MsgRecvPacket. + RecvPacket(ctx context.Context, in *MsgRecvPacket, opts ...grpc.CallOption) (*MsgRecvPacketResponse, error) + // Timeout defines a rpc handler method for MsgTimeout. + Timeout(ctx context.Context, in *MsgTimeout, opts ...grpc.CallOption) (*MsgTimeoutResponse, error) + // Acknowledgement defines a rpc handler method for MsgAcknowledgement. + Acknowledgement(ctx context.Context, in *MsgAcknowledgement, opts ...grpc.CallOption) (*MsgAcknowledgementResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) CreateChannel(ctx context.Context, in *MsgCreateChannel, opts ...grpc.CallOption) (*MsgCreateChannelResponse, error) { + out := new(MsgCreateChannelResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/CreateChannel", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RegisterCounterparty(ctx context.Context, in *MsgRegisterCounterparty, opts ...grpc.CallOption) (*MsgRegisterCounterpartyResponse, error) { + out := new(MsgRegisterCounterpartyResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/RegisterCounterparty", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) SendPacket(ctx context.Context, in *MsgSendPacket, opts ...grpc.CallOption) (*MsgSendPacketResponse, error) { + out := new(MsgSendPacketResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/SendPacket", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RecvPacket(ctx context.Context, in *MsgRecvPacket, opts ...grpc.CallOption) (*MsgRecvPacketResponse, error) { + out := new(MsgRecvPacketResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/RecvPacket", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Timeout(ctx context.Context, in *MsgTimeout, opts ...grpc.CallOption) (*MsgTimeoutResponse, error) { + out := new(MsgTimeoutResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/Timeout", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Acknowledgement(ctx context.Context, in *MsgAcknowledgement, opts ...grpc.CallOption) (*MsgAcknowledgementResponse, error) { + out := new(MsgAcknowledgementResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/Acknowledgement", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // CreateChannel defines a rpc handler method for MsgCreateChannel + CreateChannel(context.Context, *MsgCreateChannel) (*MsgCreateChannelResponse, error) + // RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. + RegisterCounterparty(context.Context, *MsgRegisterCounterparty) (*MsgRegisterCounterpartyResponse, error) + // SendPacket defines a rpc handler method for MsgSendPacket. + SendPacket(context.Context, *MsgSendPacket) (*MsgSendPacketResponse, error) + // RecvPacket defines a rpc handler method for MsgRecvPacket. + RecvPacket(context.Context, *MsgRecvPacket) (*MsgRecvPacketResponse, error) + // Timeout defines a rpc handler method for MsgTimeout. + Timeout(context.Context, *MsgTimeout) (*MsgTimeoutResponse, error) + // Acknowledgement defines a rpc handler method for MsgAcknowledgement. + Acknowledgement(context.Context, *MsgAcknowledgement) (*MsgAcknowledgementResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) CreateChannel(ctx context.Context, req *MsgCreateChannel) (*MsgCreateChannelResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateChannel not implemented") +} +func (*UnimplementedMsgServer) RegisterCounterparty(ctx context.Context, req *MsgRegisterCounterparty) (*MsgRegisterCounterpartyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterCounterparty not implemented") +} +func (*UnimplementedMsgServer) SendPacket(ctx context.Context, req *MsgSendPacket) (*MsgSendPacketResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SendPacket not implemented") +} +func (*UnimplementedMsgServer) RecvPacket(ctx context.Context, req *MsgRecvPacket) (*MsgRecvPacketResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RecvPacket not implemented") +} +func (*UnimplementedMsgServer) Timeout(ctx context.Context, req *MsgTimeout) (*MsgTimeoutResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Timeout not implemented") +} +func (*UnimplementedMsgServer) Acknowledgement(ctx context.Context, req *MsgAcknowledgement) (*MsgAcknowledgementResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Acknowledgement not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_CreateChannel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateChannel) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateChannel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/CreateChannel", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateChannel(ctx, req.(*MsgCreateChannel)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RegisterCounterparty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRegisterCounterparty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RegisterCounterparty(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/RegisterCounterparty", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RegisterCounterparty(ctx, req.(*MsgRegisterCounterparty)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_SendPacket_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSendPacket) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SendPacket(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/SendPacket", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SendPacket(ctx, req.(*MsgSendPacket)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RecvPacket_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRecvPacket) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RecvPacket(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/RecvPacket", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RecvPacket(ctx, req.(*MsgRecvPacket)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Timeout_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgTimeout) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Timeout(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/Timeout", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Timeout(ctx, req.(*MsgTimeout)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Acknowledgement_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAcknowledgement) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Acknowledgement(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/Acknowledgement", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Acknowledgement(ctx, req.(*MsgAcknowledgement)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ibc.core.channel.v2.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateChannel", + Handler: _Msg_CreateChannel_Handler, + }, + { + MethodName: "RegisterCounterparty", + Handler: _Msg_RegisterCounterparty_Handler, + }, + { + MethodName: "SendPacket", + Handler: _Msg_SendPacket_Handler, + }, + { + MethodName: "RecvPacket", + Handler: _Msg_RecvPacket_Handler, + }, + { + MethodName: "Timeout", + Handler: _Msg_Timeout_Handler, + }, + { + MethodName: "Acknowledgement", + Handler: _Msg_Acknowledgement_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/core/channel/v2/tx.proto", +} + +func (m *MsgCreateChannel) 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 *MsgCreateChannel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x1a + } + { + size, err := m.MerklePathPrefix.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.ClientId) > 0 { + i -= len(m.ClientId) + copy(dAtA[i:], m.ClientId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ClientId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateChannelResponse) 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 *MsgCreateChannelResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateChannelResponse) 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 = encodeVarintTx(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterCounterparty) 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 *MsgRegisterCounterparty) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x1a + } + if len(m.CounterpartyChannelId) > 0 { + i -= len(m.CounterpartyChannelId) + copy(dAtA[i:], m.CounterpartyChannelId) + i = encodeVarintTx(dAtA, i, uint64(len(m.CounterpartyChannelId))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterCounterpartyResponse) 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 *MsgRegisterCounterpartyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterCounterpartyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgSendPacket) 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 *MsgSendPacket) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSendPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x22 + } + if len(m.Payloads) > 0 { + for iNdEx := len(m.Payloads) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Payloads[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.TimeoutTimestamp != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.TimeoutTimestamp)) + i-- + dAtA[i] = 0x10 + } + if len(m.SourceChannel) > 0 { + i -= len(m.SourceChannel) + copy(dAtA[i:], m.SourceChannel) + i = encodeVarintTx(dAtA, i, uint64(len(m.SourceChannel))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSendPacketResponse) 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 *MsgSendPacketResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSendPacketResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgRecvPacket) 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 *MsgRecvPacket) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRecvPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x22 + } + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ProofCommitment) > 0 { + i -= len(m.ProofCommitment) + copy(dAtA[i:], m.ProofCommitment) + i = encodeVarintTx(dAtA, i, uint64(len(m.ProofCommitment))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Packet.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *MsgRecvPacketResponse) 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 *MsgRecvPacketResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRecvPacketResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Result != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Result)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgTimeout) 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 *MsgTimeout) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgTimeout) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x2a + } + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ProofUnreceived) > 0 { + i -= len(m.ProofUnreceived) + copy(dAtA[i:], m.ProofUnreceived) + i = encodeVarintTx(dAtA, i, uint64(len(m.ProofUnreceived))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Packet.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *MsgTimeoutResponse) 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 *MsgTimeoutResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgTimeoutResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Result != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Result)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgAcknowledgement) 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 *MsgAcknowledgement) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAcknowledgement) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x2a + } + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if len(m.ProofAcked) > 0 { + i -= len(m.ProofAcked) + copy(dAtA[i:], m.ProofAcked) + i = encodeVarintTx(dAtA, i, uint64(len(m.ProofAcked))) + i-- + dAtA[i] = 0x1a + } + { + size, err := m.Acknowledgement.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.Packet.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *MsgAcknowledgementResponse) 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 *MsgAcknowledgementResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAcknowledgementResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Result != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Result)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgCreateChannel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.MerklePathPrefix.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateChannelResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRegisterCounterparty) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.CounterpartyChannelId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRegisterCounterpartyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgSendPacket) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SourceChannel) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.TimeoutTimestamp != 0 { + n += 1 + sovTx(uint64(m.TimeoutTimestamp)) + } + if len(m.Payloads) > 0 { + for _, e := range m.Payloads { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSendPacketResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sequence != 0 { + n += 1 + sovTx(uint64(m.Sequence)) + } + return n +} + +func (m *MsgRecvPacket) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Packet.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.ProofCommitment) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.ProofHeight.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRecvPacketResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Result != 0 { + n += 1 + sovTx(uint64(m.Result)) + } + return n +} + +func (m *MsgTimeout) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Packet.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.ProofUnreceived) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.ProofHeight.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgTimeoutResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Result != 0 { + n += 1 + sovTx(uint64(m.Result)) + } + return n +} + +func (m *MsgAcknowledgement) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Packet.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.Acknowledgement.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.ProofAcked) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.ProofHeight.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgAcknowledgementResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Result != 0 { + n += 1 + sovTx(uint64(m.Result)) + } + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgCreateChannel) 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 ErrIntOverflowTx + } + 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: MsgCreateChannel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateChannel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClientId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MerklePathPrefix", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MerklePathPrefix.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateChannelResponse) 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 ErrIntOverflowTx + } + 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: MsgCreateChannelResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateChannelResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRegisterCounterparty) 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 ErrIntOverflowTx + } + 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: MsgRegisterCounterparty: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterCounterparty: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CounterpartyChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRegisterCounterpartyResponse) 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 ErrIntOverflowTx + } + 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: MsgRegisterCounterpartyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterCounterpartyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSendPacket) 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 ErrIntOverflowTx + } + 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: MsgSendPacket: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSendPacket: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourceChannel", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SourceChannel = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutTimestamp", wireType) + } + m.TimeoutTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutTimestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payloads", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payloads = append(m.Payloads, Payload{}) + if err := m.Payloads[len(m.Payloads)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSendPacketResponse) 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 ErrIntOverflowTx + } + 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: MsgSendPacketResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSendPacketResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRecvPacket) 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 ErrIntOverflowTx + } + 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: MsgRecvPacket: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRecvPacket: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Packet", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Packet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofCommitment", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProofCommitment = append(m.ProofCommitment[:0], dAtA[iNdEx:postIndex]...) + if m.ProofCommitment == nil { + m.ProofCommitment = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProofHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRecvPacketResponse) 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 ErrIntOverflowTx + } + 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: MsgRecvPacketResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRecvPacketResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) + } + m.Result = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Result |= ResponseResultType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgTimeout) 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 ErrIntOverflowTx + } + 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: MsgTimeout: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgTimeout: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Packet", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Packet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofUnreceived", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProofUnreceived = append(m.ProofUnreceived[:0], dAtA[iNdEx:postIndex]...) + if m.ProofUnreceived == nil { + m.ProofUnreceived = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProofHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgTimeoutResponse) 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 ErrIntOverflowTx + } + 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: MsgTimeoutResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgTimeoutResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) + } + m.Result = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Result |= ResponseResultType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAcknowledgement) 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 ErrIntOverflowTx + } + 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: MsgAcknowledgement: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAcknowledgement: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Packet", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Packet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Acknowledgement", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Acknowledgement.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofAcked", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProofAcked = append(m.ProofAcked[:0], dAtA[iNdEx:postIndex]...) + if m.ProofAcked == nil { + m.ProofAcked = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProofHeight", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProofHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAcknowledgementResponse) 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 ErrIntOverflowTx + } + 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: MsgAcknowledgementResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAcknowledgementResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) + } + m.Result = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Result |= ResponseResultType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/05-port/keeper/keeper.go b/modules/core/05-port/keeper/keeper.go index a35288a48c1..41bce412efc 100644 --- a/modules/core/05-port/keeper/keeper.go +++ b/modules/core/05-port/keeper/keeper.go @@ -9,12 +9,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" + "github.com/cosmos/ibc-go/v9/modules/core/api" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) // Keeper defines the IBC connection keeper type Keeper struct { - Router *types.Router + Router *types.Router + RouterV2 *api.Router } // NewKeeper creates a new IBC connection Keeper instance diff --git a/modules/core/23-commitment/types/v2/merkle.go b/modules/core/23-commitment/types/v2/merkle.go index 08293709684..7cdccc1f39d 100644 --- a/modules/core/23-commitment/types/v2/merkle.go +++ b/modules/core/23-commitment/types/v2/merkle.go @@ -1,6 +1,7 @@ package v2 import ( + "errors" "fmt" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -28,3 +29,36 @@ func (mp MerklePath) GetKey(i uint64) ([]byte, error) { func (mp MerklePath) Empty() bool { return len(mp.KeyPath) == 0 } + +// ValidateAsPrefix validates the MerklePath to ensure it is a valid prefix +// Thus every element of the merkle path must be non-empty except for the last element +// which may be empty. In this case, the ICS24 path will be appended to the last element +// to form the full path. +func (mp MerklePath) ValidateAsPrefix() error { + if mp.Empty() { + return errors.New("path cannot have length 0") + } + + for i, key := range mp.KeyPath { + if len(key) == 0 && i != len(mp.KeyPath)-1 { + return fmt.Errorf("key at index %d cannot be empty", i) + } + } + return nil +} + +// ValidateAsPath validates the MerklePath as a fully constructed path. +// Here every element must be non-empty since the MerklePath is no longer +// acting as a prefix but is instead the full path intended for verification. +func (mp MerklePath) ValidateAsPath() error { + if mp.Empty() { + return errors.New("path cannot have length 0") + } + + for i, key := range mp.KeyPath { + if len(key) == 0 { + return fmt.Errorf("key at index %d cannot be empty", i) + } + } + return nil +} diff --git a/modules/core/23-commitment/types/v2/merkle_test.go b/modules/core/23-commitment/types/v2/merkle_test.go new file mode 100644 index 00000000000..f0701bd10f9 --- /dev/null +++ b/modules/core/23-commitment/types/v2/merkle_test.go @@ -0,0 +1,64 @@ +package v2 + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestMerklePathValidation(t *testing.T) { + cases := []struct { + name string + path MerklePath + expPrefixErr error + expPathErr error + }{ + { + "success: prefix and path", + NewMerklePath([]byte("key1"), []byte("key2")), + nil, + nil, + }, + { + "prefix with empty last key", + NewMerklePath([]byte("key1"), []byte("")), + nil, + errors.New("key at index 1 cannot be empty"), + }, + { + "prefix with single empty key", + NewMerklePath([]byte("")), + nil, + errors.New("key at index 0 cannot be empty"), + }, + { + "failure: empty path", + NewMerklePath(), + errors.New("path cannot have length 0"), + errors.New("path cannot have length 0"), + }, + { + "failure: prefix with empty first key", + NewMerklePath([]byte(""), []byte("key2")), + errors.New("key at index 0 cannot be empty"), + errors.New("key at index 0 cannot be empty"), + }, + } + + for _, tc := range cases { + err := tc.path.ValidateAsPrefix() + if tc.expPrefixErr == nil { + require.NoError(t, err, tc.name) + } else { + require.ErrorContains(t, err, tc.expPrefixErr.Error(), tc.name) + } + + err = tc.path.ValidateAsPath() + if tc.expPathErr == nil { + require.NoError(t, err, tc.name) + } else { + require.ErrorContains(t, err, tc.expPathErr.Error(), tc.name) + } + } +} diff --git a/modules/core/24-host/v2/packet_key_test.go b/modules/core/24-host/v2/packet_key_test.go new file mode 100644 index 00000000000..36642005f75 --- /dev/null +++ b/modules/core/24-host/v2/packet_key_test.go @@ -0,0 +1,34 @@ +package v2_test + +import ( + "encoding/hex" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" +) + +// TestPacketCommitmentKey is primarily used to document the expected key output +// so that other implementations (such as the IBC Solidity) can replicate the +// same key output. But it is also useful to catch any changes in the keys. +func TestPacketCommitmentKey(t *testing.T) { + actual := hex.EncodeToString(v2.PacketCommitmentKey("channel-0", 1)) + require.Equal(t, "6368616e6e656c2d30010000000000000001", actual) +} + +// TestPacketReceiptKey is primarily used to document the expected key output +// so that other implementations (such as the IBC Solidity) can replicate the +// same key output. But it is also useful to catch any changes in the keys. +func TestPacketReceiptKey(t *testing.T) { + actual := hex.EncodeToString(v2.PacketReceiptKey("channel-0", 1)) + require.Equal(t, "6368616e6e656c2d30020000000000000001", actual) +} + +// TestPacketAcknowledgementKey is primarily used to document the expected key output +// so that other implementations (such as the IBC Solidity) can replicate the +// same key output. But it is also useful to catch any changes in the keys. +func TestPacketAcknowledgementKey(t *testing.T) { + actual := hex.EncodeToString(v2.PacketAcknowledgementKey("channel-0", 1)) + require.Equal(t, "6368616e6e656c2d30030000000000000001", actual) +} diff --git a/modules/core/24-host/v2/packet_keys.go b/modules/core/24-host/v2/packet_keys.go new file mode 100644 index 00000000000..a95814198f8 --- /dev/null +++ b/modules/core/24-host/v2/packet_keys.go @@ -0,0 +1,32 @@ +package v2 + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// PacketCommitmentKey returns the store key of under which a packet commitment is stored. +func PacketCommitmentKey(channelID string, sequence uint64) []byte { + return append(append([]byte(channelID), byte(1)), sdk.Uint64ToBigEndian(sequence)...) +} + +// PacketCommitmentPrefixKey returns the store key prefix under which packet commitments for a particular channel are stored. +func PacketCommitmentPrefixKey(channelID string) []byte { + return append([]byte(channelID), byte(1)) +} + +// PacketReceiptKey returns the store key of under which a packet receipt is stored. +func PacketReceiptKey(channelID string, sequence uint64) []byte { + return append(append([]byte(channelID), byte(2)), sdk.Uint64ToBigEndian(sequence)...) +} + +// PacketAcknowledgementKey returns the store key of under which a packet acknowledgement is stored. +func PacketAcknowledgementKey(channelID string, sequence uint64) []byte { + return append(append([]byte(channelID), byte(3)), sdk.Uint64ToBigEndian(sequence)...) +} + +// NextSequenceSendKey returns the store key for the next sequence send of a given channelID. +func NextSequenceSendKey(channelID string) []byte { + return []byte(fmt.Sprintf("nextSequenceSend/%s", channelID)) +} diff --git a/modules/core/ante/ante.go b/modules/core/ante/ante.go index 243a25f7442..d3620ebdec9 100644 --- a/modules/core/ante/ante.go +++ b/modules/core/ante/ante.go @@ -7,6 +7,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" "github.com/cosmos/ibc-go/v9/modules/core/keeper" ) @@ -89,6 +90,36 @@ func (rrd RedundantRelayDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula return ctx, err } + case *channeltypesv2.MsgTimeout: + response, err := rrd.k.ChannelKeeperV2.Timeout(ctx, msg) + if err != nil { + return ctx, err + } + + if response.Result == channeltypesv2.NOOP { + redundancies++ + } + packetMsgs++ + case *channeltypesv2.MsgAcknowledgement: + response, err := rrd.k.ChannelKeeperV2.Acknowledgement(ctx, msg) + if err != nil { + return ctx, err + } + + if response.Result == channeltypesv2.NOOP { + redundancies++ + } + packetMsgs++ + case *channeltypesv2.MsgRecvPacket: + response, err := rrd.k.ChannelKeeperV2.RecvPacket(ctx, msg) + if err != nil { + return ctx, err + } + + if response.Result == channeltypesv2.NOOP { + redundancies++ + } + packetMsgs++ default: // if the multiMsg tx has a msg that is not a packet msg or update msg, then we will not return error // regardless of if all packet messages are redundant. This ensures that non-packet messages get processed diff --git a/modules/core/ante/ante_test.go b/modules/core/ante/ante_test.go index 1543e5803f4..a7fd7062f5e 100644 --- a/modules/core/ante/ante_test.go +++ b/modules/core/ante/ante_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "testing" + "time" "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" @@ -13,12 +14,15 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" "github.com/cosmos/ibc-go/v9/modules/core/ante" "github.com/cosmos/ibc-go/v9/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" + "github.com/cosmos/ibc-go/v9/testing/mock/v2" ) type AnteTestSuite struct { @@ -74,6 +78,25 @@ func (suite *AnteTestSuite) createRecvPacketMessage(isRedundant bool) *channelty return channeltypes.NewMsgRecvPacket(packet, proof, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String()) } +// createRecvPacketMessageV2 creates a V2 RecvPacket message for a packet sent from chain A to chain B. +func (suite *AnteTestSuite) createRecvPacketMessageV2(isRedundant bool) *channeltypesv2.MsgRecvPacket { + packet, err := suite.path.EndpointA.MsgSendPacket(suite.chainA.GetTimeoutTimestampSecs(), mock.NewMockPayload(mock.ModuleNameA, mock.ModuleNameB)) + suite.Require().NoError(err) + + if isRedundant { + err = suite.path.EndpointB.MsgRecvPacket(packet) + suite.Require().NoError(err) + } + + err = suite.path.EndpointB.UpdateClient() + suite.Require().NoError(err) + + packetKey := hostv2.PacketCommitmentKey(packet.SourceChannel, packet.Sequence) + proof, proofHeight := suite.chainA.QueryProof(packetKey) + + return channeltypesv2.NewMsgRecvPacket(packet, proof, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String()) +} + // createAcknowledgementMessage creates an Acknowledgement message for a packet sent from chain B to chain A. func (suite *AnteTestSuite) createAcknowledgementMessage(isRedundant bool) sdk.Msg { sequence, err := suite.path.EndpointB.SendPacket(clienttypes.NewHeight(2, 0), 0, ibctesting.MockPacketData) @@ -97,6 +120,26 @@ func (suite *AnteTestSuite) createAcknowledgementMessage(isRedundant bool) sdk.M return channeltypes.NewMsgAcknowledgement(packet, ibctesting.MockAcknowledgement, proof, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String()) } +// createAcknowledgementMessageV2 creates a V2 Acknowledgement message for a packet sent from chain B to chain A. +func (suite *AnteTestSuite) createAcknowledgementMessageV2(isRedundant bool) *channeltypesv2.MsgAcknowledgement { + packet, err := suite.path.EndpointB.MsgSendPacket(suite.chainB.GetTimeoutTimestampSecs(), mock.NewMockPayload(mock.ModuleNameA, mock.ModuleNameB)) + suite.Require().NoError(err) + + err = suite.path.EndpointA.MsgRecvPacket(packet) + suite.Require().NoError(err) + + ack := channeltypesv2.Acknowledgement{AppAcknowledgements: [][]byte{mock.MockRecvPacketResult.Acknowledgement}} + if isRedundant { + err = suite.path.EndpointB.MsgAcknowledgePacket(packet, ack) + suite.Require().NoError(err) + } + + packetKey := hostv2.PacketAcknowledgementKey(packet.DestinationChannel, packet.Sequence) + proof, proofHeight := suite.chainA.QueryProof(packetKey) + + return channeltypesv2.NewMsgAcknowledgement(packet, ack, proof, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String()) +} + // createTimeoutMessage creates an Timeout message for a packet sent from chain B to chain A. func (suite *AnteTestSuite) createTimeoutMessage(isRedundant bool) sdk.Msg { height := suite.chainA.LatestCommittedHeader.GetHeight() @@ -126,6 +169,27 @@ func (suite *AnteTestSuite) createTimeoutMessage(isRedundant bool) sdk.Msg { return channeltypes.NewMsgTimeout(packet, sequence, proof, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String()) } +// createTimeoutMessageV2 creates a V2 Timeout message for a packet sent from chain B to chain A. +func (suite *AnteTestSuite) createTimeoutMessageV2(isRedundant bool) *channeltypesv2.MsgTimeout { + timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Unix()) + packet, err := suite.path.EndpointB.MsgSendPacket(timeoutTimestamp, mock.NewMockPayload(mock.ModuleNameA, mock.ModuleNameB)) + suite.Require().NoError(err) + + suite.coordinator.IncrementTimeBy(time.Hour) + err = suite.path.EndpointB.UpdateClient() + suite.Require().NoError(err) + + if isRedundant { + err = suite.path.EndpointB.MsgTimeoutPacket(packet) + suite.Require().NoError(err) + } + + packetKey := hostv2.PacketReceiptKey(packet.SourceChannel, packet.Sequence) + proof, proofHeight := suite.chainA.QueryProof(packetKey) + + return channeltypesv2.NewMsgTimeout(packet, proof, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String()) +} + // createTimeoutOnCloseMessage creates an TimeoutOnClose message for a packet sent from chain B to chain A. func (suite *AnteTestSuite) createTimeoutOnCloseMessage(isRedundant bool) sdk.Msg { height := suite.chainA.LatestCommittedHeader.GetHeight() @@ -193,6 +257,15 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() { }, nil, }, + { + "success on one new V2 RecvPacket message", + func(suite *AnteTestSuite) []sdk.Msg { + suite.path.SetupV2() + // the RecvPacket message has not been submitted to the chain yet, so it will succeed + return []sdk.Msg{suite.createRecvPacketMessageV2(false)} + }, + nil, + }, { "success on one new Acknowledgement message", func(suite *AnteTestSuite) []sdk.Msg { @@ -201,6 +274,15 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() { }, nil, }, + { + "success on one new V2 Acknowledgement message", + func(suite *AnteTestSuite) []sdk.Msg { + suite.path.SetupV2() + // the Acknowledgement message has not been submitted to the chain yet, so it will succeed + return []sdk.Msg{suite.createAcknowledgementMessageV2(false)} + }, + nil, + }, { "success on one new Timeout message", func(suite *AnteTestSuite) []sdk.Msg { @@ -209,6 +291,15 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() { }, nil, }, + { + "success on one new Timeout V2 message", + func(suite *AnteTestSuite) []sdk.Msg { + suite.path.SetupV2() + // the Timeout message has not been submitted to the chain yet, so it will succeed + return []sdk.Msg{suite.createTimeoutMessageV2(false)} + }, + nil, + }, { "success on one new TimeoutOnClose message", func(suite *AnteTestSuite) []sdk.Msg { @@ -368,6 +459,14 @@ func (suite *AnteTestSuite) TestAnteDecoratorCheckTx() { }, channeltypes.ErrRedundantTx, }, + { + "no success on one redundant V2 RecvPacket message", + func(suite *AnteTestSuite) []sdk.Msg { + suite.path.SetupV2() + return []sdk.Msg{suite.createRecvPacketMessageV2(true)} + }, + channeltypes.ErrRedundantTx, + }, { "no success on three redundant messages of each type", func(suite *AnteTestSuite) []sdk.Msg { @@ -555,6 +654,15 @@ func (suite *AnteTestSuite) TestAnteDecoratorReCheckTx() { }, nil, }, + { + "success on one new V2 RecvPacket message", + func(suite *AnteTestSuite) []sdk.Msg { + suite.path.SetupV2() + // the RecvPacket message has not been submitted to the chain yet, so it will succeed + return []sdk.Msg{suite.createRecvPacketMessageV2(false)} + }, + nil, + }, { "success on one redundant and one new RecvPacket message", func(suite *AnteTestSuite) []sdk.Msg { @@ -595,6 +703,14 @@ func (suite *AnteTestSuite) TestAnteDecoratorReCheckTx() { }, channeltypes.ErrRedundantTx, }, + { + "no success on one redundant V2 RecvPacket message", + func(suite *AnteTestSuite) []sdk.Msg { + suite.path.SetupV2() + return []sdk.Msg{suite.createRecvPacketMessageV2(true)} + }, + channeltypes.ErrRedundantTx, + }, } for _, tc := range testCases { diff --git a/modules/core/api/api_test.go b/modules/core/api/api_test.go new file mode 100644 index 00000000000..799bc785209 --- /dev/null +++ b/modules/core/api/api_test.go @@ -0,0 +1,15 @@ +package api_test + +import ( + "testing" + + testifysuite "github.com/stretchr/testify/suite" +) + +type APITestSuite struct { + testifysuite.Suite +} + +func TestApiTestSuite(t *testing.T) { + testifysuite.Run(t, new(APITestSuite)) +} diff --git a/modules/core/api/module.go b/modules/core/api/module.go new file mode 100644 index 00000000000..4d26947f42a --- /dev/null +++ b/modules/core/api/module.go @@ -0,0 +1,55 @@ +package api + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// IBCModule defines an interface that implements all the callbacks +// that modules must define as specified in IBC Protocol V2. +type IBCModule interface { + // OnSendPacket is executed when a packet is being sent from sending chain. + // this callback is provided with the source and destination IDs, the signer, the packet sequence and the packet data + // for this specific application. + OnSendPacket( + ctx context.Context, + sourceChannel string, + destinationChannel string, + sequence uint64, + payload channeltypesv2.Payload, + signer sdk.AccAddress, + ) error + + OnRecvPacket( + ctx context.Context, + sourceChannel string, + destinationChannel string, + sequence uint64, + payload channeltypesv2.Payload, + relayer sdk.AccAddress, + ) channeltypesv2.RecvPacketResult + + // OnTimeoutPacket is executed when a packet has timed out on the receiving chain. + OnTimeoutPacket( + ctx context.Context, + sourceChannel string, + destinationChannel string, + sequence uint64, + payload channeltypesv2.Payload, + relayer sdk.AccAddress, + ) error + + // OnAcknowledgementPacket is executed when a packet gets acknowledged + OnAcknowledgementPacket( + ctx context.Context, + sourceChannel string, + destinationChannel string, + sequence uint64, + acknowledgement []byte, + payload channeltypesv2.Payload, + relayer sdk.AccAddress, + ) error +} diff --git a/modules/core/api/router.go b/modules/core/api/router.go new file mode 100644 index 00000000000..893dece45a9 --- /dev/null +++ b/modules/core/api/router.go @@ -0,0 +1,69 @@ +package api + +import ( + "errors" + "fmt" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Router contains all the module-defined callbacks required by IBC Protocol V2. +type Router struct { + routes map[string]IBCModule +} + +// NewRouter creates a new Router instance. +func NewRouter() *Router { + return &Router{ + routes: make(map[string]IBCModule), + } +} + +// AddRoute registers a route for a given module name. +func (rtr *Router) AddRoute(module string, cbs IBCModule) *Router { + if !sdk.IsAlphaNumeric(module) { + panic(errors.New("route expressions can only contain alphanumeric characters")) + } + + if rtr.HasRoute(module) { + panic(fmt.Errorf("route %s has already been registered", module)) + } + + rtr.routes[module] = cbs + + return rtr +} + +// Route returns the IBCModule for a given module name. +func (rtr *Router) Route(module string) IBCModule { + route, ok := rtr.routeOrPrefixedRoute(module) + if !ok { + panic(fmt.Sprintf("no route for %s", module)) + } + return route +} + +// HasRoute returns true if the Router has a module registered or false otherwise. +func (rtr *Router) HasRoute(module string) bool { + _, ok := rtr.routeOrPrefixedRoute(module) + return ok +} + +// routeOrPrefixedRoute returns the IBCModule for a given module name. +// if an exact match is not found, a route with the provided prefix is searched for instead. +func (rtr *Router) routeOrPrefixedRoute(module string) (IBCModule, bool) { + route, ok := rtr.routes[module] + if ok { + return route, true + } + + // it's possible that some routes have been dynamically added e.g. with interchain accounts. + // in this case, we need to check if the module has the specified prefix. + for prefix, ibcModule := range rtr.routes { + if strings.HasPrefix(module, prefix) { + return ibcModule, true + } + } + return nil, false +} diff --git a/modules/core/api/router_test.go b/modules/core/api/router_test.go new file mode 100644 index 00000000000..bdcaa3e9c5a --- /dev/null +++ b/modules/core/api/router_test.go @@ -0,0 +1,81 @@ +package api_test + +import ( + "github.com/cosmos/ibc-go/v9/modules/core/api" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" +) + +func (suite *APITestSuite) TestRouter() { + var router *api.Router + + testCases := []struct { + name string + malleate func() + assertionFn func() + }{ + { + name: "success", + malleate: func() { + router.AddRoute("module01", &mockv2.IBCModule{}) + }, + assertionFn: func() { + suite.Require().True(router.HasRoute("module01")) + }, + }, + { + name: "success: multiple modules", + malleate: func() { + router.AddRoute("module01", &mockv2.IBCModule{}) + router.AddRoute("module02", &mockv2.IBCModule{}) + router.AddRoute("module03", &mockv2.IBCModule{}) + }, + assertionFn: func() { + suite.Require().True(router.HasRoute("module01")) + suite.Require().True(router.HasRoute("module02")) + suite.Require().True(router.HasRoute("module03")) + }, + }, + { + name: "success: find by prefix", + malleate: func() { + router.AddRoute("module01", &mockv2.IBCModule{}) + }, + assertionFn: func() { + suite.Require().True(router.HasRoute("module01-foo")) + }, + }, + { + name: "failure: panics on duplicate module", + malleate: func() { + router.AddRoute("module01", &mockv2.IBCModule{}) + }, + assertionFn: func() { + suite.Require().PanicsWithError("route module01 has already been registered", func() { + router.AddRoute("module01", &mockv2.IBCModule{}) + }) + }, + }, + { + name: "failure: panics invalid-name", + malleate: func() { + router.AddRoute("module01", &mockv2.IBCModule{}) + }, + assertionFn: func() { + suite.Require().PanicsWithError("route expressions can only contain alphanumeric characters", func() { + router.AddRoute("module-02", &mockv2.IBCModule{}) + }) + }, + }, + } + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + router = api.NewRouter() + + tc.malleate() + + tc.assertionFn() + }) + } +} diff --git a/modules/core/client/cli/cli.go b/modules/core/client/cli/cli.go index ef28df054a6..7edaf621076 100644 --- a/modules/core/client/cli/cli.go +++ b/modules/core/client/cli/cli.go @@ -8,6 +8,7 @@ import ( ibcclient "github.com/cosmos/ibc-go/v9/modules/core/02-client" connection "github.com/cosmos/ibc-go/v9/modules/core/03-connection" channel "github.com/cosmos/ibc-go/v9/modules/core/04-channel" + channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -24,6 +25,7 @@ func GetTxCmd() *cobra.Command { ibcTxCmd.AddCommand( ibcclient.GetTxCmd(), channel.GetTxCmd(), + channelv2.GetTxCmd(), ) return ibcTxCmd @@ -44,6 +46,7 @@ func GetQueryCmd() *cobra.Command { ibcclient.GetQueryCmd(), connection.GetQueryCmd(), channel.GetQueryCmd(), + channelv2.GetQueryCmd(), ) return ibcQueryCmd diff --git a/modules/core/internal/errors/errors.go b/modules/core/internal/errors/errors.go new file mode 100644 index 00000000000..99acf8c02a5 --- /dev/null +++ b/modules/core/internal/errors/errors.go @@ -0,0 +1,25 @@ +package errors + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + coretypes "github.com/cosmos/ibc-go/v9/modules/core/types" +) + +// ConvertToErrorEvents converts all events to error events by appending the +// error attribute prefix to each event's attribute key. +func ConvertToErrorEvents(events sdk.Events) sdk.Events { + if events == nil { + return nil + } + + newEvents := make(sdk.Events, len(events)) + for i, event := range events { + newEvents[i] = sdk.NewEvent(coretypes.ErrorAttributeKeyPrefix + event.Type) + for _, attribute := range event.Attributes { + newEvents[i] = newEvents[i].AppendAttributes(sdk.NewAttribute(coretypes.ErrorAttributeKeyPrefix+attribute.Key, attribute.Value)) + } + } + + return newEvents +} diff --git a/modules/core/internal/v2/telemetry/packet.go b/modules/core/internal/v2/telemetry/packet.go new file mode 100644 index 00000000000..7c5c8588247 --- /dev/null +++ b/modules/core/internal/v2/telemetry/packet.go @@ -0,0 +1,14 @@ +package telemetry + +import ( + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// ReportRecvPacket TODO: https://github.com/cosmos/ibc-go/issues/7437 +func ReportRecvPacket(packet channeltypesv2.Packet) {} + +// ReportTimeoutPacket TODO: https://github.com/cosmos/ibc-go/issues/7437 +func ReportTimeoutPacket(packet channeltypesv2.Packet, timeoutType string) {} + +// ReportAcknowledgePacket TODO: https://github.com/cosmos/ibc-go/issues/7437 +func ReportAcknowledgePacket(packet channeltypesv2.Packet) {} diff --git a/modules/core/keeper/events_test.go b/modules/core/keeper/events_test.go index 98915ac13c1..359322833f0 100644 --- a/modules/core/keeper/events_test.go +++ b/modules/core/keeper/events_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v9/modules/core/keeper" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" "github.com/cosmos/ibc-go/v9/modules/core/types" ) @@ -99,7 +99,7 @@ func TestConvertToErrorEvents(t *testing.T) { tc.malleate() - newEvents := keeper.ConvertToErrorEvents(events) + newEvents := internalerrors.ConvertToErrorEvents(events) require.Equal(t, expEvents, newEvents) }) } diff --git a/modules/core/keeper/expected_keeper.go b/modules/core/keeper/expected_keeper.go new file mode 100644 index 00000000000..0f2320dd488 --- /dev/null +++ b/modules/core/keeper/expected_keeper.go @@ -0,0 +1,38 @@ +package keeper + +import ( + "context" + + channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +type PacketHandler interface { + RecvPacket( + ctx context.Context, + packet channeltypes.Packet, + proof []byte, + proofHeight exported.Height) (string, error) + + WriteAcknowledgement( + ctx context.Context, + packet exported.PacketI, + acknowledgement exported.Acknowledgement, + ) error + + AcknowledgePacket( + ctx context.Context, + packet channeltypes.Packet, + acknowledgement []byte, + proof []byte, + proofHeight exported.Height, + ) (string, error) + + TimeoutPacket( + ctx context.Context, + packet channeltypes.Packet, + proof []byte, + proofHeight exported.Height, + nextSequenceRecv uint64, + ) (string, error) +} diff --git a/modules/core/keeper/export_test.go b/modules/core/keeper/export_test.go deleted file mode 100644 index 81d79ea7aa9..00000000000 --- a/modules/core/keeper/export_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package keeper - -import sdk "github.com/cosmos/cosmos-sdk/types" - -// ConvertToErrorEvents is a wrapper around convertToErrorEvents -// to allow the function to be directly called in tests. -func ConvertToErrorEvents(events sdk.Events) sdk.Events { - return convertToErrorEvents(events) -} diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index ccb1abe974d..7f5831d18b9 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -13,8 +13,10 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectionkeeper "github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper" channelkeeper "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" + channelkeeperv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" portkeeper "github.com/cosmos/ibc-go/v9/modules/core/05-port/keeper" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" + "github.com/cosmos/ibc-go/v9/modules/core/api" "github.com/cosmos/ibc-go/v9/modules/core/types" ) @@ -23,6 +25,7 @@ type Keeper struct { ClientKeeper *clientkeeper.Keeper ConnectionKeeper *connectionkeeper.Keeper ChannelKeeper *channelkeeper.Keeper + ChannelKeeperV2 *channelkeeperv2.Keeper PortKeeper *portkeeper.Keeper cdc codec.BinaryCodec @@ -48,12 +51,14 @@ func NewKeeper( connectionKeeper := connectionkeeper.NewKeeper(cdc, storeService, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper() channelKeeper := channelkeeper.NewKeeper(cdc, storeService, clientKeeper, connectionKeeper) + channelKeeperV2 := channelkeeperv2.NewKeeper(cdc, storeService, clientKeeper, channelKeeper, connectionKeeper) return &Keeper{ cdc: cdc, ClientKeeper: clientKeeper, ConnectionKeeper: connectionKeeper, ChannelKeeper: channelKeeper, + ChannelKeeperV2: channelKeeperV2, PortKeeper: portKeeper, authority: authority, } @@ -75,6 +80,11 @@ func (k *Keeper) SetRouter(rtr *porttypes.Router) { k.PortKeeper.Router.Seal() } +// SetRouterV2 sets the v2 router for the IBC Keeper. +func (k *Keeper) SetRouterV2(rtr *api.Router) { + k.ChannelKeeperV2.Router = rtr +} + // GetAuthority returns the ibc module's authority. func (k *Keeper) GetAuthority() string { return k.authority diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 9ec65058344..396f89b5e9b 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -14,8 +14,8 @@ import ( channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" "github.com/cosmos/ibc-go/v9/modules/core/internal/telemetry" - coretypes "github.com/cosmos/ibc-go/v9/modules/core/types" ) var ( @@ -433,7 +433,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack writeFn() } else { // Modify events in cached context to reflect unsuccessful acknowledgement - ctx.EventManager().EmitEvents(convertToErrorEvents(cacheCtx.EventManager().Events())) + ctx.EventManager().EmitEvents(internalerrors.ConvertToErrorEvents(cacheCtx.EventManager().Events())) } // Set packet acknowledgement only if the acknowledgement is not nil. @@ -488,11 +488,6 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* return nil, errorsmod.Wrap(err, "timeout packet verification failed") } - // Delete packet commitment - if err = k.ChannelKeeper.TimeoutExecuted(ctx, msg.Packet); err != nil { - return nil, err - } - // Perform application logic callback err = cbs.OnTimeoutPacket(ctx, channelVersion, msg.Packet, relayer) if err != nil { @@ -542,11 +537,6 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime return nil, errorsmod.Wrap(err, "timeout on close packet verification failed") } - // Delete packet commitment - if err = k.ChannelKeeper.TimeoutExecuted(ctx, msg.Packet); err != nil { - return nil, err - } - // Perform application logic callback // // NOTE: MsgTimeout and MsgTimeoutOnClose use the same "OnTimeoutPacket" @@ -574,6 +564,7 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } + // Retrieve callbacks from router cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort) if !ok { ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to portID: %s", msg.Packet.SourcePort)) @@ -984,23 +975,3 @@ func (k *Keeper) UpdateChannelParams(goCtx context.Context, msg *channeltypes.Ms return &channeltypes.MsgUpdateParamsResponse{}, nil } - -// convertToErrorEvents converts all events to error events by appending the -// error attribute prefix to each event's attribute key. -func convertToErrorEvents(events sdk.Events) sdk.Events { - if events == nil { - return nil - } - - newEvents := make(sdk.Events, len(events)) - for i, event := range events { - newAttributes := make([]sdk.Attribute, len(event.Attributes)) - for j, attribute := range event.Attributes { - newAttributes[j] = sdk.NewAttribute(coretypes.ErrorAttributeKeyPrefix+attribute.Key, attribute.Value) - } - - newEvents[i] = sdk.NewEvent(coretypes.ErrorAttributeKeyPrefix+event.Type, newAttributes...) - } - - return newEvents -} diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index b787a7f0bad..72b5f5a71b0 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -20,7 +20,7 @@ import ( host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/keeper" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" ibcmock "github.com/cosmos/ibc-go/v9/testing/mock" @@ -185,13 +185,13 @@ func (suite *KeeperTestSuite) TestHandleRecvPacket() { if tc.expRevert { // context events should contain error events - suite.Require().Contains(events, keeper.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) + suite.Require().Contains(events, internalerrors.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) suite.Require().NotContains(events, ibcmock.NewMockRecvPacketEvent()) } else { if tc.replay { // context should not contain application events suite.Require().NotContains(events, ibcmock.NewMockRecvPacketEvent()) - suite.Require().NotContains(events, keeper.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) + suite.Require().NotContains(events, internalerrors.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) } else { // context events should contain application events suite.Require().Contains(events, ibcmock.NewMockRecvPacketEvent()) diff --git a/modules/core/module.go b/modules/core/module.go index aeac13f2862..32e2589d075 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -24,6 +24,8 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channelkeeper "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channelkeeperv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" "github.com/cosmos/ibc-go/v9/modules/core/client/cli" "github.com/cosmos/ibc-go/v9/modules/core/exported" "github.com/cosmos/ibc-go/v9/modules/core/keeper" @@ -91,6 +93,10 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r if err != nil { panic(err) } + err = channeltypesv2.RegisterQueryHandlerClient(context.Background(), mux, channeltypesv2.NewQueryClient(clientCtx)) + if err != nil { + panic(err) + } } // GetTxCmd returns the root tx command for the ibc module. @@ -131,9 +137,12 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { clienttypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) connectiontypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) channeltypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) + channeltypesv2.RegisterMsgServer(cfg.MsgServer(), am.keeper.ChannelKeeperV2) + clienttypes.RegisterQueryServer(cfg.QueryServer(), clientkeeper.NewQueryServer(am.keeper.ClientKeeper)) connectiontypes.RegisterQueryServer(cfg.QueryServer(), connectionkeeper.NewQueryServer(am.keeper.ConnectionKeeper)) channeltypes.RegisterQueryServer(cfg.QueryServer(), channelkeeper.NewQueryServer(am.keeper.ChannelKeeper)) + channeltypesv2.RegisterQueryServer(cfg.QueryServer(), channelkeeperv2.NewQueryServer(am.keeper.ChannelKeeperV2)) clientMigrator := clientkeeper.NewMigrator(am.keeper.ClientKeeper) if err := cfg.RegisterMigration(exported.ModuleName, 2, clientMigrator.Migrate2to3); err != nil { diff --git a/modules/core/types/codec.go b/modules/core/types/codec.go index 270096bc88d..d704d725ea3 100644 --- a/modules/core/types/codec.go +++ b/modules/core/types/codec.go @@ -6,6 +6,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" ) @@ -16,4 +17,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { connectiontypes.RegisterInterfaces(registry) channeltypes.RegisterInterfaces(registry) commitmenttypes.RegisterInterfaces(registry) + + channeltypesv2.RegisterInterfaces(registry) } diff --git a/modules/light-clients/06-solomachine/light_client_module_test.go b/modules/light-clients/06-solomachine/light_client_module_test.go index b011d130931..7d4ad2e94c3 100644 --- a/modules/light-clients/06-solomachine/light_client_module_test.go +++ b/modules/light-clients/06-solomachine/light_client_module_test.go @@ -440,7 +440,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { 0, ) - commitmentBz := channeltypes.CommitPacket(suite.chainA.Codec, packet) + commitmentBz := channeltypes.CommitPacket(packet) path = sm.GetPacketCommitmentPath(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) diff --git a/modules/light-clients/07-tendermint/light_client_module_test.go b/modules/light-clients/07-tendermint/light_client_module_test.go index 87119309949..f196ac0aa3e 100644 --- a/modules/light-clients/07-tendermint/light_client_module_test.go +++ b/modules/light-clients/07-tendermint/light_client_module_test.go @@ -342,7 +342,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { proof, proofHeight = testingpath.EndpointB.QueryProof(key) - value = channeltypes.CommitPacket(suite.chainA.App.GetIBCKeeper().Codec(), packet) + value = channeltypes.CommitPacket(packet) }, nil, }, { diff --git a/modules/light-clients/08-wasm/Dockerfile b/modules/light-clients/08-wasm/Dockerfile index 8e4bc8999a0..317a9b2a3fe 100644 --- a/modules/light-clients/08-wasm/Dockerfile +++ b/modules/light-clients/08-wasm/Dockerfile @@ -1,19 +1,11 @@ -FROM golang:1.22-alpine3.20 as builder - +FROM golang:1.22-alpine3.20 AS builder-base ARG LIBWASM_VERSION -ARG LIBWASM_CHECKSUM +ARG TARGETARCH RUN test -n "${LIBWASM_VERSION}" -RUN test -n "${LIBWASM_CHECKSUM}" - -RUN set -eux; apk add --no-cache git libusb-dev linux-headers gcc musl-dev make; - ENV GOPATH="" -# Grab the static library and copy it to location that will be found by the linker flag `-lwasmvm_muslc`. -ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASM_VERSION}/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a -RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep ${LIBWASM_CHECKSUM} -RUN cp /lib/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a +RUN set -eux; apk add --no-cache ca-certificates build-base git libusb-dev linux-headers curl; # Copy relevant files before go mod download. Replace directives to local paths break if local # files are not copied before go mod download. @@ -25,14 +17,32 @@ ADD LICENSE LICENSE COPY go.mod . COPY go.sum . +RUN go mod download + + +# Since it is not easy to fully cache a RUN script download of libwasmvm, we use two different stages +# and copy the correct file in the final stage. The multistage setup also helps speed up the build process +FROM alpine:3.18 AS amd64-stage +ARG LIBWASM_VERSION +ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASM_VERSION}/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a + + +FROM alpine:3.18 AS arm64-stage +ARG LIBWASM_VERSION +ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASM_VERSION}/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a + +# We have this one with nothing else in it, because COPY --from can't use variables (but FROM can) +FROM ${TARGETARCH}-stage AS libwasm-stage + +# Having this is a separate stage allows the previous stages to run in parallel +FROM builder-base AS builder WORKDIR /go/modules/light-clients/08-wasm -RUN go mod download +COPY --from=libwasm-stage /lib/libwasmvm_muslc.* /lib/ -RUN GOOS=linux GOARCH=amd64 go build -mod=readonly -tags "netgo ledger muslc" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=sim -X github.com/cosmos/cosmos-sdk/version.AppName=simd -X github.com/cosmos/cosmos-sdk/version.Version= -X github.com/cosmos/cosmos-sdk/version.Commit= -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo ledger muslc," -w -s -linkmode=external -extldflags "-Wl,-z,muldefs -static"' -trimpath -o /go/build/ ./... +RUN go build -mod=readonly -tags "netgo ledger muslc" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=sim -X github.com/cosmos/cosmos-sdk/version.AppName=simd -X github.com/cosmos/cosmos-sdk/version.Version= -X github.com/cosmos/cosmos-sdk/version.Commit= -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo ledger muslc," -w -s -linkmode=external -extldflags "-Wl,-z,muldefs -static"' -trimpath -o /go/build/ ./... -FROM alpine:3.18 +FROM alpine:3.18 COPY --from=builder /go/build/simd /bin/simd - ENTRYPOINT ["simd"] diff --git a/modules/light-clients/08-wasm/go.mod b/modules/light-clients/08-wasm/go.mod index d6d179edb94..165b89fb6d9 100644 --- a/modules/light-clients/08-wasm/go.mod +++ b/modules/light-clients/08-wasm/go.mod @@ -31,6 +31,7 @@ require ( github.com/cosmos/ibc-go/v9 v9.0.0 github.com/golang/protobuf v1.5.4 github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/prysmaticlabs/prysm/v4 v4.2.1 // used by simapp for custom querier github.com/spf13/cast v1.7.0 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 @@ -87,6 +88,7 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.7.0 // indirect github.com/emicklei/dot v1.6.2 // indirect + github.com/ethereum/go-ethereum v1.13.5-0.20231027145059-2d7dba024d76 // indirect github.com/fatih/color v1.17.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect @@ -102,7 +104,7 @@ require ( github.com/golang/glog v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/mock v1.6.0 // indirect - github.com/golang/snappy v0.0.4 // indirect + github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/btree v1.1.3 // indirect github.com/google/flatbuffers v24.3.25+incompatible // indirect github.com/google/go-cmp v0.6.0 // indirect @@ -129,6 +131,7 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/hdevalence/ed25519consensus v0.2.0 // indirect + github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e // indirect github.com/huandu/skiplist v1.2.0 // indirect github.com/iancoleman/strcase v0.3.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect @@ -136,6 +139,7 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/klauspost/compress v1.17.9 // indirect + github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/lib/pq v1.10.9 // indirect @@ -145,9 +149,11 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/minio/highwayhash v1.0.3 // indirect + github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect @@ -160,6 +166,8 @@ require ( github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.60.1 // indirect github.com/prometheus/procfs v0.15.1 // indirect + github.com/prysmaticlabs/fastssz v0.0.0-20221107182844-78142813af44 // indirect + github.com/prysmaticlabs/gohashtree v0.0.3-alpha // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/cors v1.11.1 // indirect @@ -168,12 +176,15 @@ require ( github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.5 // indirect github.com/shamaton/msgpack/v2 v2.2.0 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect + github.com/supranational/blst v0.3.11 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect + github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect github.com/tidwall/btree v1.7.0 // indirect github.com/ulikunitz/xz v0.5.11 // indirect github.com/zondax/hid v0.9.2 // indirect diff --git a/modules/light-clients/08-wasm/go.sum b/modules/light-clients/08-wasm/go.sum index 7bd5f694b49..90ddd395a79 100644 --- a/modules/light-clients/08-wasm/go.sum +++ b/modules/light-clients/08-wasm/go.sum @@ -265,6 +265,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX github.com/aws/aws-sdk-go v1.44.224 h1:09CiaaF35nRmxrzWZ2uRq5v6Ghg/d2RiPjZnSgtt+RQ= github.com/aws/aws-sdk-go v1.44.224/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= +github.com/bazelbuild/rules_go v0.23.2 h1:Wxu7JjqnF78cKZbsBsARLSXx/jlGaSLCnUV3mTlyHvM= +github.com/bazelbuild/rules_go v0.23.2/go.mod h1:MC23Dc/wkXEyk3Wpq6lCqz0ZAYOZDw2DR5y3N1q2i7M= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -374,6 +376,8 @@ github.com/creachadair/tomledit v0.0.24 h1:5Xjr25R2esu1rKCbQEmjZYlrhFkDspoAbAKb6 github.com/creachadair/tomledit v0.0.24/go.mod h1:9qHbShRWQzSCcn617cMzg4eab1vbLCOjOshAWSzWr8U= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U= +github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo= github.com/danieljoos/wincred v1.2.1 h1:dl9cBrupW8+r5250DYkYxocLeZ1Y4vB1kxgtjxw8GQs= github.com/danieljoos/wincred v1.2.1/go.mod h1:uGaFL9fDn3OLTvzCGulzE+SzjEe5NGlh5FdCcyfPwps= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -422,6 +426,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ethereum/go-ethereum v1.13.5-0.20231027145059-2d7dba024d76 h1:xH3SZXIWPj57ogsCYLpfQ9ka1BU1TjmYFrgRvqgMBmw= +github.com/ethereum/go-ethereum v1.13.5-0.20231027145059-2d7dba024d76/go.mod h1:5SYZGkLhciK5Ds7nXpWz7YNP5iBZb4uqaRHkj+GdTWo= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= @@ -529,8 +535,9 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= @@ -678,6 +685,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/hdevalence/ed25519consensus v0.2.0 h1:37ICyZqdyj0lAZ8P4D1d1id3HqbbG1N3iBb1Tb4rdcU= github.com/hdevalence/ed25519consensus v0.2.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= +github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e h1:wCMygKUQhmcQAjlk2Gquzq6dLmyMv2kF+llRspoRgrk= +github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c= github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U= @@ -724,6 +733,8 @@ github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= +github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -767,6 +778,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/minio/highwayhash v1.0.3 h1:kbnuUMoHYyVl7szWjSxJnxw11k2U709jqFPPmIUyD6Q= github.com/minio/highwayhash v1.0.3/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ= +github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= +github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -784,6 +797,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -814,13 +829,13 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= -github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q= -github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= @@ -894,6 +909,12 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/prysmaticlabs/fastssz v0.0.0-20221107182844-78142813af44 h1:c3p3UzV4vFA7xaCDphnDWOjpxcadrQ26l5b+ypsvyxo= +github.com/prysmaticlabs/fastssz v0.0.0-20221107182844-78142813af44/go.mod h1:MA5zShstUwCQaE9faGHgCGvEWUbG87p4SAXINhmCkvg= +github.com/prysmaticlabs/gohashtree v0.0.3-alpha h1:1EVinCWdb3Lorq7xn8DYQHf48nCcdAM3Vb18KsFlRWY= +github.com/prysmaticlabs/gohashtree v0.0.3-alpha/go.mod h1:4pWaT30XoEx1j8KNJf3TV+E3mQkaufn7mf+jRNb/Fuk= +github.com/prysmaticlabs/prysm/v4 v4.2.1 h1:eHdK4OuJBUCJCmHgI3c07y0u/vWrKCyOsRN2l/VXQxc= +github.com/prysmaticlabs/prysm/v4 v4.2.1/go.mod h1:0Iz1Q/WiuClvdm/9vQbiKKeToeL/uD3QBjEwV9UExBQ= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -972,10 +993,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= +github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e h1:cR8/SYRgyQCt5cNCMniB/ZScMkhI9nk8U5C7SbISXjo= +github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e/go.mod h1:Tu4lItkATkonrYuvtVjG0/rhy15qrNGNTjPdaphtZ/8= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -1281,11 +1306,13 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index 6c63e87e97e..4137782a89b 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -107,6 +107,7 @@ import ( wasm "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" wasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing/simapp/customquery" wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" ica "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts" icacontroller "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller" @@ -122,10 +123,13 @@ import ( "github.com/cosmos/ibc-go/v9/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v9/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + transferv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2" + ibctransferkeeperv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/keeper" ibc "github.com/cosmos/ibc-go/v9/modules/core" ibcclienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" ibcconnectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" + ibcapi "github.com/cosmos/ibc-go/v9/modules/core/api" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" @@ -197,6 +201,7 @@ type SimApp struct { ICAHostKeeper icahostkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper TransferKeeper ibctransferkeeper.Keeper + TransferKeeperV2 *ibctransferkeeperv2.Keeper WasmClientKeeper wasmkeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper GroupKeeper groupkeeper.Keeper @@ -434,9 +439,17 @@ func NewSimApp( authtypes.NewModuleAddress(govtypes.ModuleName).String(), mockVM, app.GRPCQueryRouter(), ) } else { + querierOption := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ + Custom: customquery.CustomQuerier(), + Stargate: wasmkeeper.AcceptListStargateQuerier( + []string{"/cosmos.base.tendermint.v1beta1.Service/ABCIQuery"}, + app.GRPCQueryRouter(), + ), + }) app.WasmClientKeeper = wasmkeeper.NewKeeperWithConfig( appCodec, runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), app.IBCKeeper.ClientKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmConfig, app.GRPCQueryRouter(), + querierOption, ) } @@ -468,6 +481,7 @@ func NewSimApp( // Create IBC Router ibcRouter := porttypes.NewRouter() + ibcRouterV2 := ibcapi.NewRouter() // Middleware Stacks @@ -554,8 +568,13 @@ func NewSimApp( feeWithMockModule := ibcfee.NewIBCMiddleware(feeMockModule, app.IBCFeeKeeper) ibcRouter.AddRoute(MockFeePort, feeWithMockModule) - // Seal the IBC Router + // register the transfer v2 module. + app.TransferKeeperV2 = ibctransferkeeperv2.NewKeeper(app.TransferKeeper, app.IBCKeeper.ChannelKeeperV2, app.MsgServiceRouter()) + ibcRouterV2.AddRoute(ibctransfertypes.ModuleName, transferv2.NewIBCModule(app.TransferKeeperV2)) + + // Seal the IBC Routers. app.IBCKeeper.SetRouter(ibcRouter) + app.IBCKeeper.SetRouterV2(ibcRouterV2) clientKeeper := app.IBCKeeper.ClientKeeper storeProvider := app.IBCKeeper.ClientKeeper.GetStoreProvider() diff --git a/modules/light-clients/08-wasm/testing/simapp/customquery/crypto.go b/modules/light-clients/08-wasm/testing/simapp/customquery/crypto.go new file mode 100644 index 00000000000..473a7b98295 --- /dev/null +++ b/modules/light-clients/08-wasm/testing/simapp/customquery/crypto.go @@ -0,0 +1,19 @@ +package customquery + +import ( + "fmt" + + "github.com/prysmaticlabs/prysm/v4/crypto/bls" +) + +func AggregatePublicKeys(publicKeys [][]byte) (bls.PublicKey, error) { + return bls.AggregatePublicKeys(publicKeys) +} + +func VerifySignature(signature []byte, message [32]byte, publicKeys [][]byte) (bool, error) { + aggregatedPublicKey, err := AggregatePublicKeys(publicKeys) + if err != nil { + return false, fmt.Errorf("failed to aggregate public keys %v", err) + } + return bls.VerifySignature(signature, message, aggregatedPublicKey) +} diff --git a/modules/light-clients/08-wasm/testing/simapp/customquery/handler.go b/modules/light-clients/08-wasm/testing/simapp/customquery/handler.go new file mode 100644 index 00000000000..e6f448ff5a3 --- /dev/null +++ b/modules/light-clients/08-wasm/testing/simapp/customquery/handler.go @@ -0,0 +1,67 @@ +package customquery + +/* + * This custom query handler is used to aggregate public keys and verify a signature using BLS. + * It is used by the 08-wasm union light client, which we we use in the solidity IBC Eureka e2e tests. + * The code here is taken from here: https://github.com/unionlabs/union/tree/main/uniond/app/custom_query + */ +import ( + "encoding/json" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + MessageSize = 32 +) + +type CustomQuery struct { + AggregateVerify *QueryAggregateVerify `json:"aggregate_verify,omitempty"` + Aggregate *QueryAggregate `json:"aggregate,omitempty"` +} +type QueryAggregate struct { + PublicKeys [][]byte `json:"public_keys"` +} +type QueryAggregateVerify struct { + PublicKeys [][]byte `json:"public_keys"` + Signature []byte `json:"signature"` + Message []byte `json:"message"` +} + +func CustomQuerier() func(sdk.Context, json.RawMessage) ([]byte, error) { + return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { + var customQuery CustomQuery + err := json.Unmarshal([]byte(request), &customQuery) + if err != nil { + return nil, fmt.Errorf("failed to parse custom query %v", err) + } + + switch { + case customQuery.Aggregate != nil: + aggregatedPublicKeys, err := AggregatePublicKeys(customQuery.Aggregate.PublicKeys) + if err != nil { + return nil, fmt.Errorf("failed to aggregate public keys %v", err) + } + + return json.Marshal(aggregatedPublicKeys.Marshal()) + case customQuery.AggregateVerify != nil: + if len(customQuery.AggregateVerify.Message) != MessageSize { + return nil, fmt.Errorf("invalid message length (%d), must be a %d bytes hash: %x", len(customQuery.AggregateVerify.Message), MessageSize, customQuery.AggregateVerify.Message) + } + + msg := [MessageSize]byte{} + for i := 0; i < MessageSize; i++ { + msg[i] = customQuery.AggregateVerify.Message[i] + } + result, err := VerifySignature(customQuery.AggregateVerify.Signature, msg, customQuery.AggregateVerify.PublicKeys) + if err != nil { + return nil, fmt.Errorf("failed to verify signature %v", err) + } + + return json.Marshal(result) + default: + return nil, fmt.Errorf("unknown custom query %v", request) + } + } +} diff --git a/modules/light-clients/09-localhost/light_client_module_test.go b/modules/light-clients/09-localhost/light_client_module_test.go index 108b52c8f99..79987c3bd89 100644 --- a/modules/light-clients/09-localhost/light_client_module_test.go +++ b/modules/light-clients/09-localhost/light_client_module_test.go @@ -150,7 +150,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { 0, ) - commitmentBz := channeltypes.CommitPacket(suite.chain.Codec, packet) + commitmentBz := channeltypes.CommitPacket(packet) suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, commitmentBz) merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())) diff --git a/proto/ibc/applications/transfer/v2/packet.proto b/proto/ibc/applications/transfer/v2/packet.proto index 5b84afe9742..05d7aecd218 100644 --- a/proto/ibc/applications/transfer/v2/packet.proto +++ b/proto/ibc/applications/transfer/v2/packet.proto @@ -48,4 +48,6 @@ message ForwardingPacketData { string destination_memo = 1; // optional intermediate path through which packet will be forwarded. repeated ibc.applications.transfer.v1.Hop hops = 2 [(gogoproto.nullable) = false]; + // timeout for the packet + uint64 timeout_timestamp = 3; } diff --git a/proto/ibc/applications/transfer/v3/query.proto b/proto/ibc/applications/transfer/v3/query.proto new file mode 100644 index 00000000000..531fbcc0a13 --- /dev/null +++ b/proto/ibc/applications/transfer/v3/query.proto @@ -0,0 +1,80 @@ +syntax = "proto3"; + +package ibc.applications.transfer.v3; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "ibc/applications/transfer/v1/transfer.proto"; +import "google/api/annotations.proto"; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types"; + +// Query provides defines the gRPC querier service. +service Query { + // Params queries all parameters of the ibc-transfer module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/ibc/apps/transfer/v2/params"; + } + + // DenomHash queries a denomination hash information. + rpc DenomHash(QueryDenomHashRequest) returns (QueryDenomHashResponse) { + option (google.api.http).get = "/ibc/apps/transfer/v2/denom_hashes/{trace=**}"; + } + + // EscrowAddress returns the escrow address for a particular port and channel id. + rpc EscrowAddress(QueryEscrowAddressRequest) returns (QueryEscrowAddressResponse) { + option (google.api.http).get = "/ibc/apps/transfer/v2/channels/{channel_id}/ports/{port_id}/escrow_address"; + } + + // TotalEscrowForDenom returns the total amount of tokens in escrow based on the denom. + rpc TotalEscrowForDenom(QueryTotalEscrowForDenomRequest) returns (QueryTotalEscrowForDenomResponse) { + option (google.api.http).get = "/ibc/apps/transfer/v2/denoms/{denom=**}/total_escrow"; + } +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + // params defines the parameters of the module. + ibc.applications.transfer.v1.Params params = 1; +} + +// QueryDenomHashRequest is the request type for the Query/DenomHash RPC +// method +message QueryDenomHashRequest { + // The denomination trace ([port_id]/[channel_id])+/[denom] + string trace = 1; +} + +// QueryDenomHashResponse is the response type for the Query/DenomHash RPC +// method. +message QueryDenomHashResponse { + // hash (in hex format) of the denomination trace information. + string hash = 1; +} + +// QueryEscrowAddressRequest is the request type for the EscrowAddress RPC method. +message QueryEscrowAddressRequest { + // unique port identifier + string port_id = 1; + // unique channel identifier + string channel_id = 2; +} + +// QueryEscrowAddressResponse is the response type of the EscrowAddress RPC method. +message QueryEscrowAddressResponse { + // the escrow account address + string escrow_address = 1; +} + +// QueryTotalEscrowForDenomRequest is the request type for TotalEscrowForDenom RPC method. +message QueryTotalEscrowForDenomRequest { + string denom = 1; +} + +// QueryTotalEscrowForDenomResponse is the response type for TotalEscrowForDenom RPC method. +message QueryTotalEscrowForDenomResponse { + cosmos.base.v1beta1.Coin amount = 1 [(gogoproto.nullable) = false]; +} diff --git a/proto/ibc/applications/transfer/v3/tx.proto b/proto/ibc/applications/transfer/v3/tx.proto new file mode 100644 index 00000000000..7ce4b098552 --- /dev/null +++ b/proto/ibc/applications/transfer/v3/tx.proto @@ -0,0 +1,61 @@ +syntax = "proto3"; + +// TODO(bznein) ugly: find a better package name? +package ibc.applications.transfer.v3; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types"; + +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "ibc/applications/transfer/v1/transfer.proto"; + +// Msg defines the ibc/transfer Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // Transfer defines a rpc handler method for MsgTransfer. + rpc Transfer(MsgTransfer) returns (MsgTransferResponse); +} + +// MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between +// ICS20 enabled chains. See ICS Spec here: +// https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures +message MsgTransfer { + option (amino.name) = "cosmos-sdk/MsgTransfer"; + option (cosmos.msg.v1.signer) = "sender"; + + option (gogoproto.goproto_getters) = false; + + // the channel by which the packet will be sent + string source_channel = 1; + // the source port for the packet + string source_port = 2; + // the destination port for the packet + string destination_port = 3; + // TODO comment + string version = 4; + // TODO comment + string encoding = 5; + // the sender address + string sender = 6; + // the recipient address on the destination chain + string receiver = 7; + // Timeout timestamp in absolute nanoseconds since unix epoch. + uint64 timeout_timestamp = 8; + // optional memo + string memo = 9; + // tokens to be transferred + repeated cosmos.base.v1beta1.Coin tokens = 10 [(gogoproto.nullable) = false]; + // optional forwarding information + ibc.applications.transfer.v1.Forwarding forwarding = 11; +} + +// MsgTransferResponse defines the Msg/Transfer response type. +message MsgTransferResponse { + option (gogoproto.goproto_getters) = false; + + // sequence number of the transfer packet sent + uint64 sequence = 1; +} diff --git a/proto/ibc/core/channel/v2/channel.proto b/proto/ibc/core/channel/v2/channel.proto new file mode 100644 index 00000000000..f3ac209cdd9 --- /dev/null +++ b/proto/ibc/core/channel/v2/channel.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package ibc.core.channel.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"; + +import "gogoproto/gogo.proto"; +import "ibc/core/commitment/v2/commitment.proto"; + +// Channel defines the channel end on a chain that is implementing the version 2 IBC protocol +// Each side will maintain its own Channel to create an IBC channel +// The channel will be referenced by a channelID which will be used to send packets +// to the counterparty +// The channel will contain the client identifier that will provide proof verification for the channel +// and the counterparty channel identifier that the other channel end will be using +// to send packets to our channel end. +message Channel { + // the client identifier of the light client representing the counterparty chain + string client_id = 1; + // the counterparty identifier that must be used by packets sent by counterparty + // to our channel end. + string counterparty_channel_id = 2; + // the key path used to store packet flow messages that the counterparty + // will use to send to us. In backwards compatible cases, we will append the channelID and sequence in order to create + // the final path. + ibc.core.commitment.v2.MerklePath merkle_path_prefix = 3 [(gogoproto.nullable) = false]; +} + +// IdentifiedChannel defines a channel with an additional channel identifier field. +message IdentifiedChannel { + option (gogoproto.goproto_getters) = false; + + // channel identified. + Channel channel = 1 [(gogoproto.nullable) = false]; + // channel identifier + string channel_id = 2; +} diff --git a/proto/ibc/core/channel/v2/genesis.proto b/proto/ibc/core/channel/v2/genesis.proto new file mode 100644 index 00000000000..a4c54a91977 --- /dev/null +++ b/proto/ibc/core/channel/v2/genesis.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package ibc.core.channel.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"; + +import "gogoproto/gogo.proto"; +import "ibc/core/channel/v2/channel.proto"; + +// GenesisState defines the ibc channel/v2 submodule's genesis state. +message GenesisState { + repeated IdentifiedChannel channels = 1 [(gogoproto.casttype) = "IdentifiedChannel", (gogoproto.nullable) = false]; + repeated PacketState acknowledgements = 2 [(gogoproto.nullable) = false]; + repeated PacketState commitments = 3 [(gogoproto.nullable) = false]; + repeated PacketState receipts = 4 [(gogoproto.nullable) = false]; + repeated PacketSequence send_sequences = 5 [(gogoproto.nullable) = false]; + // the sequence for the next generated channel identifier + uint64 next_channel_sequence = 6; +} + +// PacketState defines the generic type necessary to retrieve and store +// packet commitments, acknowledgements, and receipts. +// Caller is responsible for knowing the context necessary to interpret this +// state as a commitment, acknowledgement, or a receipt. +message PacketState { + option (gogoproto.goproto_getters) = false; + + // channel unique identifier. + string channel_id = 1; + // packet sequence. + uint64 sequence = 2; + // embedded data that represents packet state. + bytes data = 3; +} + +// PacketSequence defines the genesis type necessary to retrieve and store next send sequences. +message PacketSequence { + // channel unique identifier. + string channel_id = 1; + // packet sequence + uint64 sequence = 2; +} diff --git a/proto/ibc/core/channel/v2/packet.proto b/proto/ibc/core/channel/v2/packet.proto new file mode 100644 index 00000000000..ea14112c643 --- /dev/null +++ b/proto/ibc/core/channel/v2/packet.proto @@ -0,0 +1,63 @@ + +syntax = "proto3"; + +package ibc.core.channel.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"; + +import "gogoproto/gogo.proto"; + +// Packet defines a type that carries data across different chains through IBC +message Packet { + // number corresponds to the order of sends and receives, where a Packet + // with an earlier sequence number must be sent and received before a Packet + // with a later sequence number. + uint64 sequence = 1; + // identifies the sending chain. + string source_channel = 2; + // identifies the receiving chain. + string destination_channel = 3; + // timeout timestamp in seconds after which the packet times out. + uint64 timeout_timestamp = 4; + // a list of payloads, each one for a specific application. + repeated Payload payloads = 5 [(gogoproto.nullable) = false]; +} + +// Payload contains the source and destination ports and payload for the application (version, encoding, raw bytes) +message Payload { + // specifies the source port of the packet. + string source_port = 1; + // specifies the destination port of the packet. + string destination_port = 2; + // version of the specified application. + string version = 3; + // the encoding used for the provided value. + string encoding = 4; + // the raw bytes for the payload. + bytes value = 5; +} + +// Acknowledgement contains a list of all ack results associated with a single packet. +message Acknowledgement { + repeated bytes app_acknowledgements = 1; +} + +// PacketStatus specifies the status of a RecvPacketResult. +enum PacketStatus { + // PACKET_STATUS_UNSPECIFIED indicates an unknown packet status. + PACKET_STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "NONE"]; + // PACKET_STATUS_SUCCESS indicates a successful packet receipt. + PACKET_STATUS_SUCCESS = 1 [(gogoproto.enumvalue_customname) = "Success"]; + // PACKET_STATUS_FAILURE indicates a failed packet receipt. + PACKET_STATUS_FAILURE = 2 [(gogoproto.enumvalue_customname) = "Failure"]; + // PACKET_STATUS_ASYNC indicates an async packet receipt. + PACKET_STATUS_ASYNC = 3 [(gogoproto.enumvalue_customname) = "Async"]; +} + +// RecvPacketResult speecifies the status of a packet as well as the acknowledgement bytes. +message RecvPacketResult { + // status of the packet + PacketStatus status = 1; + // acknowledgement of the packet + bytes acknowledgement = 2; +} diff --git a/proto/ibc/core/channel/v2/query.proto b/proto/ibc/core/channel/v2/query.proto new file mode 100644 index 00000000000..159b9efd907 --- /dev/null +++ b/proto/ibc/core/channel/v2/query.proto @@ -0,0 +1,191 @@ +syntax = "proto3"; + +package ibc.core.channel.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"; + +import "cosmos/base/query/v1beta1/pagination.proto"; +import "ibc/core/channel/v2/channel.proto"; +import "ibc/core/channel/v2/genesis.proto"; +import "ibc/core/client/v1/client.proto"; +import "google/api/annotations.proto"; +import "gogoproto/gogo.proto"; + +// Query provides defines the gRPC querier service +service Query { + // Channel queries the counterparty of an IBC client. + rpc Channel(QueryChannelRequest) returns (QueryChannelResponse) { + option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}"; + } + + // NextSequenceSend returns the next send sequence for a given channel. + rpc NextSequenceSend(QueryNextSequenceSendRequest) returns (QueryNextSequenceSendResponse) { + option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/next_sequence_send"; + } + + // PacketCommitment queries a stored packet commitment hash. + rpc PacketCommitment(QueryPacketCommitmentRequest) returns (QueryPacketCommitmentResponse) { + option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/packet_commitments/{sequence}"; + } + + // PacketCommitments queries a stored packet commitment hash. + rpc PacketCommitments(QueryPacketCommitmentsRequest) returns (QueryPacketCommitmentsResponse) { + option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/packet_commitments"; + } + + // PacketAcknowledgement queries a stored acknowledgement commitment hash. + rpc PacketAcknowledgement(QueryPacketAcknowledgementRequest) returns (QueryPacketAcknowledgementResponse) { + option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/packet_acks/{sequence}"; + } + + // PacketReceipt queries a stored packet receipt. + rpc PacketReceipt(QueryPacketReceiptRequest) returns (QueryPacketReceiptResponse) { + option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/packet_receipts/{sequence}"; + } + + // UnreceivedPakcets returns all unreceived packets. + rpc UnreceivedPackets(QueryUnreceivedPacketsRequest) returns (QueryUnreceivedPacketsResponse) { + option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/packet_commitments/" + "{sequences}/unreceived_packets"; + } + + // UnreceivedAcks returns all the unreceived IBC acknowledgements associated with a channel and sequences. + rpc UnreceivedAcks(QueryUnreceivedAcksRequest) returns (QueryUnreceivedAcksResponse) { + option (google.api.http).get = + "/ibc/core/channel/v2/channels/{channel_id}/packet_commitments/{packet_ack_sequences}/unreceived_acks"; + } +} + +// QueryChannelRequest is the request type for the Query/Channel RPC method +message QueryChannelRequest { + string channel_id = 1; +} + +// QueryChannelRequest is the response type for the Query/Channel RPC method +message QueryChannelResponse { + // the channel associated with the provided channel id + Channel channel = 1 [(gogoproto.nullable) = false]; +} + +// QueryNextSequenceSendRequest is the request type for the Query/QueryNextSequenceSend RPC method +message QueryNextSequenceSendRequest { + // channel unique identifier + string channel_id = 1; +} + +// QueryNextSequenceSendResponse is the response type for the Query/QueryNextSequenceSend RPC method +message QueryNextSequenceSendResponse { + // next sequence send number + uint64 next_sequence_send = 1; + // merkle proof of existence + bytes proof = 2; + // height at which the proof was retrieved + ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; +} + +// QueryPacketCommitmentRequest is the request type for the Query/PacketCommitment RPC method. +message QueryPacketCommitmentRequest { + // channel unique identifier + string channel_id = 1; + // packet sequence + uint64 sequence = 2; +} + +// QueryPacketCommitmentResponse is the response type for the Query/PacketCommitment RPC method. +message QueryPacketCommitmentResponse { + // packet associated with the request fields + bytes commitment = 1; + // merkle proof of existence + bytes proof = 2; + // height at which the proof was retrieved + ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; +} + +// QueryPacketCommitmentsRequest is the request type for the Query/PacketCommitments RPC method. +message QueryPacketCommitmentsRequest { + // channel unique identifier + string channel_id = 1; + // pagination request + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +// QueryPacketCommitmentResponse is the response type for the Query/PacketCommitment RPC method. +message QueryPacketCommitmentsResponse { + // collection of packet commitments for the requested channel identifier. + repeated ibc.core.channel.v2.PacketState commitments = 1; + // pagination response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; + // query block height. + ibc.core.client.v1.Height height = 3 [(gogoproto.nullable) = false]; +} + +// QueryPacketAcknowledgementRequest is the request type for the Query/PacketAcknowledgement RPC method. +message QueryPacketAcknowledgementRequest { + // channel unique identifier + string channel_id = 1; + // packet sequence + uint64 sequence = 2; +} + +// QueryPacketAcknowledgementResponse is the response type for the Query/PacketAcknowledgement RPC method. +message QueryPacketAcknowledgementResponse { + // acknowledgement associated with the request fields + bytes acknowledgement = 1; + // merkle proof of existence + bytes proof = 2; + // height at which the proof was retrieved + ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; +} + +// QueryPacketReceiptRequest is the request type for the Query/PacketReceipt RPC method. +message QueryPacketReceiptRequest { + // port unique identifier + string port_id = 1; + // channel unique identifier + string channel_id = 2; + // packet sequence + uint64 sequence = 3; +} + +// QueryPacketReceiptResponse is the response type for the Query/PacketReceipt RPC method. +message QueryPacketReceiptResponse { + // success flag for if receipt exists + bool received = 2; + // merkle proof of existence or absence + bytes proof = 3; + // height at which the proof was retrieved + ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false]; +} + +// QueryUnreceivedPacketsRequest is the request type for the Query/UnreceivedPackets RPC method +message QueryUnreceivedPacketsRequest { + // channel unique identifier + string channel_id = 1; + // list of packet sequences + repeated uint64 sequences = 2; +} + +// QueryUnreceivedPacketsResponse is the response type for the Query/UnreceivedPacketCommitments RPC method +message QueryUnreceivedPacketsResponse { + // list of unreceived packet sequences + repeated uint64 sequences = 1; + // query block height + ibc.core.client.v1.Height height = 2 [(gogoproto.nullable) = false]; +} +// QueryUnreceivedAcks is the request type for the +// Query/UnreceivedAcks RPC method +message QueryUnreceivedAcksRequest { + // channel unique identifier + string channel_id = 1; + // list of acknowledgement sequences + repeated uint64 packet_ack_sequences = 2; +} + +// QueryUnreceivedAcksResponse is the response type for the +// Query/UnreceivedAcks RPC method +message QueryUnreceivedAcksResponse { + // list of unreceived acknowledgement sequences + repeated uint64 sequences = 1; + // query block height + ibc.core.client.v1.Height height = 2 [(gogoproto.nullable) = false]; +} diff --git a/proto/ibc/core/channel/v2/tx.proto b/proto/ibc/core/channel/v2/tx.proto new file mode 100644 index 00000000000..27eaa08c805 --- /dev/null +++ b/proto/ibc/core/channel/v2/tx.proto @@ -0,0 +1,164 @@ +syntax = "proto3"; + +package ibc.core.channel.v2; + +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"; + +import "gogoproto/gogo.proto"; +import "cosmos/msg/v1/msg.proto"; +import "ibc/core/channel/v2/packet.proto"; +import "ibc/core/client/v1/client.proto"; +import "ibc/core/commitment/v2/commitment.proto"; + +// Msg defines the ibc/channel/v2 Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // CreateChannel defines a rpc handler method for MsgCreateChannel + rpc CreateChannel(MsgCreateChannel) returns (MsgCreateChannelResponse); + + // RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty. + rpc RegisterCounterparty(MsgRegisterCounterparty) returns (MsgRegisterCounterpartyResponse); + + // SendPacket defines a rpc handler method for MsgSendPacket. + rpc SendPacket(MsgSendPacket) returns (MsgSendPacketResponse); + + // RecvPacket defines a rpc handler method for MsgRecvPacket. + rpc RecvPacket(MsgRecvPacket) returns (MsgRecvPacketResponse); + + // Timeout defines a rpc handler method for MsgTimeout. + rpc Timeout(MsgTimeout) returns (MsgTimeoutResponse); + + // Acknowledgement defines a rpc handler method for MsgAcknowledgement. + rpc Acknowledgement(MsgAcknowledgement) returns (MsgAcknowledgementResponse); +} + +// MsgCreateChannel defines the message used to create a v2 Channel. +message MsgCreateChannel { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + // the client identifier of the light client representing the counterparty chain + string client_id = 1; + // the key path used to store packet flow messages that the counterparty + // will use to send to us. + ibc.core.commitment.v2.MerklePath merkle_path_prefix = 2 [(gogoproto.nullable) = false]; + // signer address + string signer = 3; +} + +// MsgCreateChannelResponse defines the Msg/CreateChannel response type. +message MsgCreateChannelResponse { + option (gogoproto.goproto_getters) = false; + + string channel_id = 1; +} + +// MsgRegisterCounterparty defines the message used to provide the counterparty channel +// identifier. +message MsgRegisterCounterparty { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + // unique identifier we will use to write all packet messages sent to counterparty + string channel_id = 1; + // counterparty channel identifier + string counterparty_channel_id = 2; + // signer address + string signer = 3; +} + +// MsgRegisterCounterpartyResponse defines the Msg/RegisterCounterparty response type. +message MsgRegisterCounterpartyResponse {} + +// MsgSendPacket sends an outgoing IBC packet. +message MsgSendPacket { + option (cosmos.msg.v1.signer) = "signer"; + option (gogoproto.goproto_getters) = false; + + string source_channel = 1; + uint64 timeout_timestamp = 2; + repeated Payload payloads = 3 [(gogoproto.nullable) = false]; + string signer = 4; +} + +// MsgSendPacketResponse defines the Msg/SendPacket response type. +message MsgSendPacketResponse { + option (gogoproto.goproto_getters) = false; + + uint64 sequence = 1; +} + +// MsgRecvPacket receives an incoming IBC packet. +message MsgRecvPacket { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + Packet packet = 1 [(gogoproto.nullable) = false]; + bytes proof_commitment = 2; + ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; + string signer = 4; +} + +// ResponseResultType defines the possible outcomes of the execution of a message +enum ResponseResultType { + option (gogoproto.goproto_enum_prefix) = false; + + // Default zero value enumeration + RESPONSE_RESULT_TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNSPECIFIED"]; + // The message did not call the IBC application callbacks (because, for example, the packet had already been relayed) + RESPONSE_RESULT_TYPE_NOOP = 1 [(gogoproto.enumvalue_customname) = "NOOP"]; + // The message was executed successfully + RESPONSE_RESULT_TYPE_SUCCESS = 2 [(gogoproto.enumvalue_customname) = "SUCCESS"]; + // The message was executed unsuccessfully + RESPONSE_RESULT_TYPE_FAILURE = 3 [(gogoproto.enumvalue_customname) = "FAILURE"]; +} + +// MsgRecvPacketResponse defines the Msg/RecvPacket response type. +message MsgRecvPacketResponse { + option (gogoproto.goproto_getters) = false; + + ResponseResultType result = 1; +} + +// MsgTimeout receives timed-out packet +message MsgTimeout { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + Packet packet = 1 [(gogoproto.nullable) = false]; + bytes proof_unreceived = 2; + ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; + string signer = 5; +} + +// MsgTimeoutResponse defines the Msg/Timeout response type. +message MsgTimeoutResponse { + option (gogoproto.goproto_getters) = false; + + ResponseResultType result = 1; +} + +// MsgAcknowledgement receives incoming IBC acknowledgement. +message MsgAcknowledgement { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + Packet packet = 1 [(gogoproto.nullable) = false]; + Acknowledgement acknowledgement = 2 [(gogoproto.nullable) = false]; + bytes proof_acked = 3; + ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false]; + string signer = 5; +} + +// MsgAcknowledgementResponse defines the Msg/Acknowledgement response type. +message MsgAcknowledgementResponse { + option (gogoproto.goproto_getters) = false; + + ResponseResultType result = 1; +} diff --git a/proto/ibc/core/client/v1/query.proto b/proto/ibc/core/client/v1/query.proto index 1cc773e5990..02c3f4b1eeb 100644 --- a/proto/ibc/core/client/v1/query.proto +++ b/proto/ibc/core/client/v1/query.proto @@ -241,4 +241,4 @@ message QueryVerifyMembershipRequest { message QueryVerifyMembershipResponse { // boolean indicating success or failure of proof verification. bool success = 1; -} \ No newline at end of file +} diff --git a/simapp/app.go b/simapp/app.go index 73f50bdb3a1..cba03e2f857 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -452,7 +452,7 @@ func NewSimApp( AddRoute(icacontrollertypes.SubModuleName, icaControllerStack). AddRoute(icahosttypes.SubModuleName, icaHostStack) - // Seal the IBC Router + // Set the IBC Routers app.IBCKeeper.SetRouter(ibcRouter) clientKeeper := app.IBCKeeper.ClientKeeper diff --git a/simapp/go.mod b/simapp/go.mod index 52a67914ea9..957296290e9 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -67,6 +67,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v1.2.0 // indirect + github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect github.com/cosmos/ics23/go v0.11.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect github.com/creachadair/atomicfile v0.3.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 02f3dc374c2..6f8550fad0d 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -360,6 +360,8 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM= github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI= +github.com/cosmos/ibc-go/modules/capability v1.0.1 h1:ibwhrpJ3SftEEZRxCRkH0fQZ9svjthrX2+oXdZvzgGI= +github.com/cosmos/ibc-go/modules/capability v1.0.1/go.mod h1:rquyOV262nGJplkumH+/LeYs04P3eV8oB7ZM4Ygqk4E= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/testing/chain.go b/testing/chain.go index a898b64fd3d..67ff41baf9e 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -557,6 +557,12 @@ func (chain *TestChain) GetTimeoutTimestamp() uint64 { return uint64(chain.GetContext().BlockTime().UnixNano()) + DefaultTimeoutTimestampDelta } +// GetTimeoutTimestampSecs is a convenience function which returns a IBC packet timeout timestamp in seconds +// to be used for testing. It returns the current block timestamp + default timestamp delta (1 hour). +func (chain *TestChain) GetTimeoutTimestampSecs() uint64 { + return uint64(chain.GetContext().BlockTime().Unix()) + uint64(time.Hour.Seconds()) +} + // DeleteKey deletes the specified key from the ibc store. func (chain *TestChain) DeleteKey(key []byte) { storeKey := chain.GetSimApp().GetKey(exported.StoreKey) diff --git a/testing/endpoint.go b/testing/endpoint.go index 5e71de994a1..1fc0be299ed 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -165,6 +165,16 @@ func (endpoint *Endpoint) UpdateClient() (err error) { return endpoint.Chain.sendMsgs(msg) } +// FreezeClient freezes the IBC client associated with the endpoint. +func (endpoint *Endpoint) FreezeClient() { + clientState := endpoint.Chain.GetClientState(endpoint.ClientID) + tmClientState, ok := clientState.(*ibctm.ClientState) + require.True(endpoint.Chain.TB, ok) + + tmClientState.FrozenHeight = clienttypes.NewHeight(0, 1) + endpoint.Chain.App.GetIBCKeeper().ClientKeeper.SetClientState(endpoint.Chain.GetContext(), endpoint.ClientID, tmClientState) +} + // UpgradeChain will upgrade a chain's chainID to the next revision number. // It will also update the counterparty client. // TODO: implement actual upgrade chain functionality via scheduling an upgrade diff --git a/testing/endpoint_v2.go b/testing/endpoint_v2.go new file mode 100644 index 00000000000..b4efd98247b --- /dev/null +++ b/testing/endpoint_v2.go @@ -0,0 +1,113 @@ +package ibctesting + +import ( + "github.com/cosmos/gogoproto/proto" + + sdk "github.com/cosmos/cosmos-sdk/types" + + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" +) + +// CreateChannel will construct and execute a new MsgCreateChannel on the associated endpoint. +func (endpoint *Endpoint) CreateChannel() (err error) { + endpoint.IncrementNextChannelSequence() + msg := channeltypesv2.NewMsgCreateChannel(endpoint.ClientID, MerklePath, endpoint.Chain.SenderAccount.GetAddress().String()) + + // create channel + res, err := endpoint.Chain.SendMsgs(msg) + if err != nil { + return err + } + + endpoint.ChannelID, err = ParseChannelIDFromEvents(res.Events) + if err != nil { + return err + } + + return nil +} + +// RegisterCounterparty will construct and execute a MsgRegisterCounterparty on the associated endpoint. +func (endpoint *Endpoint) RegisterCounterparty() (err error) { + msg := channeltypesv2.NewMsgRegisterCounterparty(endpoint.ChannelID, endpoint.Counterparty.ChannelID, endpoint.Chain.SenderAccount.GetAddress().String()) + + // setup counterparty + _, err = endpoint.Chain.SendMsgs(msg) + + return err +} + +// MsgSendPacket sends a packet on the associated endpoint. The constructed packet is returned. +func (endpoint *Endpoint) MsgSendPacket(timeoutTimestamp uint64, payload channeltypesv2.Payload) (channeltypesv2.Packet, error) { + msgSendPacket := channeltypesv2.NewMsgSendPacket(endpoint.ChannelID, timeoutTimestamp, endpoint.Chain.SenderAccount.GetAddress().String(), payload) + + res, err := endpoint.Chain.SendMsgs(msgSendPacket) + if err != nil { + return channeltypesv2.Packet{}, err + } + + if err := endpoint.Counterparty.UpdateClient(); err != nil { + return channeltypesv2.Packet{}, err + } + + // TODO: parse the packet from events instead of from the response. https://github.com/cosmos/ibc-go/issues/7459 + // get sequence from msg response + var msgData sdk.TxMsgData + err = proto.Unmarshal(res.Data, &msgData) + if err != nil { + return channeltypesv2.Packet{}, err + } + msgResponse := msgData.MsgResponses[0] + var sendResponse channeltypesv2.MsgSendPacketResponse + err = proto.Unmarshal(msgResponse.Value, &sendResponse) + if err != nil { + return channeltypesv2.Packet{}, err + } + packet := channeltypesv2.NewPacket(sendResponse.Sequence, endpoint.ChannelID, endpoint.Counterparty.ChannelID, timeoutTimestamp, payload) + + return packet, nil +} + +// MsgRecvPacket sends a MsgRecvPacket on the associated endpoint with the provided packet. +func (endpoint *Endpoint) MsgRecvPacket(packet channeltypesv2.Packet) error { + // get proof of packet commitment from chainA + packetKey := hostv2.PacketCommitmentKey(packet.SourceChannel, packet.Sequence) + proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) + + msg := channeltypesv2.NewMsgRecvPacket(packet, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) + + if err := endpoint.Chain.sendMsgs(msg); err != nil { + return err + } + + return endpoint.Counterparty.UpdateClient() +} + +// MsgAcknowledgePacket sends a MsgAcknowledgement on the associated endpoint with the provided packet and ack. +func (endpoint *Endpoint) MsgAcknowledgePacket(packet channeltypesv2.Packet, ack channeltypesv2.Acknowledgement) error { + packetKey := hostv2.PacketAcknowledgementKey(packet.DestinationChannel, packet.Sequence) + proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) + + msg := channeltypesv2.NewMsgAcknowledgement(packet, ack, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) + + if err := endpoint.Chain.sendMsgs(msg); err != nil { + return err + } + + return endpoint.Counterparty.UpdateClient() +} + +// MsgTimeoutPacket sends a MsgTimeout on the associated endpoint with the provided packet. +func (endpoint *Endpoint) MsgTimeoutPacket(packet channeltypesv2.Packet) error { + packetKey := hostv2.PacketReceiptKey(packet.DestinationChannel, packet.Sequence) + proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) + + msg := channeltypesv2.NewMsgTimeout(packet, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) + + if err := endpoint.Chain.sendMsgs(msg); err != nil { + return err + } + + return endpoint.Counterparty.UpdateClient() +} diff --git a/testing/events.go b/testing/events.go index 7c467c5e48c..a4caaf46a9e 100644 --- a/testing/events.go +++ b/testing/events.go @@ -14,6 +14,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) // ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the @@ -44,10 +45,10 @@ func ParseConnectionIDFromEvents(events []abci.Event) (string, error) { } // ParseChannelIDFromEvents parses events emitted from a MsgChannelOpenInit or -// MsgChannelOpenTry and returns the channel identifier. +// MsgChannelOpenTry or a MsgCreateChannel and returns the channel identifier. func ParseChannelIDFromEvents(events []abci.Event) (string, error) { for _, ev := range events { - if ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry { + if ev.Type == channeltypesv2.EventTypeCreateChannel || ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry { if attribute, found := attributeByKey(ev.Attributes, channeltypes.AttributeKeyChannelID); found { return attribute.Value, nil } diff --git a/testing/mock/v2/ibc_app.go b/testing/mock/v2/ibc_app.go new file mode 100644 index 00000000000..7b72f4bac30 --- /dev/null +++ b/testing/mock/v2/ibc_app.go @@ -0,0 +1,16 @@ +package mock + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +type IBCApp struct { + OnSendPacket func(goCtx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, signer sdk.AccAddress) error + OnRecvPacket func(goCtx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult + OnTimeoutPacket func(goCtx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, relayer sdk.AccAddress) error + OnAcknowledgementPacket func(goCtx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, acknowledgement []byte, relayer sdk.AccAddress) error +} diff --git a/testing/mock/v2/ibc_module.go b/testing/mock/v2/ibc_module.go new file mode 100644 index 00000000000..8ea9fad704a --- /dev/null +++ b/testing/mock/v2/ibc_module.go @@ -0,0 +1,60 @@ +package mock + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + "github.com/cosmos/ibc-go/v9/modules/core/api" +) + +var _ api.IBCModule = (*IBCModule)(nil) + +const ( + // ModuleNameA is a name that can be used for the first mock application. + ModuleNameA = ModuleName + "A" + // ModuleNameB is a name that can be used for the second mock application. + ModuleNameB = ModuleName + "B" +) + +// IBCModule is a mock implementation of the IBCModule interface. +// which delegates calls to the underlying IBCApp. +type IBCModule struct { + IBCApp *IBCApp +} + +// NewIBCModule creates a new IBCModule with an underlying mock IBC application. +func NewIBCModule() IBCModule { + return IBCModule{ + IBCApp: &IBCApp{}, + } +} + +func (im IBCModule) OnSendPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, data channeltypesv2.Payload, signer sdk.AccAddress) error { + if im.IBCApp.OnSendPacket != nil { + return im.IBCApp.OnSendPacket(ctx, sourceChannel, destinationChannel, sequence, data, signer) + } + return nil +} + +func (im IBCModule) OnRecvPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, data channeltypesv2.Payload, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult { + if im.IBCApp.OnRecvPacket != nil { + return im.IBCApp.OnRecvPacket(ctx, sourceChannel, destinationChannel, sequence, data, relayer) + } + return MockRecvPacketResult +} + +func (im IBCModule) OnAcknowledgementPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, acknowledgement []byte, payload channeltypesv2.Payload, relayer sdk.AccAddress) error { + if im.IBCApp.OnAcknowledgementPacket != nil { + return im.IBCApp.OnAcknowledgementPacket(ctx, sourceChannel, destinationChannel, sequence, payload, acknowledgement, relayer) + } + return nil +} + +func (im IBCModule) OnTimeoutPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, relayer sdk.AccAddress) error { + if im.IBCApp.OnTimeoutPacket != nil { + return im.IBCApp.OnTimeoutPacket(ctx, sourceChannel, destinationChannel, sequence, payload, relayer) + } + return nil +} diff --git a/testing/mock/v2/mock.go b/testing/mock/v2/mock.go new file mode 100644 index 00000000000..3d2a0bd8201 --- /dev/null +++ b/testing/mock/v2/mock.go @@ -0,0 +1,32 @@ +package mock + +import ( + transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + mockv1 "github.com/cosmos/ibc-go/v9/testing/mock" +) + +const ( + ModuleName = "mockv2" +) + +var ( + MockRecvPacketResult = channeltypesv2.RecvPacketResult{ + Status: channeltypesv2.PacketStatus_Success, + Acknowledgement: mockv1.MockAcknowledgement.Acknowledgement(), + } + MockFailRecvPacketResult = channeltypesv2.RecvPacketResult{ + Status: channeltypesv2.PacketStatus_Success, + Acknowledgement: mockv1.MockFailAcknowledgement.Acknowledgement(), + } +) + +func NewMockPayload(sourcePort, destPort string) channeltypesv2.Payload { + return channeltypesv2.Payload{ + SourcePort: sourcePort, + DestinationPort: destPort, + Encoding: transfertypes.EncodingProtobuf, + Value: mockv1.MockPacketData, + Version: mockv1.Version, + } +} diff --git a/testing/path.go b/testing/path.go index 53c25467441..cc2949158e7 100644 --- a/testing/path.go +++ b/testing/path.go @@ -89,7 +89,7 @@ func (path *Path) RelayPacket(packet channeltypes.Packet) error { // - An error if a relay step fails or the packet commitment does not exist on either endpoint. func (path *Path) RelayPacketWithResults(packet channeltypes.Packet) (*abci.ExecTxResult, []byte, error) { pc := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointA.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointA.Chain.App.AppCodec(), packet)) { + if bytes.Equal(pc, channeltypes.CommitPacket(packet)) { // packet found, relay from A to B if err := path.EndpointB.UpdateClient(); err != nil { return nil, nil, err @@ -113,8 +113,7 @@ func (path *Path) RelayPacketWithResults(packet channeltypes.Packet) (*abci.Exec } pc = path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointB.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointB.Chain.App.AppCodec(), packet)) { - + if bytes.Equal(pc, channeltypes.CommitPacket(packet)) { // packet found, relay B to A if err := path.EndpointA.UpdateClient(); err != nil { return nil, nil, err @@ -140,6 +139,13 @@ func (path *Path) RelayPacketWithResults(packet channeltypes.Packet) (*abci.Exec return nil, nil, errors.New("packet commitment does not exist on either endpoint for provided packet") } +// Reversed returns a new path with endpoints reversed. +func (path *Path) Reversed() *Path { + reversedPath := *path + reversedPath.EndpointA, reversedPath.EndpointB = path.EndpointB, path.EndpointA + return &reversedPath +} + // Setup constructs a TM client, connection, and channel on both chains provided. It will // fail if any error occurs. func (path *Path) Setup() { @@ -149,6 +155,16 @@ func (path *Path) Setup() { path.CreateChannels() } +// SetupV2 constructs clients on both sides and then provides the counterparties for both sides +// This is all that is necessary for path setup with the Eureka (V2) protocol +func (path *Path) SetupV2() { + path.SetupClients() + + path.CreateChannelsV2() + + path.SetupCounterparties() +} + // SetupClients is a helper function to create clients on both chains. It assumes the // caller does not anticipate any errors. func (path *Path) SetupClients() { @@ -163,6 +179,18 @@ func (path *Path) SetupClients() { } } +// SetupCounterparties is a helper function to set the counterparties supporting ibc-eureka on both +// chains. It assumes the caller does not anticipate any errors. +func (path *Path) SetupCounterparties() { + if err := path.EndpointB.RegisterCounterparty(); err != nil { + panic(err) + } + + if err := path.EndpointA.RegisterCounterparty(); err != nil { + panic(err) + } +} + // SetupConnections is a helper function to create clients and the appropriate // connections on both the source and counterparty chain. It assumes the caller does not // anticipate any errors. @@ -234,6 +262,19 @@ func (path *Path) CreateChannels() { } } +// CreateChannelsV2 initializes two channel endpoints by executing CreateChannel on both chainA and chainB. +func (path *Path) CreateChannelsV2() { + err := path.EndpointA.CreateChannel() + if err != nil { + panic(err) + } + + err = path.EndpointB.CreateChannel() + if err != nil { + panic(err) + } +} + // EnableFeeOnPath enables fee on a channel given a path. func EnableFeeOnPath(path *Path) *Path { path.EndpointA.ChannelConfig.Version = ibcmock.MockFeeVersion diff --git a/testing/simapp/app.go b/testing/simapp/app.go index ab92189a84a..82152b57f50 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -96,15 +96,20 @@ import ( "github.com/cosmos/ibc-go/v9/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v9/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" + transferv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2" + ibctransferkeeperv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/keeper" + ibctransfertypesv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types" ibc "github.com/cosmos/ibc-go/v9/modules/core" ibcclienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" ibcconnectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" + ibcapi "github.com/cosmos/ibc-go/v9/modules/core/api" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibcmock "github.com/cosmos/ibc-go/v9/testing/mock" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" ibctestingtypes "github.com/cosmos/ibc-go/v9/testing/types" ) @@ -166,6 +171,7 @@ type SimApp struct { ICAControllerKeeper icacontrollerkeeper.Keeper ICAHostKeeper icahostkeeper.Keeper TransferKeeper ibctransferkeeper.Keeper + TransferKeeperV2 *ibctransferkeeperv2.Keeper ConsensusParamsKeeper consensusparamkeeper.Keeper // make IBC modules public for test purposes @@ -174,6 +180,9 @@ type SimApp struct { ICAAuthModule ibcmock.IBCModule FeeMockModule ibcmock.IBCModule + MockModuleV2A mockv2.IBCModule + MockModuleV2B mockv2.IBCModule + // the module manager ModuleManager *module.Manager BasicModuleManager module.BasicManager @@ -375,6 +384,7 @@ func NewSimApp( // Create IBC Router ibcRouter := porttypes.NewRouter() + ibcRouterV2 := ibcapi.NewRouter() // Middleware Stacks @@ -469,8 +479,23 @@ func NewSimApp( feeWithMockModule := ibcfee.NewIBCMiddleware(feeMockModule, app.IBCFeeKeeper) ibcRouter.AddRoute(MockFeePort, feeWithMockModule) + // create two separate mock v2 applications so that it is possible to test multi packet data. + mockV2A := mockv2.NewIBCModule() + ibcRouterV2.AddRoute(mockv2.ModuleNameA, mockV2A) + app.MockModuleV2A = mockV2A + + mockV2B := mockv2.NewIBCModule() + ibcRouterV2.AddRoute(mockv2.ModuleNameB, mockV2B) + app.MockModuleV2B = mockV2B + + // register the transfer v2 module. + app.TransferKeeperV2 = ibctransferkeeperv2.NewKeeper(app.TransferKeeper, app.IBCKeeper.ChannelKeeperV2, app.MsgServiceRouter()) + + ibcRouterV2.AddRoute(ibctransfertypes.ModuleName, transferv2.NewIBCModule(app.TransferKeeperV2)) + // Seal the IBC Router app.IBCKeeper.SetRouter(ibcRouter) + app.IBCKeeper.SetRouterV2(ibcRouterV2) clientKeeper := app.IBCKeeper.ClientKeeper storeProvider := app.IBCKeeper.ClientKeeper.GetStoreProvider() @@ -506,6 +531,7 @@ func NewSimApp( // IBC modules ibc.NewAppModule(app.IBCKeeper), transfer.NewAppModule(app.TransferKeeper), + transferv2.NewAppModule(app.TransferKeeperV2), ibcfee.NewAppModule(app.IBCFeeKeeper), ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), mockModule, @@ -573,7 +599,7 @@ func NewSimApp( authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, - ibcexported.ModuleName, genutiltypes.ModuleName, authz.ModuleName, ibctransfertypes.ModuleName, + ibcexported.ModuleName, genutiltypes.ModuleName, authz.ModuleName, ibctransfertypes.ModuleName, ibctransfertypesv2.ModuleName, icatypes.ModuleName, ibcfeetypes.ModuleName, ibcmock.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, group.ModuleName, consensusparamtypes.ModuleName, } diff --git a/testing/solomachine.go b/testing/solomachine.go index cca8908a33a..f5af6866287 100644 --- a/testing/solomachine.go +++ b/testing/solomachine.go @@ -568,7 +568,7 @@ func (solo *Solomachine) GenerateChanClosedProof(portID, version, counterpartyCh // GenerateCommitmentProof generates a commitment proof for the provided packet. func (solo *Solomachine) GenerateCommitmentProof(packet channeltypes.Packet) []byte { - commitment := channeltypes.CommitPacket(solo.cdc, packet) + commitment := channeltypes.CommitPacket(packet) path := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) signBytes := &solomachine.SignBytes{ diff --git a/testing/utils.go b/testing/utils.go index 53d84ab559a..861bb54e1a6 100644 --- a/testing/utils.go +++ b/testing/utils.go @@ -87,6 +87,7 @@ func UnmarshalMsgResponses(cdc codec.Codec, data []byte, msgs ...codec.ProtoMars // RequireErrorIsOrContains verifies that the passed error is either a target error or contains its error message. func RequireErrorIsOrContains(t *testing.T, err, targetError error, msgAndArgs ...interface{}) { t.Helper() + require.Error(t, err) require.True( t, errors.Is(err, targetError) || diff --git a/testing/values.go b/testing/values.go index c5920910681..79c995b4974 100644 --- a/testing/values.go +++ b/testing/values.go @@ -22,10 +22,12 @@ import ( ) const ( - FirstClientID = "07-tendermint-0" - SecondClientID = "07-tendermint-1" - FirstChannelID = "channel-0" - FirstConnectionID = "connection-0" + FirstClientID = "07-tendermint-0" + SecondClientID = "07-tendermint-1" + FirstChannelID = "channel-0" + SecondChannelID = "channel-1" + FirstConnectionID = "connection-0" + SecondConnectionID = "connection-1" // Default params constants used to create a TM client TrustingPeriod time.Duration = time.Hour * 24 * 7 * 2 @@ -77,4 +79,5 @@ var ( prefix = commitmenttypes.NewMerklePrefix([]byte("ibc")) // unusedHash is a placeholder hash used for testing. unusedHash = tmhash.Sum([]byte{0x00}) + MerklePath = commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) )