From af63941af9387795812c81df36fa498b4a350670 Mon Sep 17 00:00:00 2001 From: Lockwarr Date: Tue, 15 Oct 2024 12:20:22 +0300 Subject: [PATCH] wip --- app/app.go | 79 +- go.mod | 7 +- testutil/common/nullify/nullify.go | 57 + testutil/common/sample/sample.go | 13 + .../contractmanager/keeper/contractmanager.go | 52 + testutil/contractmanager/network/network.go | 96 + testutil/feerefunder/keeper/fee.go | 52 + .../keeper/interchainqueries.go | 64 + testutil/interchainqueries/network/network.go | 96 + .../interchaintxs/keeper/interchaintxs.go | 67 + .../interchaintxs/keeper/sudo_middleware.go | 30 + testutil/interchaintxs/network/network.go | 96 + testutil/mocks/cron/types/expected_keepers.go | 89 + .../mocks/feeburner/types/expected_keepers.go | 129 + testutil/mocks/feerefunder/types/keepers.go | 168 + testutil/mocks/gomock.go | 6 + .../mocks/interchainqueries/keeper/verify.go | 107 + .../types/expected_keepers.go | 183 + .../mocks/interchainqueries/types/verify.go | 107 + .../interchaintxs/types/expected_keepers.go | 420 ++ .../mocks/transfer/types/expected_keepers.go | 247 + testutil/test_helpers.go | 631 ++- testutil/transfer/keeper/keeper.go | 72 + x/contractmanager/client/cli/query.go | 31 + x/contractmanager/client/cli/query_failure.go | 114 + .../client/cli/query_failure_test.go | 174 + x/contractmanager/client/cli/query_params.go | 35 + x/contractmanager/genesis.go | 31 + x/contractmanager/genesis_test.go | 61 + x/contractmanager/ibc_middleware.go | 90 + x/contractmanager/ibc_middleware_test.go | 76 + x/contractmanager/keeper/failure.go | 131 + x/contractmanager/keeper/failure_test.go | 246 + x/contractmanager/keeper/grpc_query.go | 7 + .../keeper/grpc_query_failure.go | 78 + .../keeper/grpc_query_failure_test.go | 137 + x/contractmanager/keeper/grpc_query_params.go | 20 + .../keeper/grpc_query_params_test.go | 21 + x/contractmanager/keeper/keeper.go | 46 + x/contractmanager/keeper/migrations.go | 22 + x/contractmanager/keeper/msg_server.go | 42 + x/contractmanager/keeper/msg_server_test.go | 44 + x/contractmanager/keeper/params.go | 35 + x/contractmanager/keeper/params_test.go | 20 + x/contractmanager/keeper/sudo.go | 133 + x/contractmanager/keeper/sudo_test.go | 108 + x/contractmanager/migrations/v2/store.go | 44 + x/contractmanager/migrations/v2/store_test.go | 70 + x/contractmanager/module.go | 168 + x/contractmanager/types/codec.go | 25 + x/contractmanager/types/constants.go | 3 + x/contractmanager/types/errors.go | 12 + x/contractmanager/types/events.go | 10 + x/contractmanager/types/expected_keepers.go | 20 + x/contractmanager/types/failure.pb.go | 471 ++ x/contractmanager/types/genesis.go | 33 + x/contractmanager/types/genesis.pb.go | 390 ++ x/contractmanager/types/genesis_test.go | 72 + x/contractmanager/types/keys.go | 45 + x/contractmanager/types/params.go | 43 + x/contractmanager/types/params.pb.go | 305 ++ x/contractmanager/types/query.pb.go | 1179 +++++ x/contractmanager/types/query.pb.gw.go | 496 +++ x/contractmanager/types/sudo.go | 59 + x/contractmanager/types/tx.go | 35 + x/contractmanager/types/tx.pb.go | 599 +++ x/contractmanager/types/types.go | 6 + x/contractmanager/types/v1/failure.pb.go | 501 +++ x/feerefunder/client/cli/query.go | 63 + x/feerefunder/client/cli/query_params.go | 35 + x/feerefunder/client/cli/query_test.go | 68 + x/feerefunder/genesis.go | 31 + x/feerefunder/genesis_test.go | 46 + x/feerefunder/keeper/export_test.go | 11 + x/feerefunder/keeper/grpc_query.go | 25 + x/feerefunder/keeper/grpc_query_params.go | 20 + .../keeper/grpc_query_params_test.go | 22 + x/feerefunder/keeper/keeper.go | 270 ++ x/feerefunder/keeper/keeper_test.go | 351 ++ x/feerefunder/keeper/msg_server.go | 42 + x/feerefunder/keeper/msg_server_test.go | 129 + x/feerefunder/keeper/params.go | 31 + x/feerefunder/keeper/params_test.go | 23 + x/feerefunder/module.go | 169 + x/feerefunder/types/codec.go | 25 + x/feerefunder/types/constants.go | 3 + x/feerefunder/types/events.go | 14 + x/feerefunder/types/expected_keepers.go | 28 + x/feerefunder/types/fee.go | 60 + x/feerefunder/types/fee.pb.go | 727 +++ x/feerefunder/types/genesis.go | 48 + x/feerefunder/types/genesis.pb.go | 667 +++ x/feerefunder/types/genesis_test.go | 192 + x/feerefunder/types/keys.go | 33 + x/feerefunder/types/params.go | 63 + x/feerefunder/types/params.pb.go | 321 ++ x/feerefunder/types/query.pb.go | 1018 +++++ x/feerefunder/types/query.pb.gw.go | 236 + x/feerefunder/types/tx.go | 40 + x/feerefunder/types/tx.pb.go | 599 +++ x/interchainqueries/client/cli/query.go | 157 + .../client/cli/query_params.go | 35 + x/interchainqueries/client/cli/tx.go | 99 + x/interchainqueries/genesis.go | 42 + x/interchainqueries/genesis_test.go | 299 ++ x/interchainqueries/keeper/grpc_query.go | 127 + .../keeper/grpc_query_params.go | 20 + .../keeper/grpc_query_params_test.go | 21 + x/interchainqueries/keeper/grpc_query_test.go | 559 +++ x/interchainqueries/keeper/keeper.go | 433 ++ x/interchainqueries/keeper/keeper_test.go | 1778 ++++++++ x/interchainqueries/keeper/msg_server.go | 379 ++ x/interchainqueries/keeper/msg_server_test.go | 537 +++ x/interchainqueries/keeper/params.go | 31 + x/interchainqueries/keeper/params_test.go | 20 + .../keeper/process_block_results.go | 211 + .../keeper/process_block_results_test.go | 398 ++ x/interchainqueries/module.go | 181 + x/interchainqueries/module_simulation.go | 49 + x/interchainqueries/simulation/simap.go | 15 + x/interchainqueries/types/codec.go | 30 + x/interchainqueries/types/constants.go | 3 + x/interchainqueries/types/errors.go | 31 + x/interchainqueries/types/expected_keepers.go | 28 + x/interchainqueries/types/genesis.go | 52 + x/interchainqueries/types/genesis.pb.go | 1336 ++++++ x/interchainqueries/types/genesis_test.go | 37 + x/interchainqueries/types/keys.go | 71 + .../types/message_remove_interchain_query.go | 55 + x/interchainqueries/types/params.go | 79 + x/interchainqueries/types/params.pb.go | 418 ++ x/interchainqueries/types/query.pb.go | 2472 ++++++++++ x/interchainqueries/types/query.pb.gw.go | 485 ++ x/interchainqueries/types/registered_query.go | 38 + x/interchainqueries/types/tx.go | 260 ++ x/interchainqueries/types/tx.pb.go | 3966 +++++++++++++++++ x/interchainqueries/types/tx_test.go | 126 + x/interchainqueries/types/types.go | 144 + x/interchainqueries/types/types_test.go | 59 + x/interchainqueries/types/verify.go | 22 + x/interchaintxs/client/cli/query.go | 27 + .../client/cli/query_interchainaccounts.go | 39 + x/interchaintxs/client/cli/query_params.go | 35 + x/interchaintxs/client/cli/tx.go | 23 + x/interchaintxs/genesis.go | 25 + x/interchaintxs/genesis_test.go | 26 + x/interchaintxs/ibc_module.go | 126 + x/interchaintxs/keeper/grpc_query.go | 7 + .../keeper/grpc_query_interchainaccount.go | 37 + .../grpc_query_interchainaccount_test.go | 55 + x/interchaintxs/keeper/grpc_query_params.go | 20 + .../keeper/grpc_query_params_test.go | 25 + x/interchaintxs/keeper/ibc_handlers.go | 114 + x/interchaintxs/keeper/ibc_handlers_test.go | 148 + x/interchaintxs/keeper/keeper.go | 109 + x/interchaintxs/keeper/msg_server.go | 218 + x/interchaintxs/keeper/msg_server_test.go | 546 +++ x/interchaintxs/keeper/params.go | 31 + x/interchaintxs/keeper/params_test.go | 20 + x/interchaintxs/module.go | 179 + x/interchaintxs/module_simulation.go | 47 + x/interchaintxs/simulation/simap.go | 15 + x/interchaintxs/types/codec.go | 52 + x/interchaintxs/types/constants.go | 3 + x/interchaintxs/types/errors.go | 20 + x/interchaintxs/types/expected_keepers.go | 55 + x/interchaintxs/types/genesis.go | 14 + x/interchaintxs/types/genesis.pb.go | 324 ++ x/interchaintxs/types/genesis_test.go | 50 + x/interchaintxs/types/keys.go | 30 + x/interchaintxs/types/params.go | 79 + x/interchaintxs/types/params.pb.go | 376 ++ x/interchaintxs/types/query.pb.go | 1017 +++++ x/interchaintxs/types/query.pb.gw.go | 298 ++ x/interchaintxs/types/tx.go | 162 + x/interchaintxs/types/tx.pb.go | 1862 ++++++++ x/interchaintxs/types/tx_test.go | 65 + x/interchaintxs/types/types.go | 59 + x/interchaintxs/types/types_test.go | 80 + x/transfer/ibc_handlers.go | 79 + x/transfer/ibc_handlers_test.go | 180 + x/transfer/keeper/keeper.go | 100 + x/transfer/keeper/keeper_test.go | 597 +++ x/transfer/module.go | 146 + x/transfer/types/codec.go | 25 + x/transfer/types/expected_keepers.go | 34 + x/transfer/types/query.pb.go | 254 ++ x/transfer/types/query.pb.gw.go | 439 ++ x/transfer/types/query.pb.gw.go_old | 439 ++ x/transfer/types/tx.go | 120 + x/transfer/types/tx.pb.go | 1368 ++++++ 191 files changed, 39511 insertions(+), 357 deletions(-) create mode 100644 testutil/common/nullify/nullify.go create mode 100644 testutil/common/sample/sample.go create mode 100644 testutil/contractmanager/keeper/contractmanager.go create mode 100644 testutil/contractmanager/network/network.go create mode 100644 testutil/feerefunder/keeper/fee.go create mode 100644 testutil/interchainqueries/keeper/interchainqueries.go create mode 100644 testutil/interchainqueries/network/network.go create mode 100644 testutil/interchaintxs/keeper/interchaintxs.go create mode 100644 testutil/interchaintxs/keeper/sudo_middleware.go create mode 100644 testutil/interchaintxs/network/network.go create mode 100644 testutil/mocks/cron/types/expected_keepers.go create mode 100644 testutil/mocks/feeburner/types/expected_keepers.go create mode 100644 testutil/mocks/feerefunder/types/keepers.go create mode 100644 testutil/mocks/interchainqueries/keeper/verify.go create mode 100644 testutil/mocks/interchainqueries/types/expected_keepers.go create mode 100644 testutil/mocks/interchainqueries/types/verify.go create mode 100644 testutil/mocks/interchaintxs/types/expected_keepers.go create mode 100644 testutil/mocks/transfer/types/expected_keepers.go create mode 100644 testutil/transfer/keeper/keeper.go create mode 100644 x/contractmanager/client/cli/query.go create mode 100644 x/contractmanager/client/cli/query_failure.go create mode 100644 x/contractmanager/client/cli/query_failure_test.go create mode 100644 x/contractmanager/client/cli/query_params.go create mode 100644 x/contractmanager/genesis.go create mode 100644 x/contractmanager/genesis_test.go create mode 100644 x/contractmanager/ibc_middleware.go create mode 100644 x/contractmanager/ibc_middleware_test.go create mode 100644 x/contractmanager/keeper/failure.go create mode 100644 x/contractmanager/keeper/failure_test.go create mode 100644 x/contractmanager/keeper/grpc_query.go create mode 100644 x/contractmanager/keeper/grpc_query_failure.go create mode 100644 x/contractmanager/keeper/grpc_query_failure_test.go create mode 100644 x/contractmanager/keeper/grpc_query_params.go create mode 100644 x/contractmanager/keeper/grpc_query_params_test.go create mode 100644 x/contractmanager/keeper/keeper.go create mode 100644 x/contractmanager/keeper/migrations.go create mode 100644 x/contractmanager/keeper/msg_server.go create mode 100644 x/contractmanager/keeper/msg_server_test.go create mode 100644 x/contractmanager/keeper/params.go create mode 100644 x/contractmanager/keeper/params_test.go create mode 100644 x/contractmanager/keeper/sudo.go create mode 100644 x/contractmanager/keeper/sudo_test.go create mode 100644 x/contractmanager/migrations/v2/store.go create mode 100644 x/contractmanager/migrations/v2/store_test.go create mode 100644 x/contractmanager/module.go create mode 100644 x/contractmanager/types/codec.go create mode 100644 x/contractmanager/types/constants.go create mode 100644 x/contractmanager/types/errors.go create mode 100644 x/contractmanager/types/events.go create mode 100644 x/contractmanager/types/expected_keepers.go create mode 100644 x/contractmanager/types/failure.pb.go create mode 100644 x/contractmanager/types/genesis.go create mode 100644 x/contractmanager/types/genesis.pb.go create mode 100644 x/contractmanager/types/genesis_test.go create mode 100644 x/contractmanager/types/keys.go create mode 100644 x/contractmanager/types/params.go create mode 100644 x/contractmanager/types/params.pb.go create mode 100644 x/contractmanager/types/query.pb.go create mode 100644 x/contractmanager/types/query.pb.gw.go create mode 100644 x/contractmanager/types/sudo.go create mode 100644 x/contractmanager/types/tx.go create mode 100644 x/contractmanager/types/tx.pb.go create mode 100644 x/contractmanager/types/types.go create mode 100644 x/contractmanager/types/v1/failure.pb.go create mode 100644 x/feerefunder/client/cli/query.go create mode 100644 x/feerefunder/client/cli/query_params.go create mode 100644 x/feerefunder/client/cli/query_test.go create mode 100644 x/feerefunder/genesis.go create mode 100644 x/feerefunder/genesis_test.go create mode 100644 x/feerefunder/keeper/export_test.go create mode 100644 x/feerefunder/keeper/grpc_query.go create mode 100644 x/feerefunder/keeper/grpc_query_params.go create mode 100644 x/feerefunder/keeper/grpc_query_params_test.go create mode 100644 x/feerefunder/keeper/keeper.go create mode 100644 x/feerefunder/keeper/keeper_test.go create mode 100644 x/feerefunder/keeper/msg_server.go create mode 100644 x/feerefunder/keeper/msg_server_test.go create mode 100644 x/feerefunder/keeper/params.go create mode 100644 x/feerefunder/keeper/params_test.go create mode 100644 x/feerefunder/module.go create mode 100644 x/feerefunder/types/codec.go create mode 100644 x/feerefunder/types/constants.go create mode 100644 x/feerefunder/types/events.go create mode 100644 x/feerefunder/types/expected_keepers.go create mode 100644 x/feerefunder/types/fee.go create mode 100644 x/feerefunder/types/fee.pb.go create mode 100644 x/feerefunder/types/genesis.go create mode 100644 x/feerefunder/types/genesis.pb.go create mode 100644 x/feerefunder/types/genesis_test.go create mode 100644 x/feerefunder/types/keys.go create mode 100644 x/feerefunder/types/params.go create mode 100644 x/feerefunder/types/params.pb.go create mode 100644 x/feerefunder/types/query.pb.go create mode 100644 x/feerefunder/types/query.pb.gw.go create mode 100644 x/feerefunder/types/tx.go create mode 100644 x/feerefunder/types/tx.pb.go create mode 100644 x/interchainqueries/client/cli/query.go create mode 100644 x/interchainqueries/client/cli/query_params.go create mode 100644 x/interchainqueries/client/cli/tx.go create mode 100644 x/interchainqueries/genesis.go create mode 100644 x/interchainqueries/genesis_test.go create mode 100644 x/interchainqueries/keeper/grpc_query.go create mode 100644 x/interchainqueries/keeper/grpc_query_params.go create mode 100644 x/interchainqueries/keeper/grpc_query_params_test.go create mode 100644 x/interchainqueries/keeper/grpc_query_test.go create mode 100644 x/interchainqueries/keeper/keeper.go create mode 100644 x/interchainqueries/keeper/keeper_test.go create mode 100644 x/interchainqueries/keeper/msg_server.go create mode 100644 x/interchainqueries/keeper/msg_server_test.go create mode 100644 x/interchainqueries/keeper/params.go create mode 100644 x/interchainqueries/keeper/params_test.go create mode 100644 x/interchainqueries/keeper/process_block_results.go create mode 100644 x/interchainqueries/keeper/process_block_results_test.go create mode 100644 x/interchainqueries/module.go create mode 100644 x/interchainqueries/module_simulation.go create mode 100644 x/interchainqueries/simulation/simap.go create mode 100644 x/interchainqueries/types/codec.go create mode 100644 x/interchainqueries/types/constants.go create mode 100644 x/interchainqueries/types/errors.go create mode 100644 x/interchainqueries/types/expected_keepers.go create mode 100644 x/interchainqueries/types/genesis.go create mode 100644 x/interchainqueries/types/genesis.pb.go create mode 100644 x/interchainqueries/types/genesis_test.go create mode 100644 x/interchainqueries/types/keys.go create mode 100644 x/interchainqueries/types/message_remove_interchain_query.go create mode 100644 x/interchainqueries/types/params.go create mode 100644 x/interchainqueries/types/params.pb.go create mode 100644 x/interchainqueries/types/query.pb.go create mode 100644 x/interchainqueries/types/query.pb.gw.go create mode 100644 x/interchainqueries/types/registered_query.go create mode 100644 x/interchainqueries/types/tx.go create mode 100644 x/interchainqueries/types/tx.pb.go create mode 100644 x/interchainqueries/types/tx_test.go create mode 100644 x/interchainqueries/types/types.go create mode 100644 x/interchainqueries/types/types_test.go create mode 100644 x/interchainqueries/types/verify.go create mode 100644 x/interchaintxs/client/cli/query.go create mode 100644 x/interchaintxs/client/cli/query_interchainaccounts.go create mode 100644 x/interchaintxs/client/cli/query_params.go create mode 100644 x/interchaintxs/client/cli/tx.go create mode 100644 x/interchaintxs/genesis.go create mode 100644 x/interchaintxs/genesis_test.go create mode 100644 x/interchaintxs/ibc_module.go create mode 100644 x/interchaintxs/keeper/grpc_query.go create mode 100644 x/interchaintxs/keeper/grpc_query_interchainaccount.go create mode 100644 x/interchaintxs/keeper/grpc_query_interchainaccount_test.go create mode 100644 x/interchaintxs/keeper/grpc_query_params.go create mode 100644 x/interchaintxs/keeper/grpc_query_params_test.go create mode 100644 x/interchaintxs/keeper/ibc_handlers.go create mode 100644 x/interchaintxs/keeper/ibc_handlers_test.go create mode 100644 x/interchaintxs/keeper/keeper.go create mode 100644 x/interchaintxs/keeper/msg_server.go create mode 100644 x/interchaintxs/keeper/msg_server_test.go create mode 100644 x/interchaintxs/keeper/params.go create mode 100644 x/interchaintxs/keeper/params_test.go create mode 100644 x/interchaintxs/module.go create mode 100644 x/interchaintxs/module_simulation.go create mode 100644 x/interchaintxs/simulation/simap.go create mode 100644 x/interchaintxs/types/codec.go create mode 100644 x/interchaintxs/types/constants.go create mode 100644 x/interchaintxs/types/errors.go create mode 100644 x/interchaintxs/types/expected_keepers.go create mode 100644 x/interchaintxs/types/genesis.go create mode 100644 x/interchaintxs/types/genesis.pb.go create mode 100644 x/interchaintxs/types/genesis_test.go create mode 100644 x/interchaintxs/types/keys.go create mode 100644 x/interchaintxs/types/params.go create mode 100644 x/interchaintxs/types/params.pb.go create mode 100644 x/interchaintxs/types/query.pb.go create mode 100644 x/interchaintxs/types/query.pb.gw.go create mode 100644 x/interchaintxs/types/tx.go create mode 100644 x/interchaintxs/types/tx.pb.go create mode 100644 x/interchaintxs/types/tx_test.go create mode 100644 x/interchaintxs/types/types.go create mode 100644 x/interchaintxs/types/types_test.go create mode 100644 x/transfer/ibc_handlers.go create mode 100644 x/transfer/ibc_handlers_test.go create mode 100644 x/transfer/keeper/keeper.go create mode 100644 x/transfer/keeper/keeper_test.go create mode 100644 x/transfer/module.go create mode 100644 x/transfer/types/codec.go create mode 100644 x/transfer/types/expected_keepers.go create mode 100644 x/transfer/types/query.pb.go create mode 100644 x/transfer/types/query.pb.gw.go create mode 100644 x/transfer/types/query.pb.gw.go_old create mode 100644 x/transfer/types/tx.go create mode 100644 x/transfer/types/tx.pb.go diff --git a/app/app.go b/app/app.go index 4794c847..d4199ead 100644 --- a/app/app.go +++ b/app/app.go @@ -11,6 +11,10 @@ import ( "github.com/spf13/cast" + capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" + ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/client/v2/autocli" @@ -487,41 +491,40 @@ func (app *App) RegisterNodeService(clientCtx client.Context, cfg config.Config) nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg) } -// TODO -// // GetTxConfig implements the TestingApp interface. -// func (app *App) GetTxConfig() client.TxConfig { -// return app.encodingConfig.TxConfig -// } - -// // GetIBCKeeper implements the TestingApp interface. -// func (app *App) GetIBCKeeper() *ibckeeper.Keeper { -// return app.IBCKeeper -// } - -// // GetScopedIBCKeeper implements the TestingApp interface. -// func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { -// return app.ScopedIBCKeeper -// } - -// // GetStakingKeeper implements the TestingApp interface. -// func (app *App) GetStakingKeeper() ibctestingtypes.StakingKeeper { -// return app.StakingKeeper -// } - -// // InitChainer application update at chain initialization. -// // ONLY FOR TESTING PURPOSES. -// func (app *App) TestInitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { -// var genesisState GenesisState -// if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { -// panic(err) -// } - -// // manually set consensus params here, cause there is no way to set it using ibctesting stuff for now -// // TODO: app.ConsensusParamsKeeper.Set(ctx, sims.DefaultConsensusParams) - -// err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()) -// if err != nil { -// return nil, fmt.Errorf("failed to set module version map: %w", err) -// } -// return app.mm.InitGenesis(ctx, app.appCodec, genesisState) -// } +// GetTxConfig implements the TestingApp interface. +func (app *App) GetTxConfig() client.TxConfig { + return app.encodingConfig.TxConfig +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *App) GetIBCKeeper() *ibckeeper.Keeper { + return app.IBCKeeper +} + +// GetScopedIBCKeeper implements the TestingApp interface. +func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return app.ScopedIBCKeeper +} + +// GetStakingKeeper implements the TestingApp interface. +func (app *App) GetStakingKeeper() ibctestingtypes.StakingKeeper { + return app.StakingKeeper +} + +// InitChainer application update at chain initialization. +// ONLY FOR TESTING PURPOSES. +func (app *App) TestInitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { + var genesisState GenesisState + if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { + panic(err) + } + + // manually set consensus params here, cause there is no way to set it using ibctesting stuff for now + // TODO: app.ConsensusParamsKeeper.Set(ctx, sims.DefaultConsensusParams) + + err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()) + if err != nil { + return nil, fmt.Errorf("failed to set module version map: %w", err) + } + return app.mm.InitGenesis(ctx, app.appCodec, genesisState) +} diff --git a/go.mod b/go.mod index faa4dcdf..695e17b7 100644 --- a/go.mod +++ b/go.mod @@ -34,11 +34,15 @@ require ( cosmossdk.io/x/feegrant v0.1.1 cosmossdk.io/x/tx v0.13.4 cosmossdk.io/x/upgrade v0.1.4 + github.com/cosmos/admin-module/v2 v2.0.0-20240430142959-8b3328d1b1a2 github.com/cosmos/cosmos-db v1.0.2 github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/ibc-go/modules/capability v1.0.1 + github.com/cosmos/ics23/go v0.10.0 + github.com/gogo/protobuf v1.3.3 github.com/golang/mock v1.6.0 github.com/hashicorp/go-metrics v0.5.3 + github.com/pkg/errors v0.9.1 google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3 google.golang.org/protobuf v1.34.2 gotest.tools/v3 v3.5.1 @@ -81,7 +85,6 @@ 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/ics23/go v0.10.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect github.com/creachadair/atomicfile v0.3.3 // indirect github.com/creachadair/tomledit v0.0.26 // indirect @@ -107,7 +110,6 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/googleapis v1.4.1 // indirect - github.com/gogo/protobuf v1.3.3 // indirect github.com/golang/glog v1.2.1 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect @@ -165,7 +167,6 @@ require ( github.com/opencontainers/runc v1.1.12 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.1 // indirect github.com/prometheus/client_model v0.6.1 // indirect diff --git a/testutil/common/nullify/nullify.go b/testutil/common/nullify/nullify.go new file mode 100644 index 00000000..3b968c09 --- /dev/null +++ b/testutil/common/nullify/nullify.go @@ -0,0 +1,57 @@ +// Package nullify provides methods to init nil values structs for test assertion. +package nullify + +import ( + "reflect" + "unsafe" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + coinType = reflect.TypeOf(sdk.Coin{}) + coinsType = reflect.TypeOf(sdk.Coins{}) +) + +// Fill analyze all struct fields and slices with +// reflection and initialize the nil and empty slices, +// structs, and pointers. +func Fill(x interface{}) interface{} { + v := reflect.Indirect(reflect.ValueOf(x)) + switch v.Kind() { + case reflect.Slice: + for i := 0; i < v.Len(); i++ { + obj := v.Index(i) + objPt := reflect.NewAt(obj.Type(), unsafe.Pointer(obj.UnsafeAddr())).Interface() + objPt = Fill(objPt) + obj.Set(reflect.ValueOf(objPt)) + } + case reflect.Struct: + for i := 0; i < v.NumField(); i++ { + f := reflect.Indirect(v.Field(i)) + if !f.CanSet() { + continue + } + switch f.Kind() { + case reflect.Slice: + f.Set(reflect.MakeSlice(f.Type(), 0, 0)) + case reflect.Struct: + switch f.Type() { + case coinType: + coin := reflect.New(coinType).Interface() + s := reflect.ValueOf(coin).Elem() + f.Set(s) + case coinsType: + coins := reflect.New(coinsType).Interface() + s := reflect.ValueOf(coins).Elem() + f.Set(s) + default: + objPt := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Interface() + s := Fill(objPt) + f.Set(reflect.ValueOf(s)) + } + } + } + } + return reflect.Indirect(v).Interface() +} diff --git a/testutil/common/sample/sample.go b/testutil/common/sample/sample.go new file mode 100644 index 00000000..98f2153e --- /dev/null +++ b/testutil/common/sample/sample.go @@ -0,0 +1,13 @@ +package sample + +import ( + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// AccAddress returns a sample account address +func AccAddress() string { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr).String() +} diff --git a/testutil/contractmanager/keeper/contractmanager.go b/testutil/contractmanager/keeper/contractmanager.go new file mode 100644 index 00000000..5eb56797 --- /dev/null +++ b/testutil/contractmanager/keeper/contractmanager.go @@ -0,0 +1,52 @@ +package keeper + +import ( + "testing" + + "cosmossdk.io/log" + metrics2 "cosmossdk.io/store/metrics" + db2 "github.com/cosmos/cosmos-db" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "cosmossdk.io/store" + storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func ContractManagerKeeper(t testing.TB, wasmKeeper types.WasmKeeper) (*keeper.Keeper, sdk.Context) { + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := db2.NewMemDB() + stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics2.NewNoOpMetrics()) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + k := keeper.NewKeeper( + cdc, + storeKey, + memStoreKey, + wasmKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + err := k.SetParams(ctx, types.DefaultParams()) + require.NoError(t, err) + + return k, ctx +} diff --git a/testutil/contractmanager/network/network.go b/testutil/contractmanager/network/network.go new file mode 100644 index 00000000..006d6991 --- /dev/null +++ b/testutil/contractmanager/network/network.go @@ -0,0 +1,96 @@ +package network + +import ( + "fmt" + "testing" + "time" + + db "github.com/cosmos/cosmos-db" + "github.com/stretchr/testify/require" + + pruningtypes "cosmossdk.io/store/pruning/types" + tmrand "github.com/cometbft/cometbft/libs/rand" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + "github.com/Nolus-Protocol/nolus-core/app" +) + +type ( + Network = network.Network + Config = network.Config +) + +// New creates instance with fully configured cosmos network. +// Accepts optional config, that will be used in place of the DefaultConfig() if provided. +func New(t *testing.T, configs ...network.Config) *network.Network { + if len(configs) > 1 { + panic("at most one config should be provided") + } + var cfg network.Config + if len(configs) == 0 { + cfg = DefaultConfig() + } else { + cfg = configs[0] + } + net, err := network.New(t, t.TempDir(), cfg) + require.NoError(t, err) + t.Cleanup(net.Cleanup) + return net +} + +// DefaultConfig will initialize config for the network with custom application, +// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig +func DefaultConfig() network.Config { + // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator + app.ModuleBasics[genutiltypes.ModuleName] = genutil.AppModuleBasic{} + app.ModuleBasics[stakingtypes.ModuleName] = staking.AppModuleBasic{} + + encoding := app.MakeEncodingConfig() + chainID := "chain-" + tmrand.NewRand().Str(6) + return network.Config{ + Codec: encoding.Marshaler, + TxConfig: encoding.TxConfig, + LegacyAmino: encoding.Amino, + InterfaceRegistry: encoding.InterfaceRegistry, + AccountRetriever: authtypes.AccountRetriever{}, + AppConstructor: func(val network.ValidatorI) servertypes.Application { + return app.New( + val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, + encoding, + sims.EmptyAppOptions{}, + nil, + baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), + baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), + baseapp.SetChainID(chainID), + ) + }, + GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), + TimeoutCommit: 2 * time.Second, + ChainID: chainID, + // Some changes are introduced to make the tests run as if neutron is a standalone chain. + // This will only work if NumValidators is set to 1. + NumValidators: 1, + BondDenom: params.DefaultBondDenom, + MinGasPrices: fmt.Sprintf("0.000006%s", params.DefaultBondDenom), + AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), + StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), + BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), + PruningStrategy: pruningtypes.PruningOptionNothing, + CleanupDir: true, + SigningAlgo: string(hd.Secp256k1Type), + KeyringOptions: []keyring.Option{}, + } +} diff --git a/testutil/feerefunder/keeper/fee.go b/testutil/feerefunder/keeper/fee.go new file mode 100644 index 00000000..a9084831 --- /dev/null +++ b/testutil/feerefunder/keeper/fee.go @@ -0,0 +1,52 @@ +package keeper + +import ( + "testing" + + "cosmossdk.io/log" + "cosmossdk.io/store" + metrics2 "cosmossdk.io/store/metrics" + storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + adminmoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types" + db2 "github.com/cosmos/cosmos-db" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/keeper" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func FeeKeeper(t testing.TB, channelKeeper types.ChannelKeeper, bankKeeper types.BankKeeper) (*keeper.Keeper, sdk.Context) { + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := db2.NewMemDB() + stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics2.NewNoOpMetrics()) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + k := keeper.NewKeeper( + cdc, + storeKey, + memStoreKey, + channelKeeper, + bankKeeper, + authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + err := k.SetParams(ctx, types.DefaultParams()) + require.NoError(t, err) + + return k, ctx +} diff --git a/testutil/interchainqueries/keeper/interchainqueries.go b/testutil/interchainqueries/keeper/interchainqueries.go new file mode 100644 index 00000000..327d5b2a --- /dev/null +++ b/testutil/interchainqueries/keeper/interchainqueries.go @@ -0,0 +1,64 @@ +package keeper + +import ( + "testing" + + "cosmossdk.io/log" + metrics2 "cosmossdk.io/store/metrics" + adminmoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types" + db2 "github.com/cosmos/cosmos-db" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" + + "cosmossdk.io/store" + storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +func InterchainQueriesKeeper( + t testing.TB, + ibcKeeper *ibckeeper.Keeper, + contractManager types.ContractManagerKeeper, + headerVerifier types.HeaderVerifier, + txVerifier types.TransactionVerifier, +) (*keeper.Keeper, sdk.Context) { + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := db2.NewMemDB() + stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics2.NewNoOpMetrics()) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + k := keeper.NewKeeper( + cdc, + storeKey, + memStoreKey, + ibcKeeper, // TODO: do a real ibc keeper + nil, // TODO: do a real wasm keeper + contractManager, + headerVerifier, + txVerifier, + authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + err := k.SetParams(ctx, types.DefaultParams()) + require.NoError(t, err) + + return k, ctx +} diff --git a/testutil/interchainqueries/network/network.go b/testutil/interchainqueries/network/network.go new file mode 100644 index 00000000..29f3b738 --- /dev/null +++ b/testutil/interchainqueries/network/network.go @@ -0,0 +1,96 @@ +package network + +import ( + "fmt" + "testing" + "time" + + pruningtypes "cosmossdk.io/store/pruning/types" + db "github.com/cosmos/cosmos-db" + "github.com/stretchr/testify/require" + + tmrand "github.com/cometbft/cometbft/libs/rand" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + "github.com/Nolus-Protocol/nolus-core/app" +) + +type ( + Network = network.Network + Config = network.Config +) + +// New creates instance with fully configured cosmos network. +// Accepts optional config, that will be used in place of the DefaultConfig() if provided. +func New(t *testing.T, configs ...network.Config) *network.Network { + if len(configs) > 1 { + panic("at most one config should be provided") + } + var cfg network.Config + if len(configs) == 0 { + cfg = DefaultConfig() + } else { + cfg = configs[0] + } + net, err := network.New(t, t.TempDir(), cfg) + require.NoError(t, err) + t.Cleanup(net.Cleanup) + return net +} + +// DefaultConfig will initialize config for the network with custom application, +// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig +func DefaultConfig() network.Config { + // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator + app.ModuleBasics[genutiltypes.ModuleName] = genutil.AppModuleBasic{} + app.ModuleBasics[stakingtypes.ModuleName] = staking.AppModuleBasic{} + + encoding := app.MakeEncodingConfig() + chainID := "chain-" + tmrand.NewRand().Str(6) + return network.Config{ + Codec: encoding.Marshaler, + TxConfig: encoding.TxConfig, + LegacyAmino: encoding.Amino, + InterfaceRegistry: encoding.InterfaceRegistry, + AccountRetriever: authtypes.AccountRetriever{}, + AppConstructor: func(val network.ValidatorI) servertypes.Application { + return app.New( + val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, + encoding, + sims.EmptyAppOptions{}, + nil, + baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), + baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), + baseapp.SetChainID(chainID), + ) + }, + GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), + TimeoutCommit: 2 * time.Second, + ChainID: chainID, + // Some changes are introduced to make the tests run as if neutron is a standalone chain. + // This will only work if NumValidators is set to 1. + NumValidators: 1, + BondDenom: params.DefaultBondDenom, + MinGasPrices: fmt.Sprintf("0.000006%s", params.DefaultBondDenom), + AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), + StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), + BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), + PruningStrategy: pruningtypes.PruningOptionNothing, + CleanupDir: true, + SigningAlgo: string(hd.Secp256k1Type), + KeyringOptions: []keyring.Option{}, + } +} diff --git a/testutil/interchaintxs/keeper/interchaintxs.go b/testutil/interchaintxs/keeper/interchaintxs.go new file mode 100644 index 00000000..98f72eed --- /dev/null +++ b/testutil/interchaintxs/keeper/interchaintxs.go @@ -0,0 +1,67 @@ +package keeper + +import ( + "testing" + + "cosmossdk.io/log" + metrics2 "cosmossdk.io/store/metrics" + adminmoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types" + db2 "github.com/cosmos/cosmos-db" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "cosmossdk.io/store" + storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func InterchainTxsKeeper( + t testing.TB, + managerKeeper types.WasmKeeper, + refunderKeeper types.FeeRefunderKeeper, + icaControllerKeeper types.ICAControllerKeeper, + icaControllerMsgServer types.ICAControllerMsgServer, + channelKeeper types.ChannelKeeper, + bankKeeper types.BankKeeper, + getFeeCollectorAddr types.GetFeeCollectorAddr, +) (*keeper.Keeper, sdk.Context) { + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := db2.NewMemDB() + stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics2.NewNoOpMetrics()) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + k := keeper.NewKeeper( + cdc, + storeKey, + memStoreKey, + channelKeeper, + icaControllerKeeper, + icaControllerMsgServer, + managerKeeper, + refunderKeeper, + bankKeeper, + getFeeCollectorAddr, + authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + err := k.SetParams(ctx, types.DefaultParams()) + require.NoError(t, err) + + return k, ctx +} diff --git a/testutil/interchaintxs/keeper/sudo_middleware.go b/testutil/interchaintxs/keeper/sudo_middleware.go new file mode 100644 index 00000000..47829046 --- /dev/null +++ b/testutil/interchaintxs/keeper/sudo_middleware.go @@ -0,0 +1,30 @@ +package keeper + +import ( + "testing" + + "cosmossdk.io/log" + "cosmossdk.io/store" + metrics2 "cosmossdk.io/store/metrics" + storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + db2 "github.com/cosmos/cosmos-db" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func NewSudoLimitWrapper(t testing.TB, cmKeeper types.ContractManagerKeeper, wasmKeeper types.WasmKeeper) (types.WasmKeeper, sdk.Context, *storetypes.KVStoreKey) { + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + db := db2.NewMemDB() + stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics2.NewNoOpMetrics()) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + require.NoError(t, stateStore.LoadLatestVersion()) + + limitWrapper := contractmanager.NewSudoLimitWrapper(cmKeeper, wasmKeeper) + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + return limitWrapper, ctx, storeKey +} diff --git a/testutil/interchaintxs/network/network.go b/testutil/interchaintxs/network/network.go new file mode 100644 index 00000000..29f3b738 --- /dev/null +++ b/testutil/interchaintxs/network/network.go @@ -0,0 +1,96 @@ +package network + +import ( + "fmt" + "testing" + "time" + + pruningtypes "cosmossdk.io/store/pruning/types" + db "github.com/cosmos/cosmos-db" + "github.com/stretchr/testify/require" + + tmrand "github.com/cometbft/cometbft/libs/rand" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + "github.com/Nolus-Protocol/nolus-core/app" +) + +type ( + Network = network.Network + Config = network.Config +) + +// New creates instance with fully configured cosmos network. +// Accepts optional config, that will be used in place of the DefaultConfig() if provided. +func New(t *testing.T, configs ...network.Config) *network.Network { + if len(configs) > 1 { + panic("at most one config should be provided") + } + var cfg network.Config + if len(configs) == 0 { + cfg = DefaultConfig() + } else { + cfg = configs[0] + } + net, err := network.New(t, t.TempDir(), cfg) + require.NoError(t, err) + t.Cleanup(net.Cleanup) + return net +} + +// DefaultConfig will initialize config for the network with custom application, +// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig +func DefaultConfig() network.Config { + // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator + app.ModuleBasics[genutiltypes.ModuleName] = genutil.AppModuleBasic{} + app.ModuleBasics[stakingtypes.ModuleName] = staking.AppModuleBasic{} + + encoding := app.MakeEncodingConfig() + chainID := "chain-" + tmrand.NewRand().Str(6) + return network.Config{ + Codec: encoding.Marshaler, + TxConfig: encoding.TxConfig, + LegacyAmino: encoding.Amino, + InterfaceRegistry: encoding.InterfaceRegistry, + AccountRetriever: authtypes.AccountRetriever{}, + AppConstructor: func(val network.ValidatorI) servertypes.Application { + return app.New( + val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, + encoding, + sims.EmptyAppOptions{}, + nil, + baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), + baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), + baseapp.SetChainID(chainID), + ) + }, + GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), + TimeoutCommit: 2 * time.Second, + ChainID: chainID, + // Some changes are introduced to make the tests run as if neutron is a standalone chain. + // This will only work if NumValidators is set to 1. + NumValidators: 1, + BondDenom: params.DefaultBondDenom, + MinGasPrices: fmt.Sprintf("0.000006%s", params.DefaultBondDenom), + AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), + StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), + BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), + PruningStrategy: pruningtypes.PruningOptionNothing, + CleanupDir: true, + SigningAlgo: string(hd.Secp256k1Type), + KeyringOptions: []keyring.Option{}, + } +} diff --git a/testutil/mocks/cron/types/expected_keepers.go b/testutil/mocks/cron/types/expected_keepers.go new file mode 100644 index 00000000..ab9265ad --- /dev/null +++ b/testutil/mocks/cron/types/expected_keepers.go @@ -0,0 +1,89 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../x/cron/types/expected_keepers.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + context "context" + reflect "reflect" + + types "github.com/CosmWasm/wasmd/x/wasm/types" + types0 "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetModuleAddress mocks base method. +func (m *MockAccountKeeper) GetModuleAddress(moduleName string) types0.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAddress", moduleName) + ret0, _ := ret[0].(types0.AccAddress) + return ret0 +} + +// GetModuleAddress indicates an expected call of GetModuleAddress. +func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(moduleName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), moduleName) +} + +// MockWasmMsgServer is a mock of WasmMsgServer interface. +type MockWasmMsgServer struct { + ctrl *gomock.Controller + recorder *MockWasmMsgServerMockRecorder +} + +// MockWasmMsgServerMockRecorder is the mock recorder for MockWasmMsgServer. +type MockWasmMsgServerMockRecorder struct { + mock *MockWasmMsgServer +} + +// NewMockWasmMsgServer creates a new mock instance. +func NewMockWasmMsgServer(ctrl *gomock.Controller) *MockWasmMsgServer { + mock := &MockWasmMsgServer{ctrl: ctrl} + mock.recorder = &MockWasmMsgServerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWasmMsgServer) EXPECT() *MockWasmMsgServerMockRecorder { + return m.recorder +} + +// ExecuteContract mocks base method. +func (m *MockWasmMsgServer) ExecuteContract(arg0 context.Context, arg1 *types.MsgExecuteContract) (*types.MsgExecuteContractResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExecuteContract", arg0, arg1) + ret0, _ := ret[0].(*types.MsgExecuteContractResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ExecuteContract indicates an expected call of ExecuteContract. +func (mr *MockWasmMsgServerMockRecorder) ExecuteContract(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecuteContract", reflect.TypeOf((*MockWasmMsgServer)(nil).ExecuteContract), arg0, arg1) +} diff --git a/testutil/mocks/feeburner/types/expected_keepers.go b/testutil/mocks/feeburner/types/expected_keepers.go new file mode 100644 index 00000000..2b89282d --- /dev/null +++ b/testutil/mocks/feeburner/types/expected_keepers.go @@ -0,0 +1,129 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../x/feeburner/types/expected_keepers.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + context "context" + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetModuleAddress mocks base method. +func (m *MockAccountKeeper) GetModuleAddress(moduleName string) types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAddress", moduleName) + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// GetModuleAddress indicates an expected call of GetModuleAddress. +func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(moduleName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), moduleName) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// BurnCoins mocks base method. +func (m *MockBankKeeper) BurnCoins(ctx context.Context, moduleName string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// BurnCoins indicates an expected call of BurnCoins. +func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amt) +} + +// GetAllBalances mocks base method. +func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// GetAllBalances indicates an expected call of GetAllBalances. +func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr) +} + +// SendCoins mocks base method. +func (m *MockBankKeeper) SendCoins(ctx context.Context, fromAddr, toAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoins indicates an expected call of SendCoins. +func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), ctx, fromAddr, toAddr, amt) +} + +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} diff --git a/testutil/mocks/feerefunder/types/keepers.go b/testutil/mocks/feerefunder/types/keepers.go new file mode 100644 index 00000000..2ed289e7 --- /dev/null +++ b/testutil/mocks/feerefunder/types/keepers.go @@ -0,0 +1,168 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../x/feerefunder/types/expected_keepers.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + context "context" + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + types0 "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// HasBalance mocks base method. +func (m *MockBankKeeper) HasBalance(ctx context.Context, addr types.AccAddress, amt types.Coin) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasBalance", ctx, addr, amt) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasBalance indicates an expected call of HasBalance. +func (mr *MockBankKeeperMockRecorder) HasBalance(ctx, addr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasBalance", reflect.TypeOf((*MockBankKeeper)(nil).HasBalance), ctx, addr, amt) +} + +// SendCoins mocks base method. +func (m *MockBankKeeper) SendCoins(ctx context.Context, fromAddr, toAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoins indicates an expected call of SendCoins. +func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), ctx, fromAddr, toAddr, amt) +} + +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} + +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) +} + +// MockChannelKeeper is a mock of ChannelKeeper interface. +type MockChannelKeeper struct { + ctrl *gomock.Controller + recorder *MockChannelKeeperMockRecorder +} + +// MockChannelKeeperMockRecorder is the mock recorder for MockChannelKeeper. +type MockChannelKeeperMockRecorder struct { + mock *MockChannelKeeper +} + +// NewMockChannelKeeper creates a new mock instance. +func NewMockChannelKeeper(ctrl *gomock.Controller) *MockChannelKeeper { + mock := &MockChannelKeeper{ctrl: ctrl} + mock.recorder = &MockChannelKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockChannelKeeper) EXPECT() *MockChannelKeeperMockRecorder { + return m.recorder +} + +// GetChannel mocks base method. +func (m *MockChannelKeeper) GetChannel(ctx types.Context, srcPort, srcChan string) (types0.Channel, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChannel", ctx, srcPort, srcChan) + ret0, _ := ret[0].(types0.Channel) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetChannel indicates an expected call of GetChannel. +func (mr *MockChannelKeeperMockRecorder) GetChannel(ctx, srcPort, srcChan interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChannel", reflect.TypeOf((*MockChannelKeeper)(nil).GetChannel), ctx, srcPort, srcChan) +} diff --git a/testutil/mocks/gomock.go b/testutil/mocks/gomock.go index 370b097d..0e0aecc5 100644 --- a/testutil/mocks/gomock.go +++ b/testutil/mocks/gomock.go @@ -1,3 +1,9 @@ package mocks //go:generate mockgen -source=./../../x/tax/types/expected_keepers.go -destination ./tax/types/expected_keepers.go +//go:generate mockgen -source=./../../x/contractmanager/types/expected_keepers.go -destination ./contractmanager/types/expected_keepers.go +//go:generate mockgen -source=./../../x/feerefunder/types/expected_keepers.go -destination ./feerefunder/types/keepers.go +//go:generate mockgen -source=./../../x/interchainqueries/types/verify.go -destination ./interchainqueries/keeper/verify.go +//go:generate mockgen -source=./../../x/interchainqueries/types/expected_keepers.go -destination ./interchainqueries/types/expected_keepers.go +//go:generate mockgen -source=./../../x/interchaintxs/types/expected_keepers.go -destination ./interchaintxs/types/expected_keepers.go +//go:generate mockgen -source=./../../x/transfer/types/expected_keepers.go -destination ./transfer/types/expected_keepers.go diff --git a/testutil/mocks/interchainqueries/keeper/verify.go b/testutil/mocks/interchainqueries/keeper/verify.go new file mode 100644 index 00000000..e5f90ace --- /dev/null +++ b/testutil/mocks/interchainqueries/keeper/verify.go @@ -0,0 +1,107 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../x/interchainqueries/types/verify.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/codec/types" + types0 "github.com/cosmos/cosmos-sdk/types" + keeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" + exported "github.com/cosmos/ibc-go/v8/modules/core/exported" + tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + gomock "github.com/golang/mock/gomock" + + types1 "github.com/neutron-org/neutron/v4/x/interchainqueries/types" +) + +// MockHeaderVerifier is a mock of HeaderVerifier interface. +type MockHeaderVerifier struct { + ctrl *gomock.Controller + recorder *MockHeaderVerifierMockRecorder +} + +// MockHeaderVerifierMockRecorder is the mock recorder for MockHeaderVerifier. +type MockHeaderVerifierMockRecorder struct { + mock *MockHeaderVerifier +} + +// NewMockHeaderVerifier creates a new mock instance. +func NewMockHeaderVerifier(ctrl *gomock.Controller) *MockHeaderVerifier { + mock := &MockHeaderVerifier{ctrl: ctrl} + mock.recorder = &MockHeaderVerifierMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHeaderVerifier) EXPECT() *MockHeaderVerifierMockRecorder { + return m.recorder +} + +// UnpackHeader mocks base method. +func (m *MockHeaderVerifier) UnpackHeader(any *types.Any) (exported.ClientMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnpackHeader", any) + ret0, _ := ret[0].(exported.ClientMessage) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UnpackHeader indicates an expected call of UnpackHeader. +func (mr *MockHeaderVerifierMockRecorder) UnpackHeader(any interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnpackHeader", reflect.TypeOf((*MockHeaderVerifier)(nil).UnpackHeader), any) +} + +// VerifyHeaders mocks base method. +func (m *MockHeaderVerifier) VerifyHeaders(ctx types0.Context, cleintkeeper keeper.Keeper, clientID string, header, nextHeader exported.ClientMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "VerifyHeaders", ctx, cleintkeeper, clientID, header, nextHeader) + ret0, _ := ret[0].(error) + return ret0 +} + +// VerifyHeaders indicates an expected call of VerifyHeaders. +func (mr *MockHeaderVerifierMockRecorder) VerifyHeaders(ctx, cleintkeeper, clientID, header, nextHeader interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VerifyHeaders", reflect.TypeOf((*MockHeaderVerifier)(nil).VerifyHeaders), ctx, cleintkeeper, clientID, header, nextHeader) +} + +// MockTransactionVerifier is a mock of TransactionVerifier interface. +type MockTransactionVerifier struct { + ctrl *gomock.Controller + recorder *MockTransactionVerifierMockRecorder +} + +// MockTransactionVerifierMockRecorder is the mock recorder for MockTransactionVerifier. +type MockTransactionVerifierMockRecorder struct { + mock *MockTransactionVerifier +} + +// NewMockTransactionVerifier creates a new mock instance. +func NewMockTransactionVerifier(ctrl *gomock.Controller) *MockTransactionVerifier { + mock := &MockTransactionVerifier{ctrl: ctrl} + mock.recorder = &MockTransactionVerifierMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockTransactionVerifier) EXPECT() *MockTransactionVerifierMockRecorder { + return m.recorder +} + +// VerifyTransaction mocks base method. +func (m *MockTransactionVerifier) VerifyTransaction(header, nextHeader *tendermint.Header, tx *types1.TxValue) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "VerifyTransaction", header, nextHeader, tx) + ret0, _ := ret[0].(error) + return ret0 +} + +// VerifyTransaction indicates an expected call of VerifyTransaction. +func (mr *MockTransactionVerifierMockRecorder) VerifyTransaction(header, nextHeader, tx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VerifyTransaction", reflect.TypeOf((*MockTransactionVerifier)(nil).VerifyTransaction), header, nextHeader, tx) +} diff --git a/testutil/mocks/interchainqueries/types/expected_keepers.go b/testutil/mocks/interchainqueries/types/expected_keepers.go new file mode 100644 index 00000000..652d8517 --- /dev/null +++ b/testutil/mocks/interchainqueries/types/expected_keepers.go @@ -0,0 +1,183 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../x/interchainqueries/types/expected_keepers.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + context "context" + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + types0 "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} + +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} + +// MockContractManagerKeeper is a mock of ContractManagerKeeper interface. +type MockContractManagerKeeper struct { + ctrl *gomock.Controller + recorder *MockContractManagerKeeperMockRecorder +} + +// MockContractManagerKeeperMockRecorder is the mock recorder for MockContractManagerKeeper. +type MockContractManagerKeeperMockRecorder struct { + mock *MockContractManagerKeeper +} + +// NewMockContractManagerKeeper creates a new mock instance. +func NewMockContractManagerKeeper(ctrl *gomock.Controller) *MockContractManagerKeeper { + mock := &MockContractManagerKeeper{ctrl: ctrl} + mock.recorder = &MockContractManagerKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockContractManagerKeeper) EXPECT() *MockContractManagerKeeperMockRecorder { + return m.recorder +} + +// HasContractInfo mocks base method. +func (m *MockContractManagerKeeper) HasContractInfo(ctx context.Context, contractAddress types.AccAddress) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasContractInfo", ctx, contractAddress) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasContractInfo indicates an expected call of HasContractInfo. +func (mr *MockContractManagerKeeperMockRecorder) HasContractInfo(ctx, contractAddress interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasContractInfo", reflect.TypeOf((*MockContractManagerKeeper)(nil).HasContractInfo), ctx, contractAddress) +} + +// SudoKVQueryResult mocks base method. +func (m *MockContractManagerKeeper) SudoKVQueryResult(ctx context.Context, contractAddress types.AccAddress, queryID uint64) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SudoKVQueryResult", ctx, contractAddress, queryID) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SudoKVQueryResult indicates an expected call of SudoKVQueryResult. +func (mr *MockContractManagerKeeperMockRecorder) SudoKVQueryResult(ctx, contractAddress, queryID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SudoKVQueryResult", reflect.TypeOf((*MockContractManagerKeeper)(nil).SudoKVQueryResult), ctx, contractAddress, queryID) +} + +// SudoTxQueryResult mocks base method. +func (m *MockContractManagerKeeper) SudoTxQueryResult(ctx context.Context, contractAddress types.AccAddress, queryID uint64, height types0.Height, data []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SudoTxQueryResult", ctx, contractAddress, queryID, height, data) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SudoTxQueryResult indicates an expected call of SudoTxQueryResult. +func (mr *MockContractManagerKeeperMockRecorder) SudoTxQueryResult(ctx, contractAddress, queryID, height, data interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SudoTxQueryResult", reflect.TypeOf((*MockContractManagerKeeper)(nil).SudoTxQueryResult), ctx, contractAddress, queryID, height, data) +} diff --git a/testutil/mocks/interchainqueries/types/verify.go b/testutil/mocks/interchainqueries/types/verify.go new file mode 100644 index 00000000..7289f3c0 --- /dev/null +++ b/testutil/mocks/interchainqueries/types/verify.go @@ -0,0 +1,107 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/interchainqueries/types/verify.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/codec/types" + types0 "github.com/cosmos/cosmos-sdk/types" + keeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" + exported "github.com/cosmos/ibc-go/v8/modules/core/exported" + types1 "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + gomock "github.com/golang/mock/gomock" + + types2 "github.com/neutron-org/neutron/v4/x/interchainqueries/types" +) + +// MockHeaderVerifier is a mock of HeaderVerifier interface. +type MockHeaderVerifier struct { + ctrl *gomock.Controller + recorder *MockHeaderVerifierMockRecorder +} + +// MockHeaderVerifierMockRecorder is the mock recorder for MockHeaderVerifier. +type MockHeaderVerifierMockRecorder struct { + mock *MockHeaderVerifier +} + +// NewMockHeaderVerifier creates a new mock instance. +func NewMockHeaderVerifier(ctrl *gomock.Controller) *MockHeaderVerifier { + mock := &MockHeaderVerifier{ctrl: ctrl} + mock.recorder = &MockHeaderVerifierMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHeaderVerifier) EXPECT() *MockHeaderVerifierMockRecorder { + return m.recorder +} + +// UnpackHeader mocks base method. +func (m *MockHeaderVerifier) UnpackHeader(any *types.Any) (exported.ClientMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnpackHeader", any) + ret0, _ := ret[0].(exported.ClientMessage) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UnpackHeader indicates an expected call of UnpackHeader. +func (mr *MockHeaderVerifierMockRecorder) UnpackHeader(any interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnpackHeader", reflect.TypeOf((*MockHeaderVerifier)(nil).UnpackHeader), any) +} + +// VerifyHeaders mocks base method. +func (m *MockHeaderVerifier) VerifyHeaders(ctx types0.Context, cleintkeeper keeper.Keeper, clientID string, header, nextHeader exported.ClientMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "VerifyHeaders", ctx, cleintkeeper, clientID, header, nextHeader) + ret0, _ := ret[0].(error) + return ret0 +} + +// VerifyHeaders indicates an expected call of VerifyHeaders. +func (mr *MockHeaderVerifierMockRecorder) VerifyHeaders(ctx, cleintkeeper, clientID, header, nextHeader interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VerifyHeaders", reflect.TypeOf((*MockHeaderVerifier)(nil).VerifyHeaders), ctx, cleintkeeper, clientID, header, nextHeader) +} + +// MockTransactionVerifier is a mock of TransactionVerifier interface. +type MockTransactionVerifier struct { + ctrl *gomock.Controller + recorder *MockTransactionVerifierMockRecorder +} + +// MockTransactionVerifierMockRecorder is the mock recorder for MockTransactionVerifier. +type MockTransactionVerifierMockRecorder struct { + mock *MockTransactionVerifier +} + +// NewMockTransactionVerifier creates a new mock instance. +func NewMockTransactionVerifier(ctrl *gomock.Controller) *MockTransactionVerifier { + mock := &MockTransactionVerifier{ctrl: ctrl} + mock.recorder = &MockTransactionVerifierMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockTransactionVerifier) EXPECT() *MockTransactionVerifierMockRecorder { + return m.recorder +} + +// VerifyTransaction mocks base method. +func (m *MockTransactionVerifier) VerifyTransaction(header, nextHeader *types1.Header, tx *types2.TxValue) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "VerifyTransaction", header, nextHeader, tx) + ret0, _ := ret[0].(error) + return ret0 +} + +// VerifyTransaction indicates an expected call of VerifyTransaction. +func (mr *MockTransactionVerifierMockRecorder) VerifyTransaction(header, nextHeader, tx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VerifyTransaction", reflect.TypeOf((*MockTransactionVerifier)(nil).VerifyTransaction), header, nextHeader, tx) +} diff --git a/testutil/mocks/interchaintxs/types/expected_keepers.go b/testutil/mocks/interchaintxs/types/expected_keepers.go new file mode 100644 index 00000000..68866d0b --- /dev/null +++ b/testutil/mocks/interchaintxs/types/expected_keepers.go @@ -0,0 +1,420 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../x/interchaintxs/types/expected_keepers.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + context "context" + reflect "reflect" + + types "github.com/CosmWasm/wasmd/x/wasm/types" + types0 "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + types2 "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + exported "github.com/cosmos/ibc-go/v8/modules/core/exported" + gomock "github.com/golang/mock/gomock" + + types3 "github.com/neutron-org/neutron/v4/x/feerefunder/types" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types0.AccAddress) types0.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types0.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// SendCoins mocks base method. +func (m *MockBankKeeper) SendCoins(ctx context.Context, fromAddr, toAddr types0.AccAddress, amt types0.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoins indicates an expected call of SendCoins. +func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), ctx, fromAddr, toAddr, amt) +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types0.AccAddress) types0.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types0.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} + +// MockWasmKeeper is a mock of WasmKeeper interface. +type MockWasmKeeper struct { + ctrl *gomock.Controller + recorder *MockWasmKeeperMockRecorder +} + +// MockWasmKeeperMockRecorder is the mock recorder for MockWasmKeeper. +type MockWasmKeeperMockRecorder struct { + mock *MockWasmKeeper +} + +// NewMockWasmKeeper creates a new mock instance. +func NewMockWasmKeeper(ctrl *gomock.Controller) *MockWasmKeeper { + mock := &MockWasmKeeper{ctrl: ctrl} + mock.recorder = &MockWasmKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWasmKeeper) EXPECT() *MockWasmKeeperMockRecorder { + return m.recorder +} + +// GetContractInfo mocks base method. +func (m *MockWasmKeeper) GetContractInfo(ctx context.Context, contractAddress types0.AccAddress) *types.ContractInfo { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetContractInfo", ctx, contractAddress) + ret0, _ := ret[0].(*types.ContractInfo) + return ret0 +} + +// GetContractInfo indicates an expected call of GetContractInfo. +func (mr *MockWasmKeeperMockRecorder) GetContractInfo(ctx, contractAddress interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContractInfo", reflect.TypeOf((*MockWasmKeeper)(nil).GetContractInfo), ctx, contractAddress) +} + +// HasContractInfo mocks base method. +func (m *MockWasmKeeper) HasContractInfo(ctx context.Context, contractAddress types0.AccAddress) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasContractInfo", ctx, contractAddress) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasContractInfo indicates an expected call of HasContractInfo. +func (mr *MockWasmKeeperMockRecorder) HasContractInfo(ctx, contractAddress interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasContractInfo", reflect.TypeOf((*MockWasmKeeper)(nil).HasContractInfo), ctx, contractAddress) +} + +// Sudo mocks base method. +func (m *MockWasmKeeper) Sudo(ctx context.Context, contractAddress types0.AccAddress, msg []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Sudo", ctx, contractAddress, msg) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Sudo indicates an expected call of Sudo. +func (mr *MockWasmKeeperMockRecorder) Sudo(ctx, contractAddress, msg interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sudo", reflect.TypeOf((*MockWasmKeeper)(nil).Sudo), ctx, contractAddress, msg) +} + +// MockICAControllerKeeper is a mock of ICAControllerKeeper interface. +type MockICAControllerKeeper struct { + ctrl *gomock.Controller + recorder *MockICAControllerKeeperMockRecorder +} + +// MockICAControllerKeeperMockRecorder is the mock recorder for MockICAControllerKeeper. +type MockICAControllerKeeperMockRecorder struct { + mock *MockICAControllerKeeper +} + +// NewMockICAControllerKeeper creates a new mock instance. +func NewMockICAControllerKeeper(ctrl *gomock.Controller) *MockICAControllerKeeper { + mock := &MockICAControllerKeeper{ctrl: ctrl} + mock.recorder = &MockICAControllerKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockICAControllerKeeper) EXPECT() *MockICAControllerKeeperMockRecorder { + return m.recorder +} + +// GetActiveChannelID mocks base method. +func (m *MockICAControllerKeeper) GetActiveChannelID(ctx types0.Context, connectionID, portID string) (string, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetActiveChannelID", ctx, connectionID, portID) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetActiveChannelID indicates an expected call of GetActiveChannelID. +func (mr *MockICAControllerKeeperMockRecorder) GetActiveChannelID(ctx, connectionID, portID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveChannelID", reflect.TypeOf((*MockICAControllerKeeper)(nil).GetActiveChannelID), ctx, connectionID, portID) +} + +// GetInterchainAccountAddress mocks base method. +func (m *MockICAControllerKeeper) GetInterchainAccountAddress(ctx types0.Context, connectionID, portID string) (string, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetInterchainAccountAddress", ctx, connectionID, portID) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetInterchainAccountAddress indicates an expected call of GetInterchainAccountAddress. +func (mr *MockICAControllerKeeperMockRecorder) GetInterchainAccountAddress(ctx, connectionID, portID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInterchainAccountAddress", reflect.TypeOf((*MockICAControllerKeeper)(nil).GetInterchainAccountAddress), ctx, connectionID, portID) +} + +// SetMiddlewareEnabled mocks base method. +func (m *MockICAControllerKeeper) SetMiddlewareEnabled(ctx types0.Context, portID, connectionID string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetMiddlewareEnabled", ctx, portID, connectionID) +} + +// SetMiddlewareEnabled indicates an expected call of SetMiddlewareEnabled. +func (mr *MockICAControllerKeeperMockRecorder) SetMiddlewareEnabled(ctx, portID, connectionID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMiddlewareEnabled", reflect.TypeOf((*MockICAControllerKeeper)(nil).SetMiddlewareEnabled), ctx, portID, connectionID) +} + +// MockICAControllerMsgServer is a mock of ICAControllerMsgServer interface. +type MockICAControllerMsgServer struct { + ctrl *gomock.Controller + recorder *MockICAControllerMsgServerMockRecorder +} + +// MockICAControllerMsgServerMockRecorder is the mock recorder for MockICAControllerMsgServer. +type MockICAControllerMsgServerMockRecorder struct { + mock *MockICAControllerMsgServer +} + +// NewMockICAControllerMsgServer creates a new mock instance. +func NewMockICAControllerMsgServer(ctrl *gomock.Controller) *MockICAControllerMsgServer { + mock := &MockICAControllerMsgServer{ctrl: ctrl} + mock.recorder = &MockICAControllerMsgServerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockICAControllerMsgServer) EXPECT() *MockICAControllerMsgServerMockRecorder { + return m.recorder +} + +// RegisterInterchainAccount mocks base method. +func (m *MockICAControllerMsgServer) RegisterInterchainAccount(arg0 context.Context, arg1 *types1.MsgRegisterInterchainAccount) (*types1.MsgRegisterInterchainAccountResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RegisterInterchainAccount", arg0, arg1) + ret0, _ := ret[0].(*types1.MsgRegisterInterchainAccountResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RegisterInterchainAccount indicates an expected call of RegisterInterchainAccount. +func (mr *MockICAControllerMsgServerMockRecorder) RegisterInterchainAccount(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterchainAccount", reflect.TypeOf((*MockICAControllerMsgServer)(nil).RegisterInterchainAccount), arg0, arg1) +} + +// SendTx mocks base method. +func (m *MockICAControllerMsgServer) SendTx(arg0 context.Context, arg1 *types1.MsgSendTx) (*types1.MsgSendTxResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendTx", arg0, arg1) + ret0, _ := ret[0].(*types1.MsgSendTxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendTx indicates an expected call of SendTx. +func (mr *MockICAControllerMsgServerMockRecorder) SendTx(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendTx", reflect.TypeOf((*MockICAControllerMsgServer)(nil).SendTx), arg0, arg1) +} + +// MockFeeRefunderKeeper is a mock of FeeRefunderKeeper interface. +type MockFeeRefunderKeeper struct { + ctrl *gomock.Controller + recorder *MockFeeRefunderKeeperMockRecorder +} + +// MockFeeRefunderKeeperMockRecorder is the mock recorder for MockFeeRefunderKeeper. +type MockFeeRefunderKeeperMockRecorder struct { + mock *MockFeeRefunderKeeper +} + +// NewMockFeeRefunderKeeper creates a new mock instance. +func NewMockFeeRefunderKeeper(ctrl *gomock.Controller) *MockFeeRefunderKeeper { + mock := &MockFeeRefunderKeeper{ctrl: ctrl} + mock.recorder = &MockFeeRefunderKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFeeRefunderKeeper) EXPECT() *MockFeeRefunderKeeperMockRecorder { + return m.recorder +} + +// DistributeAcknowledgementFee mocks base method. +func (m *MockFeeRefunderKeeper) DistributeAcknowledgementFee(ctx context.Context, receiver types0.AccAddress, packetID types3.PacketID) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DistributeAcknowledgementFee", ctx, receiver, packetID) +} + +// DistributeAcknowledgementFee indicates an expected call of DistributeAcknowledgementFee. +func (mr *MockFeeRefunderKeeperMockRecorder) DistributeAcknowledgementFee(ctx, receiver, packetID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DistributeAcknowledgementFee", reflect.TypeOf((*MockFeeRefunderKeeper)(nil).DistributeAcknowledgementFee), ctx, receiver, packetID) +} + +// DistributeTimeoutFee mocks base method. +func (m *MockFeeRefunderKeeper) DistributeTimeoutFee(ctx context.Context, receiver types0.AccAddress, packetID types3.PacketID) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DistributeTimeoutFee", ctx, receiver, packetID) +} + +// DistributeTimeoutFee indicates an expected call of DistributeTimeoutFee. +func (mr *MockFeeRefunderKeeperMockRecorder) DistributeTimeoutFee(ctx, receiver, packetID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DistributeTimeoutFee", reflect.TypeOf((*MockFeeRefunderKeeper)(nil).DistributeTimeoutFee), ctx, receiver, packetID) +} + +// LockFees mocks base method. +func (m *MockFeeRefunderKeeper) LockFees(ctx context.Context, payer types0.AccAddress, packetID types3.PacketID, fee types3.Fee) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LockFees", ctx, payer, packetID, fee) + ret0, _ := ret[0].(error) + return ret0 +} + +// LockFees indicates an expected call of LockFees. +func (mr *MockFeeRefunderKeeperMockRecorder) LockFees(ctx, payer, packetID, fee interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LockFees", reflect.TypeOf((*MockFeeRefunderKeeper)(nil).LockFees), ctx, payer, packetID, fee) +} + +// MockChannelKeeper is a mock of ChannelKeeper interface. +type MockChannelKeeper struct { + ctrl *gomock.Controller + recorder *MockChannelKeeperMockRecorder +} + +// MockChannelKeeperMockRecorder is the mock recorder for MockChannelKeeper. +type MockChannelKeeperMockRecorder struct { + mock *MockChannelKeeper +} + +// NewMockChannelKeeper creates a new mock instance. +func NewMockChannelKeeper(ctrl *gomock.Controller) *MockChannelKeeper { + mock := &MockChannelKeeper{ctrl: ctrl} + mock.recorder = &MockChannelKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockChannelKeeper) EXPECT() *MockChannelKeeperMockRecorder { + return m.recorder +} + +// GetChannel mocks base method. +func (m *MockChannelKeeper) GetChannel(ctx types0.Context, srcPort, srcChan string) (types2.Channel, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChannel", ctx, srcPort, srcChan) + ret0, _ := ret[0].(types2.Channel) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetChannel indicates an expected call of GetChannel. +func (mr *MockChannelKeeperMockRecorder) GetChannel(ctx, srcPort, srcChan interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChannel", reflect.TypeOf((*MockChannelKeeper)(nil).GetChannel), ctx, srcPort, srcChan) +} + +// GetConnection mocks base method. +func (m *MockChannelKeeper) GetConnection(ctx types0.Context, connectionID string) (exported.ConnectionI, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetConnection", ctx, connectionID) + ret0, _ := ret[0].(exported.ConnectionI) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetConnection indicates an expected call of GetConnection. +func (mr *MockChannelKeeperMockRecorder) GetConnection(ctx, connectionID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConnection", reflect.TypeOf((*MockChannelKeeper)(nil).GetConnection), ctx, connectionID) +} + +// GetNextSequenceSend mocks base method. +func (m *MockChannelKeeper) GetNextSequenceSend(ctx types0.Context, portID, channelID string) (uint64, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetNextSequenceSend", ctx, portID, channelID) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetNextSequenceSend indicates an expected call of GetNextSequenceSend. +func (mr *MockChannelKeeperMockRecorder) GetNextSequenceSend(ctx, portID, channelID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNextSequenceSend", reflect.TypeOf((*MockChannelKeeper)(nil).GetNextSequenceSend), ctx, portID, channelID) +} diff --git a/testutil/mocks/transfer/types/expected_keepers.go b/testutil/mocks/transfer/types/expected_keepers.go new file mode 100644 index 00000000..b1cc375e --- /dev/null +++ b/testutil/mocks/transfer/types/expected_keepers.go @@ -0,0 +1,247 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../x/transfer/types/expected_keepers.go + +// Package mock_types is a generated GoMock package. +package mock_types + +import ( + context "context" + reflect "reflect" + + types "github.com/cosmos/cosmos-sdk/types" + types0 "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + gomock "github.com/golang/mock/gomock" + + types1 "github.com/neutron-org/neutron/v4/x/feerefunder/types" +) + +// MockWasmKeeper is a mock of WasmKeeper interface. +type MockWasmKeeper struct { + ctrl *gomock.Controller + recorder *MockWasmKeeperMockRecorder +} + +// MockWasmKeeperMockRecorder is the mock recorder for MockWasmKeeper. +type MockWasmKeeperMockRecorder struct { + mock *MockWasmKeeper +} + +// NewMockWasmKeeper creates a new mock instance. +func NewMockWasmKeeper(ctrl *gomock.Controller) *MockWasmKeeper { + mock := &MockWasmKeeper{ctrl: ctrl} + mock.recorder = &MockWasmKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWasmKeeper) EXPECT() *MockWasmKeeperMockRecorder { + return m.recorder +} + +// HasContractInfo mocks base method. +func (m *MockWasmKeeper) HasContractInfo(ctx context.Context, contractAddress types.AccAddress) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasContractInfo", ctx, contractAddress) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasContractInfo indicates an expected call of HasContractInfo. +func (mr *MockWasmKeeperMockRecorder) HasContractInfo(ctx, contractAddress interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasContractInfo", reflect.TypeOf((*MockWasmKeeper)(nil).HasContractInfo), ctx, contractAddress) +} + +// Sudo mocks base method. +func (m *MockWasmKeeper) Sudo(ctx context.Context, contractAddress types.AccAddress, msg []byte) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Sudo", ctx, contractAddress, msg) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Sudo indicates an expected call of Sudo. +func (mr *MockWasmKeeperMockRecorder) Sudo(ctx, contractAddress, msg interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sudo", reflect.TypeOf((*MockWasmKeeper)(nil).Sudo), ctx, contractAddress, msg) +} + +// MockFeeRefunderKeeper is a mock of FeeRefunderKeeper interface. +type MockFeeRefunderKeeper struct { + ctrl *gomock.Controller + recorder *MockFeeRefunderKeeperMockRecorder +} + +// MockFeeRefunderKeeperMockRecorder is the mock recorder for MockFeeRefunderKeeper. +type MockFeeRefunderKeeperMockRecorder struct { + mock *MockFeeRefunderKeeper +} + +// NewMockFeeRefunderKeeper creates a new mock instance. +func NewMockFeeRefunderKeeper(ctrl *gomock.Controller) *MockFeeRefunderKeeper { + mock := &MockFeeRefunderKeeper{ctrl: ctrl} + mock.recorder = &MockFeeRefunderKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFeeRefunderKeeper) EXPECT() *MockFeeRefunderKeeperMockRecorder { + return m.recorder +} + +// DistributeAcknowledgementFee mocks base method. +func (m *MockFeeRefunderKeeper) DistributeAcknowledgementFee(ctx context.Context, receiver types.AccAddress, packetID types1.PacketID) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DistributeAcknowledgementFee", ctx, receiver, packetID) +} + +// DistributeAcknowledgementFee indicates an expected call of DistributeAcknowledgementFee. +func (mr *MockFeeRefunderKeeperMockRecorder) DistributeAcknowledgementFee(ctx, receiver, packetID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DistributeAcknowledgementFee", reflect.TypeOf((*MockFeeRefunderKeeper)(nil).DistributeAcknowledgementFee), ctx, receiver, packetID) +} + +// DistributeTimeoutFee mocks base method. +func (m *MockFeeRefunderKeeper) DistributeTimeoutFee(ctx context.Context, receiver types.AccAddress, packetID types1.PacketID) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DistributeTimeoutFee", ctx, receiver, packetID) +} + +// DistributeTimeoutFee indicates an expected call of DistributeTimeoutFee. +func (mr *MockFeeRefunderKeeperMockRecorder) DistributeTimeoutFee(ctx, receiver, packetID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DistributeTimeoutFee", reflect.TypeOf((*MockFeeRefunderKeeper)(nil).DistributeTimeoutFee), ctx, receiver, packetID) +} + +// LockFees mocks base method. +func (m *MockFeeRefunderKeeper) LockFees(ctx context.Context, payer types.AccAddress, packetID types1.PacketID, fee types1.Fee) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LockFees", ctx, payer, packetID, fee) + ret0, _ := ret[0].(error) + return ret0 +} + +// LockFees indicates an expected call of LockFees. +func (mr *MockFeeRefunderKeeperMockRecorder) LockFees(ctx, payer, packetID, fee interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LockFees", reflect.TypeOf((*MockFeeRefunderKeeper)(nil).LockFees), ctx, payer, packetID, fee) +} + +// MockChannelKeeper is a mock of ChannelKeeper interface. +type MockChannelKeeper struct { + ctrl *gomock.Controller + recorder *MockChannelKeeperMockRecorder +} + +// MockChannelKeeperMockRecorder is the mock recorder for MockChannelKeeper. +type MockChannelKeeperMockRecorder struct { + mock *MockChannelKeeper +} + +// NewMockChannelKeeper creates a new mock instance. +func NewMockChannelKeeper(ctrl *gomock.Controller) *MockChannelKeeper { + mock := &MockChannelKeeper{ctrl: ctrl} + mock.recorder = &MockChannelKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockChannelKeeper) EXPECT() *MockChannelKeeperMockRecorder { + return m.recorder +} + +// GetAllChannelsWithPortPrefix mocks base method. +func (m *MockChannelKeeper) GetAllChannelsWithPortPrefix(ctx types.Context, portPrefix string) []types0.IdentifiedChannel { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllChannelsWithPortPrefix", ctx, portPrefix) + ret0, _ := ret[0].([]types0.IdentifiedChannel) + return ret0 +} + +// GetAllChannelsWithPortPrefix indicates an expected call of GetAllChannelsWithPortPrefix. +func (mr *MockChannelKeeperMockRecorder) GetAllChannelsWithPortPrefix(ctx, portPrefix interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllChannelsWithPortPrefix", reflect.TypeOf((*MockChannelKeeper)(nil).GetAllChannelsWithPortPrefix), ctx, portPrefix) +} + +// GetChannel mocks base method. +func (m *MockChannelKeeper) GetChannel(ctx types.Context, srcPort, srcChan string) (types0.Channel, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChannel", ctx, srcPort, srcChan) + ret0, _ := ret[0].(types0.Channel) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetChannel indicates an expected call of GetChannel. +func (mr *MockChannelKeeperMockRecorder) GetChannel(ctx, srcPort, srcChan interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChannel", reflect.TypeOf((*MockChannelKeeper)(nil).GetChannel), ctx, srcPort, srcChan) +} + +// GetNextSequenceSend mocks base method. +func (m *MockChannelKeeper) GetNextSequenceSend(ctx types.Context, portID, channelID string) (uint64, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetNextSequenceSend", ctx, portID, channelID) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetNextSequenceSend indicates an expected call of GetNextSequenceSend. +func (mr *MockChannelKeeperMockRecorder) GetNextSequenceSend(ctx, portID, channelID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNextSequenceSend", reflect.TypeOf((*MockChannelKeeper)(nil).GetNextSequenceSend), ctx, portID, channelID) +} + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetModuleAccount mocks base method. +func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, name string) types.ModuleAccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAccount", ctx, name) + ret0, _ := ret[0].(types.ModuleAccountI) + return ret0 +} + +// GetModuleAccount indicates an expected call of GetModuleAccount. +func (mr *MockAccountKeeperMockRecorder) GetModuleAccount(ctx, name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAccount), ctx, name) +} + +// GetModuleAddress mocks base method. +func (m *MockAccountKeeper) GetModuleAddress(name string) types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAddress", name) + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// GetModuleAddress indicates an expected call of GetModuleAddress. +func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name) +} diff --git a/testutil/test_helpers.go b/testutil/test_helpers.go index 86906698..2617a1e0 100644 --- a/testutil/test_helpers.go +++ b/testutil/test_helpers.go @@ -1,318 +1,317 @@ package testutil -// TODO -// import ( -// "context" -// "encoding/json" -// "fmt" -// "os" -// "time" - -// "cosmossdk.io/log" - -// icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" -// "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" -// ibctesting "github.com/cosmos/ibc-go/v8/testing" - -// "github.com/CosmWasm/wasmd/x/wasm/keeper" -// wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - -// db2 "github.com/cosmos/cosmos-db" - -// "github.com/cosmos/cosmos-sdk/baseapp" -// "github.com/cosmos/cosmos-sdk/testutil/sims" -// sdk "github.com/cosmos/cosmos-sdk/types" -// slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" -// channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" -// "github.com/stretchr/testify/suite" - -// "github.com/Nolus-Protocol/nolus-core/app" -// "github.com/Nolus-Protocol/nolus-core/app/params" - -// tmos "github.com/cometbft/cometbft/libs/os" -// tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - -// ictxstypes "github.com/neutron-org/neutron/v4/x/interchaintxs/types" -// ) - -// var ( -// // TestOwnerAddress defines a reusable bech32 address for testing purposes. -// TestOwnerAddress = "nolus17dtl0mjt3t77kpuhg2edqzjpszulwhgzcdvagh" - -// TestInterchainID = "owner_id" - -// Connection = "connection-0" - -// // TestVersion defines a reusable interchainaccounts version string for testing purposes. -// TestVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{ -// Version: icatypes.Version, -// ControllerConnectionId: Connection, -// HostConnectionId: Connection, -// Encoding: icatypes.EncodingProtobuf, -// TxType: icatypes.TxTypeSDKMultiMsg, -// })) -// ) - -// func init() { -// ibctesting.DefaultTestingAppInit = SetupTestingApp -// params.GetDefaultConfig() -// // Disable cache since enabled cache triggers test errors when `AccAddress.String()` -// // gets called before setting nolus bech32 prefix -// sdk.SetAddrCacheEnabled(false) -// } - -// type IBCConnectionTestSuite struct { -// suite.Suite -// Coordinator *ibctesting.Coordinator - -// // testing chains used for convenience and readability -// ChainA *ibctesting.TestChain -// ChainB *ibctesting.TestChain - -// Path *ibctesting.Path -// TransferPath *ibctesting.Path -// } - -// func (suite *IBCConnectionTestSuite) SetupTest() { -// // we need to redefine this variable to make tests work cause we use unls as default bond denom in nolus -// sdk.DefaultBondDenom = params.DefaultBondDenom - -// suite.Coordinator = ibctesting.NewCoordinator(suite.T(), 2) // initialize 2 test chains -// suite.ChainA = suite.Coordinator.GetChain(ibctesting.GetChainID(1)) -// suite.ChainB = suite.Coordinator.GetChain(ibctesting.GetChainID(2)) - -// // move chains to the next block -// suite.ChainA.NextBlock() -// suite.ChainB.NextBlock() - -// // path := ibctesting.NewPath(suite.ChainA, suite.ChainB) // clientID, connectionID, channelID empty -// // suite.Coordinator.Setup(path) // clientID, connectionID, channelID filled -// // suite.Require().Equal("07-tendermint-0", path.EndpointA.ClientID) -// // suite.Require().Equal("connection-0", path.EndpointA.ClientID) -// // suite.Require().Equal("channel-0", path.EndpointA.ClientID) - -// suite.Path = NewICAPath(suite.ChainA, suite.ChainB) - -// // suite.ConfigureTransferChannel() -// suite.Coordinator.Setup(suite.Path) -// } - -// func (suite *IBCConnectionTestSuite) ConfigureTransferChannel() { -// suite.TransferPath = NewTransferPath(suite.ChainA, suite.ChainB) -// suite.Coordinator.SetupConnections(suite.TransferPath) -// err := SetupTransferPath(suite.TransferPath) -// suite.Require().NoError(err) -// } - -// func (suite *IBCConnectionTestSuite) GetNolusZoneApp(chain *ibctesting.TestChain) *app.App { -// testApp, ok := chain.App.(*app.App) -// if !ok { -// panic("not NolusZone app") -// } - -// return testApp -// } - -// func (suite *IBCConnectionTestSuite) StoreTestCode(ctx sdk.Context, addr sdk.AccAddress, path string) uint64 { -// // wasm file built with https://github.com/neutron-org/neutron-sdk/tree/main/contracts/reflect -// // wasm file built with https://github.com/neutron-org/neutron-dev-contracts/tree/feat/ica-register-fee-update/contracts/neutron_interchain_txs -// wasmCode, err := os.ReadFile(path) -// suite.Require().NoError(err) - -// codeID, _, err := keeper.NewDefaultPermissionKeeper(suite.GetNolusZoneApp(suite.ChainA).WasmKeeper).Create(ctx, addr, wasmCode, &wasmtypes.AccessConfig{Permission: wasmtypes.AccessTypeEverybody}) -// suite.Require().NoError(err) - -// return codeID -// } - -// func (suite *IBCConnectionTestSuite) InstantiateTestContract(ctx sdk.Context, funder sdk.AccAddress, codeID uint64) sdk.AccAddress { -// initMsgBz := []byte("{}") -// contractKeeper := keeper.NewDefaultPermissionKeeper(suite.GetNolusZoneApp(suite.ChainA).WasmKeeper) -// addr, _, err := contractKeeper.Instantiate(ctx, codeID, funder, funder, initMsgBz, "demo contract", nil) -// suite.Require().NoError(err) - -// return addr -// } - -// func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { -// path := ibctesting.NewPath(chainA, chainB) -// path.EndpointA.Counterparty = path.EndpointB -// path.EndpointB.Counterparty = path.EndpointA - -// path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID -// path.EndpointB.ChannelConfig.PortID = icatypes.HostPortID -// path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED -// path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED -// path.EndpointA.ChannelConfig.Version = TestVersion -// path.EndpointB.ChannelConfig.Version = TestVersion - -// path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = 3600000000000 -// path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = 1200000000000 - -// path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = 3600000000000 -// path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = 1200000000000 -// return path -// } - -// // SetupICAPath invokes the InterchainAccounts entrypoint and subsequent channel handshake handlers. -// func SetupICAPath(path *ibctesting.Path, owner string) error { -// if err := RegisterInterchainAccount(path.EndpointA, owner); err != nil { -// return err -// } - -// if err := path.EndpointB.ChanOpenTry(); err != nil { -// return err -// } - -// if err := path.EndpointA.ChanOpenAck(); err != nil { -// return err -// } - -// return path.EndpointB.ChanOpenConfirm() -// } - -// // RegisterInterchainAccount is a helper function for starting the channel handshake. -// func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error { -// icaOwner, _ := ictxstypes.NewICAOwner(owner, TestInterchainID) -// portID, err := icatypes.NewControllerPortID(icaOwner.String()) -// if err != nil { -// return err -// } - -// ctx := endpoint.Chain.GetContext() - -// channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(ctx) - -// a, ok := endpoint.Chain.App.(*app.App) -// if !ok { -// return fmt.Errorf("not NolusZoneApp") -// } - -// // TODO(pr0n00gler): are we sure it's okay? -// if err := a.ICAControllerKeeper.RegisterInterchainAccount(ctx, endpoint.ConnectionID, icaOwner.String(), ""); err != nil { -// return err -// } - -// // commit state changes for proof verification -// endpoint.Chain.NextBlock() - -// // update port/channel ids -// endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) -// endpoint.ChannelConfig.PortID = portID - -// return nil -// } - -// var tempDir = func() string { -// dir, err := os.MkdirTemp("", "nolusd") -// if err != nil { -// panic("failed to create temp dir: " + err.Error()) -// } -// defer os.RemoveAll(dir) - -// return dir -// } - -// // fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of -// // an IAVLStore for faster simulation speed. -// func fauxMerkleModeOpt(bapp *baseapp.BaseApp) { -// bapp.SetFauxMerkleMode() -// } - -// // SetupTestingApp initializes the IBC-go testing application. -// func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { -// encoding := app.MakeEncodingConfig(app.ModuleBasics) -// db := db2.NewMemDB() - -// temp := tempDir() - -// testApp := app.New( -// log.NewNopLogger(), -// db, -// nil, -// false, -// map[int64]bool{}, -// temp, -// 0, -// encoding, -// sims.EmptyAppOptions{}, -// fauxMerkleModeOpt, -// ) - -// ctx := testApp.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "testchain-1", Time: time.Now().UTC()}) - -// // Manually set validator signing info, otherwise we panic -// vals, err := testApp.StakingKeeper.GetAllValidators(context.TODO()) -// if err != nil { -// panic(err) -// } -// for _, val := range vals { -// consAddr, _ := val.GetConsAddr() -// signingInfo := slashingtypes.NewValidatorSigningInfo( -// consAddr, -// ctx.BlockHeight(), -// 0, -// time.Unix(0, 0), -// false, -// 0, -// ) -// err := testApp.SlashingKeeper.SetValidatorSigningInfo(ctx, consAddr, signingInfo) -// if err != nil { -// panic(err) -// } -// } - -// // we need to set up a TestInitChainer where we can redefine MaxBlockGas in ConsensusParamsKeeper -// testApp.SetInitChainer(testApp.TestInitChainer) -// // and then we manually init baseapp and load states -// if err := testApp.LoadLatestVersion(); err != nil { -// tmos.Exit(err.Error()) -// } - -// // Initialize pinned codes in wasmvm as they are not persisted there -// if err := testApp.WasmKeeper.InitializePinnedCodes(ctx); err != nil { -// panic(err) -// } - -// genesisState := app.NewDefaultGenesisState(encoding) - -// // genesisState := app.NewDefaultGenesisState(encoding) - -// return testApp, genesisState -// } - -// func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { -// path := ibctesting.NewPath(chainA, chainB) -// path.EndpointA.ChannelConfig.PortID = types.PortID -// path.EndpointB.ChannelConfig.PortID = types.PortID -// path.EndpointA.ChannelConfig.Order = channeltypes.UNORDERED -// path.EndpointB.ChannelConfig.Order = channeltypes.UNORDERED -// path.EndpointA.ChannelConfig.Version = types.Version -// path.EndpointB.ChannelConfig.Version = types.Version - -// return path -// } - -// // SetupTransferPath. -// func SetupTransferPath(path *ibctesting.Path) error { -// channelSequence := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(path.EndpointA.Chain.GetContext()) -// channelSequenceB := path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(path.EndpointB.Chain.GetContext()) - -// // update port/channel ids -// path.EndpointA.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) -// path.EndpointB.ChannelID = channeltypes.FormatChannelIdentifier(channelSequenceB) - -// if err := path.EndpointA.ChanOpenInit(); err != nil { -// return err -// } - -// if err := path.EndpointB.ChanOpenTry(); err != nil { -// return err -// } - -// if err := path.EndpointA.ChanOpenAck(); err != nil { -// return err -// } - -// return path.EndpointB.ChanOpenConfirm() -// } +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + "cosmossdk.io/log" + + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" + + "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + + db2 "github.com/cosmos/cosmos-db" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + "github.com/stretchr/testify/suite" + + "github.com/Nolus-Protocol/nolus-core/app" + "github.com/Nolus-Protocol/nolus-core/app/params" + + tmos "github.com/cometbft/cometbft/libs/os" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + + ictxstypes "github.com/neutron-org/neutron/v4/x/interchaintxs/types" +) + +var ( + // TestOwnerAddress defines a reusable bech32 address for testing purposes. + TestOwnerAddress = "nolus17dtl0mjt3t77kpuhg2edqzjpszulwhgzcdvagh" + + TestInterchainID = "owner_id" + + Connection = "connection-0" + + // TestVersion defines a reusable interchainaccounts version string for testing purposes. + TestVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{ + Version: icatypes.Version, + ControllerConnectionId: Connection, + HostConnectionId: Connection, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, + })) +) + +func init() { + ibctesting.DefaultTestingAppInit = SetupTestingApp + params.GetDefaultConfig() + // Disable cache since enabled cache triggers test errors when `AccAddress.String()` + // gets called before setting nolus bech32 prefix + sdk.SetAddrCacheEnabled(false) +} + +type IBCConnectionTestSuite struct { + suite.Suite + Coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + ChainA *ibctesting.TestChain + ChainB *ibctesting.TestChain + + Path *ibctesting.Path + TransferPath *ibctesting.Path +} + +func (suite *IBCConnectionTestSuite) SetupTest() { + // we need to redefine this variable to make tests work cause we use unls as default bond denom in nolus + sdk.DefaultBondDenom = params.DefaultBondDenom + + suite.Coordinator = ibctesting.NewCoordinator(suite.T(), 2) // initialize 2 test chains + suite.ChainA = suite.Coordinator.GetChain(ibctesting.GetChainID(1)) + suite.ChainB = suite.Coordinator.GetChain(ibctesting.GetChainID(2)) + + // move chains to the next block + suite.ChainA.NextBlock() + suite.ChainB.NextBlock() + + // path := ibctesting.NewPath(suite.ChainA, suite.ChainB) // clientID, connectionID, channelID empty + // suite.Coordinator.Setup(path) // clientID, connectionID, channelID filled + // suite.Require().Equal("07-tendermint-0", path.EndpointA.ClientID) + // suite.Require().Equal("connection-0", path.EndpointA.ClientID) + // suite.Require().Equal("channel-0", path.EndpointA.ClientID) + + suite.Path = NewICAPath(suite.ChainA, suite.ChainB) + + // suite.ConfigureTransferChannel() + suite.Coordinator.Setup(suite.Path) +} + +func (suite *IBCConnectionTestSuite) ConfigureTransferChannel() { + suite.TransferPath = NewTransferPath(suite.ChainA, suite.ChainB) + suite.Coordinator.SetupConnections(suite.TransferPath) + err := SetupTransferPath(suite.TransferPath) + suite.Require().NoError(err) +} + +func (suite *IBCConnectionTestSuite) GetNolusZoneApp(chain *ibctesting.TestChain) *app.App { + testApp, ok := chain.App.(*app.App) + if !ok { + panic("not NolusZone app") + } + + return testApp +} + +func (suite *IBCConnectionTestSuite) StoreTestCode(ctx sdk.Context, addr sdk.AccAddress, path string) uint64 { + // wasm file built with https://github.com/neutron-org/neutron-sdk/tree/main/contracts/reflect + // wasm file built with https://github.com/neutron-org/neutron-dev-contracts/tree/feat/ica-register-fee-update/contracts/neutron_interchain_txs + wasmCode, err := os.ReadFile(path) + suite.Require().NoError(err) + + codeID, _, err := keeper.NewDefaultPermissionKeeper(suite.GetNolusZoneApp(suite.ChainA).WasmKeeper).Create(ctx, addr, wasmCode, &wasmtypes.AccessConfig{Permission: wasmtypes.AccessTypeEverybody}) + suite.Require().NoError(err) + + return codeID +} + +func (suite *IBCConnectionTestSuite) InstantiateTestContract(ctx sdk.Context, funder sdk.AccAddress, codeID uint64) sdk.AccAddress { + initMsgBz := []byte("{}") + contractKeeper := keeper.NewDefaultPermissionKeeper(suite.GetNolusZoneApp(suite.ChainA).WasmKeeper) + addr, _, err := contractKeeper.Instantiate(ctx, codeID, funder, funder, initMsgBz, "demo contract", nil) + suite.Require().NoError(err) + + return addr +} + +func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { + path := ibctesting.NewPath(chainA, chainB) + path.EndpointA.Counterparty = path.EndpointB + path.EndpointB.Counterparty = path.EndpointA + + path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID + path.EndpointB.ChannelConfig.PortID = icatypes.HostPortID + path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointA.ChannelConfig.Version = TestVersion + path.EndpointB.ChannelConfig.Version = TestVersion + + path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = 3600000000000 + path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = 1200000000000 + + path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = 3600000000000 + path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = 1200000000000 + return path +} + +// SetupICAPath invokes the InterchainAccounts entrypoint and subsequent channel handshake handlers. +func SetupICAPath(path *ibctesting.Path, owner string) error { + if err := RegisterInterchainAccount(path.EndpointA, owner); err != nil { + return err + } + + if err := path.EndpointB.ChanOpenTry(); err != nil { + return err + } + + if err := path.EndpointA.ChanOpenAck(); err != nil { + return err + } + + return path.EndpointB.ChanOpenConfirm() +} + +// RegisterInterchainAccount is a helper function for starting the channel handshake. +func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error { + icaOwner, _ := ictxstypes.NewICAOwner(owner, TestInterchainID) + portID, err := icatypes.NewControllerPortID(icaOwner.String()) + if err != nil { + return err + } + + ctx := endpoint.Chain.GetContext() + + channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(ctx) + + a, ok := endpoint.Chain.App.(*app.App) + if !ok { + return fmt.Errorf("not NolusZoneApp") + } + + // TODO(pr0n00gler): are we sure it's okay? + if err := a.ICAControllerKeeper.RegisterInterchainAccount(ctx, endpoint.ConnectionID, icaOwner.String(), ""); err != nil { + return err + } + + // commit state changes for proof verification + endpoint.Chain.NextBlock() + + // update port/channel ids + endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) + endpoint.ChannelConfig.PortID = portID + + return nil +} + +var tempDir = func() string { + dir, err := os.MkdirTemp("", "nolusd") + if err != nil { + panic("failed to create temp dir: " + err.Error()) + } + defer os.RemoveAll(dir) + + return dir +} + +// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of +// an IAVLStore for faster simulation speed. +func fauxMerkleModeOpt(bapp *baseapp.BaseApp) { + bapp.SetFauxMerkleMode() +} + +// SetupTestingApp initializes the IBC-go testing application. +func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { + encoding := app.MakeEncodingConfig(app.ModuleBasics) + db := db2.NewMemDB() + + temp := tempDir() + + testApp := app.New( + log.NewNopLogger(), + db, + nil, + false, + map[int64]bool{}, + temp, + 0, + encoding, + sims.EmptyAppOptions{}, + fauxMerkleModeOpt, + ) + + ctx := testApp.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "testchain-1", Time: time.Now().UTC()}) + + // Manually set validator signing info, otherwise we panic + vals, err := testApp.StakingKeeper.GetAllValidators(context.TODO()) + if err != nil { + panic(err) + } + for _, val := range vals { + consAddr, _ := val.GetConsAddr() + signingInfo := slashingtypes.NewValidatorSigningInfo( + consAddr, + ctx.BlockHeight(), + 0, + time.Unix(0, 0), + false, + 0, + ) + err := testApp.SlashingKeeper.SetValidatorSigningInfo(ctx, consAddr, signingInfo) + if err != nil { + panic(err) + } + } + + // we need to set up a TestInitChainer where we can redefine MaxBlockGas in ConsensusParamsKeeper + testApp.SetInitChainer(testApp.TestInitChainer) + // and then we manually init baseapp and load states + if err := testApp.LoadLatestVersion(); err != nil { + tmos.Exit(err.Error()) + } + + // Initialize pinned codes in wasmvm as they are not persisted there + if err := testApp.WasmKeeper.InitializePinnedCodes(ctx); err != nil { + panic(err) + } + + genesisState := app.NewDefaultGenesisState(encoding) + + // genesisState := app.NewDefaultGenesisState(encoding) + + return testApp, genesisState +} + +func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { + path := ibctesting.NewPath(chainA, chainB) + path.EndpointA.ChannelConfig.PortID = types.PortID + path.EndpointB.ChannelConfig.PortID = types.PortID + path.EndpointA.ChannelConfig.Order = channeltypes.UNORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.UNORDERED + path.EndpointA.ChannelConfig.Version = types.Version + path.EndpointB.ChannelConfig.Version = types.Version + + return path +} + +// SetupTransferPath. +func SetupTransferPath(path *ibctesting.Path) error { + channelSequence := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(path.EndpointA.Chain.GetContext()) + channelSequenceB := path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(path.EndpointB.Chain.GetContext()) + + // update port/channel ids + path.EndpointA.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) + path.EndpointB.ChannelID = channeltypes.FormatChannelIdentifier(channelSequenceB) + + if err := path.EndpointA.ChanOpenInit(); err != nil { + return err + } + + if err := path.EndpointB.ChanOpenTry(); err != nil { + return err + } + + if err := path.EndpointA.ChanOpenAck(); err != nil { + return err + } + + return path.EndpointB.ChanOpenConfirm() +} diff --git a/testutil/transfer/keeper/keeper.go b/testutil/transfer/keeper/keeper.go new file mode 100644 index 00000000..bfe30940 --- /dev/null +++ b/testutil/transfer/keeper/keeper.go @@ -0,0 +1,72 @@ +package keeper + +import ( + "testing" + + "cosmossdk.io/log" + metrics2 "cosmossdk.io/store/metrics" + db2 "github.com/cosmos/cosmos-db" + capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + + "cosmossdk.io/store" + storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/require" + + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + + keeper "github.com/Nolus-Protocol/nolus-core/x/transfer/keeper" + "github.com/Nolus-Protocol/nolus-core/x/transfer/types" +) + +func TransferKeeper( + t testing.TB, + managerKeeper types.WasmKeeper, + refunderKeeper types.FeeRefunderKeeper, + channelKeeper types.ChannelKeeper, + authKeeper types.AccountKeeper, +) (*keeper.KeeperTransferWrapper, sdk.Context, *storetypes.KVStoreKey) { + storeKey := storetypes.NewKVStoreKey(transfertypes.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey("mem_" + transfertypes.StoreKey) + + db := db2.NewMemDB() + stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics2.NewNoOpMetrics()) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + paramsSubspace := typesparams.NewSubspace(cdc, + types.Amino, + storeKey, + memStoreKey, + "TransferParams", + ) + k := keeper.NewKeeper( + cdc, + storeKey, + paramsSubspace, + nil, // iscwrapper + channelKeeper, + nil, + authKeeper, + nil, + capabilitykeeper.ScopedKeeper{}, + refunderKeeper, + managerKeeper, + "authority", + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + k.SetParams(ctx, transfertypes.DefaultParams()) + + return &k, ctx, storeKey +} diff --git a/x/contractmanager/client/cli/query.go b/x/contractmanager/client/cli/query.go new file mode 100644 index 00000000..51e20450 --- /dev/null +++ b/x/contractmanager/client/cli/query.go @@ -0,0 +1,31 @@ +package cli + +import ( + "fmt" + // "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group contractmanager queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdFailures()) + cmd.AddCommand(CmdFailureDetails()) + // this line is used by starport scaffolding # 1 + + return cmd +} diff --git a/x/contractmanager/client/cli/query_failure.go b/x/contractmanager/client/cli/query_failure.go new file mode 100644 index 00000000..f19ca2f9 --- /dev/null +++ b/x/contractmanager/client/cli/query_failure.go @@ -0,0 +1,114 @@ +package cli + +import ( + "fmt" + "strconv" + "strings" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + "github.com/spf13/cobra" + + contractmanagertypes "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func CmdFailures() *cobra.Command { + cmd := &cobra.Command{ + Use: "failures [address]", + Short: "shows all failures or failures from specific contract address", + Args: cobra.RangeArgs(0, 1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := contractmanagertypes.NewQueryClient(clientCtx) + + address := "" + if len(args) > 0 { + address = args[0] + } + + params := &contractmanagertypes.QueryFailuresRequest{ + Address: address, + Pagination: pageReq, + } + + res, err := queryClient.Failures(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddPaginationFlagsToCmd(cmd, cmd.Use) + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// CmdFailureDetails returns the command handler for the failure's detailed error querying. +func CmdFailureDetails() *cobra.Command { + cmd := &cobra.Command{ + Use: "failure-details [address] [failure-id]", + Short: "Query the detailed error related to a contract's sudo call failure", + Long: "Query the detailed error related to a contract's sudo call failure based on contract's address and failure ID", + Args: cobra.ExactArgs(2), + Example: fmt.Sprintf("%s query failure-details neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0 0", version.AppName), + RunE: func(cmd *cobra.Command, args []string) error { + address := args[0] + failureID, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return fmt.Errorf("invalid failure ID %s: expected a uint64: %v", args[1], err) + } + + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := contractmanagertypes.NewQueryClient(clientCtx) + if _, err = queryClient.AddressFailure( + cmd.Context(), + &contractmanagertypes.QueryFailuresRequest{Address: address, FailureId: failureID}, + ); err != nil { + return err + } + + searchEvents := []string{ + fmt.Sprintf("%s.%s='%s'", wasmtypes.EventTypeSudo, wasmtypes.AttributeKeyContractAddr, address), + fmt.Sprintf("%s.%s='%d'", wasmtypes.EventTypeSudo, contractmanagertypes.AttributeKeySudoFailureID, failureID), + } + // TODO: search events + result, err := tx.QueryTxsByEvents(clientCtx, 1, 1, strings.Join(searchEvents, ","), "") // only a single tx for a pair address+failure_id is expected + if err != nil { + return err + } + + for _, tx := range result.Txs { + for _, event := range tx.Events { + if event.Type == wasmtypes.EventTypeSudo { + for _, attr := range event.Attributes { + if attr.Key == contractmanagertypes.AttributeKeySudoError { + return clientCtx.PrintString(attr.Value) + } + } + } + } + } + return fmt.Errorf("detailed failure error message not found in node events") + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/contractmanager/client/cli/query_failure_test.go b/x/contractmanager/client/cli/query_failure_test.go new file mode 100644 index 00000000..4f6768ed --- /dev/null +++ b/x/contractmanager/client/cli/query_failure_test.go @@ -0,0 +1,174 @@ +package cli_test + +import ( + "crypto/rand" + "fmt" + "strconv" + "testing" + + "github.com/Nolus-Protocol/nolus-core/app/params" + "github.com/Nolus-Protocol/nolus-core/testutil/common/nullify" + + tmcli "github.com/cometbft/cometbft/libs/cli" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdktypes "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/network" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/client/cli" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func networkWithFailureObjects(t *testing.T, n int) (*network.Network, []types.Failure) { + t.Helper() + cfg := network.DefaultConfig() + state := types.GenesisState{} + require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) + + pubBz := make([]byte, ed25519.PubKeySize) + pub := &ed25519.PubKey{Key: pubBz} + + for i := 0; i < n; i++ { + _, err := rand.Read(pub.Key) + require.NoError(t, err) + acc := sdktypes.AccAddress(pub.Address()) + failure := types.Failure{ + Address: acc.String(), + SudoPayload: []byte("&channeltypes.Packet{}"), + } + nullify.Fill(&failure) + state.FailuresList = append(state.FailuresList, failure) + } + buf, err := cfg.Codec.MarshalJSON(&state) + require.NoError(t, err) + cfg.GenesisState[types.ModuleName] = buf + return network.New(t, cfg), state.FailuresList +} + +func TestAddressFailures(t *testing.T) { + _ = params.GetDefaultConfig() + + net, objs := networkWithFailureObjects(t, 2) + + ctx := net.Validators[0].ClientCtx + common := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + for _, tc := range []struct { + desc string + idIndex string + + args []string + err error + obj []types.Failure + }{ + { + desc: "found", + idIndex: objs[0].Address, + + args: common, + obj: []types.Failure{objs[0]}, + }, + { + desc: "not found", + idIndex: strconv.Itoa(100000), + + args: common, + err: status.Error(codes.NotFound, "not found"), + }, + } { + tc := tc + t.Run(tc.desc, func(t *testing.T) { + args := []string{ + tc.idIndex, + } + args = append(args, tc.args...) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdFailures(), args) + if tc.err != nil { + stat, ok := status.FromError(tc.err) + require.True(t, ok) + require.ErrorIs(t, stat.Err(), tc.err) + } else { + require.NoError(t, err) + var resp types.QueryFailuresResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NotNil(t, resp.Failures) + require.Equal(t, + nullify.Fill(&tc.obj), + nullify.Fill(&resp.Failures), + ) + } + }) + } +} + +func TestListFailure(t *testing.T) { + net, objs := networkWithFailureObjects(t, 5) + + ctx := net.Validators[0].ClientCtx + request := func(next []byte, offset, limit uint64, total bool) []string { + args := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + if next == nil { + args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) + } else { + args = append(args, fmt.Sprintf("--%s=%s", flags.FlagPageKey, next)) + } + args = append(args, fmt.Sprintf("--%s=%d", flags.FlagLimit, limit)) + if total { + args = append(args, fmt.Sprintf("--%s", flags.FlagCountTotal)) + } + return args + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < len(objs); i += step { + args := request(nil, uint64(i), uint64(step), false) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdFailures(), args) + require.NoError(t, err) + var resp types.QueryFailuresResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.LessOrEqual(t, len(resp.Failures), step) + require.Subset(t, + nullify.Fill(objs), + nullify.Fill(resp.Failures), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < len(objs); i += step { + args := request(next, 0, uint64(step), false) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdFailures(), args) + require.NoError(t, err) + var resp types.QueryFailuresResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.LessOrEqual(t, len(resp.Failures), step) + require.Subset(t, + nullify.Fill(objs), + nullify.Fill(resp.Failures), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + args := request(nil, 0, uint64(len(objs)), true) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdFailures(), args) + require.NoError(t, err) + var resp types.QueryFailuresResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, err) + require.Equal(t, len(objs), int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(objs), + nullify.Fill(resp.Failures), + ) + }) +} diff --git a/x/contractmanager/client/cli/query_params.go b/x/contractmanager/client/cli/query_params.go new file mode 100644 index 00000000..5bda2468 --- /dev/null +++ b/x/contractmanager/client/cli/query_params.go @@ -0,0 +1,35 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/contractmanager/genesis.go b/x/contractmanager/genesis.go new file mode 100644 index 00000000..9af749ac --- /dev/null +++ b/x/contractmanager/genesis.go @@ -0,0 +1,31 @@ +package contractmanager + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // Set all the failure + for _, elem := range genState.FailuresList { + k.AddContractFailure(ctx, elem.Address, elem.SudoPayload, elem.Error) + } + // this line is used by starport scaffolding # genesis/module/init + err := k.SetParams(ctx, genState.Params) + if err != nil { + panic(err) + } +} + +// ExportGenesis returns the module's exported genesis +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + genesis.FailuresList = k.GetAllFailures(ctx) + + return genesis +} diff --git a/x/contractmanager/genesis_test.go b/x/contractmanager/genesis_test.go new file mode 100644 index 00000000..3ed580bf --- /dev/null +++ b/x/contractmanager/genesis_test.go @@ -0,0 +1,61 @@ +package contractmanager_test + +import ( + "testing" + + "github.com/Nolus-Protocol/nolus-core/testutil/common/nullify" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + "github.com/stretchr/testify/require" + + keepertest "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func TestGenesis(t *testing.T) { + payload1, err := keeper.PrepareSudoCallbackMessage( + channeltypes.Packet{ + Sequence: 1, + }, + &channeltypes.Acknowledgement{ + Response: &channeltypes.Acknowledgement_Result{ + Result: []byte("Result"), + }, + }) + require.NoError(t, err) + payload2, err := keeper.PrepareSudoCallbackMessage( + channeltypes.Packet{ + Sequence: 2, + }, nil) + require.NoError(t, err) + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + + FailuresList: []types.Failure{ + { + Address: "address1", + Id: 1, + SudoPayload: payload1, + }, + { + Address: "address1", + Id: 2, + SudoPayload: payload2, + }, + }, + } + + k, ctx := keepertest.ContractManagerKeeper(t, nil) + contractmanager.InitGenesis(ctx, *k, genesisState) + got := contractmanager.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + nullify.Fill(&genesisState) + nullify.Fill(got) + + require.ElementsMatch(t, genesisState.FailuresList, got.FailuresList) +} diff --git a/x/contractmanager/ibc_middleware.go b/x/contractmanager/ibc_middleware.go new file mode 100644 index 00000000..aaf371a6 --- /dev/null +++ b/x/contractmanager/ibc_middleware.go @@ -0,0 +1,90 @@ +package contractmanager + +import ( + "context" + "fmt" + + "cosmossdk.io/log" + "cosmossdk.io/store/types" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + contractmanagerkeeper "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + contractmanagertypes "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +type SudoLimitWrapper struct { + contractManager contractmanagertypes.ContractManagerKeeper + contractmanagertypes.WasmKeeper +} + +// NewSudoLimitWrapper suppresses an error from a Sudo contract handler and saves it to a store +func NewSudoLimitWrapper(contractManager contractmanagertypes.ContractManagerKeeper, sudoKeeper contractmanagertypes.WasmKeeper) contractmanagertypes.WasmKeeper { + return SudoLimitWrapper{ + contractManager, + sudoKeeper, + } +} + +// Sudo calls underlying Sudo handlers with a limited amount of gas +// in case of `out of gas` panic it converts the panic into an error and stops `out of gas` panic propagation +// if error happens during the Sudo call, we store the data that raised the error, and return the error +func (k SudoLimitWrapper) Sudo(ctx context.Context, contractAddress sdk.AccAddress, msg []byte) (resp []byte, err error) { + c := sdk.UnwrapSDKContext(ctx) + + cacheCtx, writeFn := createCachedContext(c, k.contractManager.GetParams(ctx).SudoCallGasLimit) + func() { + defer outOfGasRecovery(cacheCtx.GasMeter(), &err) + // Actually we have only one kind of error returned from acknowledgement + // maybe later we'll retrieve actual errors from events + resp, err = k.WasmKeeper.Sudo(cacheCtx, contractAddress, msg) + }() + if err != nil { // the contract either returned an error or panicked with `out of gas` + failure := k.contractManager.AddContractFailure( + ctx, + contractAddress.String(), + msg, + contractmanagerkeeper.RedactError(err).Error(), + ) + c.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + wasmtypes.EventTypeSudo, + sdk.NewAttribute(wasmtypes.AttributeKeyContractAddr, contractAddress.String()), + sdk.NewAttribute(contractmanagertypes.AttributeKeySudoFailureID, fmt.Sprintf("%d", failure.Id)), + sdk.NewAttribute(contractmanagertypes.AttributeKeySudoError, err.Error()), + ), + }) + } else { + writeFn() + } + + c.GasMeter().ConsumeGas(cacheCtx.GasMeter().GasConsumedToLimit(), "consume gas from cached context") + return resp, err +} + +func (k SudoLimitWrapper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", contractmanagertypes.ModuleName)) +} + +// outOfGasRecovery converts `out of gas` panic into an error +// leaving unprocessed any other kinds of panics +func outOfGasRecovery( + gasMeter types.GasMeter, + err *error, +) { + if r := recover(); r != nil { + _, ok := r.(types.ErrorOutOfGas) + if !ok || !gasMeter.IsOutOfGas() { + panic(r) + } + *err = contractmanagertypes.ErrSudoOutOfGas + } +} + +// createCachedContext creates a cached context with a limited gas meter. +func createCachedContext(ctx sdk.Context, gasLimit uint64) (sdk.Context, func()) { + cacheCtx, writeFn := ctx.CacheContext() + gasMeter := types.NewGasMeter(gasLimit) + cacheCtx = cacheCtx.WithGasMeter(gasMeter) + return cacheCtx, writeFn +} diff --git a/x/contractmanager/ibc_middleware_test.go b/x/contractmanager/ibc_middleware_test.go new file mode 100644 index 00000000..3a95c0e3 --- /dev/null +++ b/x/contractmanager/ibc_middleware_test.go @@ -0,0 +1,76 @@ +package contractmanager_test + +import ( + "testing" + + types2 "cosmossdk.io/store/types" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + test_keeper "github.com/Nolus-Protocol/nolus-core/testutil/interchaintxs/keeper" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/contractmanager/types" + contractmanagerkeeper "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +var ( + ShouldNotBeWrittenKey = []byte("shouldnotkey") + ShouldNotBeWritten = []byte("should not be written") + ShouldBeWritten = []byte("should be written") + TestOwnerAddress = "neutron17dtl0mjt3t77kpuhg2edqzjpszulwhgzcdvagh" +) + +func ShouldBeWrittenKey(suffix string) []byte { + return append([]byte("shouldkey"), []byte(suffix)...) +} + +func TestSudo(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + cmKeeper := mock_types.NewMockContractManagerKeeper(ctrl) + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + middleware, infCtx, storeKey := test_keeper.NewSudoLimitWrapper(t, cmKeeper, wmKeeper) + st := infCtx.KVStore(storeKey) + + // at this point the payload struct does not matter + msg := []byte("sudo_payload") + contractAddress := sdk.AccAddress{} + + // success during Sudo + ctx := infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + cmKeeper.EXPECT().GetParams(ctx).Return(types.Params{SudoCallGasLimit: 10000}) + wmKeeper.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddress, msg).Do(func(cachedCtx sdk.Context, _ sdk.AccAddress, _ []byte) { + st := cachedCtx.KVStore(storeKey) + st.Set(ShouldBeWrittenKey("sudo"), ShouldBeWritten) + }).Return(nil, nil) + _, err := middleware.Sudo(ctx, contractAddress, msg) + require.NoError(t, err) + require.Equal(t, ShouldBeWritten, st.Get(ShouldBeWrittenKey("sudo"))) + + // error during Sudo + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + cmKeeper.EXPECT().GetParams(ctx).Return(types.Params{SudoCallGasLimit: 10000}) + cmKeeper.EXPECT().AddContractFailure(ctx, contractAddress.String(), msg, contractmanagerkeeper.RedactError(wasmtypes.ErrExecuteFailed).Error()) + wmKeeper.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddress, msg).Do(func(cachedCtx sdk.Context, _ sdk.AccAddress, _ []byte) { + st := cachedCtx.KVStore(storeKey) + st.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) + }).Return(nil, wasmtypes.ErrExecuteFailed) + _, err = middleware.Sudo(ctx, contractAddress, msg) + require.Error(t, err) + require.Nil(t, st.Get(ShouldNotBeWrittenKey)) + + // ou of gas during Sudo + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + cmKeeper.EXPECT().GetParams(ctx).Return(types.Params{SudoCallGasLimit: 10000}) + cmKeeper.EXPECT().AddContractFailure(ctx, contractAddress.String(), msg, contractmanagerkeeper.RedactError(types.ErrSudoOutOfGas).Error()) + wmKeeper.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddress, msg).Do(func(cachedCtx sdk.Context, _ sdk.AccAddress, _ []byte) { + st := cachedCtx.KVStore(storeKey) + st.Set(ShouldNotBeWrittenKey, ShouldNotBeWritten) + cachedCtx.GasMeter().ConsumeGas(10001, "heavy calculations") + }) + _, err = middleware.Sudo(ctx, contractAddress, msg) + require.ErrorContains(t, err, types.ErrSudoOutOfGas.Error()) + require.Nil(t, st.Get(ShouldNotBeWrittenKey)) +} diff --git a/x/contractmanager/keeper/failure.go b/x/contractmanager/keeper/failure.go new file mode 100644 index 00000000..374f82b7 --- /dev/null +++ b/x/contractmanager/keeper/failure.go @@ -0,0 +1,131 @@ +package keeper + +import ( + "context" + "fmt" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +// AddContractFailure adds a specific failure to the store. The provided address is used to determine +// the failure ID and they both are used to create a storage key for the failure. +// +// WARNING: The errMsg string parameter is expected to be deterministic. It means that the errMsg +// must be OS/library version agnostic and carry a concrete defined error message. One of the good +// ways to do so is to redact error using the RedactError func as it is done in SudoLimitWrapper +// Sudo method: +// https://github.com/neutron-org/neutron/blob/eb8b5ae50907439ff9af0527a42ef0cb448a78b5/x/contractmanager/ibc_middleware.go#L42. +// Another good way could be passing here some constant value. +func (k Keeper) AddContractFailure(ctx context.Context, address string, sudoPayload []byte, errMsg string) types.Failure { + c := sdk.UnwrapSDKContext(ctx) + + failure := types.Failure{ + Address: address, + SudoPayload: sudoPayload, + Error: errMsg, + } + nextFailureID := k.GetNextFailureIDKey(ctx, failure.GetAddress()) + failure.Id = nextFailureID + + store := c.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&failure) + store.Set(types.GetFailureKey(failure.GetAddress(), nextFailureID), bz) + return failure +} + +func (k Keeper) GetNextFailureIDKey(ctx context.Context, address string) uint64 { + c := sdk.UnwrapSDKContext(ctx) + + store := prefix.NewStore(c.KVStore(k.storeKey), types.GetFailureKeyPrefix(address)) + iterator := storetypes.KVStoreReversePrefixIterator(store, []byte{}) + defer iterator.Close() + + if iterator.Valid() { + var val types.Failure + k.cdc.MustUnmarshal(iterator.Value(), &val) + + return val.Id + 1 + } + + return 0 +} + +// GetAllFailures returns all failures +func (k Keeper) GetAllFailures(ctx context.Context) (list []types.Failure) { + c := sdk.UnwrapSDKContext(ctx) + + store := prefix.NewStore(c.KVStore(k.storeKey), types.ContractFailuresKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.Failure + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} + +func (k Keeper) GetFailure(ctx sdk.Context, contractAddr sdk.AccAddress, id uint64) (*types.Failure, error) { + store := ctx.KVStore(k.storeKey) + key := types.GetFailureKey(contractAddr.String(), id) + + bz := store.Get(key) + if bz == nil { + return nil, errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "no failure found for contractAddress = %s and failureId = %d", contractAddr.String(), id) + } + var res types.Failure + k.cdc.MustUnmarshal(bz, &res) + + return &res, nil +} + +// ResubmitFailure tries to call sudo handler for contract with same parameters as initially. +func (k Keeper) ResubmitFailure(ctx sdk.Context, contractAddr sdk.AccAddress, failure *types.Failure) error { + if failure.SudoPayload == nil { + return errorsmod.Wrapf(types.ErrIncorrectFailureToResubmit, "cannot resubmit failure without sudo payload; failureId = %d", failure.Id) + } + + if _, err := k.wasmKeeper.Sudo(ctx, contractAddr, failure.SudoPayload); err != nil { + return errorsmod.Wrapf(types.ErrFailedToResubmitFailure, "cannot resubmit failure; failureId = %d; err = %s", failure.Id, err) + } + + // Cleanup failure since we resubmitted it successfully + k.removeFailure(ctx, contractAddr, failure.Id) + + return nil +} + +func (k Keeper) removeFailure(ctx sdk.Context, contractAddr sdk.AccAddress, id uint64) { + store := ctx.KVStore(k.storeKey) + failureKey := types.GetFailureKey(contractAddr.String(), id) + store.Delete(failureKey) +} + +// RedactError removes non-determenistic details from the error returning just codespace and core +// of the error. Returns full error for system errors. +// +// Copy+paste from https://github.com/neutron-org/wasmd/blob/5b59886e41ed55a7a4a9ae196e34b0852285503d/x/wasm/keeper/msg_dispatcher.go#L175-L190 +func RedactError(err error) error { + // Do not redact system errors + // SystemErrors must be created in x/wasm and we can ensure determinism + if wasmvmtypes.ToSystemError(err) != nil { + return err + } + + // FIXME: do we want to hardcode some constant string mappings here as well? + // Or better document them? (SDK error string may change on a patch release to fix wording) + // sdk/11 is out of gas + // sdk/5 is insufficient funds (on bank send) + // (we can theoretically redact less in the future, but this is a first step to safety) + codespace, code, _ := errorsmod.ABCIInfo(err, false) + return fmt.Errorf("codespace: %s, code: %d", codespace, code) +} diff --git a/x/contractmanager/keeper/failure_test.go b/x/contractmanager/keeper/failure_test.go new file mode 100644 index 00000000..da56f0dd --- /dev/null +++ b/x/contractmanager/keeper/failure_test.go @@ -0,0 +1,246 @@ +package keeper_test + +import ( + "crypto/rand" + "encoding/json" + "fmt" + "strconv" + "testing" + + "github.com/Nolus-Protocol/nolus-core/testutil/common/nullify" + + "github.com/golang/mock/gomock" + + "github.com/Nolus-Protocol/nolus-core/testutil" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/contractmanager/types" + + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + keepertest "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func createNFailure(k *keeper.Keeper, ctx sdk.Context, addresses, failures int) [][]types.Failure { + pubBz := make([]byte, ed25519.PubKeySize) + pub := &ed25519.PubKey{Key: pubBz} + + items := make([][]types.Failure, addresses) + for i := range items { + items[i] = make([]types.Failure, failures) + rand.Read(pub.Key) //nolint:errcheck + acc := sdk.AccAddress(pub.Address()) + + for c := range items[i] { + p := channeltypes.Packet{ + Sequence: 0, + SourcePort: "port-n", + } + items[i][c].Address = acc.String() + items[i][c].Id = uint64(c) + sudo, err := keeper.PrepareSudoCallbackMessage(p, nil) + if err != nil { + panic(err) + } + items[i][c].SudoPayload = sudo + items[i][c].Error = "test error" + k.AddContractFailure(ctx, items[i][c].Address, sudo, "test error") + } + } + return items +} + +func flattenFailures(items [][]types.Failure) []types.Failure { + m := len(items) + n := len(items[0]) + + flattenItems := make([]types.Failure, m*n) + for i, failures := range items { + for c, failure := range failures { + flattenItems[i*n+c] = failure + } + } + + return flattenItems +} + +func TestGetAllFailures(t *testing.T) { + k, ctx := keepertest.ContractManagerKeeper(t, nil) + items := createNFailure(k, ctx, 10, 4) + flattenItems := flattenFailures(items) + + allFailures := k.GetAllFailures(ctx) + + require.ElementsMatch(t, + nullify.Fill(flattenItems), + nullify.Fill(allFailures), + ) +} + +func TestAddGetFailure(t *testing.T) { + // test adding and getting failure + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + k, ctx := keepertest.ContractManagerKeeper(t, nil) + failureID := k.GetNextFailureIDKey(ctx, contractAddress.String()) + sudoPayload := []byte("payload") + k.AddContractFailure(ctx, contractAddress.String(), sudoPayload, "test error") + failure, err := k.GetFailure(ctx, contractAddress, failureID) + require.NoError(t, err) + require.Equal(t, failureID, failure.Id) + require.Equal(t, sudoPayload, failure.SudoPayload) + require.Equal(t, "test error", failure.Error) + + // non-existent id + _, err = k.GetFailure(ctx, contractAddress, failureID+1) + require.Error(t, err) + + // non-existent contract address + _, err = k.GetFailure(ctx, sdk.MustAccAddressFromBech32("neutron1nseacn2aqezhj3ssatfg778ctcfjuknm8ucc0l"), failureID) + require.Error(t, err) +} + +func TestResubmitFailure(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + wk := mock_types.NewMockWasmKeeper(ctrl) + k, ctx := keepertest.ContractManagerKeeper(t, wk) + + contractAddr := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + data := []byte("Result") + ack := channeltypes.Acknowledgement{ + Response: &channeltypes.Acknowledgement_Result{Result: data}, + } + ackError := channeltypes.Acknowledgement{ + Response: &channeltypes.Acknowledgement_Error{Error: "not able to do IBC tx"}, + } + + // add ack failure + packet := channeltypes.Packet{} + failureID := k.GetNextFailureIDKey(ctx, contractAddr.String()) + payload, err := keeper.PrepareSudoCallbackMessage(packet, &ack) + require.NoError(t, err) + k.AddContractFailure(ctx, contractAddr.String(), payload, "test error") + + // success response + xSuc := types.MessageSudoCallback{Response: &types.ResponseSudoPayload{ + Request: channeltypes.Packet{}, + Data: data, + }} + msgSuc, err := json.Marshal(xSuc) + require.NoError(t, err) + // error response + xErr := types.MessageSudoCallback{Error: &types.ErrorSudoPayload{ + Request: channeltypes.Packet{}, + Details: "not able to do IBC tx", + }} + msgErr, err := json.Marshal(xErr) + require.NoError(t, err) + // timeout response + xTimeout := types.MessageSudoCallback{Timeout: &types.TimeoutPayload{Request: channeltypes.Packet{}}} + msgTimeout, err := json.Marshal(xTimeout) + require.NoError(t, err) + + // case: successful resubmit with ack and ack = response + wk.EXPECT().Sudo(ctx, contractAddr, msgSuc).Return([]byte{}, nil) + + failure, err := k.GetFailure(ctx, contractAddr, failureID) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure) + require.NoError(t, err) + // failure should be deleted + _, err = k.GetFailure(ctx, contractAddr, failureID) + require.ErrorContains(t, err, "key not found") + + // case: failed resubmit with ack and ack = response + failureID2 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + payload, err = keeper.PrepareSudoCallbackMessage(packet, &ack) + require.NoError(t, err) + k.AddContractFailure(ctx, contractAddr.String(), payload, "test error") + + wk.EXPECT().Sudo(ctx, contractAddr, msgSuc).Return(nil, fmt.Errorf("failed to sudo")) + + failure2, err := k.GetFailure(ctx, contractAddr, failureID2) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure2) + require.ErrorContains(t, err, "cannot resubmit failure") + // failure is still there + failureAfter2, err := k.GetFailure(ctx, contractAddr, failureID2) + require.NoError(t, err) + require.Equal(t, failureAfter2.Id, failure2.Id) + + // case: successful resubmit with ack and ack = error + // add error failure + failureID3 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + payload, err = keeper.PrepareSudoCallbackMessage(packet, &ackError) + require.NoError(t, err) + k.AddContractFailure(ctx, contractAddr.String(), payload, "test error") + + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgErr).Return([]byte{}, nil) + + failure3, err := k.GetFailure(ctx, contractAddr, failureID3) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure3) + require.NoError(t, err) + // failure should be deleted + _, err = k.GetFailure(ctx, contractAddr, failureID3) + require.ErrorContains(t, err, "key not found") + + // case: failed resubmit with ack and ack = error + failureID4 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + payload, err = keeper.PrepareSudoCallbackMessage(packet, &ackError) + require.NoError(t, err) + k.AddContractFailure(ctx, contractAddr.String(), payload, "test error") + + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgErr).Return(nil, fmt.Errorf("failed to sudo")) + + failure4, err := k.GetFailure(ctx, contractAddr, failureID4) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure4) + require.ErrorContains(t, err, "cannot resubmit failure") + // failure is still there + failureAfter4, err := k.GetFailure(ctx, contractAddr, failureID4) + require.NoError(t, err) + require.Equal(t, failureAfter4.Id, failure4.Id) + + // case: successful resubmit with timeout + // add error failure + failureID5 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + payload, err = keeper.PrepareSudoCallbackMessage(packet, nil) + require.NoError(t, err) + k.AddContractFailure(ctx, contractAddr.String(), payload, "test error") + + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgTimeout).Return([]byte{}, nil) + + failure5, err := k.GetFailure(ctx, contractAddr, failureID5) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure5) + require.NoError(t, err) + // failure should be deleted + _, err = k.GetFailure(ctx, contractAddr, failureID5) + require.ErrorContains(t, err, "key not found") + + // case: failed resubmit with timeout + failureID6 := k.GetNextFailureIDKey(ctx, contractAddr.String()) + payload, err = keeper.PrepareSudoCallbackMessage(packet, nil) + require.NoError(t, err) + k.AddContractFailure(ctx, contractAddr.String(), payload, "test error") + + wk.EXPECT().Sudo(gomock.AssignableToTypeOf(ctx), contractAddr, msgTimeout).Return(nil, fmt.Errorf("failed to sudo")) + + failure6, err := k.GetFailure(ctx, contractAddr, failureID6) + require.NoError(t, err) + err = k.ResubmitFailure(ctx, contractAddr, failure6) + require.ErrorContains(t, err, "cannot resubmit failure") + // failure is still there + failureAfter6, err := k.GetFailure(ctx, contractAddr, failureID6) + require.NoError(t, err) + require.Equal(t, failureAfter6.Id, failure6.Id) +} diff --git a/x/contractmanager/keeper/grpc_query.go b/x/contractmanager/keeper/grpc_query.go new file mode 100644 index 00000000..b2473555 --- /dev/null +++ b/x/contractmanager/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/contractmanager/keeper/grpc_query_failure.go b/x/contractmanager/keeper/grpc_query_failure.go new file mode 100644 index 00000000..93f6080a --- /dev/null +++ b/x/contractmanager/keeper/grpc_query_failure.go @@ -0,0 +1,78 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +const FailuresQueryMaxLimit uint64 = query.DefaultLimit + +func (k Keeper) Failures(c context.Context, req *types.QueryFailuresRequest) (*types.QueryFailuresResponse, error) { + return k.AddressFailures(c, req) +} + +func (k Keeper) AddressFailures(c context.Context, req *types.QueryFailuresRequest) (*types.QueryFailuresResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + pagination := req.GetPagination() + if pagination != nil && pagination.Limit > FailuresQueryMaxLimit { + return nil, status.Errorf(codes.InvalidArgument, "limit is more than maximum allowed (%d > %d)", pagination.Limit, FailuresQueryMaxLimit) + } + + var failures []types.Failure + ctx := sdk.UnwrapSDKContext(c) + + store := ctx.KVStore(k.storeKey) + + var failureStore prefix.Store + if req.Address != "" { + if _, err := sdk.AccAddressFromBech32(req.Address); err != nil { + return nil, status.Errorf(codes.InvalidArgument, "failed to parse address: %s", req.Address) + } + failureStore = prefix.NewStore(store, types.GetFailureKeyPrefix(req.Address)) + } else { + failureStore = prefix.NewStore(store, types.ContractFailuresKey) + } + + pageRes, err := query.Paginate(failureStore, req.Pagination, func(_, value []byte) error { + var failure types.Failure + if err := k.cdc.Unmarshal(value, &failure); err != nil { + return err + } + + failures = append(failures, failure) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryFailuresResponse{Failures: failures, Pagination: pageRes}, nil +} + +func (k Keeper) AddressFailure(c context.Context, req *types.QueryFailuresRequest) (*types.QueryFailuresResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "request field must not be empty") + } + + addr, err := sdk.AccAddressFromBech32(req.Address) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid address: %v", err) + } + + resp, err := k.GetFailure(sdk.UnwrapSDKContext(c), addr, req.GetFailureId()) + if err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + return &types.QueryFailuresResponse{Failures: []types.Failure{*resp}}, nil +} diff --git a/x/contractmanager/keeper/grpc_query_failure_test.go b/x/contractmanager/keeper/grpc_query_failure_test.go new file mode 100644 index 00000000..e665a069 --- /dev/null +++ b/x/contractmanager/keeper/grpc_query_failure_test.go @@ -0,0 +1,137 @@ +package keeper_test + +import ( + "strconv" + "testing" + + "github.com/Nolus-Protocol/nolus-core/testutil/common/nullify" + + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + keepertest "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func TestFailureQuerySingle(t *testing.T) { + k, ctx := keepertest.ContractManagerKeeper(t, nil) + msgs := createNFailure(k, ctx, 2, 2) + for _, tc := range []struct { + desc string + request *types.QueryFailuresRequest + response *types.QueryFailuresResponse + err error + }{ + { + desc: "First", + request: &types.QueryFailuresRequest{ + Address: msgs[0][0].Address, + }, + response: &types.QueryFailuresResponse{Failures: msgs[0], Pagination: &query.PageResponse{Total: 2}}, + }, + { + desc: "Second", + request: &types.QueryFailuresRequest{ + Address: msgs[1][0].Address, + }, + response: &types.QueryFailuresResponse{Failures: msgs[1], Pagination: &query.PageResponse{Total: 2}}, + }, + { + desc: "KeyIsAbsent", + request: &types.QueryFailuresRequest{ + Address: "neutron17dtl0mjt3t77kpuhg2edqzjpszulwhgzcdvagh", + }, + response: &types.QueryFailuresResponse{Failures: []types.Failure{}, Pagination: &query.PageResponse{Total: 0}}, + }, + { + desc: "InvalidAddress", + request: &types.QueryFailuresRequest{ + Address: "wrong_address", + }, + err: status.Error(codes.InvalidArgument, "failed to parse address: wrong_address"), + }, + { + desc: "InvalidRequest", + err: status.Error(codes.InvalidArgument, "invalid request"), + }, + } { + t.Run(tc.desc, func(t *testing.T) { + response, err := k.AddressFailures(ctx, tc.request) + if tc.err != nil { + require.ErrorIs(t, err, tc.err) + } else { + require.NoError(t, err) + require.Equal(t, + nullify.Fill(tc.response), + nullify.Fill(response), + ) + } + }) + } +} + +func TestFailureQueryPaginated(t *testing.T) { + k, ctx := keepertest.ContractManagerKeeper(t, nil) + msgs := createNFailure(k, ctx, 5, 3) + flattenItems := flattenFailures(msgs) + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryFailuresRequest { + return &types.QueryFailuresRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < len(flattenItems); i += step { + resp, err := k.Failures(ctx, request(nil, uint64(i), uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.Failures), step) + require.Subset(t, + nullify.Fill(flattenItems), + nullify.Fill(resp.Failures), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < len(flattenItems); i += step { + resp, err := k.Failures(ctx, request(next, 0, uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.Failures), step) + require.Subset(t, + nullify.Fill(flattenItems), + nullify.Fill(resp.Failures), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + resp, err := k.Failures(ctx, request(nil, 0, 0, true)) + require.NoError(t, err) + require.Equal(t, len(flattenItems), int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(flattenItems), + nullify.Fill(resp.Failures), + ) + }) + t.Run("MoreThanLimit", func(t *testing.T) { + _, err := k.Failures(ctx, request(nil, 0, keeper.FailuresQueryMaxLimit+1, true)) + require.ErrorContains(t, err, "limit is more than maximum allowed") + }) + t.Run("InvalidRequest", func(t *testing.T) { + _, err := k.Failures(ctx, nil) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + }) +} diff --git a/x/contractmanager/keeper/grpc_query_params.go b/x/contractmanager/keeper/grpc_query_params.go new file mode 100644 index 00000000..0efac257 --- /dev/null +++ b/x/contractmanager/keeper/grpc_query_params.go @@ -0,0 +1,20 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/contractmanager/keeper/grpc_query_params_test.go b/x/contractmanager/keeper/grpc_query_params_test.go new file mode 100644 index 00000000..ba8929d7 --- /dev/null +++ b/x/contractmanager/keeper/grpc_query_params_test.go @@ -0,0 +1,21 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func TestParamsQuery(t *testing.T) { + keeper, ctx := testkeeper.ContractManagerKeeper(t, nil) + params := types.DefaultParams() + err := keeper.SetParams(ctx, params) + require.NoError(t, err) + + response, err := keeper.Params(ctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) +} diff --git a/x/contractmanager/keeper/keeper.go b/x/contractmanager/keeper/keeper.go new file mode 100644 index 00000000..bc88c083 --- /dev/null +++ b/x/contractmanager/keeper/keeper.go @@ -0,0 +1,46 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/log" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + wasmKeeper types.WasmKeeper + authority string + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + wasmKeeper types.WasmKeeper, + authority string, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + wasmKeeper: wasmKeeper, + authority: authority, + } +} + +func (k Keeper) GetAuthority() string { + return k.authority +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} diff --git a/x/contractmanager/keeper/migrations.go b/x/contractmanager/keeper/migrations.go new file mode 100644 index 00000000..cf221696 --- /dev/null +++ b/x/contractmanager/keeper/migrations.go @@ -0,0 +1,22 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + v2 "github.com/Nolus-Protocol/nolus-core/x/contractmanager/migrations/v2" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +// Migrate1to2 migrates from version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v2.MigrateStore(ctx, m.keeper.storeKey) +} diff --git a/x/contractmanager/keeper/msg_server.go b/x/contractmanager/keeper/msg_server.go new file mode 100644 index 00000000..9a296727 --- /dev/null +++ b/x/contractmanager/keeper/msg_server.go @@ -0,0 +1,42 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// UpdateParams updates the module parameters +func (k Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgUpdateParams") + } + + authority := k.GetAuthority() + if authority != req.Authority { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.SetParams(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/contractmanager/keeper/msg_server_test.go b/x/contractmanager/keeper/msg_server_test.go new file mode 100644 index 00000000..fbdab921 --- /dev/null +++ b/x/contractmanager/keeper/msg_server_test.go @@ -0,0 +1,44 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func TestMsgUpdateParamsValidate(t *testing.T) { + k, ctx := keeper.ContractManagerKeeper(t, nil) + + tests := []struct { + name string + msg types.MsgUpdateParams + expectedErr string + }{ + { + "empty authority", + types.MsgUpdateParams{ + Authority: "", + }, + "authority is invalid", + }, + { + "invalid authority", + types.MsgUpdateParams{ + Authority: "invalid authority", + }, + "authority is invalid", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := k.UpdateParams(ctx, &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} diff --git a/x/contractmanager/keeper/params.go b/x/contractmanager/keeper/params.go new file mode 100644 index 00000000..e4e006cc --- /dev/null +++ b/x/contractmanager/keeper/params.go @@ -0,0 +1,35 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx context.Context) (params types.Params) { + c := sdk.UnwrapSDKContext(ctx) + store := c.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams set the params +func (k Keeper) SetParams(ctx context.Context, params types.Params) error { + c := sdk.UnwrapSDKContext(ctx) + store := c.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + + store.Set(types.ParamsKey, bz) + return nil +} diff --git a/x/contractmanager/keeper/params_test.go b/x/contractmanager/keeper/params_test.go new file mode 100644 index 00000000..2db0d14b --- /dev/null +++ b/x/contractmanager/keeper/params_test.go @@ -0,0 +1,20 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func TestGetParams(t *testing.T) { + k, ctx := testkeeper.ContractManagerKeeper(t, nil) + params := types.DefaultParams() + + err := k.SetParams(ctx, params) + require.NoError(t, err) + + require.EqualValues(t, params, k.GetParams(ctx)) +} diff --git a/x/contractmanager/keeper/sudo.go b/x/contractmanager/keeper/sudo.go new file mode 100644 index 00000000..74e81fbb --- /dev/null +++ b/x/contractmanager/keeper/sudo.go @@ -0,0 +1,133 @@ +package keeper + +/* +Wasm contracts have the special entrypoint called sudo. The main purpose of the entrypoint is to be called from a trusted cosmos module, e.g. via a governance process. +We use the entrypoint to send back an ibc acknowledgement for an ibc transaction. +*/ + +import ( + "context" + "encoding/json" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func (k Keeper) HasContractInfo(ctx context.Context, contractAddress sdk.AccAddress) bool { + return k.wasmKeeper.HasContractInfo(ctx, contractAddress) +} + +func PrepareSudoCallbackMessage(request channeltypes.Packet, ack *channeltypes.Acknowledgement) ([]byte, error) { + m := types.MessageSudoCallback{} + if ack != nil && ack.GetError() == "" { //nolint:gocritic // + m.Response = &types.ResponseSudoPayload{ + Data: ack.GetResult(), + Request: request, + } + } else if ack != nil { + m.Error = &types.ErrorSudoPayload{ + Request: request, + Details: ack.GetError(), + } + } else { + m.Timeout = &types.TimeoutPayload{Request: request} + } + data, err := json.Marshal(m) + if err != nil { + return nil, fmt.Errorf("failed to marshal MessageSudoCallback: %v", err) + } + return data, nil +} + +func PrepareOpenAckCallbackMessage(details types.OpenAckDetails) ([]byte, error) { + x := types.MessageOnChanOpenAck{ + OpenAck: details, + } + m, err := json.Marshal(x) + if err != nil { + return nil, fmt.Errorf("failed to marshal MessageOnChanOpenAck: %v", err) + } + return m, nil +} + +// SudoTxQueryResult is used to pass a tx query result to the contract that registered the query +// to: +// 1. check whether the transaction actually satisfies the initial query arguments; +// 2. execute business logic related to the tx query result / save the result to state. +func (k Keeper) SudoTxQueryResult( + ctx context.Context, + contractAddress sdk.AccAddress, + queryID uint64, + height ibcclienttypes.Height, + data []byte, +) ([]byte, error) { + c := sdk.UnwrapSDKContext(ctx) + + k.Logger(c).Debug("SudoTxQueryResult", "contractAddress", contractAddress) + + if !k.wasmKeeper.HasContractInfo(ctx, contractAddress) { + k.Logger(c).Debug("SudoTxQueryResult: contract not found", "contractAddress", contractAddress) + return nil, fmt.Errorf("%s is not a contract address", contractAddress) + } + + x := types.MessageTxQueryResult{} + x.TxQueryResult.QueryID = queryID + x.TxQueryResult.Height = height + x.TxQueryResult.Data = data + + m, err := json.Marshal(x) + if err != nil { + k.Logger(c).Error("SudoTxQueryResult: failed to marshal MessageTxQueryResult message", + "error", err, "contract_address", contractAddress) + return nil, fmt.Errorf("failed to marshal MessageTxQueryResult: %v", err) + } + + resp, err := k.wasmKeeper.Sudo(ctx, contractAddress, m) + if err != nil { + k.Logger(c).Debug("SudoTxQueryResult: failed to sudo", + "error", err, "contract_address", contractAddress) + return nil, fmt.Errorf("failed to sudo: %v", err) + } + + return resp, nil +} + +// SudoKVQueryResult is used to pass a kv query id to the contract that registered the query +// when a query result is provided by the relayer. +func (k Keeper) SudoKVQueryResult( + ctx context.Context, + contractAddress sdk.AccAddress, + queryID uint64, +) ([]byte, error) { + c := sdk.UnwrapSDKContext(ctx) + + k.Logger(c).Info("SudoKVQueryResult", "contractAddress", contractAddress) + + if !k.wasmKeeper.HasContractInfo(ctx, contractAddress) { + k.Logger(c).Debug("SudoKVQueryResult: contract was not found", "contractAddress", contractAddress) + return nil, fmt.Errorf("%s is not a contract address", contractAddress) + } + + x := types.MessageKVQueryResult{} + x.KVQueryResult.QueryID = queryID + + m, err := json.Marshal(x) + if err != nil { + k.Logger(c).Error("SudoKVQueryResult: failed to marshal MessageKVQueryResult message", + "error", err, "contract_address", contractAddress) + return nil, fmt.Errorf("failed to marshal MessageKVQueryResult: %v", err) + } + + resp, err := k.wasmKeeper.Sudo(ctx, contractAddress, m) + if err != nil { + k.Logger(c).Debug("SudoKVQueryResult: failed to sudo", + "error", err, "contract_address", contractAddress) + return nil, fmt.Errorf("failed to sudo: %v", err) + } + + return resp, nil +} diff --git a/x/contractmanager/keeper/sudo_test.go b/x/contractmanager/keeper/sudo_test.go new file mode 100644 index 00000000..964d1503 --- /dev/null +++ b/x/contractmanager/keeper/sudo_test.go @@ -0,0 +1,108 @@ +package keeper_test + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil" + keepertest "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/keeper" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/contractmanager/types" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func init() { + params.GetDefaultConfig() +} + +func TestSudoTxQueryResult(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + wk := mock_types.NewMockWasmKeeper(ctrl) + + k, ctx := keepertest.ContractManagerKeeper(t, wk) + address := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + + sudoTxQueryResultMsg := types.MessageTxQueryResult{} + wk.EXPECT().Sudo(gomock.Any(), address, mustJSON(sudoTxQueryResultMsg)).Return([]byte("success"), nil) + wk.EXPECT().HasContractInfo(gomock.Any(), address).Return(true) + resp, err := k.SudoTxQueryResult(ctx, + address, + sudoTxQueryResultMsg.TxQueryResult.QueryID, + sudoTxQueryResultMsg.TxQueryResult.Height, + sudoTxQueryResultMsg.TxQueryResult.Data, + ) + require.NoError(t, err) + require.Equal(t, []byte("success"), resp) + + wk.EXPECT().Sudo(gomock.Any(), address, mustJSON(sudoTxQueryResultMsg)).Return(nil, fmt.Errorf("internal contract error")) + wk.EXPECT().HasContractInfo(gomock.Any(), address).Return(true) + resp, err = k.SudoTxQueryResult(ctx, + address, + sudoTxQueryResultMsg.TxQueryResult.QueryID, + sudoTxQueryResultMsg.TxQueryResult.Height, + sudoTxQueryResultMsg.TxQueryResult.Data, + ) + require.Nil(t, resp) + require.ErrorContains(t, err, "internal contract error") + + wk.EXPECT().HasContractInfo(gomock.Any(), address).Return(false) + resp, err = k.SudoTxQueryResult(ctx, + address, + sudoTxQueryResultMsg.TxQueryResult.QueryID, + sudoTxQueryResultMsg.TxQueryResult.Height, + sudoTxQueryResultMsg.TxQueryResult.Data, + ) + require.Nil(t, resp) + require.ErrorContains(t, err, "is not a contract address") +} + +func TestSudoKvQueryResult(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + wk := mock_types.NewMockWasmKeeper(ctrl) + + k, ctx := keepertest.ContractManagerKeeper(t, wk) + address := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + + sudoTxQueryResultMsg := types.MessageKVQueryResult{} + wk.EXPECT().Sudo(gomock.Any(), address, mustJSON(sudoTxQueryResultMsg)).Return([]byte("success"), nil) + wk.EXPECT().HasContractInfo(gomock.Any(), address).Return(true) + resp, err := k.SudoKVQueryResult(ctx, + address, + sudoTxQueryResultMsg.KVQueryResult.QueryID, + ) + require.NoError(t, err) + require.Equal(t, []byte("success"), resp) + + wk.EXPECT().Sudo(gomock.Any(), address, mustJSON(sudoTxQueryResultMsg)).Return(nil, fmt.Errorf("internal contract error")) + wk.EXPECT().HasContractInfo(gomock.Any(), address).Return(true) + resp, err = k.SudoKVQueryResult(ctx, + address, + sudoTxQueryResultMsg.KVQueryResult.QueryID, + ) + require.Nil(t, resp) + require.ErrorContains(t, err, "internal contract error") + + wk.EXPECT().HasContractInfo(gomock.Any(), address).Return(false) + resp, err = k.SudoKVQueryResult(ctx, + address, + sudoTxQueryResultMsg.KVQueryResult.QueryID, + ) + require.Nil(t, resp) + require.ErrorContains(t, err, "is not a contract address") +} + +func mustJSON(v interface{}) []byte { + data, err := json.Marshal(v) + if err != nil { + panic(err) + } + return data +} diff --git a/x/contractmanager/migrations/v2/store.go b/x/contractmanager/migrations/v2/store.go new file mode 100644 index 00000000..585baf8c --- /dev/null +++ b/x/contractmanager/migrations/v2/store.go @@ -0,0 +1,44 @@ +package v2 + +import ( + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +// MigrateStore performs in-place store migrations. +// The migration rearranges removes all old failures, +// since they do not have the necessary fields packet and ack for resubmission +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error { + return migrateFailures(ctx, storeKey) +} + +func migrateFailures(ctx sdk.Context, storeKey storetypes.StoreKey) error { + ctx.Logger().Info("Migrating failures...") + + // fetch list of all old failure keys + failureKeys := make([][]byte, 0) + iteratorStore := prefix.NewStore(ctx.KVStore(storeKey), types.ContractFailuresKey) + iterator := storetypes.KVStorePrefixIterator(iteratorStore, []byte{}) + + for ; iterator.Valid(); iterator.Next() { + failureKeys = append(failureKeys, iterator.Key()) + } + + err := iterator.Close() + if err != nil { + return err + } + + // remove failures + store := prefix.NewStore(ctx.KVStore(storeKey), types.ContractFailuresKey) + for _, key := range failureKeys { + store.Delete(key) + } + + ctx.Logger().Info("Finished migrating failures") + + return nil +} diff --git a/x/contractmanager/migrations/v2/store_test.go b/x/contractmanager/migrations/v2/store_test.go new file mode 100644 index 00000000..274ec430 --- /dev/null +++ b/x/contractmanager/migrations/v2/store_test.go @@ -0,0 +1,70 @@ +package v2_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" + + "github.com/Nolus-Protocol/nolus-core/testutil" + v2 "github.com/Nolus-Protocol/nolus-core/x/contractmanager/migrations/v2" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" + typesv1 "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types/v1" +) + +type V2ContractManagerMigrationTestSuite struct { + testutil.IBCConnectionTestSuite +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(V2ContractManagerMigrationTestSuite)) +} + +func (suite *V2ContractManagerMigrationTestSuite) TestFailuresUpgrade() { + var ( + app = suite.GetNolusZoneApp(suite.ChainA) + storeKey = app.GetKey(types.StoreKey) + ctx = suite.ChainA.GetContext() + cdc = app.AppCodec() + ) + + addressOne := testutil.TestOwnerAddress + addressTwo := "nolus1fxudpred77a0grgh69u0j7y84yks5ev4n5050z45kecz792jnd6scqu98z" + + // Write old state + store := ctx.KVStore(storeKey) + var i uint64 + for i = 0; i < 4; i++ { + var addr string + if i < 2 { + addr = addressOne + } else { + addr = addressTwo + } + failure := typesv1.Failure{ + ChannelId: "channel-0", + Address: addr, + Id: i % 2, + AckType: types.Ack, + } + bz := cdc.MustMarshal(&failure) + store.Set(types.GetFailureKey(failure.Address, failure.Id), bz) + } + + // Run migration + suite.NoError(v2.MigrateStore(ctx, storeKey)) + + // Check elements should be empty + expected := app.ContractManagerKeeper.GetAllFailures(ctx) + suite.Require().ElementsMatch(expected, []types.Failure{}) + + // Non-existent returns error + _, err := app.ContractManagerKeeper.GetFailure(ctx, sdk.MustAccAddressFromBech32(addressTwo), 0) + suite.Require().Error(err) + + // Check next id key is reset + oneKey := app.ContractManagerKeeper.GetNextFailureIDKey(ctx, addressOne) + suite.Require().Equal(oneKey, uint64(0)) + twoKey := app.ContractManagerKeeper.GetNextFailureIDKey(ctx, addressTwo) + suite.Require().Equal(twoKey, uint64(0)) +} diff --git a/x/contractmanager/module.go b/x/contractmanager/module.go new file mode 100644 index 00000000..b5e015fe --- /dev/null +++ b/x/contractmanager/module.go @@ -0,0 +1,168 @@ +package contractmanager + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + + // this line is used by starport scaffolding # 1 + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/client/cli" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +var ( + _ appmodule.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- +var _ appmodule.AppModule = AppModule{} + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() { // marker +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() { // marker +} + +// Deprecated: use RegisterServices +func (AppModule) QuerierRoute() string { return types.RouterKey } + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + + m := keeper.NewMigrator(am.keeper) + if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { + panic(fmt.Sprintf("failed to migrate x/contractmanager from version 1 to 2: %v", err)) + } +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return types.ConsensusVersion } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(_ sdk.Context) {} + +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(_ sdk.Context) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/contractmanager/types/codec.go b/x/contractmanager/types/codec.go new file mode 100644 index 00000000..14f5aff7 --- /dev/null +++ b/x/contractmanager/types/codec.go @@ -0,0 +1,25 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgUpdateParams{}, "neutron.contractmanager.v1.MsgUpdateParams", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgUpdateParams{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/contractmanager/types/constants.go b/x/contractmanager/types/constants.go new file mode 100644 index 00000000..4c93fbef --- /dev/null +++ b/x/contractmanager/types/constants.go @@ -0,0 +1,3 @@ +package types + +const ConsensusVersion = 2 diff --git a/x/contractmanager/types/errors.go b/x/contractmanager/types/errors.go new file mode 100644 index 00000000..ba32da1f --- /dev/null +++ b/x/contractmanager/types/errors.go @@ -0,0 +1,12 @@ +package types + +import ( + "cosmossdk.io/errors" +) + +// x/contractmanager module sentinel errors +var ( + ErrIncorrectFailureToResubmit = errors.Register(ModuleName, 1101, "incorrect failure to resubmit") + ErrFailedToResubmitFailure = errors.Register(ModuleName, 1102, "failed to resubmit failure") + ErrSudoOutOfGas = errors.Register(ModuleName, 1103, "sudo handling went beyond the gas limit allowed by the module") +) diff --git a/x/contractmanager/types/events.go b/x/contractmanager/types/events.go new file mode 100644 index 00000000..36ccef85 --- /dev/null +++ b/x/contractmanager/types/events.go @@ -0,0 +1,10 @@ +package types + +// Contractmanager events +const ( + // AttributeKeySudoError indicates an attribute containing detailed Sudo call error. + AttributeKeySudoError = "error" + // AttributeKeySudoFailureID indicates attribute containing ID of the failure related to an + // error Sudo call. + AttributeKeySudoFailureID = "failure_id" +) diff --git a/x/contractmanager/types/expected_keepers.go b/x/contractmanager/types/expected_keepers.go new file mode 100644 index 00000000..cbbd12d3 --- /dev/null +++ b/x/contractmanager/types/expected_keepers.go @@ -0,0 +1,20 @@ +package types + +import ( + "context" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// WasmKeeper defines the expected interface needed to cam cosmwasm contracts. +type WasmKeeper interface { + HasContractInfo(ctx context.Context, contractAddress sdk.AccAddress) bool + GetContractInfo(ctx context.Context, contractAddress sdk.AccAddress) *wasmtypes.ContractInfo + Sudo(ctx context.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) +} + +type ContractManagerKeeper interface { + AddContractFailure(ctx context.Context, address string, sudoPayload []byte, errMsg string) Failure + GetParams(ctx context.Context) (params Params) +} diff --git a/x/contractmanager/types/failure.pb.go b/x/contractmanager/types/failure.pb.go new file mode 100644 index 00000000..108230c3 --- /dev/null +++ b/x/contractmanager/types/failure.pb.go @@ -0,0 +1,471 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/failure.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + proto "github.com/cosmos/gogoproto/proto" + _ "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +// 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 + +// Failure message contains information about ACK failures and can be used to +// replay ACK in case of requirement. +// Note that Failure means that sudo handler to cosmwasm contract failed for +// some reason +type Failure struct { + // Address of the failed contract + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // Id of the failure under specific address + Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` + // Serialized MessageSudoCallback with Packet and Ack(if exists) + SudoPayload []byte `protobuf:"bytes,3,opt,name=sudo_payload,json=sudoPayload,proto3" json:"sudo_payload,omitempty"` + // Redacted error response of the sudo call. Full error is emitted as an event + Error string `protobuf:"bytes,4,opt,name=error,proto3" json:"error,omitempty"` +} + +func (m *Failure) Reset() { *m = Failure{} } +func (m *Failure) String() string { return proto.CompactTextString(m) } +func (*Failure) ProtoMessage() {} +func (*Failure) Descriptor() ([]byte, []int) { + return fileDescriptor_fba0c26e85dad46e, []int{0} +} +func (m *Failure) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Failure) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Failure.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 *Failure) XXX_Merge(src proto.Message) { + xxx_messageInfo_Failure.Merge(m, src) +} +func (m *Failure) XXX_Size() int { + return m.Size() +} +func (m *Failure) XXX_DiscardUnknown() { + xxx_messageInfo_Failure.DiscardUnknown(m) +} + +var xxx_messageInfo_Failure proto.InternalMessageInfo + +func (m *Failure) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Failure) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *Failure) GetSudoPayload() []byte { + if m != nil { + return m.SudoPayload + } + return nil +} + +func (m *Failure) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func init() { + proto.RegisterType((*Failure)(nil), "neutron.contractmanager.Failure") +} + +func init() { + proto.RegisterFile("neutron/contractmanager/failure.proto", fileDescriptor_fba0c26e85dad46e) +} + +var fileDescriptor_fba0c26e85dad46e = []byte{ + // 248 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0xc9, 0x4d, 0xcc, 0x4b, + 0x4c, 0x4f, 0x2d, 0xd2, 0x4f, 0x4b, 0xcc, 0xcc, 0x29, 0x2d, 0x4a, 0xd5, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x12, 0x87, 0x2a, 0xd3, 0x43, 0x53, 0x26, 0xa5, 0x98, 0x99, 0x94, 0xac, 0x9f, 0x9c, + 0x5f, 0x94, 0xaa, 0x9f, 0x9c, 0x91, 0x98, 0x97, 0x97, 0x9a, 0xa3, 0x5f, 0x66, 0x08, 0x63, 0x42, + 0xf4, 0x2a, 0xe5, 0x70, 0xb1, 0xbb, 0x41, 0x0c, 0x13, 0x92, 0xe0, 0x62, 0x4f, 0x4c, 0x49, 0x29, + 0x4a, 0x2d, 0x2e, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0x71, 0x85, 0xf8, 0xb8, 0x98, + 0x32, 0x53, 0x24, 0x98, 0x14, 0x18, 0x35, 0x58, 0x82, 0x98, 0x32, 0x53, 0x84, 0x14, 0xb9, 0x78, + 0x8a, 0x4b, 0x53, 0xf2, 0xe3, 0x0b, 0x12, 0x2b, 0x73, 0xf2, 0x13, 0x53, 0x24, 0x98, 0x15, 0x18, + 0x35, 0x78, 0x82, 0xb8, 0x41, 0x62, 0x01, 0x10, 0x21, 0x21, 0x11, 0x2e, 0xd6, 0xd4, 0xa2, 0xa2, + 0xfc, 0x22, 0x09, 0x16, 0xb0, 0x51, 0x10, 0x8e, 0x53, 0xf0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, + 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, + 0x1e, 0xcb, 0x31, 0x44, 0x59, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, + 0x43, 0xbd, 0xa3, 0x9b, 0x5f, 0x94, 0x0e, 0x63, 0xeb, 0x97, 0x99, 0xe8, 0x57, 0x60, 0x04, 0x43, + 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x27, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x5c, 0xc6, 0x5f, 0x6f, 0x2e, 0x01, 0x00, 0x00, +} + +func (m *Failure) 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 *Failure) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Failure) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Error) > 0 { + i -= len(m.Error) + copy(dAtA[i:], m.Error) + i = encodeVarintFailure(dAtA, i, uint64(len(m.Error))) + i-- + dAtA[i] = 0x22 + } + if len(m.SudoPayload) > 0 { + i -= len(m.SudoPayload) + copy(dAtA[i:], m.SudoPayload) + i = encodeVarintFailure(dAtA, i, uint64(len(m.SudoPayload))) + i-- + dAtA[i] = 0x1a + } + if m.Id != 0 { + i = encodeVarintFailure(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintFailure(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintFailure(dAtA []byte, offset int, v uint64) int { + offset -= sovFailure(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Failure) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + if m.Id != 0 { + n += 1 + sovFailure(uint64(m.Id)) + } + l = len(m.SudoPayload) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + l = len(m.Error) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + return n +} + +func sovFailure(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozFailure(x uint64) (n int) { + return sovFailure(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Failure) 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 ErrIntOverflowFailure + } + 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: Failure: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Failure: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + 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 ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SudoPayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthFailure + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SudoPayload = append(m.SudoPayload[:0], dAtA[iNdEx:postIndex]...) + if m.SudoPayload == nil { + m.SudoPayload = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + 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 ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Error = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipFailure(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFailure + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipFailure(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, ErrIntOverflowFailure + } + 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, ErrIntOverflowFailure + } + 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, ErrIntOverflowFailure + } + 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, ErrInvalidLengthFailure + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupFailure + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthFailure + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthFailure = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowFailure = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupFailure = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/contractmanager/types/genesis.go b/x/contractmanager/types/genesis.go new file mode 100644 index 00000000..5b63d3c6 --- /dev/null +++ b/x/contractmanager/types/genesis.go @@ -0,0 +1,33 @@ +package types + +import ( + "fmt" +) + +// DefaultIndex is the default global index +const DefaultIndex uint64 = 1 + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + FailuresList: []Failure{}, + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + // Check for duplicated index in failure + failureIndexMap := make(map[string]struct{}) + + for _, elem := range gs.FailuresList { + index := string(GetFailureKey(elem.Address, elem.Id)) + if _, ok := failureIndexMap[index]; ok { + return fmt.Errorf("duplicated address for failure") + } + failureIndexMap[index] = struct{}{} + } + + return gs.Params.Validate() +} diff --git a/x/contractmanager/types/genesis.pb.go b/x/contractmanager/types/genesis.pb.go new file mode 100644 index 00000000..198452ee --- /dev/null +++ b/x/contractmanager/types/genesis.pb.go @@ -0,0 +1,390 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 contractmanager module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // List of the contract failures + FailuresList []Failure `protobuf:"bytes,2,rep,name=failures_list,json=failuresList,proto3" json:"failures_list"` +} + +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_cf4a1534315a7490, []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) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetFailuresList() []Failure { + if m != nil { + return m.FailuresList + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "neutron.contractmanager.GenesisState") +} + +func init() { + proto.RegisterFile("neutron/contractmanager/genesis.proto", fileDescriptor_cf4a1534315a7490) +} + +var fileDescriptor_cf4a1534315a7490 = []byte{ + // 251 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcd, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0xc9, 0x4d, 0xcc, 0x4b, + 0x4c, 0x4f, 0x2d, 0xd2, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x12, 0x87, 0x2a, 0xd3, 0x43, 0x53, 0x26, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, + 0xa3, 0x0f, 0x62, 0x41, 0x94, 0x4b, 0xe1, 0x34, 0x35, 0x2d, 0x31, 0x33, 0xa7, 0xb4, 0x28, 0x15, + 0xaa, 0x4c, 0x05, 0x97, 0xb2, 0x82, 0xc4, 0xa2, 0xc4, 0x5c, 0xa8, 0xdd, 0x4a, 0xb3, 0x18, 0xb9, + 0x78, 0xdc, 0x21, 0xae, 0x09, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0xb2, 0xe5, 0x62, 0x83, 0x28, 0x90, + 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd7, 0xc3, 0xe1, 0x3a, 0xbd, 0x00, 0xb0, 0x32, 0x27, + 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, 0x9a, 0x84, 0xbc, 0xb9, 0x78, 0xa1, 0xce, 0x28, 0x8e, + 0xcf, 0xc9, 0x2c, 0x2e, 0x91, 0x60, 0x52, 0x60, 0xd6, 0xe0, 0x36, 0x52, 0xc0, 0x69, 0x8a, 0x1b, + 0x44, 0x35, 0xd4, 0x18, 0x1e, 0x98, 0x66, 0x9f, 0xcc, 0xe2, 0x12, 0xa7, 0xe0, 0x13, 0x8f, 0xe4, + 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, + 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, 0x4c, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, + 0xce, 0xcf, 0xd5, 0x87, 0x9a, 0xac, 0x9b, 0x5f, 0x94, 0x0e, 0x63, 0xeb, 0x97, 0x99, 0xe8, 0x57, + 0x60, 0x78, 0xbc, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x71, 0x63, 0x40, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x2d, 0x60, 0xd9, 0xc7, 0x9d, 0x01, 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.FailuresList) > 0 { + for iNdEx := len(m.FailuresList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FailuresList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.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 = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.FailuresList) > 0 { + for _, e := range m.FailuresList { + l = e.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 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 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FailuresList", 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.FailuresList = append(m.FailuresList, Failure{}) + if err := m.FailuresList[len(m.FailuresList)-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 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/x/contractmanager/types/genesis_test.go b/x/contractmanager/types/genesis_test.go new file mode 100644 index 00000000..25d7740a --- /dev/null +++ b/x/contractmanager/types/genesis_test.go @@ -0,0 +1,72 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" +) + +func TestGenesisState_Validate(t *testing.T) { + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + FailuresList: []types.Failure{ + { + Address: "address1", + Id: 1, + }, + { + Address: "address1", + Id: 2, + }, + { + Address: "address2", + Id: 1, + }, + }, + }, + valid: true, + }, + { + desc: "duplicated failure", + genState: &types.GenesisState{ + FailuresList: []types.Failure{ + { + Address: "address1", + Id: 1, + }, + { + Address: "address1", + Id: 1, + }, + { + Address: "address2", + Id: 1, + }, + }, + }, + valid: false, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/contractmanager/types/keys.go b/x/contractmanager/types/keys.go new file mode 100644 index 00000000..62447d84 --- /dev/null +++ b/x/contractmanager/types/keys.go @@ -0,0 +1,45 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +const ( + // ModuleName defines the module name + ModuleName = "contractmanager" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_" + ModuleName +) + +const ( + prefixContractFailures = iota + 1 + prefixParamsKey +) + +var ( + ContractFailuresKey = []byte{prefixContractFailures} + ParamsKey = []byte{prefixParamsKey} +) + +// GetFailureKeyPrefix returns the store key for the failures of the specific address +func GetFailureKeyPrefix( + address string, +) []byte { + key := ContractFailuresKey + key = append(key, []byte(address)...) + return append(key, []byte("/")...) +} + +// GetFailureKey returns the store key to retrieve a Failure from the index fields +func GetFailureKey( + address string, + offset uint64, +) []byte { + key := GetFailureKeyPrefix(address) + return append(key, sdk.Uint64ToBigEndian(offset)...) +} diff --git a/x/contractmanager/types/params.go b/x/contractmanager/types/params.go new file mode 100644 index 00000000..5a2a9c29 --- /dev/null +++ b/x/contractmanager/types/params.go @@ -0,0 +1,43 @@ +package types + +import ( + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +const DefaultSudoCallGasLimit = uint64(1_000_000) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams(sudoCallGasLimit uint64) Params { + return Params{ + SudoCallGasLimit: sudoCallGasLimit, + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams(DefaultSudoCallGasLimit) +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{} +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/contractmanager/types/params.pb.go b/x/contractmanager/types/params.pb.go new file mode 100644 index 00000000..2ca0e44c --- /dev/null +++ b/x/contractmanager/types/params.pb.go @@ -0,0 +1,305 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/params.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 + +// Params defines the parameters for the module. +type Params struct { + SudoCallGasLimit uint64 `protobuf:"varint,1,opt,name=sudo_call_gas_limit,json=sudoCallGasLimit,proto3" json:"sudo_call_gas_limit,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_121b05e48c7a8737, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetSudoCallGasLimit() uint64 { + if m != nil { + return m.SudoCallGasLimit + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "neutron.contractmanager.Params") +} + +func init() { + proto.RegisterFile("neutron/contractmanager/params.proto", fileDescriptor_121b05e48c7a8737) +} + +var fileDescriptor_121b05e48c7a8737 = []byte{ + // 204 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc9, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0xc9, 0x4d, 0xcc, 0x4b, + 0x4c, 0x4f, 0x2d, 0xd2, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x87, 0xaa, 0xd2, 0x43, 0x53, 0x25, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, + 0x0f, 0x62, 0x41, 0x94, 0x2b, 0xd9, 0x72, 0xb1, 0x05, 0x80, 0xb5, 0x0b, 0xe9, 0x72, 0x09, 0x17, + 0x97, 0xa6, 0xe4, 0xc7, 0x27, 0x27, 0xe6, 0xe4, 0xc4, 0xa7, 0x27, 0x16, 0xc7, 0xe7, 0x64, 0xe6, + 0x66, 0x96, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0x09, 0x80, 0xa4, 0x9c, 0x13, 0x73, 0x72, + 0xdc, 0x13, 0x8b, 0x7d, 0x40, 0xe2, 0x56, 0x2c, 0x33, 0x16, 0xc8, 0x33, 0x38, 0x05, 0x9f, 0x78, + 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, + 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x65, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, + 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xd4, 0x49, 0xba, 0xf9, 0x45, 0xe9, 0x30, 0xb6, 0x7e, 0x99, 0x89, + 0x7e, 0x05, 0x86, 0x4f, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x4e, 0x33, 0x06, 0x04, + 0x00, 0x00, 0xff, 0xff, 0xa9, 0x1e, 0x26, 0x1c, 0xf1, 0x00, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SudoCallGasLimit != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.SudoCallGasLimit)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SudoCallGasLimit != 0 { + n += 1 + sovParams(uint64(m.SudoCallGasLimit)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SudoCallGasLimit", wireType) + } + m.SudoCallGasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SudoCallGasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/contractmanager/types/query.pb.go b/x/contractmanager/types/query.pb.go new file mode 100644 index 00000000..7e3209a8 --- /dev/null +++ b/x/contractmanager/types/query.pb.go @@ -0,0 +1,1179 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/query.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + 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" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// 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 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_f9524a427f219917, []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 response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +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_f9524a427f219917, []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() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// QueryFailuresRequest is request type for the Query/Failures RPC method. +type QueryFailuresRequest struct { + // address of the contract which Sudo call failed. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // ID of the failure for the given contract. + FailureId uint64 `protobuf:"varint,2,opt,name=failure_id,json=failureId,proto3" json:"failure_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryFailuresRequest) Reset() { *m = QueryFailuresRequest{} } +func (m *QueryFailuresRequest) String() string { return proto.CompactTextString(m) } +func (*QueryFailuresRequest) ProtoMessage() {} +func (*QueryFailuresRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f9524a427f219917, []int{2} +} +func (m *QueryFailuresRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryFailuresRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryFailuresRequest.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 *QueryFailuresRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryFailuresRequest.Merge(m, src) +} +func (m *QueryFailuresRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryFailuresRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryFailuresRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryFailuresRequest proto.InternalMessageInfo + +func (m *QueryFailuresRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *QueryFailuresRequest) GetFailureId() uint64 { + if m != nil { + return m.FailureId + } + return 0 +} + +func (m *QueryFailuresRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryFailuresResponse is response type for the Query/Failures RPC method. +type QueryFailuresResponse struct { + Failures []Failure `protobuf:"bytes,1,rep,name=failures,proto3" json:"failures"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryFailuresResponse) Reset() { *m = QueryFailuresResponse{} } +func (m *QueryFailuresResponse) String() string { return proto.CompactTextString(m) } +func (*QueryFailuresResponse) ProtoMessage() {} +func (*QueryFailuresResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f9524a427f219917, []int{3} +} +func (m *QueryFailuresResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryFailuresResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryFailuresResponse.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 *QueryFailuresResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryFailuresResponse.Merge(m, src) +} +func (m *QueryFailuresResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryFailuresResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryFailuresResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryFailuresResponse proto.InternalMessageInfo + +func (m *QueryFailuresResponse) GetFailures() []Failure { + if m != nil { + return m.Failures + } + return nil +} + +func (m *QueryFailuresResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "neutron.contractmanager.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "neutron.contractmanager.QueryParamsResponse") + proto.RegisterType((*QueryFailuresRequest)(nil), "neutron.contractmanager.QueryFailuresRequest") + proto.RegisterType((*QueryFailuresResponse)(nil), "neutron.contractmanager.QueryFailuresResponse") +} + +func init() { + proto.RegisterFile("neutron/contractmanager/query.proto", fileDescriptor_f9524a427f219917) +} + +var fileDescriptor_f9524a427f219917 = []byte{ + // 531 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x94, 0x41, 0x6b, 0x13, 0x41, + 0x14, 0xc7, 0x33, 0x69, 0x1b, 0xdb, 0x29, 0x28, 0x8c, 0x11, 0x43, 0xd0, 0x4d, 0xba, 0x55, 0x1b, + 0xad, 0x99, 0xa1, 0xa9, 0x07, 0x15, 0x04, 0xcd, 0xa1, 0xe2, 0xad, 0xae, 0x9e, 0xbc, 0xc8, 0x24, + 0x19, 0xc7, 0x85, 0x66, 0x66, 0x3b, 0x33, 0x5b, 0x2c, 0xa5, 0x17, 0x6f, 0x82, 0x07, 0x41, 0xc1, + 0x2f, 0xa0, 0x1f, 0xc0, 0x6f, 0xd1, 0x63, 0xc1, 0x8b, 0x27, 0x91, 0xc4, 0x0f, 0x22, 0x99, 0x99, + 0xb4, 0x4d, 0xca, 0x36, 0xf1, 0xa0, 0xb7, 0xd9, 0xb7, 0xef, 0xff, 0xde, 0xef, 0xfd, 0xe7, 0xed, + 0xc2, 0x65, 0xc1, 0x52, 0xa3, 0xa4, 0x20, 0x6d, 0x29, 0x8c, 0xa2, 0x6d, 0xd3, 0xa5, 0x82, 0x72, + 0xa6, 0xc8, 0x76, 0xca, 0xd4, 0x2e, 0x4e, 0x94, 0x34, 0x12, 0x5d, 0xf6, 0x49, 0x78, 0x2c, 0xa9, + 0x7c, 0xab, 0x2d, 0x75, 0x57, 0x6a, 0xd2, 0xa2, 0x9a, 0x39, 0x05, 0xd9, 0x59, 0x6b, 0x31, 0x43, + 0xd7, 0x48, 0x42, 0x79, 0x2c, 0xa8, 0x89, 0xa5, 0x70, 0x45, 0xca, 0x45, 0x2e, 0xb9, 0xb4, 0x47, + 0x32, 0x38, 0xf9, 0xe8, 0x15, 0x2e, 0x25, 0xdf, 0x62, 0x84, 0x26, 0x31, 0xa1, 0x42, 0x48, 0x63, + 0x25, 0xda, 0xbf, 0xbd, 0x9e, 0x45, 0xf7, 0x8a, 0xc6, 0x5b, 0xa9, 0x62, 0x3e, 0xed, 0x5a, 0x56, + 0x5a, 0x42, 0x15, 0xed, 0xfa, 0x62, 0x61, 0x11, 0xa2, 0xa7, 0x03, 0xc4, 0x4d, 0x1b, 0x8c, 0xd8, + 0x76, 0xca, 0xb4, 0x09, 0x9f, 0xc3, 0x8b, 0x23, 0x51, 0x9d, 0x48, 0xa1, 0x19, 0x7a, 0x00, 0x0b, + 0x4e, 0x5c, 0x02, 0x55, 0x50, 0x5b, 0x6c, 0x54, 0x70, 0x86, 0x07, 0xd8, 0x09, 0x9b, 0xb3, 0x07, + 0x3f, 0x2b, 0xb9, 0xc8, 0x8b, 0xc2, 0xcf, 0x00, 0x16, 0x6d, 0xd9, 0x0d, 0x07, 0x3a, 0x6c, 0x87, + 0x4a, 0xf0, 0x1c, 0xed, 0x74, 0x14, 0xd3, 0xae, 0xf0, 0x42, 0x34, 0x7c, 0x44, 0x57, 0x21, 0xf4, + 0x53, 0xbd, 0x8c, 0x3b, 0xa5, 0x7c, 0x15, 0xd4, 0x66, 0xa3, 0x05, 0x1f, 0x79, 0xd2, 0x41, 0x1b, + 0x10, 0x1e, 0x5b, 0x5a, 0x9a, 0xb1, 0x50, 0x37, 0xb0, 0xf3, 0x1f, 0x0f, 0xfc, 0xc7, 0xee, 0xc6, + 0xbc, 0xff, 0x78, 0x93, 0x72, 0xe6, 0x9b, 0x46, 0x27, 0x94, 0xe1, 0x17, 0x00, 0x2f, 0x8d, 0x91, + 0xf9, 0x91, 0x9b, 0x70, 0xde, 0xb7, 0x1b, 0xb0, 0xcd, 0xd4, 0x16, 0x1b, 0xd5, 0xcc, 0xa1, 0xbd, + 0xd8, 0x4f, 0x7d, 0xa4, 0x43, 0x8f, 0x47, 0x28, 0xf3, 0x96, 0x72, 0x65, 0x22, 0xa5, 0x03, 0x38, + 0x89, 0xd9, 0x78, 0x37, 0x07, 0xe7, 0x2c, 0x26, 0x7a, 0x0f, 0x60, 0xc1, 0x79, 0x8c, 0x56, 0x33, + 0x79, 0x4e, 0x5f, 0x6c, 0xf9, 0xf6, 0x74, 0xc9, 0xae, 0x77, 0xb8, 0xf2, 0xf6, 0xfb, 0xef, 0x8f, + 0xf9, 0x25, 0x54, 0x21, 0x67, 0xef, 0x12, 0xfa, 0x06, 0xe0, 0xf9, 0x47, 0xee, 0xca, 0xbc, 0x09, + 0xa8, 0x7e, 0x76, 0xa7, 0xb1, 0x15, 0x28, 0xe3, 0x69, 0xd3, 0x3d, 0xda, 0x43, 0x8b, 0x76, 0x1f, + 0xdd, 0x25, 0x13, 0xbe, 0x06, 0x4d, 0xf6, 0xfc, 0x32, 0xed, 0x93, 0xbd, 0xe3, 0x5d, 0xda, 0x47, + 0x5f, 0x01, 0xbc, 0x30, 0xca, 0xac, 0xff, 0x35, 0xf4, 0xba, 0x85, 0xae, 0xa3, 0xd5, 0xbf, 0x80, + 0x46, 0x9f, 0x00, 0x9c, 0xff, 0x5f, 0x80, 0x37, 0x2d, 0xe0, 0x32, 0x5a, 0x9a, 0x08, 0xd8, 0x7c, + 0x76, 0xd0, 0x0b, 0xc0, 0x61, 0x2f, 0x00, 0xbf, 0x7a, 0x01, 0xf8, 0xd0, 0x0f, 0x72, 0x87, 0xfd, + 0x20, 0xf7, 0xa3, 0x1f, 0xe4, 0x5e, 0xdc, 0xe3, 0xb1, 0x79, 0x9d, 0xb6, 0x70, 0x5b, 0x76, 0x87, + 0x65, 0xea, 0x52, 0xf1, 0xa3, 0x92, 0x3b, 0x77, 0xc8, 0x9b, 0x53, 0x75, 0xcd, 0x6e, 0xc2, 0x74, + 0xab, 0x60, 0x7f, 0x4a, 0xeb, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x96, 0xc1, 0xe7, 0xbe, 0x81, + 0x05, 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 { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // Queries a Failure by contract address and failure ID. + AddressFailure(ctx context.Context, in *QueryFailuresRequest, opts ...grpc.CallOption) (*QueryFailuresResponse, error) + // Queries Failures by contract address. + AddressFailures(ctx context.Context, in *QueryFailuresRequest, opts ...grpc.CallOption) (*QueryFailuresResponse, error) + // Queries a list of Failures occurred on the network. + Failures(ctx context.Context, in *QueryFailuresRequest, opts ...grpc.CallOption) (*QueryFailuresResponse, 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, "/neutron.contractmanager.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AddressFailure(ctx context.Context, in *QueryFailuresRequest, opts ...grpc.CallOption) (*QueryFailuresResponse, error) { + out := new(QueryFailuresResponse) + err := c.cc.Invoke(ctx, "/neutron.contractmanager.Query/AddressFailure", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AddressFailures(ctx context.Context, in *QueryFailuresRequest, opts ...grpc.CallOption) (*QueryFailuresResponse, error) { + out := new(QueryFailuresResponse) + err := c.cc.Invoke(ctx, "/neutron.contractmanager.Query/AddressFailures", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Failures(ctx context.Context, in *QueryFailuresRequest, opts ...grpc.CallOption) (*QueryFailuresResponse, error) { + out := new(QueryFailuresResponse) + err := c.cc.Invoke(ctx, "/neutron.contractmanager.Query/Failures", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // Queries a Failure by contract address and failure ID. + AddressFailure(context.Context, *QueryFailuresRequest) (*QueryFailuresResponse, error) + // Queries Failures by contract address. + AddressFailures(context.Context, *QueryFailuresRequest) (*QueryFailuresResponse, error) + // Queries a list of Failures occurred on the network. + Failures(context.Context, *QueryFailuresRequest) (*QueryFailuresResponse, 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) AddressFailure(ctx context.Context, req *QueryFailuresRequest) (*QueryFailuresResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddressFailure not implemented") +} +func (*UnimplementedQueryServer) AddressFailures(ctx context.Context, req *QueryFailuresRequest) (*QueryFailuresResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddressFailures not implemented") +} +func (*UnimplementedQueryServer) Failures(ctx context.Context, req *QueryFailuresRequest) (*QueryFailuresResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Failures 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: "/neutron.contractmanager.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_AddressFailure_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryFailuresRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AddressFailure(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.contractmanager.Query/AddressFailure", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AddressFailure(ctx, req.(*QueryFailuresRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AddressFailures_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryFailuresRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AddressFailures(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.contractmanager.Query/AddressFailures", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AddressFailures(ctx, req.(*QueryFailuresRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Failures_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryFailuresRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Failures(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.contractmanager.Query/Failures", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Failures(ctx, req.(*QueryFailuresRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.contractmanager.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "AddressFailure", + Handler: _Query_AddressFailure_Handler, + }, + { + MethodName: "AddressFailures", + Handler: _Query_AddressFailures_Handler, + }, + { + MethodName: "Failures", + Handler: _Query_Failures_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/contractmanager/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 + { + 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 *QueryFailuresRequest) 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 *QueryFailuresRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryFailuresRequest) 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] = 0x1a + } + if m.FailureId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.FailureId)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryFailuresResponse) 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 *QueryFailuresResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryFailuresResponse) 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.Failures) > 0 { + for iNdEx := len(m.Failures) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Failures[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 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 + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryFailuresRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.FailureId != 0 { + n += 1 + sovQuery(uint64(m.FailureId)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryFailuresResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Failures) > 0 { + for _, e := range m.Failures { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.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 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 *QueryFailuresRequest) 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: QueryFailuresRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryFailuresRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", 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.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FailureId", wireType) + } + m.FailureId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FailureId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + 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 *QueryFailuresResponse) 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: QueryFailuresResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryFailuresResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Failures", 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.Failures = append(m.Failures, Failure{}) + if err := m.Failures[len(m.Failures)-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 + 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/x/contractmanager/types/query.pb.gw.go b/x/contractmanager/types/query.pb.gw.go new file mode 100644 index 00000000..2c201192 --- /dev/null +++ b/x/contractmanager/types/query.pb.gw.go @@ -0,0 +1,496 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: neutron/contractmanager/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 + +} + +var ( + filter_Query_AddressFailure_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0, "failure_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} +) + +func request_Query_AddressFailure_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFailuresRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + val, ok = pathParams["failure_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "failure_id") + } + + protoReq.FailureId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "failure_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_AddressFailure_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AddressFailure(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AddressFailure_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFailuresRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + val, ok = pathParams["failure_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "failure_id") + } + + protoReq.FailureId, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "failure_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_AddressFailure_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AddressFailure(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AddressFailures_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_AddressFailures_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFailuresRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", 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_AddressFailures_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AddressFailures(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AddressFailures_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFailuresRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", 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_AddressFailures_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AddressFailures(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Failures_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Failures_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFailuresRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Failures_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Failures(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Failures_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFailuresRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Failures_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Failures(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_AddressFailure_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_AddressFailure_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_AddressFailure_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AddressFailures_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_AddressFailures_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_AddressFailures_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Failures_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_Failures_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_Failures_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_AddressFailure_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_AddressFailure_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_AddressFailure_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AddressFailures_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_AddressFailures_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_AddressFailures_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Failures_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_Failures_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_Failures_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}, []string{"neutron", "contractmanager", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AddressFailure_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"neutron", "contractmanager", "failures", "address", "failure_id"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AddressFailures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"neutron", "contractmanager", "failures", "address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Failures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"neutron", "contractmanager", "failures"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_AddressFailure_0 = runtime.ForwardResponseMessage + + forward_Query_AddressFailures_0 = runtime.ForwardResponseMessage + + forward_Query_Failures_0 = runtime.ForwardResponseMessage +) diff --git a/x/contractmanager/types/sudo.go b/x/contractmanager/types/sudo.go new file mode 100644 index 00000000..5cdc8634 --- /dev/null +++ b/x/contractmanager/types/sudo.go @@ -0,0 +1,59 @@ +package types + +import ( + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +// MessageTxQueryResult is passed to a contract's sudo() entrypoint when a tx was submitted +// for a transaction query. +type MessageTxQueryResult struct { + TxQueryResult struct { + QueryID uint64 `json:"query_id"` + Height ibcclienttypes.Height `json:"height"` + Data []byte `json:"data"` + } `json:"tx_query_result"` +} + +// MessageKVQueryResult is passed to a contract's sudo() entrypoint when a result +// was submitted for a kv-query. +type MessageKVQueryResult struct { + KVQueryResult struct { + QueryID uint64 `json:"query_id"` + } `json:"kv_query_result"` +} + +// MessageSudoCallback is passed to a contract's sudo() entrypoint when an interchain +// transaction ended up with Success/Error or timed out. +type MessageSudoCallback struct { + Response *ResponseSudoPayload `json:"response,omitempty"` + Error *ErrorSudoPayload `json:"error,omitempty"` + Timeout *TimeoutPayload `json:"timeout,omitempty"` +} + +type ResponseSudoPayload struct { + Request channeltypes.Packet `json:"request"` + Data []byte `json:"data"` // Message data +} + +type ErrorSudoPayload struct { + Request channeltypes.Packet `json:"request"` + Details string `json:"details"` +} + +type TimeoutPayload struct { + Request channeltypes.Packet `json:"request"` +} + +// MessageOnChanOpenAck is passed to a contract's sudo() entrypoint when an interchain +// account was successfully registered. +type MessageOnChanOpenAck struct { + OpenAck OpenAckDetails `json:"open_ack"` +} + +type OpenAckDetails struct { + PortID string `json:"port_id"` + ChannelID string `json:"channel_id"` + CounterpartyChannelID string `json:"counterparty_channel_id"` + CounterpartyVersion string `json:"counterparty_version"` +} diff --git a/x/contractmanager/types/tx.go b/x/contractmanager/types/tx.go new file mode 100644 index 00000000..7b965fc0 --- /dev/null +++ b/x/contractmanager/types/tx.go @@ -0,0 +1,35 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +func (msg *MsgUpdateParams) Type() string { + return "update-params" +} + +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgUpdateParams) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgUpdateParams) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errorsmod.Wrap(err, "authority is invalid") + } + return nil +} diff --git a/x/contractmanager/types/tx.pb.go b/x/contractmanager/types/tx.pb.go new file mode 100644 index 00000000..eaad796e --- /dev/null +++ b/x/contractmanager/types/tx.pb.go @@ -0,0 +1,599 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-proto" + _ "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" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// 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 + +// MsgUpdateParams is the MsgUpdateParams request type. +// +// Since: 0.47 +type MsgUpdateParams struct { + // Authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/contractmanager parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_4dc444ed708d435f, []int{0} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4dc444ed708d435f, []int{1} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "neutron.contractmanager.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "neutron.contractmanager.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("neutron/contractmanager/tx.proto", fileDescriptor_4dc444ed708d435f) } + +var fileDescriptor_4dc444ed708d435f = []byte{ + // 351 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc8, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0xc9, 0x4d, 0xcc, 0x4b, + 0x4c, 0x4f, 0x2d, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x87, 0xaa, + 0xd0, 0x43, 0x53, 0x21, 0x25, 0x98, 0x98, 0x9b, 0x99, 0x97, 0xaf, 0x0f, 0x26, 0x21, 0x6a, 0xa5, + 0xc4, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x73, 0x8b, 0xd3, 0xf5, 0xcb, 0x0c, 0x41, 0x14, + 0x54, 0x42, 0x12, 0x22, 0x11, 0x0f, 0xe6, 0xe9, 0x43, 0x38, 0x50, 0x29, 0x91, 0xf4, 0xfc, 0xf4, + 0x7c, 0x88, 0x38, 0x88, 0x05, 0x15, 0x55, 0xc1, 0xe5, 0xae, 0x82, 0xc4, 0xa2, 0xc4, 0x5c, 0xa8, + 0x5e, 0xa5, 0x83, 0x8c, 0x5c, 0xfc, 0xbe, 0xc5, 0xe9, 0xa1, 0x05, 0x29, 0x89, 0x25, 0xa9, 0x01, + 0x60, 0x19, 0x21, 0x33, 0x2e, 0xce, 0xc4, 0xd2, 0x92, 0x8c, 0xfc, 0xa2, 0xcc, 0x92, 0x4a, 0x09, + 0x46, 0x05, 0x46, 0x0d, 0x4e, 0x27, 0x89, 0x4b, 0x5b, 0x74, 0x45, 0xa0, 0x96, 0x3a, 0xa6, 0xa4, + 0x14, 0xa5, 0x16, 0x17, 0x07, 0x97, 0x14, 0x65, 0xe6, 0xa5, 0x07, 0x21, 0x94, 0x0a, 0x39, 0x71, + 0xb1, 0x41, 0xcc, 0x96, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd7, 0xc3, 0xe1, 0x71, 0x3d, + 0x88, 0x45, 0x4e, 0x9c, 0x27, 0xee, 0xc9, 0x33, 0xac, 0x78, 0xbe, 0x41, 0x8b, 0x31, 0x08, 0xaa, + 0xd3, 0xca, 0xa8, 0xe9, 0xf9, 0x06, 0x2d, 0x84, 0x99, 0x5d, 0xcf, 0x37, 0x68, 0xc9, 0xa3, 0x7b, + 0x00, 0xcd, 0xbd, 0x4a, 0x92, 0x5c, 0xe2, 0x68, 0x42, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, + 0xa9, 0x46, 0x15, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x42, 0x59, 0x5c, 0x3c, 0x28, 0x3e, 0xd4, 0xc0, + 0xe9, 0x32, 0x34, 0x83, 0xa4, 0x0c, 0x88, 0x55, 0x09, 0xb3, 0x52, 0x8a, 0xb5, 0x01, 0xe4, 0x21, + 0xa7, 0xe0, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, + 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, 0x4c, 0xcf, 0x2c, + 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x1a, 0xae, 0x9b, 0x5f, 0x94, 0x0e, 0x63, + 0xeb, 0x97, 0x99, 0xe8, 0x57, 0x60, 0x26, 0xa6, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0xa4, + 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb0, 0xe1, 0xbf, 0xee, 0x74, 0x02, 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 { + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/neutron.contractmanager.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.contractmanager.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.contractmanager.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/contractmanager/tx.proto", +} + +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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 *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + 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 *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 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.Params.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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 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/x/contractmanager/types/types.go b/x/contractmanager/types/types.go new file mode 100644 index 00000000..e7d6010f --- /dev/null +++ b/x/contractmanager/types/types.go @@ -0,0 +1,6 @@ +package types + +const ( + Ack = "ack" + Timeout = "timeout" +) diff --git a/x/contractmanager/types/v1/failure.pb.go b/x/contractmanager/types/v1/failure.pb.go new file mode 100644 index 00000000..af2f2875 --- /dev/null +++ b/x/contractmanager/types/v1/failure.pb.go @@ -0,0 +1,501 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/contractmanager/v1/failure.proto + +package v1 + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 + +// Deprecated. Used only for migration purposes. +type Failure struct { + // ChannelId + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // Address of the failed contract + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + // id of the failure under specific address + Id uint64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` + // ACK id to restore + AckId uint64 `protobuf:"varint,4,opt,name=ack_id,json=ackId,proto3" json:"ack_id,omitempty"` + // Acknowledgement type + AckType string `protobuf:"bytes,5,opt,name=ack_type,json=ackType,proto3" json:"ack_type,omitempty"` +} + +func (m *Failure) Reset() { *m = Failure{} } +func (m *Failure) String() string { return proto.CompactTextString(m) } +func (*Failure) ProtoMessage() {} +func (*Failure) Descriptor() ([]byte, []int) { + return fileDescriptor_c0f2c436fd0f28b7, []int{0} +} +func (m *Failure) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Failure) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Failure.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 *Failure) XXX_Merge(src proto.Message) { + xxx_messageInfo_Failure.Merge(m, src) +} +func (m *Failure) XXX_Size() int { + return m.Size() +} +func (m *Failure) XXX_DiscardUnknown() { + xxx_messageInfo_Failure.DiscardUnknown(m) +} + +var xxx_messageInfo_Failure proto.InternalMessageInfo + +func (m *Failure) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *Failure) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Failure) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *Failure) GetAckId() uint64 { + if m != nil { + return m.AckId + } + return 0 +} + +func (m *Failure) GetAckType() string { + if m != nil { + return m.AckType + } + return "" +} + +func init() { + proto.RegisterType((*Failure)(nil), "neutron.contractmanager.v1.Failure") +} + +func init() { + proto.RegisterFile("neutron/contractmanager/v1/failure.proto", fileDescriptor_c0f2c436fd0f28b7) +} + +var fileDescriptor_c0f2c436fd0f28b7 = []byte{ + // 248 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xc8, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0xce, 0xcf, 0x2b, 0x29, 0x4a, 0x4c, 0x2e, 0xc9, 0x4d, 0xcc, 0x4b, + 0x4c, 0x4f, 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x4f, 0x4b, 0xcc, 0xcc, 0x29, 0x2d, 0x4a, 0xd5, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x82, 0xaa, 0xd4, 0x43, 0x53, 0xa9, 0x57, 0x66, 0xa8, 0xd4, + 0xc2, 0xc8, 0xc5, 0xee, 0x06, 0x51, 0x2d, 0x24, 0xcb, 0xc5, 0x95, 0x9c, 0x91, 0x98, 0x97, 0x97, + 0x9a, 0x13, 0x9f, 0x99, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0xc4, 0x09, 0x15, 0xf1, 0x4c, + 0x11, 0x92, 0xe0, 0x62, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x96, 0x60, 0x02, 0xcb, 0xc1, + 0xb8, 0x42, 0x7c, 0x5c, 0x4c, 0x99, 0x29, 0x12, 0xcc, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x4c, 0x99, + 0x29, 0x42, 0xa2, 0x5c, 0x6c, 0x89, 0xc9, 0xd9, 0x20, 0x43, 0x58, 0xc0, 0x62, 0xac, 0x89, 0xc9, + 0xd9, 0x9e, 0x29, 0x42, 0x92, 0x5c, 0x1c, 0x20, 0xe1, 0x92, 0xca, 0x82, 0x54, 0x09, 0x56, 0xa8, + 0x09, 0xc9, 0xd9, 0x21, 0x95, 0x05, 0xa9, 0x4e, 0x61, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, + 0x2c, 0xc7, 0x10, 0x65, 0x93, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, + 0xf5, 0x87, 0x6e, 0x7e, 0x51, 0x3a, 0x8c, 0xad, 0x5f, 0x66, 0xa2, 0x5f, 0x81, 0x11, 0x04, 0x20, + 0x2b, 0x8a, 0xf5, 0xcb, 0x0c, 0x93, 0xd8, 0xc0, 0x21, 0x60, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, + 0xd7, 0xff, 0xd9, 0x5a, 0x2d, 0x01, 0x00, 0x00, +} + +func (m *Failure) 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 *Failure) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Failure) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AckType) > 0 { + i -= len(m.AckType) + copy(dAtA[i:], m.AckType) + i = encodeVarintFailure(dAtA, i, uint64(len(m.AckType))) + i-- + dAtA[i] = 0x2a + } + if m.AckId != 0 { + i = encodeVarintFailure(dAtA, i, uint64(m.AckId)) + i-- + dAtA[i] = 0x20 + } + if m.Id != 0 { + i = encodeVarintFailure(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x18 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintFailure(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintFailure(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintFailure(dAtA []byte, offset int, v uint64) int { + offset -= sovFailure(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Failure) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + if m.Id != 0 { + n += 1 + sovFailure(uint64(m.Id)) + } + if m.AckId != 0 { + n += 1 + sovFailure(uint64(m.AckId)) + } + l = len(m.AckType) + if l > 0 { + n += 1 + l + sovFailure(uint64(l)) + } + return n +} + +func sovFailure(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozFailure(x uint64) (n int) { + return sovFailure(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Failure) 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 ErrIntOverflowFailure + } + 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: Failure: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Failure: 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 ErrIntOverflowFailure + } + 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 ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + 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 Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + 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 ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AckId", wireType) + } + m.AckId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AckId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AckType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFailure + } + 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 ErrInvalidLengthFailure + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFailure + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AckType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipFailure(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFailure + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipFailure(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, ErrIntOverflowFailure + } + 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, ErrIntOverflowFailure + } + 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, ErrIntOverflowFailure + } + 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, ErrInvalidLengthFailure + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupFailure + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthFailure + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthFailure = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowFailure = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupFailure = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/feerefunder/client/cli/query.go b/x/feerefunder/client/cli/query.go new file mode 100644 index 00000000..4b6e3396 --- /dev/null +++ b/x/feerefunder/client/cli/query.go @@ -0,0 +1,63 @@ +package cli + +import ( + "context" + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group feerefunder queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdFeeInfo()) + + return cmd +} + +func CmdFeeInfo() *cobra.Command { + cmd := &cobra.Command{ + Use: "fee-info [port_id] [channel_id] [sequence]", + Short: "queries fee info by port id, channel id and sequence", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + queryClient := types.NewQueryClient(clientCtx) + + sequence, err := strconv.ParseUint(args[2], 10, 64) + if err != nil { + return fmt.Errorf("failed to parse sequence: %w", err) + } + + res, err := queryClient.FeeInfo(context.Background(), &types.FeeInfoRequest{ + ChannelId: args[1], + PortId: args[0], + Sequence: sequence, + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/feerefunder/client/cli/query_params.go b/x/feerefunder/client/cli/query_params.go new file mode 100644 index 00000000..1856da45 --- /dev/null +++ b/x/feerefunder/client/cli/query_params.go @@ -0,0 +1,35 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/feerefunder/client/cli/query_test.go b/x/feerefunder/client/cli/query_test.go new file mode 100644 index 00000000..3665b142 --- /dev/null +++ b/x/feerefunder/client/cli/query_test.go @@ -0,0 +1,68 @@ +package cli_test + +import ( + "testing" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + "cosmossdk.io/math" + + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil/contractmanager/network" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/client/cli" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func feeRefunderNetwork(t *testing.T, feeInfo types.Fee) *network.Network { + t.Helper() + cfg := network.DefaultConfig() + state := types.DefaultGenesis() + require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], state)) + state.FeeInfos = []types.FeeInfo{{ + Payer: "neutron17dtl0mjt3t77kpuhg2edqzjpszulwhgzcdvagh", + PacketId: types.PacketID{ + ChannelId: "channel-0", + PortId: "transfer", + Sequence: 111, + }, + Fee: feeInfo, + }} + buf, err := cfg.Codec.MarshalJSON(state) + require.NoError(t, err) + cfg.GenesisState[types.ModuleName] = buf + return network.New(t, cfg) +} + +func TestQueryFeeInfo(t *testing.T) { + _ = params.GetDefaultConfig() + + feeInfo := types.Fee{ + RecvFee: sdk.NewCoins(), + AckFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(1001))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(2001))), + } + net := feeRefunderNetwork(t, feeInfo) + + ctx := net.Validators[0].ClientCtx + validArgs := []string{ + "transfer", + "channel-0", + "111", + } + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdFeeInfo(), validArgs) + require.NoError(t, err) + var resp types.FeeInfoResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.Equal(t, feeInfo, resp.GetFeeInfo().GetFee()) + + invalidArgs := []string{ + "wrongport", + "channel-0", + "111", + } + _, err = clitestutil.ExecTestCLICmd(ctx, cli.CmdFeeInfo(), invalidArgs) + require.ErrorContains(t, err, "no fee info found for port_id = wrongport, channel_id=channel-0, sequence=111") +} diff --git a/x/feerefunder/genesis.go b/x/feerefunder/genesis.go new file mode 100644 index 00000000..be3dab78 --- /dev/null +++ b/x/feerefunder/genesis.go @@ -0,0 +1,31 @@ +package feerefunder + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/keeper" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // this line is used by starport scaffolding # genesis/module/init + err := k.SetParams(ctx, genState.Params) + if err != nil { + panic(err) + } + + for _, info := range genState.FeeInfos { + k.StoreFeeInfo(ctx, info) + } +} + +// ExportGenesis returns the module's exported genesis +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + genesis.FeeInfos = k.GetAllFeeInfos(ctx) + + return genesis +} diff --git a/x/feerefunder/genesis_test.go b/x/feerefunder/genesis_test.go new file mode 100644 index 00000000..6b811099 --- /dev/null +++ b/x/feerefunder/genesis_test.go @@ -0,0 +1,46 @@ +package feerefunder_test + +import ( + "testing" + + "cosmossdk.io/math" + + "github.com/Nolus-Protocol/nolus-core/app/params" + "github.com/Nolus-Protocol/nolus-core/testutil/feerefunder/keeper" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil/common/nullify" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +const TestContractAddressNeutron = "neutron14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s5c2epq" + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestContractAddressNeutron, + PacketId: types.NewPacketID("port", "channel-1", 64), + Fee: types.Fee{ + RecvFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(0))), + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(types.DefaultFees.AckFee.AmountOf(params.DefaultBondDenom).Int64()+1))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(types.DefaultFees.TimeoutFee.AmountOf(params.DefaultBondDenom).Int64()+1))), + }, + }}, + } + + require.EqualValues(t, genesisState.Params, types.DefaultParams()) + + k, ctx := keeper.FeeKeeper(t, nil, nil) + feerefunder.InitGenesis(ctx, *k, genesisState) + got := feerefunder.ExportGenesis(ctx, *k) + + require.EqualValues(t, got.Params, types.DefaultParams()) + require.NotNil(t, got) + + nullify.Fill(&genesisState) + nullify.Fill(got) +} diff --git a/x/feerefunder/keeper/export_test.go b/x/feerefunder/keeper/export_test.go new file mode 100644 index 00000000..e2aaa39d --- /dev/null +++ b/x/feerefunder/keeper/export_test.go @@ -0,0 +1,11 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func (k Keeper) CheckFees(ctx sdk.Context, fees types.Fee) error { + return k.checkFees(ctx, fees) +} diff --git a/x/feerefunder/keeper/grpc_query.go b/x/feerefunder/keeper/grpc_query.go new file mode 100644 index 00000000..4975e871 --- /dev/null +++ b/x/feerefunder/keeper/grpc_query.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +var _ types.QueryServer = Keeper{} + +func (k Keeper) FeeInfo(goCtx context.Context, request *types.FeeInfoRequest) (*types.FeeInfoResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + feeInfo, err := k.GetFeeInfo(ctx, types.NewPacketID(request.PortId, request.ChannelId, request.Sequence)) + if err != nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "no fee info found for port_id = %s, channel_id=%s, sequence=%d", request.PortId, request.ChannelId, request.Sequence) + } + + return &types.FeeInfoResponse{FeeInfo: feeInfo}, nil +} diff --git a/x/feerefunder/keeper/grpc_query_params.go b/x/feerefunder/keeper/grpc_query_params.go new file mode 100644 index 00000000..bb116159 --- /dev/null +++ b/x/feerefunder/keeper/grpc_query_params.go @@ -0,0 +1,20 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/feerefunder/keeper/grpc_query_params_test.go b/x/feerefunder/keeper/grpc_query_params_test.go new file mode 100644 index 00000000..87422ece --- /dev/null +++ b/x/feerefunder/keeper/grpc_query_params_test.go @@ -0,0 +1,22 @@ +package keeper_test + +import ( + "testing" + + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/feerefunder/keeper" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func TestParamsQuery(t *testing.T) { + keeper, ctx := testkeeper.FeeKeeper(t, nil, nil) + params := types.DefaultParams() + err := keeper.SetParams(ctx, params) + require.NoError(t, err) + + response, err := keeper.Params(ctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) +} diff --git a/x/feerefunder/keeper/keeper.go b/x/feerefunder/keeper/keeper.go new file mode 100644 index 00000000..31e34438 --- /dev/null +++ b/x/feerefunder/keeper/keeper.go @@ -0,0 +1,270 @@ +package keeper + +import ( + "context" + "fmt" + "strconv" + + "cosmossdk.io/errors" + "cosmossdk.io/log" + + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + bankKeeper types.BankKeeper + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + channelKeeper types.ChannelKeeper + authority string + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + channelKeeper types.ChannelKeeper, + bankKeeper types.BankKeeper, + authority string, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + channelKeeper: channelKeeper, + bankKeeper: bankKeeper, + authority: authority, + } +} + +func (k Keeper) GetAuthority() string { + return k.authority +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +func (k Keeper) LockFees(ctx context.Context, payer sdk.AccAddress, packetID types.PacketID, fee types.Fee) error { + c := sdk.UnwrapSDKContext(ctx) + + k.Logger(c).Debug("Trying to lock fees", "packetID", packetID, "fee", fee) + + if _, ok := k.channelKeeper.GetChannel(c, packetID.PortId, packetID.ChannelId); !ok { + return errors.Wrapf(channeltypes.ErrChannelNotFound, "channel with id %s and port %s not found", packetID.ChannelId, packetID.PortId) + } + + if err := k.checkFees(c, fee); err != nil { + return errors.Wrapf(err, "failed to lock fees") + } + + feeInfo := types.FeeInfo{ + Payer: payer.String(), + Fee: fee, + PacketId: packetID, + } + k.StoreFeeInfo(c, feeInfo) + + if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, payer, types.ModuleName, fee.Total()); err != nil { + return errors.Wrapf(err, "failed to send coins during fees locking") + } + + c.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeLockFees, + sdk.NewAttribute(types.AttributeKeyPayer, payer.String()), + sdk.NewAttribute(types.AttributeKeyPortID, packetID.PortId), + sdk.NewAttribute(types.AttributeKeyChannelID, packetID.ChannelId), + sdk.NewAttribute(types.AttributeKeySequence, strconv.FormatUint(packetID.Sequence, 10)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + }) + + return nil +} + +func (k Keeper) DistributeAcknowledgementFee(ctx context.Context, receiver sdk.AccAddress, packetID types.PacketID) { + c := sdk.UnwrapSDKContext(ctx) + + k.Logger(c).Debug("Trying to distribute ack fee", "packetID", packetID) + feeInfo, err := k.GetFeeInfo(c, packetID) + if err != nil { + k.Logger(c).Error("no fee info", "error", err) + panic(errors.Wrapf(err, "no fee info")) + } + + // try to distribute ack fee + if err := k.distributeFee(c, receiver, feeInfo.Fee.AckFee); err != nil { + k.Logger(c).Error("error distributing ack fee", "receiver", receiver, "payer", feeInfo.Payer, "packet", packetID) + panic(errors.Wrapf(err, "error distributing ack fee: receiver = %s, packetID=%v", receiver, packetID)) + } + + // try to return unused timeout fee + if err := k.distributeFee(c, sdk.MustAccAddressFromBech32(feeInfo.Payer), feeInfo.Fee.TimeoutFee); err != nil { + k.Logger(c).Error("error returning unused timeout fee", "receiver", feeInfo.Payer, "packet", packetID) + panic(errors.Wrapf(err, "error distributing unused timeout fee: receiver = %s, packetID=%v", feeInfo.Payer, packetID)) + } + + c.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeDistributeAcknowledgementFee, + sdk.NewAttribute(types.AttributeKeyReceiver, receiver.String()), + sdk.NewAttribute(types.AttributeKeyPortID, packetID.PortId), + sdk.NewAttribute(types.AttributeKeyChannelID, packetID.ChannelId), + sdk.NewAttribute(types.AttributeKeySequence, strconv.FormatUint(packetID.Sequence, 10)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + }) + + k.removeFeeInfo(c, packetID) +} + +func (k Keeper) DistributeTimeoutFee(ctx context.Context, receiver sdk.AccAddress, packetID types.PacketID) { + c := sdk.UnwrapSDKContext(ctx) + + k.Logger(c).Debug("Trying to distribute timeout fee", "packetID", packetID) + feeInfo, err := k.GetFeeInfo(c, packetID) + if err != nil { + k.Logger(c).Error("no fee info", "error", err) + panic(errors.Wrapf(err, "no fee info")) + } + + // try to distribute timeout fee + if err := k.distributeFee(c, receiver, feeInfo.Fee.TimeoutFee); err != nil { + k.Logger(c).Error("error distributing timeout fee", "receiver", receiver, "payer", feeInfo.Payer, "packet", packetID) + panic(errors.Wrapf(err, "error distributing timeout fee: receiver = %s, packetID=%v", receiver, packetID)) + } + + // try to return unused ack fee + if err := k.distributeFee(c, sdk.MustAccAddressFromBech32(feeInfo.Payer), feeInfo.Fee.AckFee); err != nil { + k.Logger(c).Error("error returning unused ack fee", "receiver", feeInfo.Payer, "packet", packetID) + panic(errors.Wrapf(err, "error distributing unused ack fee: receiver = %s, packetID=%v", feeInfo.Payer, packetID)) + } + + c.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeDistributeTimeoutFee, + sdk.NewAttribute(types.AttributeKeyReceiver, receiver.String()), + sdk.NewAttribute(types.AttributeKeyPortID, packetID.PortId), + sdk.NewAttribute(types.AttributeKeyChannelID, packetID.ChannelId), + sdk.NewAttribute(types.AttributeKeySequence, strconv.FormatUint(packetID.Sequence, 10)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + }) + + k.removeFeeInfo(c, packetID) +} + +func (k Keeper) GetFeeInfo(ctx sdk.Context, packetID types.PacketID) (*types.FeeInfo, error) { + store := ctx.KVStore(k.storeKey) + + var feeInfo types.FeeInfo + bzFeeInfo := store.Get(types.GetFeePacketKey(packetID)) + if bzFeeInfo == nil { + return nil, errors.Wrapf(sdkerrors.ErrKeyNotFound, "no fee info for the given channelID = %s, portID = %s and sequence = %d", packetID.ChannelId, packetID.PortId, packetID.Sequence) + } + k.cdc.MustUnmarshal(bzFeeInfo, &feeInfo) + + return &feeInfo, nil +} + +func (k Keeper) GetAllFeeInfos(ctx sdk.Context) []types.FeeInfo { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.FeeKey) + + infos := make([]types.FeeInfo, 0) + + iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var info types.FeeInfo + k.cdc.MustUnmarshal(iterator.Value(), &info) + infos = append(infos, info) + } + + return infos +} + +func (k Keeper) StoreFeeInfo(ctx sdk.Context, feeInfo types.FeeInfo) { + store := ctx.KVStore(k.storeKey) + + bzFeeInfo := k.cdc.MustMarshal(&feeInfo) + store.Set(types.GetFeePacketKey(feeInfo.PacketId), bzFeeInfo) +} + +func (k Keeper) GetMinFee(ctx sdk.Context) types.Fee { + params := k.GetParams(ctx) + return params.GetMinFee() +} + +func (k Keeper) removeFeeInfo(ctx sdk.Context, packetID types.PacketID) { + store := ctx.KVStore(k.storeKey) + + store.Delete(types.GetFeePacketKey(packetID)) +} + +func (k Keeper) checkFees(ctx sdk.Context, fees types.Fee) error { + params := k.GetParams(ctx) + + if !fees.TimeoutFee.IsAnyGTE(params.MinFee.TimeoutFee) { + return errors.Wrapf(sdkerrors.ErrInsufficientFee, "provided timeout fee is less than min governance set timeout fee: %v < %v", fees.TimeoutFee, params.MinFee.TimeoutFee) + } + + if !fees.AckFee.IsAnyGTE(params.MinFee.AckFee) { + return errors.Wrapf(sdkerrors.ErrInsufficientFee, "provided ack fee is less than min governance set ack fee: %v < %v", fees.AckFee, params.MinFee.AckFee) + } + + if allowedCoins(fees.TimeoutFee, params.MinFee.TimeoutFee) { + return errors.Wrapf(sdkerrors.ErrInvalidCoins, "timeout fee cannot have coins other than in params") + } + + if allowedCoins(fees.AckFee, params.MinFee.AckFee) { + return errors.Wrapf(sdkerrors.ErrInvalidCoins, "ack fee cannot have coins other than in params") + } + + // we don't allow users to set recv fees, because we can't refund relayers for such messages + if !fees.RecvFee.IsZero() { + return errors.Wrapf(sdkerrors.ErrInvalidCoins, "recv fee must be zero") + } + + return nil +} + +func (k Keeper) distributeFee(ctx sdk.Context, receiver sdk.AccAddress, fee sdk.Coins) error { + err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiver, fee) + if err != nil { + k.Logger(ctx).Error("error distributing fee", "receiver address", receiver, "fee", fee) + return errors.Wrapf(err, "error distributing fee to a receiver: %s", receiver.String()) + } + return nil +} + +// allowedCoins returns true if one or more coins from `fees` are not present in coins from `params` +// assumes that `params` is sorted +func allowedCoins(fees, params sdk.Coins) bool { + for _, fee := range fees { + if params.AmountOf(fee.Denom).IsZero() { + return true + } + } + return false +} diff --git a/x/feerefunder/keeper/keeper_test.go b/x/feerefunder/keeper/keeper_test.go new file mode 100644 index 00000000..faf45591 --- /dev/null +++ b/x/feerefunder/keeper/keeper_test.go @@ -0,0 +1,351 @@ +package keeper_test + +import ( + "fmt" + "strconv" + "testing" + + "cosmossdk.io/math" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + + "github.com/Nolus-Protocol/nolus-core/testutil" + testutil_keeper "github.com/Nolus-Protocol/nolus-core/testutil/feerefunder/keeper" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/feerefunder/types" + + cosmoserrors "cosmossdk.io/errors" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/pkg/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +const ( + TestAddress = "neutron17dtl0mjt3t77kpuhg2edqzjpszulwhgzcdvagh" +) + +func TestKeeperCheckFees(t *testing.T) { + k, ctx := testutil_keeper.FeeKeeper(t, nil, nil) + + err := k.SetParams(ctx, types.Params{ + MinFee: types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(100)), sdk.NewCoin("denom2", math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(100)), sdk.NewCoin("denom2", math.NewInt(100))), + }, + }) + require.NoError(t, err) + + for _, tc := range []struct { + desc string + fees *types.Fee + minFees types.Fee + err *cosmoserrors.Error + }{ + { + desc: "SingleProperDenomInsufficient", + fees: &types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(1))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(1))), + }, + err: sdkerrors.ErrInsufficientFee, + }, + { + desc: "SufficientTimeout-InsufficientAck", + fees: &types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(1))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + }, + err: sdkerrors.ErrInsufficientFee, + }, + { + desc: "NonNilRecvFee", + fees: &types.Fee{ + RecvFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + }, + err: sdkerrors.ErrInvalidCoins, + }, + { + desc: "SingleDenomSufficient", + fees: &types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + }, + err: nil, + }, + { + desc: "MultipleDenomsOneIsEnough", + fees: &types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101)), sdk.NewCoin("denom2", math.NewInt(1))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101)), sdk.NewCoin("denom2", math.NewInt(1))), + }, + err: nil, + }, + { + desc: "NoProperDenom", + fees: &types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom3", math.NewInt(1))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom3", math.NewInt(1))), + }, + err: sdkerrors.ErrInsufficientFee, + }, + { + desc: "ProperDenomPlusRandomAckOne", + fees: &types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101)), sdk.NewCoin("denom3", math.NewInt(1))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + }, + err: sdkerrors.ErrInvalidCoins, + }, + { + desc: "ProperDenomPlusRandomTimeoutOne", + fees: &types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101)), sdk.NewCoin("denom3", math.NewInt(1))), + }, + err: sdkerrors.ErrInvalidCoins, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := k.CheckFees(ctx, *tc.fees) + if tc.err == nil { + require.NoError(t, err) + } else { + require.Error(t, err) + require.Equal(t, tc.err.Error(), errors.Unwrap(err).Error()) + } + }) + } +} + +func TestKeeperLockFees(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + channelKeeper := mock_types.NewMockChannelKeeper(ctrl) + k, ctx := testutil_keeper.FeeKeeper(t, channelKeeper, bankKeeper) + + payer := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + + err := k.SetParams(ctx, types.Params{ + MinFee: types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(100)), sdk.NewCoin("denom2", math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(100)), sdk.NewCoin("denom2", math.NewInt(100))), + }, + }) + require.NoError(t, err) + + packet := types.PacketID{ + ChannelId: "channel-0", + PortId: "transfer", + Sequence: 111, + } + + channelKeeper.EXPECT().GetChannel(ctx, packet.PortId, packet.ChannelId).Return(channeltypes.Channel{}, false) + err = k.LockFees(ctx, payer, packet, types.Fee{}) + require.True(t, channeltypes.ErrChannelNotFound.Is(err)) + + channelKeeper.EXPECT().GetChannel(ctx, packet.PortId, packet.ChannelId).Return(channeltypes.Channel{}, true) + err = k.LockFees(ctx, payer, packet, types.Fee{}) + require.True(t, sdkerrors.ErrInsufficientFee.Is(err)) + + validFee := types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("denom1", math.NewInt(101))), + } + channelKeeper.EXPECT().GetChannel(ctx, packet.PortId, packet.ChannelId).Return(channeltypes.Channel{}, true) + bankKeeper.EXPECT().SendCoinsFromAccountToModule(ctx, payer, types.ModuleName, validFee.Total()).Return(fmt.Errorf("bank error")) + err = k.LockFees(ctx, payer, packet, validFee) + require.ErrorContains(t, err, "bank error") + + channelKeeper.EXPECT().GetChannel(ctx, packet.PortId, packet.ChannelId).Return(channeltypes.Channel{}, true) + bankKeeper.EXPECT().SendCoinsFromAccountToModule(ctx, payer, types.ModuleName, validFee.Total()).Return(nil) + err = k.LockFees(ctx, payer, packet, validFee) + require.NoError(t, err) + require.Equal(t, sdk.Events{ + sdk.NewEvent( + types.EventTypeLockFees, + sdk.NewAttribute(types.AttributeKeyPayer, payer.String()), + sdk.NewAttribute(types.AttributeKeyPortID, packet.PortId), + sdk.NewAttribute(types.AttributeKeyChannelID, packet.ChannelId), + sdk.NewAttribute(types.AttributeKeySequence, strconv.FormatUint(packet.Sequence, 10)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + }, ctx.EventManager().Events()) +} + +func TestDistributeAcknowledgementFee(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + channelKeeper := mock_types.NewMockChannelKeeper(ctrl) + k, ctx := testutil_keeper.FeeKeeper(t, channelKeeper, bankKeeper) + + validFee := types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(1001))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(2001))), + } + packet := types.PacketID{ + ChannelId: "channel-0", + PortId: "transfer", + Sequence: 111, + } + payer := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + receiver := sdk.MustAccAddressFromBech32(TestAddress) + + // prepare the fees we want to distribute + k.StoreFeeInfo(ctx, types.FeeInfo{ + Payer: payer.String(), + Fee: validFee, + PacketId: packet, + }) + + invalidPacket := types.PacketID{ + ChannelId: "channel-0", + PortId: "transfer", + Sequence: 1, + } + panicErrorToCatch := errors.Wrapf(errors.Wrapf(sdkerrors.ErrKeyNotFound, "no fee info for the given channelID = %s, portID = %s and sequence = %d", invalidPacket.ChannelId, invalidPacket.PortId, invalidPacket.Sequence), "no fee info") + assert.PanicsWithError(t, panicErrorToCatch.Error(), func() { k.DistributeAcknowledgementFee(ctx, receiver, invalidPacket) }) + + panicErrorToCatch = errors.Wrapf(errors.Wrapf(fmt.Errorf("bank module error"), "error distributing fee to a receiver: %s", receiver.String()), "error distributing ack fee: receiver = %s, packetID=%v", receiver, packet) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiver, validFee.AckFee).Return(fmt.Errorf("bank module error")) + assert.PanicsWithError(t, panicErrorToCatch.Error(), func() { k.DistributeAcknowledgementFee(ctx, receiver, packet) }) + + panicErrorToCatch = errors.Wrapf(errors.Wrapf(fmt.Errorf("bank module error"), "error distributing fee to a receiver: %s", payer.String()), "error distributing unused timeout fee: receiver = %s, packetID=%v", receiver, packet) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiver, validFee.AckFee).Return(nil) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, payer, validFee.TimeoutFee).Return(fmt.Errorf("bank module error")) + assert.PanicsWithError(t, panicErrorToCatch.Error(), func() { k.DistributeAcknowledgementFee(ctx, receiver, packet) }) + + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiver, validFee.AckFee).Return(nil) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, payer, validFee.TimeoutFee).Return(nil) + assert.NotPanics(t, func() { k.DistributeAcknowledgementFee(ctx, receiver, packet) }) + require.Equal(t, sdk.Events{ + sdk.NewEvent( + types.EventTypeDistributeAcknowledgementFee, + sdk.NewAttribute(types.AttributeKeyReceiver, TestAddress), + sdk.NewAttribute(types.AttributeKeyPortID, packet.PortId), + sdk.NewAttribute(types.AttributeKeyChannelID, packet.ChannelId), + sdk.NewAttribute(types.AttributeKeySequence, strconv.FormatUint(packet.Sequence, 10)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + }, ctx.EventManager().Events()) + + feeInfo, err := k.GetFeeInfo(ctx, packet) + require.Nil(t, feeInfo) + require.ErrorContains(t, err, "no fee info") +} + +func TestDistributeTimeoutFee(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + channelKeeper := mock_types.NewMockChannelKeeper(ctrl) + k, ctx := testutil_keeper.FeeKeeper(t, channelKeeper, bankKeeper) + + validFee := types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(1001))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(2001))), + } + packet := types.PacketID{ + ChannelId: "channel-0", + PortId: "transfer", + Sequence: 111, + } + payer := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + receiver := sdk.MustAccAddressFromBech32(TestAddress) + + // prepare the fees we want to distribute + k.StoreFeeInfo(ctx, types.FeeInfo{ + Payer: payer.String(), + Fee: validFee, + PacketId: packet, + }) + + invalidPacket := types.PacketID{ + ChannelId: "channel-0", + PortId: "transfer", + Sequence: 1, + } + panicErrorToCatch := errors.Wrapf(errors.Wrapf(sdkerrors.ErrKeyNotFound, "no fee info for the given channelID = %s, portID = %s and sequence = %d", invalidPacket.ChannelId, invalidPacket.PortId, invalidPacket.Sequence), "no fee info") + assert.PanicsWithError(t, panicErrorToCatch.Error(), func() { k.DistributeTimeoutFee(ctx, receiver, invalidPacket) }) + + panicErrorToCatch = errors.Wrapf(errors.Wrapf(fmt.Errorf("bank module error"), "error distributing fee to a receiver: %s", receiver.String()), "error distributing timeout fee: receiver = %s, packetID=%v", receiver, packet) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiver, validFee.TimeoutFee).Return(fmt.Errorf("bank module error")) + assert.PanicsWithError(t, panicErrorToCatch.Error(), func() { k.DistributeTimeoutFee(ctx, receiver, packet) }) + + panicErrorToCatch = errors.Wrapf(errors.Wrapf(fmt.Errorf("bank module error"), "error distributing fee to a receiver: %s", payer.String()), "error distributing unused ack fee: receiver = %s, packetID=%v", receiver, packet) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiver, validFee.TimeoutFee).Return(nil) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, payer, validFee.AckFee).Return(fmt.Errorf("bank module error")) + assert.PanicsWithError(t, panicErrorToCatch.Error(), func() { k.DistributeTimeoutFee(ctx, receiver, packet) }) + + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiver, validFee.TimeoutFee).Return(nil) + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, types.ModuleName, payer, validFee.AckFee).Return(nil) + assert.NotPanics(t, func() { k.DistributeTimeoutFee(ctx, receiver, packet) }) + require.Equal(t, sdk.Events{ + sdk.NewEvent( + types.EventTypeDistributeTimeoutFee, + sdk.NewAttribute(types.AttributeKeyReceiver, receiver.String()), + sdk.NewAttribute(types.AttributeKeyPortID, packet.PortId), + sdk.NewAttribute(types.AttributeKeyChannelID, packet.ChannelId), + sdk.NewAttribute(types.AttributeKeySequence, strconv.FormatUint(packet.Sequence, 10)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + ), + }, ctx.EventManager().Events()) + + feeInfo, err := k.GetFeeInfo(ctx, packet) + require.Nil(t, feeInfo) + require.ErrorContains(t, err, "no fee info") +} + +func TestFeeInfo(t *testing.T) { + k, ctx := testutil_keeper.FeeKeeper(t, nil, nil) + validFee := types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(1001))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin("untrn", math.NewInt(1001))), + } + for i := uint64(0); i < 1000; i++ { + packet := types.PacketID{ + ChannelId: "channel-0", + PortId: "transfer", + Sequence: i, + } + payer := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + + k.StoreFeeInfo(ctx, types.FeeInfo{ + Payer: payer.String(), + Fee: validFee, + PacketId: packet, + }) + } + infos := k.GetAllFeeInfos(ctx) + require.Equal(t, 1000, len(infos)) +} diff --git a/x/feerefunder/keeper/msg_server.go b/x/feerefunder/keeper/msg_server.go new file mode 100644 index 00000000..17458d63 --- /dev/null +++ b/x/feerefunder/keeper/msg_server.go @@ -0,0 +1,42 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// UpdateParams updates the module parameters +func (k Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgUpdateParams") + } + + authority := k.GetAuthority() + if authority != req.Authority { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.SetParams(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/feerefunder/keeper/msg_server_test.go b/x/feerefunder/keeper/msg_server_test.go new file mode 100644 index 00000000..91b05b14 --- /dev/null +++ b/x/feerefunder/keeper/msg_server_test.go @@ -0,0 +1,129 @@ +package keeper_test + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/app/params" + "github.com/Nolus-Protocol/nolus-core/testutil" + "github.com/Nolus-Protocol/nolus-core/testutil/feerefunder/keeper" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func TestMsgUpdateParamsValidate(t *testing.T) { + k, ctx := keeper.FeeKeeper(t, nil, nil) + + tests := []struct { + name string + msg types.MsgUpdateParams + expectedErr string + }{ + { + "empty authority", + types.MsgUpdateParams{ + Authority: "", + }, + "authority is invalid", + }, + { + "invalid authority", + types.MsgUpdateParams{ + Authority: "invalid authority", + }, + "authority is invalid", + }, + { + "invalid ack fee", + types.MsgUpdateParams{ + Authority: testutil.TestOwnerAddress, + Params: types.Params{ + MinFee: types.Fee{ + RecvFee: nil, + AckFee: sdk.Coins{ + { + Denom: "{}!@#a", + Amount: math.NewInt(100), + }, + }, + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + }, + sdkerrors.ErrInvalidCoins.Error(), + }, + { + "invalid timeout fee", + types.MsgUpdateParams{ + Authority: testutil.TestOwnerAddress, + Params: types.Params{ + MinFee: types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.Coins{ + { + Denom: params.DefaultBondDenom, + Amount: math.NewInt(-100), + }, + }, + }, + }, + }, + sdkerrors.ErrInvalidCoins.Error(), + }, + { + "non-zero recv fee", + types.MsgUpdateParams{ + Authority: testutil.TestOwnerAddress, + Params: types.Params{ + MinFee: types.Fee{ + RecvFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + }, + sdkerrors.ErrInvalidCoins.Error(), + }, + { + "zero ack fee", + types.MsgUpdateParams{ + Authority: testutil.TestOwnerAddress, + Params: types.Params{ + MinFee: types.Fee{ + RecvFee: nil, + AckFee: nil, + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + }, + sdkerrors.ErrInvalidCoins.Error(), + }, + { + "zero timeout fee", + types.MsgUpdateParams{ + Authority: testutil.TestOwnerAddress, + Params: types.Params{ + MinFee: types.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: nil, + }, + }, + }, + sdkerrors.ErrInvalidCoins.Error(), + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := k.UpdateParams(ctx, &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} diff --git a/x/feerefunder/keeper/params.go b/x/feerefunder/keeper/params.go new file mode 100644 index 00000000..614bd03a --- /dev/null +++ b/x/feerefunder/keeper/params.go @@ -0,0 +1,31 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + + store.Set(types.ParamsKey, bz) + return nil +} diff --git a/x/feerefunder/keeper/params_test.go b/x/feerefunder/keeper/params_test.go new file mode 100644 index 00000000..5ea363ef --- /dev/null +++ b/x/feerefunder/keeper/params_test.go @@ -0,0 +1,23 @@ +package keeper_test + +import ( + "testing" + + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/feerefunder/keeper" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +func TestGetParams(t *testing.T) { + k, ctx := testkeeper.FeeKeeper(t, nil, nil) + params := types.DefaultParams() + + err := k.SetParams(ctx, params) + if err != nil { + panic(err) + } + + require.EqualValues(t, params, k.GetParams(ctx)) +} diff --git a/x/feerefunder/module.go b/x/feerefunder/module.go new file mode 100644 index 00000000..de59070f --- /dev/null +++ b/x/feerefunder/module.go @@ -0,0 +1,169 @@ +package feerefunder + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + + // this line is used by starport scaffolding # 1 + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/client/cli" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/keeper" + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +var ( + _ appmodule.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func (a AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +var _ appmodule.AppModule = AppModule{} + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() { // marker +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() { // marker +} + +// Deprecated: use RegisterServices +func (AppModule) QuerierRoute() string { return types.RouterKey } + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return types.ConsensusVersion } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(_ sdk.Context) {} + +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(_ sdk.Context) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/feerefunder/types/codec.go b/x/feerefunder/types/codec.go new file mode 100644 index 00000000..81d2f74b --- /dev/null +++ b/x/feerefunder/types/codec.go @@ -0,0 +1,25 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgUpdateParams{}, "neutron.feerefunder.MsgUpdateParams", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgUpdateParams{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/feerefunder/types/constants.go b/x/feerefunder/types/constants.go new file mode 100644 index 00000000..6bad94d0 --- /dev/null +++ b/x/feerefunder/types/constants.go @@ -0,0 +1,3 @@ +package types + +const ConsensusVersion = 1 diff --git a/x/feerefunder/types/events.go b/x/feerefunder/types/events.go new file mode 100644 index 00000000..e1b28b86 --- /dev/null +++ b/x/feerefunder/types/events.go @@ -0,0 +1,14 @@ +package types + +// feerefunder module event types +const ( + EventTypeDistributeAcknowledgementFee = "distribute_ack_fee" + EventTypeDistributeTimeoutFee = "distribute_timeout_fee" + EventTypeLockFees = "lock_fees" + + AttributeKeyReceiver = "receiver" + AttributeKeyChannelID = "channel_id" + AttributeKeyPortID = "port_id" + AttributeKeySequence = "sequence" + AttributeKeyPayer = "payer" +) diff --git a/x/feerefunder/types/expected_keepers.go b/x/feerefunder/types/expected_keepers.go new file mode 100644 index 00000000..dacf78d4 --- /dev/null +++ b/x/feerefunder/types/expected_keepers.go @@ -0,0 +1,28 @@ +package types + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error + HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool + SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + // Methods imported from bank should be defined here +} + +// ChannelKeeper defines the expected IBC channel keeper +type ChannelKeeper interface { + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) +} diff --git a/x/feerefunder/types/fee.go b/x/feerefunder/types/fee.go new file mode 100644 index 00000000..a3e09440 --- /dev/null +++ b/x/feerefunder/types/fee.go @@ -0,0 +1,60 @@ +package types + +import ( + "strings" + + "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func NewPacketID(portID, channelID string, sequence uint64) PacketID { + return PacketID{ + ChannelId: channelID, + PortId: portID, + Sequence: sequence, + } +} + +// NewFee creates and returns a new Fee struct encapsulating the receive, acknowledgement and timeout fees as sdk.Coins +func NewFee(recvFee, ackFee, timeoutFee sdk.Coins) Fee { + return Fee{ + RecvFee: recvFee, + AckFee: ackFee, + TimeoutFee: timeoutFee, + } +} + +// Total returns the total amount for a given Fee +func (m Fee) Total() sdk.Coins { + return m.RecvFee.Add(m.AckFee...).Add(m.TimeoutFee...) +} + +// Validate asserts that each Fee is valid: +// * RecvFee must be zero; +// * AckFee and TimeoutFee must be non-zero +func (m Fee) Validate() error { + var errFees []string + if !m.AckFee.IsValid() { + errFees = append(errFees, "ack fee is invalid") + } + if !m.TimeoutFee.IsValid() { + errFees = append(errFees, "timeout fee invalid") + } + + if len(errFees) > 0 { + return errors.Wrapf(sdkerrors.ErrInvalidCoins, "contains invalid fees: %s", strings.Join(errFees, " , ")) + } + + if !m.RecvFee.IsZero() { + return errors.Wrapf(sdkerrors.ErrInvalidCoins, "recv fee must be zero") + } + + // if ack or timeout fees are zero or empty return an error + if m.AckFee.IsZero() || m.TimeoutFee.IsZero() { + return errors.Wrap(sdkerrors.ErrInvalidCoins, "ack fee or timeout fee is zero") + } + + return nil +} diff --git a/x/feerefunder/types/fee.pb.go b/x/feerefunder/types/fee.pb.go new file mode 100644 index 00000000..e69c1410 --- /dev/null +++ b/x/feerefunder/types/fee.pb.go @@ -0,0 +1,727 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/feerefunder/fee.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 + +// Fee defines the ICS29 receive, acknowledgement and timeout fees +type Fee struct { + // the packet receive fee + RecvFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=recv_fee,json=recvFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"recv_fee" yaml:"recv_fee"` + // the packet acknowledgement fee + AckFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=ack_fee,json=ackFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"ack_fee" yaml:"ack_fee"` + // the packet timeout fee + TimeoutFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=timeout_fee,json=timeoutFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"timeout_fee" yaml:"timeout_fee"` +} + +func (m *Fee) Reset() { *m = Fee{} } +func (m *Fee) String() string { return proto.CompactTextString(m) } +func (*Fee) ProtoMessage() {} +func (*Fee) Descriptor() ([]byte, []int) { + return fileDescriptor_08c389f5f82f1076, []int{0} +} +func (m *Fee) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Fee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Fee.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 *Fee) XXX_Merge(src proto.Message) { + xxx_messageInfo_Fee.Merge(m, src) +} +func (m *Fee) XXX_Size() int { + return m.Size() +} +func (m *Fee) XXX_DiscardUnknown() { + xxx_messageInfo_Fee.DiscardUnknown(m) +} + +var xxx_messageInfo_Fee proto.InternalMessageInfo + +func (m *Fee) GetRecvFee() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.RecvFee + } + return nil +} + +func (m *Fee) GetAckFee() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.AckFee + } + return nil +} + +func (m *Fee) GetTimeoutFee() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.TimeoutFee + } + return nil +} + +type PacketID struct { + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + PortId string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + Sequence uint64 `protobuf:"varint,3,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *PacketID) Reset() { *m = PacketID{} } +func (m *PacketID) String() string { return proto.CompactTextString(m) } +func (*PacketID) ProtoMessage() {} +func (*PacketID) Descriptor() ([]byte, []int) { + return fileDescriptor_08c389f5f82f1076, []int{1} +} +func (m *PacketID) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PacketID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PacketID.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 *PacketID) XXX_Merge(src proto.Message) { + xxx_messageInfo_PacketID.Merge(m, src) +} +func (m *PacketID) XXX_Size() int { + return m.Size() +} +func (m *PacketID) XXX_DiscardUnknown() { + xxx_messageInfo_PacketID.DiscardUnknown(m) +} + +var xxx_messageInfo_PacketID proto.InternalMessageInfo + +func (m *PacketID) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *PacketID) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *PacketID) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +func init() { + proto.RegisterType((*Fee)(nil), "neutron.feerefunder.Fee") + proto.RegisterType((*PacketID)(nil), "neutron.feerefunder.PacketID") +} + +func init() { proto.RegisterFile("neutron/feerefunder/fee.proto", fileDescriptor_08c389f5f82f1076) } + +var fileDescriptor_08c389f5f82f1076 = []byte{ + // 384 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xbd, 0x6e, 0xe2, 0x40, + 0x14, 0x85, 0x3d, 0xb0, 0xe2, 0x67, 0x90, 0x76, 0x25, 0xef, 0x4a, 0xcb, 0x22, 0x61, 0x90, 0x2b, + 0x37, 0x78, 0xc4, 0xfe, 0x34, 0x5b, 0x42, 0x84, 0x44, 0x95, 0x88, 0x32, 0x45, 0x90, 0x3d, 0xbe, + 0x18, 0xcb, 0x78, 0x86, 0xd8, 0x63, 0x2b, 0xb4, 0x79, 0x82, 0x3c, 0x47, 0x9e, 0x84, 0x92, 0x32, + 0x15, 0x89, 0xe0, 0x0d, 0xd2, 0x47, 0x8a, 0xc6, 0x1e, 0x22, 0x52, 0x21, 0xaa, 0x39, 0x33, 0x47, + 0xe7, 0x7c, 0x77, 0xa4, 0x8b, 0xdb, 0x0c, 0x52, 0x11, 0x73, 0x46, 0x66, 0x00, 0x31, 0xcc, 0x52, + 0xe6, 0x41, 0x2c, 0xb5, 0xbd, 0x8c, 0xb9, 0xe0, 0xfa, 0x77, 0x65, 0xdb, 0x47, 0x76, 0xcb, 0xa0, + 0x3c, 0x89, 0x78, 0x42, 0x5c, 0x27, 0x01, 0x92, 0xf5, 0x5d, 0x10, 0x4e, 0x9f, 0x50, 0x1e, 0xb0, + 0x22, 0xd4, 0xfa, 0xe1, 0x73, 0x9f, 0xe7, 0x92, 0x48, 0x55, 0xbc, 0x9a, 0x6f, 0x25, 0x5c, 0x1e, + 0x01, 0xe8, 0x2b, 0x5c, 0x8b, 0x81, 0x66, 0xd3, 0x19, 0x40, 0x13, 0x75, 0xcb, 0x56, 0xe3, 0xf7, + 0x2f, 0xbb, 0x28, 0xb4, 0x65, 0xa1, 0xad, 0x0a, 0xed, 0x21, 0x0f, 0xd8, 0x60, 0xb8, 0xde, 0x76, + 0xb4, 0xd7, 0x6d, 0xe7, 0xdb, 0xca, 0x89, 0x16, 0xff, 0xcd, 0x43, 0xd0, 0x7c, 0x7c, 0xee, 0x58, + 0x7e, 0x20, 0xe6, 0xa9, 0x6b, 0x53, 0x1e, 0x11, 0x35, 0x50, 0x71, 0xf4, 0x12, 0x2f, 0x24, 0x62, + 0xb5, 0x84, 0x24, 0xef, 0x48, 0x26, 0x55, 0x19, 0x93, 0xe8, 0x0c, 0x57, 0x1d, 0x1a, 0xe6, 0xe4, + 0xd2, 0x29, 0xf2, 0x40, 0x91, 0xbf, 0x16, 0x64, 0x95, 0x3b, 0x0f, 0x5c, 0x71, 0x68, 0x28, 0xb9, + 0xf7, 0x08, 0x37, 0x44, 0x10, 0x01, 0x4f, 0x45, 0x0e, 0x2f, 0x9f, 0x82, 0x8f, 0x14, 0x5c, 0x2f, + 0xe0, 0x47, 0xd9, 0xf3, 0x06, 0xc0, 0x2a, 0x39, 0x02, 0x30, 0x6f, 0x70, 0xed, 0xca, 0xa1, 0x21, + 0x88, 0xf1, 0x85, 0xde, 0xc6, 0x98, 0xce, 0x1d, 0xc6, 0x60, 0x31, 0x0d, 0xbc, 0x26, 0xea, 0x22, + 0xab, 0x3e, 0xa9, 0xab, 0x97, 0xb1, 0xa7, 0xff, 0xc4, 0xd5, 0x25, 0x8f, 0x85, 0xf4, 0x4a, 0xb9, + 0x57, 0x91, 0xd7, 0xb1, 0xa7, 0xb7, 0x70, 0x2d, 0x81, 0xdb, 0x14, 0x18, 0x95, 0x9f, 0x40, 0xd6, + 0x97, 0xc9, 0xc7, 0x7d, 0x70, 0xb9, 0xde, 0x19, 0x68, 0xb3, 0x33, 0xd0, 0xcb, 0xce, 0x40, 0x0f, + 0x7b, 0x43, 0xdb, 0xec, 0x0d, 0xed, 0x69, 0x6f, 0x68, 0xd7, 0xff, 0x8e, 0xe6, 0x55, 0xfb, 0xd4, + 0xe3, 0xb1, 0x7f, 0xd0, 0x24, 0xfb, 0x4b, 0xee, 0x3e, 0xed, 0x5f, 0xfe, 0x05, 0xb7, 0x92, 0xef, + 0xcd, 0x9f, 0xf7, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x9c, 0xd3, 0x7d, 0xa3, 0x02, 0x00, 0x00, +} + +func (m *Fee) 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 *Fee) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Fee) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.TimeoutFee) > 0 { + for iNdEx := len(m.TimeoutFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TimeoutFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.AckFee) > 0 { + for iNdEx := len(m.AckFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AckFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.RecvFee) > 0 { + for iNdEx := len(m.RecvFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RecvFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintFee(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *PacketID) 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 *PacketID) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PacketID) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintFee(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x18 + } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintFee(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintFee(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintFee(dAtA []byte, offset int, v uint64) int { + offset -= sovFee(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Fee) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.RecvFee) > 0 { + for _, e := range m.RecvFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } + } + if len(m.AckFee) > 0 { + for _, e := range m.AckFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } + } + if len(m.TimeoutFee) > 0 { + for _, e := range m.TimeoutFee { + l = e.Size() + n += 1 + l + sovFee(uint64(l)) + } + } + return n +} + +func (m *PacketID) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovFee(uint64(l)) + } + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovFee(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovFee(uint64(m.Sequence)) + } + return n +} + +func sovFee(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozFee(x uint64) (n int) { + return sovFee(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Fee) 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 ErrIntOverflowFee + } + 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: Fee: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Fee: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RecvFee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFee + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthFee + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RecvFee = append(m.RecvFee, types.Coin{}) + if err := m.RecvFee[len(m.RecvFee)-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 AckFee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFee + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthFee + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AckFee = append(m.AckFee, types.Coin{}) + if err := m.AckFee[len(m.AckFee)-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 TimeoutFee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFee + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthFee + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TimeoutFee = append(m.TimeoutFee, types.Coin{}) + if err := m.TimeoutFee[len(m.TimeoutFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipFee(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFee + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PacketID) 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 ErrIntOverflowFee + } + 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: PacketID: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PacketID: 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 ErrIntOverflowFee + } + 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 ErrInvalidLengthFee + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFee + } + 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 PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFee + } + 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 ErrInvalidLengthFee + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFee + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = 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 ErrIntOverflowFee + } + 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 := skipFee(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFee + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipFee(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, ErrIntOverflowFee + } + 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, ErrIntOverflowFee + } + 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, ErrIntOverflowFee + } + 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, ErrInvalidLengthFee + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupFee + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthFee + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthFee = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowFee = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupFee = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/feerefunder/types/genesis.go b/x/feerefunder/types/genesis.go new file mode 100644 index 00000000..a37d1ed3 --- /dev/null +++ b/x/feerefunder/types/genesis.go @@ -0,0 +1,48 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/errors" + + // this line is used by starport scaffolding # genesis/types/import + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" +) + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + for _, info := range gs.FeeInfos { + addr, err := sdk.AccAddressFromBech32(info.Payer) + if err != nil { + return fmt.Errorf("failed to parse the payer address %s: %w", info.Payer, err) + } + + if len(addr) != wasmtypes.ContractAddrLen { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "fee payer address %s is not a contract", info.Payer) + } + + if err := host.PortIdentifierValidator(info.PacketId.PortId); err != nil { + return fmt.Errorf("port id %s is invalid: %w", info.PacketId.PortId, err) + } + + if err := host.ChannelIdentifierValidator(info.PacketId.ChannelId); err != nil { + return fmt.Errorf("channel id %s is invalid: %w", info.PacketId.PortId, err) + } + + if err := info.Fee.Validate(); err != nil { + return fmt.Errorf("invalid fees %s: %w", info.Fee, err) + } + } + return gs.Params.Validate() +} diff --git a/x/feerefunder/types/genesis.pb.go b/x/feerefunder/types/genesis.pb.go new file mode 100644 index 00000000..800255d3 --- /dev/null +++ b/x/feerefunder/types/genesis.pb.go @@ -0,0 +1,667 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/feerefunder/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 fee module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + FeeInfos []FeeInfo `protobuf:"bytes,2,rep,name=fee_infos,json=feeInfos,proto3" json:"fee_infos"` +} + +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_43aedfe31f06653d, []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) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetFeeInfos() []FeeInfo { + if m != nil { + return m.FeeInfos + } + return nil +} + +type FeeInfo struct { + Payer string `protobuf:"bytes,1,opt,name=payer,proto3" json:"payer,omitempty"` + PacketId PacketID `protobuf:"bytes,2,opt,name=packet_id,json=packetId,proto3" json:"packet_id"` + Fee Fee `protobuf:"bytes,3,opt,name=fee,proto3" json:"fee"` +} + +func (m *FeeInfo) Reset() { *m = FeeInfo{} } +func (m *FeeInfo) String() string { return proto.CompactTextString(m) } +func (*FeeInfo) ProtoMessage() {} +func (*FeeInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_43aedfe31f06653d, []int{1} +} +func (m *FeeInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FeeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FeeInfo.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 *FeeInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_FeeInfo.Merge(m, src) +} +func (m *FeeInfo) XXX_Size() int { + return m.Size() +} +func (m *FeeInfo) XXX_DiscardUnknown() { + xxx_messageInfo_FeeInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_FeeInfo proto.InternalMessageInfo + +func (m *FeeInfo) GetPayer() string { + if m != nil { + return m.Payer + } + return "" +} + +func (m *FeeInfo) GetPacketId() PacketID { + if m != nil { + return m.PacketId + } + return PacketID{} +} + +func (m *FeeInfo) GetFee() Fee { + if m != nil { + return m.Fee + } + return Fee{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "neutron.feerefunder.GenesisState") + proto.RegisterType((*FeeInfo)(nil), "neutron.feerefunder.FeeInfo") +} + +func init() { proto.RegisterFile("neutron/feerefunder/genesis.proto", fileDescriptor_43aedfe31f06653d) } + +var fileDescriptor_43aedfe31f06653d = []byte{ + // 314 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4f, 0x02, 0x31, + 0x14, 0xc6, 0xaf, 0xa0, 0x28, 0xc5, 0xa9, 0x32, 0x5c, 0x50, 0x2a, 0x32, 0xb1, 0x78, 0x35, 0xa8, + 0x83, 0x93, 0x86, 0x18, 0x0d, 0x93, 0x06, 0x37, 0x17, 0x72, 0xc0, 0xeb, 0x79, 0x31, 0xb4, 0x97, + 0x5e, 0x31, 0xf2, 0x2f, 0x38, 0x99, 0xf8, 0x4f, 0x31, 0x32, 0x3a, 0x19, 0xc3, 0xfd, 0x23, 0xe6, + 0xda, 0x92, 0x68, 0x72, 0x6c, 0xef, 0xe5, 0xfb, 0x7d, 0xef, 0xfb, 0xf2, 0xf0, 0xb1, 0x80, 0x99, + 0x56, 0x52, 0x30, 0x0e, 0xa0, 0x80, 0xcf, 0xc4, 0x04, 0x14, 0x8b, 0x40, 0x40, 0x1a, 0xa7, 0x41, + 0xa2, 0xa4, 0x96, 0x64, 0xdf, 0x21, 0xc1, 0x1f, 0xa4, 0x51, 0x8f, 0x64, 0x24, 0x8d, 0xce, 0xf2, + 0xc9, 0xa2, 0x8d, 0x66, 0xd1, 0x35, 0x0e, 0xe0, 0xe4, 0x56, 0x91, 0x9c, 0x84, 0x2a, 0x9c, 0xba, + 0xac, 0xf6, 0x3b, 0xc2, 0x7b, 0x77, 0x36, 0xfd, 0x51, 0x87, 0x1a, 0xc8, 0x25, 0xae, 0x58, 0xc0, + 0x47, 0x2d, 0xd4, 0xa9, 0x75, 0x0f, 0x82, 0x82, 0x36, 0xc1, 0x83, 0x41, 0x7a, 0x5b, 0x8b, 0xef, + 0x23, 0x6f, 0xe0, 0x0c, 0xe4, 0x0a, 0x57, 0x39, 0xc0, 0x30, 0x16, 0x5c, 0xa6, 0x7e, 0xa9, 0x55, + 0xee, 0xd4, 0xba, 0x87, 0x85, 0xee, 0x5b, 0x80, 0xbe, 0xe0, 0xd2, 0xd9, 0x77, 0xb9, 0x5d, 0xd3, + 0xf6, 0x27, 0xc2, 0x3b, 0x4e, 0x23, 0x75, 0xbc, 0x9d, 0x84, 0x73, 0x50, 0xa6, 0x46, 0x75, 0x60, + 0x17, 0x72, 0x8d, 0xab, 0x49, 0x38, 0x7e, 0x01, 0x3d, 0x8c, 0x27, 0x7e, 0xc9, 0x14, 0x6c, 0x6e, + 0x28, 0x98, 0x53, 0xfd, 0x9b, 0x75, 0x86, 0x75, 0xf5, 0x27, 0xe4, 0x14, 0x97, 0x39, 0x80, 0x5f, + 0x36, 0x5e, 0x7f, 0x53, 0x3d, 0x67, 0xcb, 0xd1, 0xde, 0xfd, 0x62, 0x45, 0xd1, 0x72, 0x45, 0xd1, + 0xcf, 0x8a, 0xa2, 0x8f, 0x8c, 0x7a, 0xcb, 0x8c, 0x7a, 0x5f, 0x19, 0xf5, 0x9e, 0x2e, 0xa2, 0x58, + 0x3f, 0xcf, 0x46, 0xc1, 0x58, 0x4e, 0x99, 0x3b, 0x74, 0x22, 0x55, 0xb4, 0x9e, 0xd9, 0xeb, 0x39, + 0x7b, 0xfb, 0xf7, 0x7a, 0x3d, 0x4f, 0x20, 0x1d, 0x55, 0xcc, 0xeb, 0xcf, 0x7e, 0x03, 0x00, 0x00, + 0xff, 0xff, 0xeb, 0xe0, 0x85, 0x41, 0x0b, 0x02, 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.FeeInfos) > 0 { + for iNdEx := len(m.FeeInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FeeInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.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 *FeeInfo) 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 *FeeInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FeeInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.PacketId.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Payer) > 0 { + i -= len(m.Payer) + copy(dAtA[i:], m.Payer) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Payer))) + 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 = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.FeeInfos) > 0 { + for _, e := range m.FeeInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *FeeInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Payer) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.PacketId.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.Fee.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 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 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeeInfos", 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.FeeInfos = append(m.FeeInfos, FeeInfo{}) + if err := m.FeeInfos[len(m.FeeInfos)-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 *FeeInfo) 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: FeeInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FeeInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payer", 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.Payer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PacketId", 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.PacketId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Fee", 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.Fee.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/x/feerefunder/types/genesis_test.go b/x/feerefunder/types/genesis_test.go new file mode 100644 index 00000000..d6b15631 --- /dev/null +++ b/x/feerefunder/types/genesis_test.go @@ -0,0 +1,192 @@ +package types_test + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +const ( + TestAddressNeutron = "neutron13xvjxhkkxxhztcugr6weyt76eedj5ucpt4xluv" + TestContractAddressJuno = "juno10h0hc64jv006rr8qy0zhlu4jsxct8qwa0vtaleayh0ujz0zynf2s2r7v8q" + TestContractAddressNeutron = "neutron14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s5c2epq" +) + +func TestGenesisState_Validate(t *testing.T) { + cfg := params.GetDefaultConfig() + cfg.Seal() + + validRecvFee := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(0))) + validAckFee := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(types.DefaultFees.AckFee.AmountOf(params.DefaultBondDenom).Int64()+1))) + validTimeoutFee := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(types.DefaultFees.TimeoutFee.AmountOf(params.DefaultBondDenom).Int64()+1))) + + invalidRecvFee := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(1))) + + validPacketID := types.NewPacketID("port", "channel-1", 64) + + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + expectedErrorMsg string + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + expectedErrorMsg: "", + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestContractAddressNeutron, + PacketId: validPacketID, + Fee: types.Fee{ + RecvFee: validRecvFee, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: true, + expectedErrorMsg: "", + }, + { + desc: "invalid payer address", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: "address", + PacketId: validPacketID, + Fee: types.Fee{ + RecvFee: validRecvFee, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: false, + expectedErrorMsg: "failed to parse the payer address", + }, + { + desc: "payer is not a contract", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestAddressNeutron, + PacketId: validPacketID, + Fee: types.Fee{ + RecvFee: validRecvFee, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: false, + expectedErrorMsg: "is not a contract", + }, + { + desc: "payer is from a wrong chain", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestContractAddressJuno, + PacketId: validPacketID, + Fee: types.Fee{ + RecvFee: validRecvFee, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: false, + expectedErrorMsg: "failed to parse the payer address", + }, + { + desc: "invalid port", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestContractAddressNeutron, + PacketId: types.NewPacketID("*", "channel", 64), + Fee: types.Fee{ + RecvFee: validRecvFee, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: false, + expectedErrorMsg: "port id", + }, + { + desc: "invalid channel", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestContractAddressNeutron, + PacketId: types.NewPacketID("port", "*", 64), + Fee: types.Fee{ + RecvFee: validRecvFee, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: false, + expectedErrorMsg: "channel id", + }, + { + desc: "Recv fee non-zero", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestContractAddressNeutron, + PacketId: validPacketID, + Fee: types.Fee{ + RecvFee: invalidRecvFee, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: false, + expectedErrorMsg: "invalid fees", + }, + { + desc: "Recv fee nil", + genState: &types.GenesisState{ + Params: types.DefaultParams(), + FeeInfos: []types.FeeInfo{{ + Payer: TestContractAddressNeutron, + PacketId: validPacketID, + Fee: types.Fee{ + RecvFee: nil, + AckFee: validAckFee, + TimeoutFee: validTimeoutFee, + }, + }}, + }, + valid: true, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErrorMsg) + } + }) + } +} diff --git a/x/feerefunder/types/keys.go b/x/feerefunder/types/keys.go new file mode 100644 index 00000000..9c99c59b --- /dev/null +++ b/x/feerefunder/types/keys.go @@ -0,0 +1,33 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +const ( + // ModuleName defines the module name + ModuleName = "feerefunder" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_" + ModuleName +) + +const ( + prefixFeeKey = iota + 1 + prefixParamsKey + + Separator = ";" +) + +var ( + FeeKey = []byte{prefixFeeKey} + ParamsKey = []byte{prefixParamsKey} +) + +func GetFeePacketKey(packet PacketID) []byte { + return append(append(FeeKey, []byte(packet.ChannelId+Separator+packet.PortId+Separator)...), sdk.Uint64ToBigEndian(packet.Sequence)...) +} diff --git a/x/feerefunder/types/params.go b/x/feerefunder/types/params.go new file mode 100644 index 00000000..b5aaa8d3 --- /dev/null +++ b/x/feerefunder/types/params.go @@ -0,0 +1,63 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" + + "github.com/Nolus-Protocol/nolus-core/app/params" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +var ( + KeyFees = []byte("FEES") + DefaultFees = Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + } +) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable(paramtypes.NewParamSetPair(KeyFees, DefaultFees, validateFee)) +} + +// NewParams creates a new Params instance +func NewParams(minfee Fee) Params { + return Params{MinFee: minfee} +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams(DefaultFees) +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{paramtypes.NewParamSetPair(KeyFees, &p.MinFee, validateFee)} +} + +// Validate validates the set of params +func (p Params) Validate() error { + return p.MinFee.Validate() +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +func validateFee(i interface{}) error { + v, ok := i.(Fee) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return v.Validate() +} diff --git a/x/feerefunder/types/params.pb.go b/x/feerefunder/types/params.pb.go new file mode 100644 index 00000000..62f1e84f --- /dev/null +++ b/x/feerefunder/types/params.pb.go @@ -0,0 +1,321 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/feerefunder/params.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 + +// Params defines the parameters for the module. +type Params struct { + MinFee Fee `protobuf:"bytes,1,opt,name=min_fee,json=minFee,proto3" json:"min_fee"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_2dae67276ca81c89, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMinFee() Fee { + if m != nil { + return m.MinFee + } + return Fee{} +} + +func init() { + proto.RegisterType((*Params)(nil), "neutron.feerefunder.Params") +} + +func init() { proto.RegisterFile("neutron/feerefunder/params.proto", fileDescriptor_2dae67276ca81c89) } + +var fileDescriptor_2dae67276ca81c89 = []byte{ + // 207 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc8, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0x4b, 0x4d, 0x2d, 0x4a, 0x4d, 0x2b, 0xcd, 0x4b, 0x49, 0x2d, 0xd2, + 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xaa, + 0xd0, 0x43, 0x52, 0x21, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x96, 0xd7, 0x07, 0xb1, 0x20, 0x4a, + 0xa5, 0x64, 0xb1, 0x19, 0x96, 0x96, 0x9a, 0x0a, 0x91, 0x56, 0x72, 0xe7, 0x62, 0x0b, 0x00, 0x9b, + 0x2c, 0x64, 0xce, 0xc5, 0x9e, 0x9b, 0x99, 0x17, 0x9f, 0x96, 0x9a, 0x2a, 0xc1, 0xa8, 0xc0, 0xa8, + 0xc1, 0x6d, 0x24, 0xa1, 0x87, 0xc5, 0x16, 0x3d, 0xb7, 0xd4, 0x54, 0x27, 0x96, 0x13, 0xf7, 0xe4, + 0x19, 0x82, 0xd8, 0x72, 0x33, 0xf3, 0xdc, 0x52, 0x53, 0xad, 0x58, 0x66, 0x2c, 0x90, 0x67, 0x70, + 0xf2, 0x3f, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, + 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xd3, 0xf4, 0xcc, 0x92, + 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0xa8, 0x89, 0xba, 0xf9, 0x45, 0xe9, 0x30, 0xb6, + 0x7e, 0x99, 0x89, 0x7e, 0x05, 0x8a, 0xeb, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x0e, + 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x22, 0x03, 0x03, 0x97, 0x0e, 0x01, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.MinFee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.MinFee.Size() + n += 1 + l + sovParams(uint64(l)) + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinFee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/feerefunder/types/query.pb.go b/x/feerefunder/types/query.pb.go new file mode 100644 index 00000000..fe73033b --- /dev/null +++ b/x/feerefunder/types/query.pb.go @@ -0,0 +1,1018 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/feerefunder/query.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// 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 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_c20b5686ec46d4e6, []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 response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +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_c20b5686ec46d4e6, []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() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type FeeInfoRequest struct { + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + PortId string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + Sequence uint64 `protobuf:"varint,3,opt,name=sequence,proto3" json:"sequence,omitempty"` +} + +func (m *FeeInfoRequest) Reset() { *m = FeeInfoRequest{} } +func (m *FeeInfoRequest) String() string { return proto.CompactTextString(m) } +func (*FeeInfoRequest) ProtoMessage() {} +func (*FeeInfoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c20b5686ec46d4e6, []int{2} +} +func (m *FeeInfoRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FeeInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FeeInfoRequest.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 *FeeInfoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_FeeInfoRequest.Merge(m, src) +} +func (m *FeeInfoRequest) XXX_Size() int { + return m.Size() +} +func (m *FeeInfoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_FeeInfoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_FeeInfoRequest proto.InternalMessageInfo + +func (m *FeeInfoRequest) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func (m *FeeInfoRequest) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *FeeInfoRequest) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + +type FeeInfoResponse struct { + FeeInfo *FeeInfo `protobuf:"bytes,1,opt,name=fee_info,json=feeInfo,proto3" json:"fee_info,omitempty"` +} + +func (m *FeeInfoResponse) Reset() { *m = FeeInfoResponse{} } +func (m *FeeInfoResponse) String() string { return proto.CompactTextString(m) } +func (*FeeInfoResponse) ProtoMessage() {} +func (*FeeInfoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c20b5686ec46d4e6, []int{3} +} +func (m *FeeInfoResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FeeInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FeeInfoResponse.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 *FeeInfoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_FeeInfoResponse.Merge(m, src) +} +func (m *FeeInfoResponse) XXX_Size() int { + return m.Size() +} +func (m *FeeInfoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_FeeInfoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_FeeInfoResponse proto.InternalMessageInfo + +func (m *FeeInfoResponse) GetFeeInfo() *FeeInfo { + if m != nil { + return m.FeeInfo + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "neutron.feerefunder.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "neutron.feerefunder.QueryParamsResponse") + proto.RegisterType((*FeeInfoRequest)(nil), "neutron.feerefunder.FeeInfoRequest") + proto.RegisterType((*FeeInfoResponse)(nil), "neutron.feerefunder.FeeInfoResponse") +} + +func init() { proto.RegisterFile("neutron/feerefunder/query.proto", fileDescriptor_c20b5686ec46d4e6) } + +var fileDescriptor_c20b5686ec46d4e6 = []byte{ + // 441 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x6b, 0xd4, 0x40, + 0x14, 0xc6, 0x77, 0xd6, 0xba, 0xdb, 0x8e, 0xa0, 0x30, 0x2d, 0x58, 0x62, 0x4d, 0xd7, 0xa8, 0xec, + 0x2a, 0x34, 0x43, 0xab, 0x22, 0x5e, 0x7b, 0x10, 0xd6, 0x8b, 0x35, 0x47, 0x2f, 0x65, 0x92, 0xbc, + 0x4c, 0x03, 0xdd, 0x79, 0xe9, 0xcc, 0xa4, 0xd8, 0xab, 0x5e, 0x3d, 0x08, 0x5e, 0xfd, 0x83, 0x7a, + 0x2c, 0x78, 0xf1, 0x24, 0xb2, 0xeb, 0x1f, 0x22, 0x99, 0x4c, 0x8b, 0xc5, 0xd8, 0xde, 0x66, 0xde, + 0xfb, 0xbe, 0x6f, 0x7e, 0xef, 0x25, 0x74, 0x53, 0x41, 0x6d, 0x35, 0x2a, 0x5e, 0x00, 0x68, 0x28, + 0x6a, 0x95, 0x83, 0xe6, 0x47, 0x35, 0xe8, 0x93, 0xb8, 0xd2, 0x68, 0x91, 0xad, 0x7a, 0x41, 0xfc, + 0x97, 0x20, 0x78, 0x9a, 0xa1, 0x99, 0xa1, 0xe1, 0xa9, 0x30, 0xd0, 0xaa, 0xf9, 0xf1, 0x76, 0x0a, + 0x56, 0x6c, 0xf3, 0x4a, 0xc8, 0x52, 0x09, 0x5b, 0xa2, 0x6a, 0x03, 0x82, 0x35, 0x89, 0x12, 0xdd, + 0x91, 0x37, 0x27, 0x5f, 0xdd, 0x90, 0x88, 0xf2, 0x10, 0xb8, 0xa8, 0x4a, 0x2e, 0x94, 0x42, 0xeb, + 0x2c, 0xc6, 0x77, 0x1f, 0x74, 0x51, 0x49, 0x50, 0x60, 0xca, 0x73, 0xc9, 0xa8, 0x4b, 0x52, 0x09, + 0x2d, 0x66, 0x5e, 0x11, 0xad, 0x51, 0xf6, 0xae, 0x41, 0xdb, 0x73, 0xc5, 0x04, 0x8e, 0x6a, 0x30, + 0x36, 0xda, 0xa3, 0xab, 0x97, 0xaa, 0xa6, 0x42, 0x65, 0x80, 0xbd, 0xa2, 0x83, 0xd6, 0xbc, 0x4e, + 0x46, 0x64, 0x72, 0x6b, 0xe7, 0x5e, 0xdc, 0x31, 0x77, 0xdc, 0x9a, 0x76, 0x97, 0x4e, 0x7f, 0x6e, + 0xf6, 0x12, 0x6f, 0x88, 0x72, 0x7a, 0xfb, 0x35, 0xc0, 0x54, 0x15, 0xe8, 0xdf, 0x60, 0xf7, 0x29, + 0xcd, 0x0e, 0x84, 0x52, 0x70, 0xb8, 0x5f, 0xe6, 0x2e, 0x70, 0x25, 0x59, 0xf1, 0x95, 0x69, 0xce, + 0xee, 0xd2, 0x61, 0x85, 0xda, 0x36, 0xbd, 0xbe, 0xeb, 0x0d, 0x9a, 0xeb, 0x34, 0x67, 0x01, 0x5d, + 0x36, 0x4d, 0x84, 0xca, 0x60, 0xfd, 0xc6, 0x88, 0x4c, 0x96, 0x92, 0x8b, 0x7b, 0xf4, 0x86, 0xde, + 0xb9, 0x78, 0xc5, 0x33, 0xbf, 0xa4, 0xcb, 0x05, 0xc0, 0x7e, 0xa9, 0x0a, 0xf4, 0xd4, 0x1b, 0x9d, + 0xd4, 0xe7, 0xbe, 0x61, 0xd1, 0x1e, 0x76, 0xbe, 0xf5, 0xe9, 0x4d, 0xb7, 0x04, 0xf6, 0x99, 0xd0, + 0x41, 0x3b, 0x14, 0x1b, 0x77, 0x7a, 0xff, 0xdd, 0x60, 0x30, 0xb9, 0x5e, 0xd8, 0x02, 0x46, 0xfc, + 0xe3, 0xf7, 0xdf, 0x5f, 0xfb, 0x4f, 0xd8, 0x98, 0x7b, 0xc7, 0x16, 0x6a, 0xc9, 0xff, 0xff, 0xe1, + 0xd8, 0x27, 0x42, 0x87, 0x9e, 0x96, 0x3d, 0xbc, 0x72, 0x16, 0xcf, 0xf2, 0xe8, 0x6a, 0x91, 0xe7, + 0xd8, 0x72, 0x1c, 0x63, 0xf6, 0xf8, 0x5a, 0x8e, 0x66, 0x97, 0xbb, 0x6f, 0x4f, 0xe7, 0x21, 0x39, + 0x9b, 0x87, 0xe4, 0xd7, 0x3c, 0x24, 0x5f, 0x16, 0x61, 0xef, 0x6c, 0x11, 0xf6, 0x7e, 0x2c, 0xc2, + 0xde, 0xfb, 0x17, 0xb2, 0xb4, 0x07, 0x75, 0x1a, 0x67, 0x38, 0xeb, 0x8c, 0x3a, 0x7e, 0xce, 0x3f, + 0x5c, 0xca, 0xb3, 0x27, 0x15, 0x98, 0x74, 0xe0, 0x7e, 0xc8, 0x67, 0x7f, 0x02, 0x00, 0x00, 0xff, + 0xff, 0xa5, 0xf2, 0x80, 0x6c, 0x6d, 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 + +// 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 { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + FeeInfo(ctx context.Context, in *FeeInfoRequest, opts ...grpc.CallOption) (*FeeInfoResponse, 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, "/neutron.feerefunder.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) FeeInfo(ctx context.Context, in *FeeInfoRequest, opts ...grpc.CallOption) (*FeeInfoResponse, error) { + out := new(FeeInfoResponse) + err := c.cc.Invoke(ctx, "/neutron.feerefunder.Query/FeeInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + FeeInfo(context.Context, *FeeInfoRequest) (*FeeInfoResponse, 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) FeeInfo(ctx context.Context, req *FeeInfoRequest) (*FeeInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method FeeInfo 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: "/neutron.feerefunder.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_FeeInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FeeInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).FeeInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.feerefunder.Query/FeeInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).FeeInfo(ctx, req.(*FeeInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.feerefunder.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "FeeInfo", + Handler: _Query_FeeInfo_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/feerefunder/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 + { + 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 *FeeInfoRequest) 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 *FeeInfoRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FeeInfoRequest) 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.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.PortId))) + 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 *FeeInfoResponse) 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 *FeeInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FeeInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.FeeInfo != nil { + { + size, err := m.FeeInfo.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 + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *FeeInfoRequest) 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)) + } + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Sequence != 0 { + n += 1 + sovQuery(uint64(m.Sequence)) + } + return n +} + +func (m *FeeInfoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.FeeInfo != nil { + l = m.FeeInfo.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 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 *FeeInfoRequest) 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: FeeInfoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FeeInfoRequest: 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 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 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 *FeeInfoResponse) 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: FeeInfoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FeeInfoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeeInfo", 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.FeeInfo == nil { + m.FeeInfo = &FeeInfo{} + } + if err := m.FeeInfo.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/x/feerefunder/types/query.pb.gw.go b/x/feerefunder/types/query.pb.gw.go new file mode 100644 index 00000000..5dce6d4e --- /dev/null +++ b/x/feerefunder/types/query.pb.gw.go @@ -0,0 +1,236 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: neutron/feerefunder/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 + +} + +var ( + filter_Query_FeeInfo_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_FeeInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq FeeInfoRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_FeeInfo_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.FeeInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_FeeInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq FeeInfoRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_FeeInfo_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.FeeInfo(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_FeeInfo_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_FeeInfo_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_FeeInfo_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_FeeInfo_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_FeeInfo_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_FeeInfo_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}, []string{"neutron-org", "neutron", "feerefunder", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_FeeInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"neutron-org", "neutron", "feerefunder", "info"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_FeeInfo_0 = runtime.ForwardResponseMessage +) diff --git a/x/feerefunder/types/tx.go b/x/feerefunder/types/tx.go new file mode 100644 index 00000000..be7e7250 --- /dev/null +++ b/x/feerefunder/types/tx.go @@ -0,0 +1,40 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +func (msg *MsgUpdateParams) Type() string { + return "update-params" +} + +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgUpdateParams) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgUpdateParams) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errorsmod.Wrap(err, "authority is invalid") + } + + if err := msg.Params.MinFee.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/feerefunder/types/tx.pb.go b/x/feerefunder/types/tx.pb.go new file mode 100644 index 00000000..8aaab733 --- /dev/null +++ b/x/feerefunder/types/tx.pb.go @@ -0,0 +1,599 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/feerefunder/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-proto" + _ "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" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// 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 + +// MsgUpdateParams is the MsgUpdateParams request type. +// +// Since: 0.47 +type MsgUpdateParams struct { + // Authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/feerefunder parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_2e613aff856d34ed, []int{0} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2e613aff856d34ed, []int{1} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "neutron.feerefunder.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "neutron.feerefunder.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("neutron/feerefunder/tx.proto", fileDescriptor_2e613aff856d34ed) } + +var fileDescriptor_2e613aff856d34ed = []byte{ + // 347 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xc9, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0x4f, 0x4b, 0x4d, 0x2d, 0x4a, 0x4d, 0x2b, 0xcd, 0x4b, 0x49, 0x2d, 0xd2, + 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xca, 0xea, 0x21, 0xc9, 0x4a, + 0x09, 0x26, 0xe6, 0x66, 0xe6, 0xe5, 0xeb, 0x83, 0x49, 0x88, 0x3a, 0x29, 0xf1, 0xe4, 0xfc, 0xe2, + 0xdc, 0xfc, 0x62, 0xfd, 0xdc, 0xe2, 0x74, 0xfd, 0x32, 0x43, 0x10, 0x05, 0x95, 0x90, 0x84, 0x48, + 0xc4, 0x83, 0x79, 0xfa, 0x10, 0x0e, 0x54, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0x22, 0x0e, 0x62, + 0x41, 0x45, 0x15, 0xb0, 0xb9, 0xa7, 0x20, 0xb1, 0x28, 0x31, 0x17, 0xaa, 0x4f, 0x69, 0x27, 0x23, + 0x17, 0xbf, 0x6f, 0x71, 0x7a, 0x68, 0x41, 0x4a, 0x62, 0x49, 0x6a, 0x00, 0x58, 0x46, 0xc8, 0x8c, + 0x8b, 0x33, 0xb1, 0xb4, 0x24, 0x23, 0xbf, 0x28, 0xb3, 0xa4, 0x52, 0x82, 0x51, 0x81, 0x51, 0x83, + 0xd3, 0x49, 0xe2, 0xd2, 0x16, 0x5d, 0x11, 0xa8, 0x85, 0x8e, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, + 0xc1, 0x25, 0x45, 0x99, 0x79, 0xe9, 0x41, 0x08, 0xa5, 0x42, 0x76, 0x5c, 0x6c, 0x10, 0xb3, 0x25, + 0x98, 0x14, 0x18, 0x35, 0xb8, 0x8d, 0xa4, 0xf5, 0xb0, 0x78, 0x58, 0x0f, 0x62, 0x89, 0x13, 0xe7, + 0x89, 0x7b, 0xf2, 0x0c, 0x2b, 0x9e, 0x6f, 0xd0, 0x62, 0x0c, 0x82, 0xea, 0xb2, 0xd2, 0x6b, 0x7a, + 0xbe, 0x41, 0x0b, 0x61, 0x5e, 0xd7, 0xf3, 0x0d, 0x5a, 0xd2, 0xc8, 0x0e, 0x47, 0x73, 0xa7, 0x92, + 0x24, 0x97, 0x38, 0x9a, 0x50, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x51, 0x01, 0x17, + 0xb3, 0x6f, 0x71, 0xba, 0x50, 0x12, 0x17, 0x0f, 0x8a, 0xcf, 0x54, 0xb0, 0xba, 0x08, 0xcd, 0x10, + 0x29, 0x1d, 0x62, 0x54, 0xc1, 0xac, 0x92, 0x62, 0x6d, 0x00, 0x79, 0xc2, 0xc9, 0xff, 0xc4, 0x23, + 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, + 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x4c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, + 0x92, 0xf3, 0x73, 0xf5, 0xa1, 0x06, 0xeb, 0xe6, 0x17, 0xa5, 0xc3, 0xd8, 0xfa, 0x65, 0x26, 0xfa, + 0x15, 0xa8, 0x09, 0xa6, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0x41, 0xc6, 0x80, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xb2, 0x97, 0x0b, 0xe2, 0x54, 0x02, 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 { + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/neutron.feerefunder.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.feerefunder.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.feerefunder.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/feerefunder/tx.proto", +} + +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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 *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + 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 *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 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.Params.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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 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/x/interchainqueries/client/cli/query.go b/x/interchainqueries/client/cli/query.go new file mode 100644 index 00000000..3cf84df5 --- /dev/null +++ b/x/interchainqueries/client/cli/query.go @@ -0,0 +1,157 @@ +package cli + +import ( + "context" + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +const ( + flagOwners = "owners" + flagConnectionID = "connection_id" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group interchainqueries queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdQueryRegisteredQueries()) + cmd.AddCommand(CmdQueryRegisteredQuery()) + cmd.AddCommand(CmdQueryRegisteredQueryResult()) + cmd.AddCommand(CmdQueryLastRemoteHeight()) + + return cmd +} + +func CmdQueryRegisteredQuery() *cobra.Command { + cmd := &cobra.Command{ + Use: "registered-query [id]", + Short: "queries registered interchain query by id", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + queryClient := types.NewQueryClient(clientCtx) + + queryID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return fmt.Errorf("failed to parse query id: %w", err) + } + + res, err := queryClient.RegisteredQuery(context.Background(), &types.QueryRegisteredQueryRequest{QueryId: queryID}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryRegisteredQueries() *cobra.Command { + cmd := &cobra.Command{ + Use: "registered-queries", + Short: "queries all the interchain queries in the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + owners, _ := cmd.Flags().GetStringArray(flagOwners) + connectionID, _ := cmd.Flags().GetString(flagConnectionID) + + res, err := queryClient.RegisteredQueries(context.Background(), &types.QueryRegisteredQueriesRequest{ + Pagination: pageReq, + Owners: owners, + ConnectionId: connectionID, + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + cmd.Flags().StringArray(flagOwners, []string{}, "(optional) filter by query owners") + cmd.Flags().String(flagConnectionID, "", "(optional) filter by connection id") + flags.AddPaginationFlagsToCmd(cmd, "registered queries") + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryRegisteredQueryResult() *cobra.Command { + cmd := &cobra.Command{ + Use: "query-result [query-id]", + Short: "queries result for registered query", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + queryID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return fmt.Errorf("failed to parse query id: %w", err) + } + + res, err := queryClient.QueryResult(context.Background(), &types.QueryRegisteredQueryResultRequest{QueryId: queryID}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryLastRemoteHeight() *cobra.Command { + cmd := &cobra.Command{ + Use: "query-last-remote-height [connection-id]", + Short: "queries last remote height by connection id", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + connectionID := args[0] + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.LastRemoteHeight(context.Background(), &types.QueryLastRemoteHeight{ConnectionId: connectionID}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/interchainqueries/client/cli/query_params.go b/x/interchainqueries/client/cli/query_params.go new file mode 100644 index 00000000..e39a4a2d --- /dev/null +++ b/x/interchainqueries/client/cli/query_params.go @@ -0,0 +1,35 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/interchainqueries/client/cli/tx.go b/x/interchainqueries/client/cli/tx.go new file mode 100644 index 00000000..2c87a749 --- /dev/null +++ b/x/interchainqueries/client/cli/tx.go @@ -0,0 +1,99 @@ +package cli + +import ( + "encoding/json" + "fmt" + "os" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(SubmitQueryResultCmd()) + cmd.AddCommand(RemoveInterchainQueryCmd()) + + return cmd +} + +func RemoveInterchainQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "remove-interchain-query [query-id]", + Short: "Remove interchain query", + Aliases: []string{"remove", "r"}, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + sender := clientCtx.GetFromAddress().String() + queryID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return fmt.Errorf("failed to parse query id: %w", err) + } + + msg := types.NewMsgRemoveInterchainQuery(sender, queryID) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func SubmitQueryResultCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "submit-query-result [query-id] [result-file]", + Short: "Submit query result", + Aliases: []string{"submit", "s"}, + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + sender := clientCtx.GetFromAddress() + queryID, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return fmt.Errorf("failed to parse query id: %w", err) + } + + resultFile := args[1] + + result, err := os.ReadFile(resultFile) + if err != nil { + return fmt.Errorf("failed to read query result file: %w", err) + } + + msg := types.MsgSubmitQueryResult{QueryId: queryID, Sender: string(sender)} + if err := json.Unmarshal(result, &msg.Result); err != nil { + return fmt.Errorf("failed to unmarshal query result: %w", err) + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/interchainqueries/genesis.go b/x/interchainqueries/genesis.go new file mode 100644 index 00000000..baffefc8 --- /dev/null +++ b/x/interchainqueries/genesis.go @@ -0,0 +1,42 @@ +package interchainqueries + +import ( + "sort" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + sort.SliceStable(genState.RegisteredQueries, func(i, j int) bool { + return genState.RegisteredQueries[i].Id < genState.RegisteredQueries[j].Id + }) + + // Set all registered queries + for _, elem := range genState.RegisteredQueries { + k.SetLastRegisteredQueryKey(ctx, elem.Id) + if err := k.SaveQuery(ctx, elem); err != nil { + panic(err) + } + + } + + err := k.SetParams(ctx, genState.Params) + if err != nil { + panic(err) + } +} + +// ExportGenesis returns the capability module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + genesis.RegisteredQueries = k.GetAllRegisteredQueries(ctx) + + return genesis +} diff --git a/x/interchainqueries/genesis_test.go b/x/interchainqueries/genesis_test.go new file mode 100644 index 00000000..6d330af1 --- /dev/null +++ b/x/interchainqueries/genesis_test.go @@ -0,0 +1,299 @@ +package interchainqueries_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil/common/nullify" + keepertest "github.com/Nolus-Protocol/nolus-core/testutil/interchainqueries/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + + RegisteredQueries: []*types.RegisteredQuery{ + { + Id: 4, + }, + { + Id: 3, + }, + { + Id: 2, + }, + { + Id: 1, + }, + }, + } + + require.EqualValues(t, genesisState.Params, types.DefaultParams()) + + k, ctx := keepertest.InterchainQueriesKeeper(t, nil, nil, nil, nil) + interchainqueries.InitGenesis(ctx, *k, genesisState) + got := interchainqueries.ExportGenesis(ctx, *k) + lastQueryID := k.GetLastRegisteredQueryKey(ctx) + + require.EqualValues(t, got.Params, types.DefaultParams()) + require.NotNil(t, got) + require.EqualValues(t, 4, lastQueryID) + + nullify.Fill(&genesisState) + nullify.Fill(got) + + require.ElementsMatch(t, genesisState.RegisteredQueries, got.RegisteredQueries) +} + +func TestGenesisNullQueries(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + } + + k, ctx := keepertest.InterchainQueriesKeeper(t, nil, nil, nil, nil) + interchainqueries.InitGenesis(ctx, *k, genesisState) + got := interchainqueries.ExportGenesis(ctx, *k) + + require.ElementsMatch(t, genesisState.RegisteredQueries, got.RegisteredQueries) +} + +func TestGenesisFilledQueries(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + RegisteredQueries: []*types.RegisteredQuery{ + { + Id: 4, + QueryType: "kv", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + Keys: []*types.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + }, + { + Id: 3, + QueryType: "kv", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + Keys: []*types.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + }, + { + Id: 2, + QueryType: "tx", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + TransactionsFilter: `[{"field":"tx.height","op":"Eq","value":1000}]`, + }, + { + Id: 1, + QueryType: "tx", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + TransactionsFilter: `[{"field":"tx.height","op":"Eq","value":1000}]`, + }, + }, + } + + k, ctx := keepertest.InterchainQueriesKeeper(t, nil, nil, nil, nil) + interchainqueries.InitGenesis(ctx, *k, genesisState) + got := interchainqueries.ExportGenesis(ctx, *k) + err := got.Validate() + require.NoError(t, err) + + require.ElementsMatch(t, genesisState.RegisteredQueries, got.RegisteredQueries) +} + +func TestGenesisMalformedQueriesInvalidTxFilter(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + RegisteredQueries: []*types.RegisteredQuery{ + { + Id: 4, + QueryType: "kv", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + Keys: []*types.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + }, + { + Id: 3, + QueryType: "kv", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + Keys: []*types.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + }, + { + Id: 2, + QueryType: "tx", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + TransactionsFilter: `[{"field":"tx.height","op":"Eq","value":1000}]`, + }, + { + Id: 1, + QueryType: "tx", + Owner: "cosmos18g0avxazu3dkgd5n5ea8h8rtl78de0hytsj9vm", + TransactionsFilter: `[{"fi>= limit { + return ids + } + } + if len(ids) == 0 { + return nil + } + return ids +} + +// calculateTxQueryRemoval creates a TxQueryToRemove populated with the data relative to the query +// with the given queryID. The result TxQueryToRemove contains up to the limit tx hashes. If the +// limit is 0, it retrieves all the hashes for the given query. +func (k Keeper) calculateTxQueryRemoval(ctx sdk.Context, queryID, limit uint64) *TxQueryToRemove { + prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetSubmittedTransactionIDForQueryKeyPrefix(queryID)) + iterator := prefixStore.Iterator(nil, nil) + defer iterator.Close() + + result := &TxQueryToRemove{ID: queryID, Hashes: make([][]byte, 0, limit)} + for ; iterator.Valid(); iterator.Next() { + result.Hashes = append(result.Hashes, iterator.Key()) + if limit != 0 && uint64(len(result.Hashes)) >= limit { + result.CompleteRemoval = !iterator.Valid() + return result + } + } + result.CompleteRemoval = true + return result +} + +func (k Keeper) GetAuthority() string { + return k.authority +} + +// TxQueryToRemove contains data related to a single query listed for removal and needed in the +// removal process. +type TxQueryToRemove struct { + // ID is the query ID. + ID uint64 + // Hashes is the list of tx hashes previously submitted for the query. It can be either + // the whole list of tx hashes of the query of only a part of them to fit removal limit. + Hashes [][]byte + // CompleteRemoval represents whether all tx hashes (true) of the query or only a part of + // them (false) are collected in the Hashes field. + CompleteRemoval bool +} diff --git a/x/interchainqueries/keeper/keeper_test.go b/x/interchainqueries/keeper/keeper_test.go new file mode 100644 index 00000000..f259cb1f --- /dev/null +++ b/x/interchainqueries/keeper/keeper_test.go @@ -0,0 +1,1778 @@ +package keeper_test + +import ( + "encoding/hex" + "fmt" + "testing" + + "cosmossdk.io/math" + ibchost "github.com/cosmos/ibc-go/v8/modules/core/exported" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/suite" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + wasmKeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + abci "github.com/cometbft/cometbft/abci/types" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" + + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/Nolus-Protocol/nolus-core/testutil" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/keeper" + iqtypes "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +var reflectContractPath = "../../../wasmbinding/testdata/reflect.wasm" + +type KeeperTestSuite struct { + testutil.IBCConnectionTestSuite +} + +func (suite *KeeperTestSuite) TestRegisterInterchainQuery() { + var msg iqtypes.MsgRegisterInterchainQuery + + tests := []struct { + name string + topupBalance bool + malleate func(sender string) + expectedErr error + }{ + { + "invalid connection", + true, + func(sender string) { + msg = iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: "unknown", + TransactionsFilter: "[]", + Keys: nil, + QueryType: string(iqtypes.InterchainQueryTypeTX), + UpdatePeriod: 1, + Sender: sender, + } + }, + iqtypes.ErrInvalidConnectionID, + }, + { + "insufficient funds for deposit", + false, + func(sender string) { + msg = iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + TransactionsFilter: "[]", + Keys: nil, + QueryType: string(iqtypes.InterchainQueryTypeTX), + UpdatePeriod: 1, + Sender: sender, + } + }, + sdkerrors.ErrInsufficientFunds, + }, + { + "not a contract address", + false, + func(_ string) { + msg = iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + TransactionsFilter: "[]", + Keys: nil, + QueryType: string(iqtypes.InterchainQueryTypeTX), + UpdatePeriod: 1, + Sender: wasmKeeper.RandomAccountAddress(suite.T()).String(), + } + }, + iqtypes.ErrNotContract, + }, + { + "invalid bech32 sender address", + false, + func(_ string) { + msg = iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + TransactionsFilter: "[]", + Keys: nil, + QueryType: string(iqtypes.InterchainQueryTypeTX), + UpdatePeriod: 1, + Sender: "notbech32", + } + }, + sdkerrors.ErrInvalidAddress, + }, + { + "valid", + true, + func(sender string) { + msg = iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + TransactionsFilter: "[]", + Keys: nil, + QueryType: string(iqtypes.InterchainQueryTypeTX), + UpdatePeriod: 1, + Sender: sender, + } + }, + nil, + }, + } + + for _, tt := range tests { + suite.SetupTest() + + var ( + ctx = suite.ChainA.GetContext() + contractOwner = wasmKeeper.RandomAccountAddress(suite.T()) + ) + + // Store code and instantiate reflect contract. + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + contractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(contractAddress) + + err := testutil.SetupICAPath(suite.Path, contractAddress.String()) + suite.Require().NoError(err) + + tt.malleate(contractAddress.String()) + + if tt.topupBalance { + // Top up contract address with native coins for deposit + senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress() + suite.TopUpWallet(ctx, senderAddress, contractAddress) + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, &msg) + + if tt.expectedErr != nil { + suite.Require().ErrorIs(err, tt.expectedErr) + suite.Require().Nil(res) + } else { + query, _ := keeper.Keeper.RegisteredQuery( + suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper, ctx, + &iqtypes.QueryRegisteredQueryRequest{QueryId: 1}) + + suite.Require().Equal(iqtypes.DefaultQueryDeposit, query.RegisteredQuery.Deposit) + suite.Require().Equal(iqtypes.DefaultQuerySubmitTimeout, query.RegisteredQuery.SubmitTimeout) + suite.Require().NoError(err) + suite.Require().NotNil(res) + } + } +} + +func (suite *KeeperTestSuite) TestUpdateInterchainQuery() { + var msg iqtypes.MsgUpdateInterchainQueryRequest + originalKVQuery := iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeKV), + Keys: []*iqtypes.KVKey{ + { + Path: "somepath", + Key: []byte("somedata"), + }, + }, + TransactionsFilter: "", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: "", + } + + originalTXQuery := iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: "", + } + + tests := []struct { + name string + malleate func(sender string) + expectedErr error + expectedPeriod uint64 + expectedQueryKeys []*iqtypes.KVKey + expectedQueryTXFilter string + query iqtypes.MsgRegisterInterchainQuery + }{ + { + "valid update period for kv", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: nil, + NewUpdatePeriod: 2, + Sender: sender, + } + }, + nil, + 2, + originalKVQuery.Keys, + "", + originalKVQuery, + }, + { + "valid update period for tx", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: nil, + NewUpdatePeriod: 2, + Sender: sender, + } + }, + nil, + 2, + nil, + originalTXQuery.TransactionsFilter, + originalTXQuery, + }, + { + "valid kv query data", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*iqtypes.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + NewUpdatePeriod: 0, + Sender: sender, + } + }, + nil, + originalKVQuery.UpdatePeriod, + []*iqtypes.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + "", + originalKVQuery, + }, + { + "valid tx filter", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewUpdatePeriod: 0, + NewTransactionsFilter: "[]", + Sender: sender, + } + }, + nil, + originalTXQuery.UpdatePeriod, + nil, + "[]", + originalTXQuery, + }, + { + "valid kv query both query keys and update period and ignore tx filter", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*iqtypes.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + NewUpdatePeriod: 2, + Sender: sender, + } + }, + nil, + 2, + []*iqtypes.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + "", + originalKVQuery, + }, + { + "valid tx query both tx filter and update period and ignore query keys", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewUpdatePeriod: 2, + NewTransactionsFilter: "[]", + Sender: sender, + } + }, + nil, + 2, + nil, + "[]", + originalTXQuery, + }, + { + "must fail on update filter for a kv query", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewUpdatePeriod: 2, + NewTransactionsFilter: "[]", + Sender: sender, + } + }, + sdkerrors.ErrInvalidRequest, + originalKVQuery.UpdatePeriod, + originalKVQuery.Keys, + originalKVQuery.TransactionsFilter, + originalKVQuery, + }, + { + "must fail on update keys for a tx query", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*iqtypes.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + NewUpdatePeriod: 2, + Sender: sender, + } + }, + sdkerrors.ErrInvalidRequest, + originalTXQuery.UpdatePeriod, + originalTXQuery.Keys, + originalTXQuery.TransactionsFilter, + originalTXQuery, + }, + { + "invalid query id", + func(sender string) { + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 2, + NewKeys: []*iqtypes.KVKey{ + { + Path: "newpath", + Key: []byte("newdata"), + }, + }, + NewUpdatePeriod: 2, + Sender: sender, + } + }, + iqtypes.ErrInvalidQueryID, + originalKVQuery.UpdatePeriod, + originalKVQuery.Keys, + "", + originalKVQuery, + }, + { + "failed due to auth error", + func(_ string) { + var ( + ctx = suite.ChainA.GetContext() + contractOwner = wasmKeeper.RandomAccountAddress(suite.T()) + ) + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + newContractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(newContractAddress) + msg = iqtypes.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: nil, + NewUpdatePeriod: 2, + Sender: newContractAddress.String(), + } + }, + sdkerrors.ErrUnauthorized, + originalKVQuery.UpdatePeriod, + originalKVQuery.Keys, + "", + originalKVQuery, + }, + } + + for i, tt := range tests { + tt := tt + suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tt.name, i+1, len(tests)), func() { + suite.SetupTest() + + var ( + ctx = suite.ChainA.GetContext() + contractOwner = wasmKeeper.RandomAccountAddress(suite.T()) + ) + + // Store code and instantiate reflect contract. + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + contractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(contractAddress) + + err := testutil.SetupICAPath(suite.Path, contractAddress.String()) + suite.Require().NoError(err) + + // Top up contract address with native coins for deposit + senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress() + suite.TopUpWallet(ctx, senderAddress, contractAddress) + + tt.malleate(contractAddress.String()) + + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + + msgSrv := keeper.NewMsgServerImpl(iqkeeper) + + tt.query.Sender = contractAddress.String() + resRegister, err := msgSrv.RegisterInterchainQuery(ctx, &tt.query) + suite.Require().NoError(err) + suite.Require().NotNil(resRegister) + + resUpdate, err := msgSrv.UpdateInterchainQuery(ctx, &msg) + + if tt.expectedErr != nil { + suite.Require().ErrorIs(err, tt.expectedErr) + suite.Require().Nil(resUpdate) + } else { + suite.Require().NoError(err) + suite.Require().NotNil(resUpdate) + } + query, err := iqkeeper.GetQueryByID(ctx, 1) + suite.Require().NoError(err) + suite.Require().Equal(tt.expectedQueryKeys, query.GetKeys()) + suite.Require().Equal(tt.expectedQueryTXFilter, query.GetTransactionsFilter()) + suite.Require().Equal(tt.expectedPeriod, query.GetUpdatePeriod()) + }) + } +} + +func (suite *KeeperTestSuite) TestRemoveInterchainQuery() { + suite.SetupTest() + + var msg iqtypes.MsgRemoveInterchainQueryRequest + var query iqtypes.MsgRegisterInterchainQuery + var txQueryHashes [][]byte + + tests := []struct { + name string + malleate func(sender string) + expectedErr error + }{ + { + "valid TX remove", + func(sender string) { + msg = iqtypes.MsgRemoveInterchainQueryRequest{ + QueryId: 1, + Sender: sender, + } + query = iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: "", + } + txQueryHashes = [][]byte{ + []byte("txhash_1"), + []byte("txhash_2"), + } + }, + nil, + }, + { + "valid large TX remove", + func(sender string) { + msg = iqtypes.MsgRemoveInterchainQueryRequest{ + QueryId: 1, + Sender: sender, + } + query = iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: "", + } + // types.DefaultTxQueryRemovalLimit is used here for it is both big and can be + // removed in a single tx hashes cleanup iteration + hashesCount := int(iqtypes.DefaultTxQueryRemovalLimit) + txQueryHashes = make([][]byte, 0, hashesCount) + for i := 1; i <= hashesCount; i++ { + txQueryHashes = append(txQueryHashes, []byte(fmt.Sprintf("txhash_%d", i))) + } + }, + nil, + }, + { + "valid KV remove", + func(sender string) { + msg = iqtypes.MsgRemoveInterchainQueryRequest{ + QueryId: 1, + Sender: sender, + } + query = iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeKV), + Keys: []*iqtypes.KVKey{{Key: []byte("key1"), Path: "path1"}}, + TransactionsFilter: "", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: "", + } + }, + nil, + }, + { + "invalid query id", + func(sender string) { + msg = iqtypes.MsgRemoveInterchainQueryRequest{ + QueryId: 2, + Sender: sender, + } + query = iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeKV), + Keys: []*iqtypes.KVKey{{Key: []byte("key1"), Path: "path1"}}, + TransactionsFilter: "", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: "", + } + }, + iqtypes.ErrInvalidQueryID, + }, + { + "failed due to auth error", + func(_ string) { + var ( + ctx = suite.ChainA.GetContext() + contractOwner = wasmKeeper.RandomAccountAddress(suite.T()) + ) + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + newContractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(newContractAddress) + msg = iqtypes.MsgRemoveInterchainQueryRequest{ + QueryId: 1, + Sender: newContractAddress.String(), + } + query = iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeKV), + Keys: []*iqtypes.KVKey{{Key: []byte("key1"), Path: "path1"}}, + TransactionsFilter: "", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: "", + } + }, + sdkerrors.ErrUnauthorized, + }, + } + + for i, tt := range tests { + suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tt.name, i+1, len(tests)), func() { + suite.SetupTest() + + var ( + ctx = suite.ChainA.GetContext() + contractOwner = wasmKeeper.RandomAccountAddress(suite.T()) + ) + + // Store code and instantiate reflect contract. + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + contractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(contractAddress) + + err := testutil.SetupICAPath(suite.Path, contractAddress.String()) + suite.Require().NoError(err) + + // Top up contract address with native coins for deposit + bankKeeper := suite.GetNeutronZoneApp(suite.ChainA).BankKeeper + senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress() + suite.TopUpWallet(ctx, senderAddress, contractAddress) + + tt.malleate(contractAddress.String()) + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + + msgSrv := keeper.NewMsgServerImpl(iqkeeper) + query.Sender = contractAddress.String() + + resRegister, err := msgSrv.RegisterInterchainQuery(ctx, &query) + suite.Require().NoError(err) + suite.Require().NotNil(resRegister) + + balance, balanceErr := bankKeeper.Balance( + ctx, + &banktypes.QueryBalanceRequest{ + Address: contractAddress.String(), + Denom: params.DefaultBondDenom, + }, + ) + expectedCoin := sdk.NewCoin(params.DefaultBondDenom, math.NewInt(int64(0))) + + suite.Require().NoError(balanceErr) + suite.Require().NotNil(balance) + suite.Require().Equal(&expectedCoin, balance.Balance) + + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + queryType := iqtypes.InterchainQueryType(query.GetQueryType()) + switch { + case queryType.IsKV(): + err = iqkeeper.SaveKVQueryResult(ctx, 1, &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + Block: nil, + Height: 1, + Revision: 1, + }) + suite.Require().NoError(err) + case queryType.IsTX(): + for _, txQueryHash := range txQueryHashes { + iqkeeper.SaveTransactionAsProcessed(ctx, 1, txQueryHash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, 1, txQueryHash)) + } + } + + respRm, err := msgSrv.RemoveInterchainQuery(ctx, &msg) + // TxQueriesCleanup is supposed to be called in the app's EndBlock, but suite.ChainA.NextBlock() + // passes an incorrect context to the EndBlock and thus Keeper's store is empty. So we + // have to call it here manually and directly pass the right context into it. + iqkeeper.TxQueriesCleanup(ctx) + if tt.expectedErr != nil { + suite.Require().ErrorIs(err, tt.expectedErr) + suite.Require().Nil(respRm) + originalQuery, queryErr := iqkeeper.GetQueryByID(ctx, 1) + suite.Require().NoError(queryErr) + suite.Require().NotNil(originalQuery) + + switch { + case queryType.IsKV(): + qr, qrerr := iqkeeper.GetQueryResultByID(ctx, 1) + suite.Require().NoError(qrerr) + suite.Require().NotNil(qr) + case queryType.IsTX(): + for _, txQueryHash := range txQueryHashes { + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, 1, txQueryHash)) + } + } + } else { + balance, balanceErr := bankKeeper.Balance( + ctx, + &banktypes.QueryBalanceRequest{ + Address: contractAddress.String(), + Denom: params.DefaultBondDenom, + }, + ) + expectedCoin := sdk.NewCoin(params.DefaultBondDenom, math.NewInt(int64(1_000_000))) + + suite.Require().NoError(balanceErr) + suite.Require().NotNil(balance) + suite.Require().Equal(&expectedCoin, balance.Balance) + + suite.Require().NoError(err) + suite.Require().NotNil(respRm) + query, queryErr := iqkeeper.GetQueryByID(ctx, 1) + suite.Require().Error(queryErr, iqtypes.ErrInvalidQueryID) + suite.Require().Nil(query) + + switch { + case queryType.IsKV(): + qr, qrerr := iqkeeper.GetQueryResultByID(ctx, 1) + suite.Require().Error(qrerr, iqtypes.ErrNoQueryResult) + suite.Require().Nil(qr) + case queryType.IsTX(): + for _, txQueryHash := range txQueryHashes { + suite.Require().False(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, 1, txQueryHash)) + } + } + } + }) + } +} + +// Test get all registered queries +func (suite *KeeperTestSuite) TestGetAllRegisteredQueries() { + suite.SetupTest() + + tests := []struct { + name string + queries []*iqtypes.RegisteredQuery + }{ + { + "all registered queries", + []*iqtypes.RegisteredQuery{ + &(iqtypes.RegisteredQuery{ + Id: 1, + QueryType: string(iqtypes.InterchainQueryTypeKV), + }), + &(iqtypes.RegisteredQuery{ + Id: 2, + QueryType: string(iqtypes.InterchainQueryTypeKV), + }), + }, + }, + { + "no registered queries", + nil, + }, + } + + for i, tt := range tests { + suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tt.name, i+1, len(tests)), func() { + suite.SetupTest() + + ctx := suite.ChainA.GetContext() + + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + for _, query := range tt.queries { + err := iqkeeper.SaveQuery(ctx, query) + suite.Require().NoError(err) + } + + allQueries := iqkeeper.GetAllRegisteredQueries(ctx) + + suite.Require().Equal(tt.queries, allQueries) + }) + } +} + +func (suite *KeeperTestSuite) TestSubmitInterchainQueryResult() { + var msg iqtypes.MsgSubmitQueryResult + + tests := []struct { + name string + malleate func(sender string, ctx sdk.Context) + expectedError error + }{ + { + "invalid query id", + func(sender string, ctx sdk.Context) { + // now we don't care what is really under the value, we just need to be sure that we can verify KV proofs + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: 1, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidQueryID, + }, + { + "valid KV storage proof", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + // suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, + // and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + nil, + }, + { + "invalid number of KvResults", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + // suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }, { + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, + // and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidSubmittedResult, + }, + { + "invalid query type", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: nil, + TransactionsFilter: "[]", + QueryType: string(iqtypes.InterchainQueryTypeTX), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + // suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, + // and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidType, + }, + { + "nil proof", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + // suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: nil, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, + // and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidType, + }, + { + "non-registered key in KV result", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: []byte("non-registered key"), + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidSubmittedResult, + }, + { + "non-registered path in KV result", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: "non-registered-path", + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, + // and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidSubmittedResult, + }, + { + "non existence KV proof", + func(sender string, ctx sdk.Context) { + clientKey := []byte("non_existed_key") + + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + // suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + // now we don't care what is really under the value, we just need to be sure that we can verify KV proofs + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, // A bit weird that query owner submits the results, but it doesn't really matter + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, + // and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + nil, + }, + { + "header with invalid height", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + ibcclienttypes.ErrConsensusStateNotFound, + }, + { + "invalid KV storage value", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: []byte("some evil data"), + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidProof, + }, + { + "query result height is too old", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + // pretend like we have a very new query result + suite.NoError(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper.UpdateLastRemoteHeight(ctx, res.Id, ibcclienttypes.NewHeight(suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), 9999))) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidHeight, + }, + { + "query result revision number check", + func(sender string, ctx sdk.Context) { + clientKey := host.FullClientStateKey(suite.Path.EndpointB.ClientID) + + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: clientKey}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + // pretend like we have a very new query result + suite.NoError(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper.UpdateLastRemoteHeight(ctx, res.Id, ibcclienttypes.NewHeight(suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), 9999))) + + // pretend like we have a very new query result with updated revision height + suite.NoError(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper.UpdateLastRemoteHeight(ctx, res.Id, ibcclienttypes.NewHeight(suite.ChainA.LastHeader.GetHeight().GetRevisionNumber()+1, 1))) + + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: clientKey, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + // we forecefully "updated" revision height + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + iqtypes.ErrInvalidHeight, + }, + // in this test we check that storageValue.Key with special bytes (characters) can be properly verified + { + "non existence KV proof with special bytes in key", + func(sender string, ctx sdk.Context) { + keyWithSpecialBytes, err := hex.DecodeString("0220c746274d3fe20c2c9d06c017e15f8e03f92598fca39d7540aab02244073efe26756a756e6f78") + suite.Require().NoError(err) + + registerMsg := iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: suite.Path.EndpointA.ConnectionID, + Keys: []*iqtypes.KVKey{ + {Path: ibchost.StoreKey, Key: keyWithSpecialBytes}, + }, + QueryType: string(iqtypes.InterchainQueryTypeKV), + UpdatePeriod: 1, + Sender: sender, + } + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.RegisterInterchainQuery(ctx, ®isterMsg) + suite.Require().NoError(err) + + // suite.NoError(suite.Path.EndpointB.UpdateClient()) + suite.NoError(suite.Path.EndpointA.UpdateClient()) + + // now we don't care what is really under the value, we just need to be sure that we can verify KV proofs + resp, err := suite.ChainB.App.Query(ctx, &abci.RequestQuery{ + Path: fmt.Sprintf("store/%s/key", ibchost.StoreKey), + Height: suite.ChainB.LastHeader.Header.Height - 1, + Data: keyWithSpecialBytes, + Prove: true, + }) + suite.Require().NoError(err) + + msg = iqtypes.MsgSubmitQueryResult{ + QueryId: res.Id, + Sender: sender, // A bit weird that query owner submits the results, but it doesn't really matter + ClientId: suite.Path.EndpointA.ClientID, + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: resp.Key, + Proof: resp.ProofOps, + Value: resp.Value, + StoragePrefix: ibchost.StoreKey, + }}, + // we don't have tests to test transactions proofs verification since it's a tendermint layer, + // and we don't have access to it here + Block: nil, + Height: uint64(resp.Height), + Revision: suite.ChainA.LastHeader.GetHeight().GetRevisionNumber(), + }, + } + }, + nil, + }, + } + + for i, tc := range tests { + tt := tc + suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tt.name, i+1, len(tests)), func() { + suite.SetupTest() + + var ( + ctx = suite.ChainA.GetContext() + contractOwner = wasmKeeper.RandomAccountAddress(suite.T()) + ) + + // Store code and instantiate reflect contract. + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + contractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(contractAddress) + + err := testutil.SetupICAPath(suite.Path, contractAddress.String()) + suite.Require().NoError(err) + + // Top up contract address with native coins for deposit + senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress() + suite.TopUpWallet(ctx, senderAddress, contractAddress) + + tt.malleate(contractAddress.String(), ctx) + + msgSrv := keeper.NewMsgServerImpl(suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper) + + res, err := msgSrv.SubmitQueryResult(ctx, &msg) + + if tt.expectedError != nil { + suite.Require().ErrorIs(err, tt.expectedError) + suite.Require().Nil(res) + } else { + suite.Require().NoError(err) + suite.Require().NotNil(res) + } + }) + } +} + +func (suite *KeeperTestSuite) TestTxQueriesCleanup() { + suite.Run("SingleIterSingleQuery", func() { + suite.SetupTest() + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + ctx := suite.ChainA.GetContext() + + // create a query and add results for it + var queryID uint64 = 1 + query := iqtypes.RegisteredQuery{Id: queryID, QueryType: string(iqtypes.InterchainQueryTypeTX)} + err := iqkeeper.SaveQuery(ctx, &query) + suite.Require().NoError(err) + _, err = iqkeeper.GetQueryByID(ctx, queryID) + suite.Require().Nil(err) + txHashes := suite.buildTxHashes(50) + for _, hash := range txHashes { + iqkeeper.SaveTransactionAsProcessed(ctx, queryID, hash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID, hash)) + } + + // remove query and call cleanup + iqkeeper.RemoveQuery(ctx, &query) + iqkeeper.TxQueriesCleanup(ctx) + + // make sure removal and cleanup worked as expected + for _, hash := range txHashes { + suite.Require().Falsef(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID, hash), "%s expected not to be in the store", hash) + } + suite.Require().Nilf(iqkeeper.GetTxQueriesToRemove(ctx, 0), "expected not to have any TX queries to remove after cleanup") + _, err = iqkeeper.GetQueryByID(ctx, queryID) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + }) + + suite.Run("SingleIterMultipeQueries", func() { + suite.SetupTest() + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + ctx := suite.ChainA.GetContext() + + txHashes := suite.buildTxHashes(100) + // create a query and add results for it + var queryID1 uint64 = 1 + query1 := iqtypes.RegisteredQuery{Id: queryID1, QueryType: string(iqtypes.InterchainQueryTypeTX)} + err := iqkeeper.SaveQuery(ctx, &query1) + suite.Require().NoError(err) + _, err = iqkeeper.GetQueryByID(ctx, queryID1) + suite.Require().NoError(err) + txHashesQ1 := txHashes[:len(txHashes)/2] // first half of the build hashes come to the first query + for _, hash := range txHashesQ1 { + iqkeeper.SaveTransactionAsProcessed(ctx, queryID1, hash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID1, hash)) + } + // create another query and add results for it + var queryID2 uint64 = 2 + query2 := iqtypes.RegisteredQuery{Id: queryID2, QueryType: string(iqtypes.InterchainQueryTypeTX)} + err = iqkeeper.SaveQuery(ctx, &query2) + suite.Require().NoError(err) + _, err = iqkeeper.GetQueryByID(ctx, queryID2) + suite.Require().NoError(err) + txHashesQ2 := txHashes[len(txHashes)/2:] // second half of the build hashes come to the second query + for _, hash := range txHashesQ2 { + iqkeeper.SaveTransactionAsProcessed(ctx, queryID2, hash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID2, hash)) + } + + // remove queries and call cleanup + iqkeeper.RemoveQuery(ctx, &query1) + iqkeeper.RemoveQuery(ctx, &query2) + iqkeeper.TxQueriesCleanup(ctx) + + // make sure removal and cleanup worked as expected + for _, hash := range txHashesQ1 { + suite.Require().Falsef(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID1, hash), "%s expected not to be in the store", hash) + } + for _, hash := range txHashesQ2 { + suite.Require().Falsef(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID2, hash), "%s expected not to be in the store", hash) + } + suite.Require().Nilf(iqkeeper.GetTxQueriesToRemove(ctx, 0), "expected not to have any TX queries to remove after cleanup") + _, err = iqkeeper.GetQueryByID(ctx, queryID1) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + _, err = iqkeeper.GetQueryByID(ctx, queryID2) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + }) + + suite.Run("MultipleIterSingleQuery", func() { + suite.SetupTest() + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + ctx := suite.ChainA.GetContext() + + // set TxQueryRemovalLimit to a low value + limit := 50 + params := iqkeeper.GetParams(ctx) + params.TxQueryRemovalLimit = uint64(limit) + err := iqkeeper.SetParams(ctx, params) + suite.Require().NoError(err) + + // create a query and add results for it + var queryID uint64 = 1 + query := iqtypes.RegisteredQuery{Id: queryID, QueryType: string(iqtypes.InterchainQueryTypeTX)} + err = iqkeeper.SaveQuery(ctx, &query) + suite.Require().NoError(err) + _, err = iqkeeper.GetQueryByID(ctx, queryID) + suite.Require().NoError(err) + limitOverflow := 10 + txHashes := suite.buildTxHashes(limit + limitOverflow) // create a bit more hashes than the limit + for _, hash := range txHashes { + iqkeeper.SaveTransactionAsProcessed(ctx, queryID, hash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID, hash)) + } + + // remove query and call cleanup + iqkeeper.RemoveQuery(ctx, &query) + iqkeeper.TxQueriesCleanup(ctx) + + // make sure removal and cleanup worked as expected + removed, left := suite.txHashesRemovalProgress(ctx, iqkeeper, queryID, txHashes) + suite.Require().Equalf(limit, removed, "first cleanup removed hashes count should be as many as limit") + suite.Require().Equalf(limitOverflow, left, "first cleanup left hashes count should be as many as limitOverflow") + suite.Require().Equalf([]uint64{queryID}, iqkeeper.GetTxQueriesToRemove(ctx, 0), "expected to have a TX query to remove after partial cleanup") + _, err = iqkeeper.GetQueryByID(ctx, queryID) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + + // call cleanup one more time and make sure it worked as expected + iqkeeper.TxQueriesCleanup(ctx) + for _, hash := range txHashes { // by this point all hashes should be removed + suite.Require().Falsef(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID, hash), "%s expected not to be in the store", hash) + } + suite.Require().Nilf(iqkeeper.GetTxQueriesToRemove(ctx, 0), "expected not to have any TX queries to remove after cleanup") + _, err = iqkeeper.GetQueryByID(ctx, queryID) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + }) + + suite.Run("MultipleIterMultipeQueries", func() { + suite.SetupTest() + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + ctx := suite.ChainA.GetContext() + + // set TxQueryRemovalLimit to a low value + limit := 50 + params := iqkeeper.GetParams(ctx) + params.TxQueryRemovalLimit = uint64(limit) + err := iqkeeper.SetParams(ctx, params) + suite.Require().NoError(err) + + limitOverflow := 10 + txHashes := suite.buildTxHashes(limit + limitOverflow) + txHashesQ1 := txHashes[:len(txHashes)/2] // first half of the build hashes come to the first query + txHashesQ2 := txHashes[len(txHashes)/2:] // second half of the build hashes come to the second query + // create a query and add results for it + var queryID1 uint64 = 1 + query1 := iqtypes.RegisteredQuery{Id: queryID1, QueryType: string(iqtypes.InterchainQueryTypeTX)} + err = iqkeeper.SaveQuery(ctx, &query1) + suite.Require().NoError(err) + _, err = iqkeeper.GetQueryByID(ctx, queryID1) + suite.Require().NoError(err) + for _, hash := range txHashesQ1 { + iqkeeper.SaveTransactionAsProcessed(ctx, queryID1, hash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID1, hash)) + } + // create another query and add results for it + var queryID2 uint64 = 2 + query2 := iqtypes.RegisteredQuery{Id: queryID2, QueryType: string(iqtypes.InterchainQueryTypeTX)} + err = iqkeeper.SaveQuery(ctx, &query2) + suite.Require().NoError(err) + _, err = iqkeeper.GetQueryByID(ctx, queryID2) + suite.Require().NoError(err) + for _, hash := range txHashesQ2 { + iqkeeper.SaveTransactionAsProcessed(ctx, queryID2, hash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID2, hash)) + } + + // remove queries and call cleanup + iqkeeper.RemoveQuery(ctx, &query1) + iqkeeper.RemoveQuery(ctx, &query2) + iqkeeper.TxQueriesCleanup(ctx) + + // make sure removal and cleanup worked as expected + removedQ1, leftQ1 := suite.txHashesRemovalProgress(ctx, iqkeeper, queryID1, txHashesQ1) + removedQ2, leftQ2 := suite.txHashesRemovalProgress(ctx, iqkeeper, queryID2, txHashesQ2) + suite.Require().Equalf(limit, removedQ1+removedQ2, "first cleanup removed hashes count should be as many as limit") + suite.Require().Equalf(limitOverflow, leftQ1+leftQ2, "first cleanup remaining hashes count should be as many as limitOverflow") + suite.Require().Equalf([]uint64{queryID2}, iqkeeper.GetTxQueriesToRemove(ctx, 0), "expected to have one TX query to remove after partial cleanup") + + // call cleanup one more time and make sure it worked as expected + iqkeeper.TxQueriesCleanup(ctx) + removedQ1, leftQ1 = suite.txHashesRemovalProgress(ctx, iqkeeper, queryID1, txHashesQ1) + removedQ2, leftQ2 = suite.txHashesRemovalProgress(ctx, iqkeeper, queryID2, txHashesQ2) + suite.Require().Equalf(limit+limitOverflow, removedQ1+removedQ2, "all hashes should be removed after the second cleanup") + suite.Require().Equalf(0, leftQ1+leftQ2, "no hashes should left after the second cleanup") + suite.Require().Nilf(iqkeeper.GetTxQueriesToRemove(ctx, 0), "expected not to have any TX queries to remove after cleanup") + _, err = iqkeeper.GetQueryByID(ctx, queryID1) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + _, err = iqkeeper.GetQueryByID(ctx, queryID2) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + }) + + suite.Run("Unlimited", func() { + suite.SetupTest() + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + ctx := suite.ChainA.GetContext() + + // set TxQueryRemovalLimit to a low value + params := iqkeeper.GetParams(ctx) + params.TxQueryRemovalLimit = 0 + err := iqkeeper.SetParams(ctx, params) + suite.Require().NoError(err) + suite.Require().Equal(uint64(0), iqkeeper.GetParams(ctx).TxQueryRemovalLimit) + + // create a query and add results for it + var queryID uint64 = 1 + query := iqtypes.RegisteredQuery{Id: queryID, QueryType: string(iqtypes.InterchainQueryTypeTX)} + err = iqkeeper.SaveQuery(ctx, &query) + suite.Require().NoError(err) + _, err = iqkeeper.GetQueryByID(ctx, queryID) + suite.Require().NoError(err) + txHashes := suite.buildTxHashes(int(iqtypes.DefaultTxQueryRemovalLimit) * 2) + for _, hash := range txHashes { + iqkeeper.SaveTransactionAsProcessed(ctx, queryID, hash) + suite.Require().True(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID, hash)) + } + + // remove query and call cleanup + iqkeeper.RemoveQuery(ctx, &query) + iqkeeper.TxQueriesCleanup(ctx) + + // make sure removal and cleanup worked as expected + for _, hash := range txHashes { + suite.Require().Falsef(iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID, hash), "%s expected not to be in the store", hash) + } + suite.Require().Nilf(iqkeeper.GetTxQueriesToRemove(ctx, 0), "expected not to have any TX queries to remove after cleanup") + _, err = iqkeeper.GetQueryByID(ctx, queryID) + suite.Require().ErrorIs(err, iqtypes.ErrInvalidQueryID) + }) +} + +// TestRemoveFreshlyCreatedICQ mostly makes sure the query's RegisteredAtHeight field works. +func (suite *KeeperTestSuite) TestRemoveFreshlyCreatedICQ() { + suite.SetupTest() + var ( + ctx = suite.ChainA.GetContext() + contractOwner = wasmKeeper.RandomAccountAddress(suite.T()) + ) + + // Store code and instantiate reflect contract. + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + contractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(contractAddress) + + // Top up contract address with native coins for deposit + senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress() + suite.TopUpWallet(ctx, senderAddress, contractAddress) + + iqkeeper := suite.GetNeutronZoneApp(suite.ChainA).InterchainQueriesKeeper + params := iqkeeper.GetParams(ctx) + params.QuerySubmitTimeout = 5 + err := iqkeeper.SetParams(ctx, params) + suite.Require().NoError(err) + msgSrv := keeper.NewMsgServerImpl(iqkeeper) + + resRegister, err := msgSrv.RegisterInterchainQuery(ctx, &iqtypes.MsgRegisterInterchainQuery{ + QueryType: string(iqtypes.InterchainQueryTypeKV), + Keys: []*iqtypes.KVKey{{Key: []byte("key1"), Path: "path1"}}, + TransactionsFilter: "", + ConnectionId: suite.Path.EndpointA.ConnectionID, + UpdatePeriod: 1, + Sender: contractAddress.String(), + }) + suite.Require().NoError(err) + suite.Require().NotNil(resRegister) + + registeredQuery, err := iqkeeper.GetQueryByID(ctx, 1) + suite.Require().NoError(err) + suite.Require().Equal(uint64(ctx.BlockHeight()), registeredQuery.RegisteredAtHeight) + suite.Require().Equal(uint64(0), registeredQuery.LastSubmittedResultLocalHeight) + suite.Require().Equal(params.QuerySubmitTimeout, registeredQuery.SubmitTimeout) + suite.Require().Greater(uint64(ctx.BlockHeight()), registeredQuery.LastSubmittedResultLocalHeight+registeredQuery.SubmitTimeout) + + newContractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(newContractAddress) + resp, err := msgSrv.RemoveInterchainQuery(ctx, &iqtypes.MsgRemoveInterchainQueryRequest{ + QueryId: 1, + Sender: newContractAddress.String(), + }) + suite.Nil(resp) + suite.ErrorContains(err, "only owner can remove a query within its service period") +} + +func (suite *KeeperTestSuite) TopUpWallet(ctx sdk.Context, sender, contractAddress sdk.AccAddress) { + coinsAmnt := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(int64(1_000_000)))) + bankKeeper := suite.GetNeutronZoneApp(suite.ChainA).BankKeeper + err := bankKeeper.SendCoins(ctx, sender, contractAddress, coinsAmnt) + suite.Require().NoError(err) +} + +// buildTxHashes generates the given amount of fake tx hashes. +func (*KeeperTestSuite) buildTxHashes(amount int) [][]byte { + txHashes := make([][]byte, 0, amount) + for i := 1; i <= amount; i++ { + txHashes = append(txHashes, []byte(fmt.Sprintf("tx_hash_%d", i))) + } + return txHashes +} + +// txHashesRemovalProgress calculates how many hashes have been removed and how many are left in the +// keeper's store for the given query. +func (*KeeperTestSuite) txHashesRemovalProgress(ctx sdk.Context, iqkeeper keeper.Keeper, queryID uint64, initHashes [][]byte) (removed, left int) { + for _, hash := range initHashes { + if iqkeeper.CheckTransactionIsAlreadyProcessed(ctx, queryID, hash) { + left++ + } else { + removed++ + } + } + return removed, left +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} diff --git a/x/interchainqueries/keeper/msg_server.go b/x/interchainqueries/keeper/msg_server.go new file mode 100644 index 00000000..31340ebc --- /dev/null +++ b/x/interchainqueries/keeper/msg_server.go @@ -0,0 +1,379 @@ +package keeper + +import ( + "bytes" + "context" + "fmt" + "strconv" + "time" + + "cosmossdk.io/errors" + tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" + ibccommitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + ics23 "github.com/cosmos/ics23/go" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +var _ types.MsgServer = msgServer{} + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +func (m msgServer) RegisterInterchainQuery(goCtx context.Context, msg *types.MsgRegisterInterchainQuery) (*types.MsgRegisterInterchainQueryResponse, error) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelRegisterInterchainQuery) + + if err := msg.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgRegisterInterchainQuery") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + ctx.Logger().Debug("RegisterInterchainQuery", "msg", msg) + + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + m.Logger(ctx).Debug("RegisterInterchainQuery: failed to parse sender address", "sender_address", msg.Sender) + return nil, errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Sender) + } + + if !m.contractManagerKeeper.HasContractInfo(ctx, senderAddr) { + m.Logger(ctx).Debug("RegisterInterchainQuery: contract not found", "sender_address", msg.Sender) + return nil, errors.Wrapf(types.ErrNotContract, "%s is not a contract address", msg.Sender) + } + + if _, err := m.ibcKeeper.ConnectionKeeper.Connection(goCtx, &ibcconnectiontypes.QueryConnectionRequest{ConnectionId: msg.ConnectionId}); err != nil { + ctx.Logger().Debug("RegisterInterchainQuery: failed to get connection with ID", "message", msg) + return nil, errors.Wrapf(types.ErrInvalidConnectionID, "failed to get connection with ID '%s': %v", msg.ConnectionId, err) + } + + lastID := m.GetLastRegisteredQueryKey(ctx) + lastID++ + + params := m.GetParams(ctx) + + registeredQuery := &types.RegisteredQuery{ + Id: lastID, + Owner: msg.Sender, + TransactionsFilter: msg.TransactionsFilter, + Keys: msg.Keys, + QueryType: msg.QueryType, + UpdatePeriod: msg.UpdatePeriod, + ConnectionId: msg.ConnectionId, + Deposit: params.QueryDeposit, + SubmitTimeout: params.QuerySubmitTimeout, + RegisteredAtHeight: uint64(ctx.BlockHeader().Height), + } + + m.SetLastRegisteredQueryKey(ctx, lastID) + + if err := m.CollectDeposit(ctx, *registeredQuery); err != nil { + ctx.Logger().Debug("RegisterInterchainQuery: failed to collect deposit", "message", &msg, "error", err) + return nil, errors.Wrapf(err, "failed to collect deposit") + } + + if err := m.SaveQuery(ctx, registeredQuery); err != nil { + ctx.Logger().Debug("RegisterInterchainQuery: failed to save query", "message", &msg, "error", err) + return nil, errors.Wrapf(err, "failed to save query: %v", err) + } + + ctx.EventManager().EmitEvents(getEventsQueryUpdated(registeredQuery)) + + return &types.MsgRegisterInterchainQueryResponse{Id: lastID}, nil +} + +func (m msgServer) RemoveInterchainQuery(goCtx context.Context, msg *types.MsgRemoveInterchainQueryRequest) (*types.MsgRemoveInterchainQueryResponse, error) { + if err := msg.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgRemoveInterchainQueryRequest") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + ctx.Logger().Debug("RemoveInterchainQuery", "msg", msg) + + query, err := m.GetQueryByID(ctx, msg.GetQueryId()) + if err != nil { + ctx.Logger().Debug("RemoveInterchainQuery: failed to GetQueryByID", + "error", err, "query_id", msg.QueryId) + return nil, errors.Wrapf(err, "failed to get query by query id: %v", err) + } + + if err := query.ValidateRemoval(ctx, msg.GetSender()); err != nil { + ctx.Logger().Debug("RemoveInterchainQuery: authorization failed", + "error", err, "msg", msg) + return nil, errors.Wrap(sdkerrors.ErrUnauthorized, err.Error()) + } + + m.RemoveQuery(ctx, query) + m.MustPayOutDeposit(ctx, query.Deposit, msg.GetSigners()[0]) + ctx.EventManager().EmitEvents(getEventsQueryRemoved(query)) + return &types.MsgRemoveInterchainQueryResponse{}, nil +} + +func (m msgServer) UpdateInterchainQuery(goCtx context.Context, msg *types.MsgUpdateInterchainQueryRequest) (*types.MsgUpdateInterchainQueryResponse, error) { + if err := msg.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgUpdateInterchainQueryRequest") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + ctx.Logger().Debug("UpdateInterchainQuery", "msg", msg) + + query, err := m.GetQueryByID(ctx, msg.GetQueryId()) + if err != nil { + ctx.Logger().Debug("UpdateInterchainQuery: failed to GetQueryByID", + "error", err, "query_id", msg.QueryId) + return nil, errors.Wrapf(err, "failed to get query by query id: %v", err) + } + + if query.GetOwner() != msg.GetSender() { + ctx.Logger().Debug("UpdateInterchainQuery: authorization failed", + "msg", msg) + return nil, errors.Wrap(sdkerrors.ErrUnauthorized, "authorization failed") + } + + if err := m.validateUpdateInterchainQueryParams(query, msg); err != nil { + ctx.Logger().Debug("UpdateInterchainQuery: invalid request", + "error", err, "query_id", msg.QueryId) + return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + } + if msg.GetNewUpdatePeriod() > 0 { + query.UpdatePeriod = msg.GetNewUpdatePeriod() + } + if len(msg.GetNewKeys()) > 0 && types.InterchainQueryType(query.GetQueryType()).IsKV() { + query.Keys = msg.GetNewKeys() + } + if msg.GetNewTransactionsFilter() != "" && types.InterchainQueryType(query.GetQueryType()).IsTX() { + query.TransactionsFilter = msg.GetNewTransactionsFilter() + } + + if err := m.SaveQuery(ctx, query); err != nil { + ctx.Logger().Debug("UpdateInterchainQuery: failed to save query", "message", &msg, "error", err) + return nil, errors.Wrapf(err, "failed to save query by query id: %v", err) + } + + ctx.EventManager().EmitEvents(getEventsQueryUpdated(query)) + + return &types.MsgUpdateInterchainQueryResponse{}, nil +} + +func (m msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmitQueryResult) (*types.MsgSubmitQueryResultResponse, error) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelRegisterInterchainQuery) + + if err := msg.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgSubmitQueryResult") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + ctx.Logger().Debug("SubmitQueryResult", "query_id", msg.QueryId) + + query, err := m.GetQueryByID(ctx, msg.QueryId) + if err != nil { + ctx.Logger().Debug("SubmitQueryResult: failed to GetQueryByID", + "error", err, "query_id", msg.QueryId) + return nil, errors.Wrapf(err, "failed to get query by id: %v", err) + } + + queryOwner, err := sdk.AccAddressFromBech32(query.Owner) + if err != nil { + ctx.Logger().Error("SubmitQueryResult: failed to decode AccAddressFromBech32", + "error", err, "query", query, "message", msg) + return nil, errors.Wrapf(err, "failed to decode owner contract address (%s)", query.Owner) + } + + if msg.Result.KvResults != nil { + if !types.InterchainQueryType(query.QueryType).IsKV() { + return nil, errors.Wrapf(types.ErrInvalidType, "invalid query result for query type: %s", query.QueryType) + } + if err := m.checkLastRemoteHeight(ctx, *query, ibcclienttypes.NewHeight(msg.Result.Revision, msg.Result.Height)); err != nil { + return nil, errors.Wrap(types.ErrInvalidHeight, err.Error()) + } + if len(msg.Result.KvResults) != len(query.Keys) { + return nil, errors.Wrapf(types.ErrInvalidSubmittedResult, "KV keys length from result is not equal to registered query keys length: %v != %v", len(msg.Result.KvResults), len(query.Keys)) + } + + resp, err := m.ibcKeeper.ConnectionConsensusState(goCtx, &ibcconnectiontypes.QueryConnectionConsensusStateRequest{ + ConnectionId: query.ConnectionId, + RevisionNumber: msg.Result.Revision, + RevisionHeight: msg.Result.Height + 1, + }) + if err != nil { + ctx.Logger().Debug("SubmitQueryResult: failed to get ConnectionConsensusState", + "error", err, "query", query, "message", msg) + return nil, errors.Wrapf(ibcclienttypes.ErrConsensusStateNotFound, "failed to get consensus state: %v", err) + } + consensusStateI, err := ibcclienttypes.UnpackConsensusState(resp.ConsensusState) + if err != nil { + ctx.Logger().Error("SubmitQueryResult: failed to UnpackConsensusState", + "error", err, "query", query, "message", msg) + return nil, fmt.Errorf("failed marshal: %s, %w", consensusStateI.String(), err) + } + + consensusState, ok := consensusStateI.(*tendermint.ConsensusState) + if !ok { + ctx.Logger().Error("SubmitQueryResult: failed to cast exported.ConsensusState to *tendermint.ConsensusState", + "error", err, "query", query, "message", msg) + return nil, errors.Wrapf(sdkerrors.ErrUnpackAny, "failed to cast interface exported.ConsensusState to type *tendermint.ConsensusState") + } + + clientState, err := m.GetClientState(ctx, msg.ClientId) + if err != nil { + return nil, err + } + + for index, result := range msg.Result.KvResults { + proof, err := ibccommitmenttypes.ConvertProofs(result.Proof) + if err != nil { + ctx.Logger().Debug("SubmitQueryResult: failed to ConvertProofs", + "error", err, "query", query, "message", msg) + return nil, errors.Wrapf(types.ErrInvalidType, "failed to convert crypto.ProofOps to MerkleProof: %v", err) + } + + if !bytes.Equal(result.Key, query.Keys[index].Key) { + return nil, errors.Wrapf(types.ErrInvalidSubmittedResult, "KV key from result is not equal to registered query key: %v != %v", result.Key, query.Keys[index].Key) + } + + if result.StoragePrefix != query.Keys[index].Path { + return nil, errors.Wrapf(types.ErrInvalidSubmittedResult, "KV path from result is not equal to registered query storage prefix: %v != %v", result.StoragePrefix, query.Keys[index].Path) + } + + path := ibccommitmenttypes.NewMerklePath(result.StoragePrefix, string(result.Key)) + // identify what kind proofs (non-existence proof always has *ics23.CommitmentProof_Nonexist as the first item) we got + // and call corresponding method to verify it + switch proof.GetProofs()[0].GetProof().(type) { + // we can get non-existence proof if someone queried some key which is not exists in the storage on remote chain + case *ics23.CommitmentProof_Nonexist: + if err := proof.VerifyNonMembership(clientState.ProofSpecs, consensusState.GetRoot(), path); err != nil { + ctx.Logger().Debug("SubmitQueryResult: failed to VerifyNonMembership", + "error", err, "query", query, "message", msg, "path", path) + return nil, errors.Wrapf(types.ErrInvalidProof, "failed to verify proof: %v", err) + } + result.Value = nil + case *ics23.CommitmentProof_Exist: + if err := proof.VerifyMembership(clientState.ProofSpecs, consensusState.GetRoot(), path, result.Value); err != nil { + ctx.Logger().Debug("SubmitQueryResult: failed to VerifyMembership", + "error", err, "query", query, "message", msg, "path", path) + return nil, errors.Wrapf(types.ErrInvalidProof, "failed to verify proof: %v", err) + } + default: + return nil, errors.Wrapf(types.ErrInvalidProof, "unknown proof type %T", proof.GetProofs()[0].GetProof()) + } + } + + if err = m.saveKVQueryResult(ctx, query, msg.Result); err != nil { + ctx.Logger().Error("SubmitQueryResult: failed to SaveKVQueryResult", + "error", err, "query", query, "message", msg) + return nil, errors.Wrapf(err, "failed to SaveKVQueryResult: %v", err) + } + + if msg.Result.GetAllowKvCallbacks() { + // Let the query owner contract process the query result. + if _, err := m.contractManagerKeeper.SudoKVQueryResult(ctx, queryOwner, query.Id); err != nil { + ctx.Logger().Debug("SubmitQueryResult: failed to SudoKVQueryResult", + "error", err, "query_id", query.GetId()) + return nil, errors.Wrapf(err, "contract %s rejected KV query result (query_id: %d)", + queryOwner, query.GetId()) + } + return &types.MsgSubmitQueryResultResponse{}, nil + } + } + + if msg.Result.Block != nil && msg.Result.Block.Tx != nil { + if !types.InterchainQueryType(query.QueryType).IsTX() { + return nil, errors.Wrapf(types.ErrInvalidType, "invalid query result for query type: %s", query.QueryType) + } + + if err := m.ProcessBlock(ctx, queryOwner, msg.QueryId, msg.ClientId, msg.Result.Block); err != nil { + ctx.Logger().Debug("SubmitQueryResult: failed to ProcessBlock", + "error", err, "query", query, "message", msg) + return nil, errors.Wrapf(err, "failed to ProcessBlock: %v", err) + } + + if err = m.UpdateLastLocalHeight(ctx, query.Id, uint64(ctx.BlockHeight())); err != nil { + return nil, errors.Wrapf(err, + "failed to update last local height for a result with id %d: %v", query.Id, err) + } + } + + return &types.MsgSubmitQueryResultResponse{}, nil +} + +// validateUpdateInterchainQueryParams checks whether the parameters to be updated corresponds +// with the query type. +func (m msgServer) validateUpdateInterchainQueryParams( + query *types.RegisteredQuery, + msg *types.MsgUpdateInterchainQueryRequest, +) error { + queryType := types.InterchainQueryType(query.GetQueryType()) + newKvKeysSet := len(msg.GetNewKeys()) != 0 + newTxFilterSet := msg.GetNewTransactionsFilter() != "" + + if queryType.IsKV() && !newKvKeysSet && newTxFilterSet { + return fmt.Errorf("params to update don't correspond with query type: can't update TX filter for a KV query") + } + if queryType.IsTX() && !newTxFilterSet && newKvKeysSet { + return fmt.Errorf("params to update don't correspond with query type: can't update KV keys for a TX query") + } + return nil +} + +// UpdateParams updates the module parameters +func (k Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgUpdateParams") + } + + authority := k.GetAuthority() + if authority != req.Authority { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.SetParams(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} + +func getEventsQueryUpdated(query *types.RegisteredQuery) sdk.Events { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeNeutronMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeValueQueryUpdated), + sdk.NewAttribute(types.AttributeKeyQueryID, strconv.FormatUint(query.Id, 10)), + sdk.NewAttribute(types.AttributeKeyConnectionID, query.ConnectionId), + sdk.NewAttribute(types.AttributeKeyOwner, query.Owner), + sdk.NewAttribute(types.AttributeKeyQueryType, query.QueryType), + sdk.NewAttribute(types.AttributeTransactionsFilterQuery, query.TransactionsFilter), + sdk.NewAttribute(types.AttributeKeyKVQuery, types.KVKeys(query.Keys).String()), + ), + } +} + +func getEventsQueryRemoved(query *types.RegisteredQuery) sdk.Events { + return sdk.Events{ + sdk.NewEvent( + types.EventTypeNeutronMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeValueQueryRemoved), + sdk.NewAttribute(types.AttributeKeyQueryID, strconv.FormatUint(query.Id, 10)), + sdk.NewAttribute(types.AttributeKeyConnectionID, query.ConnectionId), + sdk.NewAttribute(types.AttributeKeyOwner, query.Owner), + sdk.NewAttribute(types.AttributeKeyQueryType, query.QueryType), + sdk.NewAttribute(types.AttributeTransactionsFilterQuery, query.TransactionsFilter), + sdk.NewAttribute(types.AttributeKeyKVQuery, types.KVKeys(query.Keys).String()), + ), + } +} diff --git a/x/interchainqueries/keeper/msg_server_test.go b/x/interchainqueries/keeper/msg_server_test.go new file mode 100644 index 00000000..95a92f6a --- /dev/null +++ b/x/interchainqueries/keeper/msg_server_test.go @@ -0,0 +1,537 @@ +package keeper_test + +import ( + "testing" + + "github.com/cometbft/cometbft/proto/tendermint/crypto" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + ibchost "github.com/cosmos/ibc-go/v8/modules/core/exported" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil" + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchainqueries/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +func TestMsgRegisterInterchainQueryValidate(t *testing.T) { + k, ctx := testkeeper.InterchainQueriesKeeper(t, nil, nil, nil, nil) + msgServer := keeper.NewMsgServerImpl(*k) + + tests := []struct { + name string + msg types.MsgRegisterInterchainQuery + expectedErr error + }{ + { + "invalid update period", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 0, + Sender: testutil.TestOwnerAddress, + }, + types.ErrInvalidUpdatePeriod, + }, + { + "empty sender", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: "", + }, + sdkerrors.ErrInvalidAddress, + }, + { + "invalid sender", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: "cosmos14234_invalid_address", + }, + sdkerrors.ErrInvalidAddress, + }, + { + "empty connection id", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: "", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + types.ErrInvalidConnectionID, + }, + { + "invalid query type", + types.MsgRegisterInterchainQuery{ + QueryType: "invalid_type", + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + types.ErrInvalidQueryType, + }, + { + "empty keys", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeKV), + Keys: nil, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + types.ErrEmptyKeys, + }, + { + "too many keys", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeKV), + Keys: make([]*types.KVKey, types.MaxKVQueryKeysCount+1), + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + types.ErrTooManyKVQueryKeys, + }, + { + "nil key", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeKV), + Keys: []*types.KVKey{{Key: []byte("key1"), Path: "path1"}, nil}, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + sdkerrors.ErrInvalidType, + }, + { + "duplicated keys", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeKV), + Keys: []*types.KVKey{{Key: []byte("key1"), Path: "path1"}, {Key: []byte("key1"), Path: "path1"}}, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + sdkerrors.ErrInvalidRequest, + }, + { + "empty key path", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeKV), + Keys: []*types.KVKey{{Key: []byte("key1"), Path: ""}}, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + types.ErrEmptyKeyPath, + }, + { + "empty key id", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeKV), + Keys: []*types.KVKey{{Key: []byte(""), Path: "path"}}, + TransactionsFilter: "[]", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + types.ErrEmptyKeyID, + }, + { + "invalid transactions filter format", + types.MsgRegisterInterchainQuery{ + QueryType: string(types.InterchainQueryTypeTX), + Keys: nil, + TransactionsFilter: "&)(^Y(*&(*&(&(*", + ConnectionId: "connection-0", + UpdatePeriod: 1, + Sender: testutil.TestOwnerAddress, + }, + types.ErrInvalidTransactionsFilter, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := msgServer.RegisterInterchainQuery(ctx, &tt.msg) + require.ErrorIs(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + +func TestMsgSubmitQueryResultValidate(t *testing.T) { + k, ctx := testkeeper.InterchainQueriesKeeper(t, nil, nil, nil, nil) + msgServer := keeper.NewMsgServerImpl(*k) + + tests := []struct { + name string + msg types.MsgSubmitQueryResult + expectedErr error + }{ + { + "empty result", + types.MsgSubmitQueryResult{ + QueryId: 1, + Sender: testutil.TestOwnerAddress, + ClientId: "client-id", + Result: nil, + }, + types.ErrEmptyResult, + }, + { + "empty kv results and block result", + types.MsgSubmitQueryResult{ + QueryId: 1, + Sender: testutil.TestOwnerAddress, + ClientId: "client-id", + Result: &types.QueryResult{ + KvResults: nil, + Block: nil, + Height: 100, + Revision: 1, + }, + }, + types.ErrEmptyResult, + }, + { + "zero query id", + types.MsgSubmitQueryResult{ + QueryId: 0, + Sender: testutil.TestOwnerAddress, + ClientId: "client-id", + Result: &types.QueryResult{ + KvResults: []*types.StorageValue{{ + Key: []byte{10}, + Proof: &crypto.ProofOps{Ops: []crypto.ProofOp{ + { + Type: "type", + Key: []byte{10}, + Data: []byte{10}, + }, + }}, + Value: []byte{10}, + StoragePrefix: ibchost.StoreKey, + }}, + Block: nil, + Height: 100, + Revision: 1, + }, + }, + types.ErrInvalidQueryID, + }, + { + "empty sender", + types.MsgSubmitQueryResult{ + QueryId: 1, + Sender: "", + ClientId: "client-id", + Result: &types.QueryResult{ + KvResults: []*types.StorageValue{{ + Key: []byte{10}, + Proof: &crypto.ProofOps{Ops: []crypto.ProofOp{ + { + Type: "type", + Key: []byte{10}, + Data: []byte{10}, + }, + }}, + Value: []byte{10}, + StoragePrefix: ibchost.StoreKey, + }}, + Block: nil, + Height: 100, + Revision: 1, + }, + }, + sdkerrors.ErrInvalidAddress, + }, + { + "invalid sender", + types.MsgSubmitQueryResult{ + QueryId: 1, + Sender: "invalid_sender", + ClientId: "client-id", + Result: &types.QueryResult{ + KvResults: []*types.StorageValue{{ + Key: []byte{10}, + Proof: &crypto.ProofOps{Ops: []crypto.ProofOp{ + { + Type: "type", + Key: []byte{10}, + Data: []byte{10}, + }, + }}, + Value: []byte{10}, + StoragePrefix: ibchost.StoreKey, + }}, + Block: nil, + Height: 100, + Revision: 1, + }, + }, + sdkerrors.ErrInvalidAddress, + }, + { + "empty client id", + types.MsgSubmitQueryResult{ + QueryId: 1, + Sender: testutil.TestOwnerAddress, + ClientId: "", + Result: &types.QueryResult{ + KvResults: nil, + Block: &types.Block{ + NextBlockHeader: nil, + Header: nil, + Tx: nil, + }, + Height: 100, + Revision: 1, + }, + }, + types.ErrInvalidClientID, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := msgServer.SubmitQueryResult(ctx, &tt.msg) + require.ErrorIs(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + +func TestMsgRemoveInterchainQueryRequestValidate(t *testing.T) { + k, ctx := testkeeper.InterchainQueriesKeeper(t, nil, nil, nil, nil) + msgServer := keeper.NewMsgServerImpl(*k) + + tests := []struct { + name string + msg types.MsgRemoveInterchainQueryRequest + expectedErr error + }{ + { + "invalid query id", + types.MsgRemoveInterchainQueryRequest{ + QueryId: 0, + Sender: testutil.TestOwnerAddress, + }, + types.ErrInvalidQueryID, + }, + { + "empty sender", + types.MsgRemoveInterchainQueryRequest{ + QueryId: 1, + Sender: "", + }, + sdkerrors.ErrInvalidAddress, + }, + { + "invalid sender", + types.MsgRemoveInterchainQueryRequest{ + QueryId: 1, + Sender: "invalid-sender", + }, + sdkerrors.ErrInvalidAddress, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := msgServer.RemoveInterchainQuery(ctx, &tt.msg) + require.ErrorIs(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + +func TestMsgUpdateInterchainQueryRequestValidate(t *testing.T) { + k, ctx := testkeeper.InterchainQueriesKeeper(t, nil, nil, nil, nil) + msgServer := keeper.NewMsgServerImpl(*k) + + tests := []struct { + name string + msg types.MsgUpdateInterchainQueryRequest + expectedErr error + }{ + { + "invalid query id", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 0, + NewKeys: []*types.KVKey{{ + Path: "staking", + Key: []byte{1, 2, 3}, + }}, + NewUpdatePeriod: 10, + Sender: testutil.TestOwnerAddress, + }, + types.ErrInvalidQueryID, + }, + { + "empty keys, update_period and tx filter", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: nil, + NewUpdatePeriod: 0, + NewTransactionsFilter: "", + Sender: testutil.TestOwnerAddress, + }, + sdkerrors.ErrInvalidRequest, + }, + { + "both keys and filter sent", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*types.KVKey{{ + Path: "staking", + Key: []byte{1, 2, 3}, + }}, + NewUpdatePeriod: 0, + NewTransactionsFilter: `{"field":"transfer.recipient","op":"eq","value":"cosmos1xxx"}`, + Sender: testutil.TestOwnerAddress, + }, + sdkerrors.ErrInvalidRequest, + }, + { + "too many keys", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: make([]*types.KVKey, types.MaxKVQueryKeysCount+1), + NewUpdatePeriod: 0, + Sender: testutil.TestOwnerAddress, + }, + types.ErrTooManyKVQueryKeys, + }, + { + "nil key", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*types.KVKey{{Key: []byte("key1"), Path: "path1"}, nil}, + NewUpdatePeriod: 0, + Sender: testutil.TestOwnerAddress, + }, + sdkerrors.ErrInvalidType, + }, + { + "duplicated keys", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*types.KVKey{{Key: []byte("key1"), Path: "path1"}, {Key: []byte("key1"), Path: "path1"}}, + NewUpdatePeriod: 0, + Sender: testutil.TestOwnerAddress, + }, + sdkerrors.ErrInvalidRequest, + }, + { + "empty key path", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*types.KVKey{{Key: []byte("key1"), Path: ""}}, + NewUpdatePeriod: 0, + Sender: testutil.TestOwnerAddress, + }, + types.ErrEmptyKeyPath, + }, + { + "empty key id", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*types.KVKey{{Key: []byte(""), Path: "path"}}, + NewUpdatePeriod: 0, + Sender: testutil.TestOwnerAddress, + }, + types.ErrEmptyKeyID, + }, + { + "empty sender", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*types.KVKey{{ + Path: "staking", + Key: []byte{1, 2, 3}, + }}, + NewUpdatePeriod: 10, + Sender: "", + }, + sdkerrors.ErrInvalidAddress, + }, + { + "invalid sender", + types.MsgUpdateInterchainQueryRequest{ + QueryId: 1, + NewKeys: []*types.KVKey{{ + Path: "staking", + Key: []byte{1, 2, 3}, + }}, + NewUpdatePeriod: 10, + Sender: "invalid-sender", + }, + sdkerrors.ErrInvalidAddress, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := msgServer.UpdateInterchainQuery(ctx, &tt.msg) + require.ErrorIs(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + +func TestMsgUpdateParamsValidate(t *testing.T) { + k, ctx := testkeeper.InterchainQueriesKeeper(t, nil, nil, nil, nil) + + tests := []struct { + name string + msg types.MsgUpdateParams + expectedErr string + }{ + { + "empty authority", + types.MsgUpdateParams{ + Authority: "", + }, + "authority is invalid", + }, + { + "invalid authority", + types.MsgUpdateParams{ + Authority: "invalid authority", + }, + "authority is invalid", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := k.UpdateParams(ctx, &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} diff --git a/x/interchainqueries/keeper/params.go b/x/interchainqueries/keeper/params.go new file mode 100644 index 00000000..d8531f5e --- /dev/null +++ b/x/interchainqueries/keeper/params.go @@ -0,0 +1,31 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + + store.Set(types.ParamsKey, bz) + return nil +} diff --git a/x/interchainqueries/keeper/params_test.go b/x/interchainqueries/keeper/params_test.go new file mode 100644 index 00000000..2849b318 --- /dev/null +++ b/x/interchainqueries/keeper/params_test.go @@ -0,0 +1,20 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchainqueries/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +func TestGetParams(t *testing.T) { + k, ctx := testkeeper.InterchainQueriesKeeper(t, nil, nil, nil, nil) + params := types.DefaultParams() + + err := k.SetParams(ctx, params) + require.NoError(t, err) + + require.EqualValues(t, params, k.GetParams(ctx)) +} diff --git a/x/interchainqueries/keeper/process_block_results.go b/x/interchainqueries/keeper/process_block_results.go new file mode 100644 index 00000000..3bac3497 --- /dev/null +++ b/x/interchainqueries/keeper/process_block_results.go @@ -0,0 +1,211 @@ +package keeper + +import ( + "bytes" + "encoding/hex" + + "cosmossdk.io/errors" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cometbft/cometbft/crypto/merkle" + tmtypes "github.com/cometbft/cometbft/types" + sdk "github.com/cosmos/cosmos-sdk/types" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + "github.com/cosmos/ibc-go/v8/modules/core/exported" + tendermintLightClientTypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +// deterministicExecTxResult strips non-deterministic fields from +// ExecTxResult and returns another ExecTxResult. +func deterministicExecTxResult(response *abci.ExecTxResult) *abci.ExecTxResult { + return &abci.ExecTxResult{ + Code: response.Code, + Data: response.Data, + GasWanted: response.GasWanted, + GasUsed: response.GasUsed, + } +} + +// checkHeadersOrder do some basic checks to verify that nextHeader is really next for the header +func checkHeadersOrder(header, nextHeader *tendermintLightClientTypes.Header) error { + if nextHeader.Header.Height != header.Header.Height+1 { + return errors.Wrapf(types.ErrInvalidHeader, "nextHeader.Height (%d) is not actually next for a header with height %d", nextHeader.Header.Height, header.Header.Height) + } + + tmHeader, err := tmtypes.HeaderFromProto(header.Header) + if err != nil { + return errors.Wrapf(types.ErrInvalidHeader, "failed to get tendermint header from proto header: %v", err) + } + tmNextHeader, err := tmtypes.HeaderFromProto(nextHeader.Header) + if err != nil { + return errors.Wrapf(types.ErrInvalidHeader, "failed to get tendermint header from proto header: %v", err) + } + + if !bytes.Equal(tmHeader.NextValidatorsHash, tmNextHeader.ValidatorsHash) { + return errors.Wrapf(types.ErrInvalidHeader, "header.NextValidatorsHash is not equal to nextHeader.ValidatorsHash: %s != %s", tmHeader.NextValidatorsHash.String(), tmNextHeader.ValidatorsHash.String()) + } + + if !bytes.Equal(tmHeader.Hash(), tmNextHeader.LastBlockID.Hash) { + return errors.Wrapf(types.ErrInvalidHeader, "header.Hash() is not equal to nextHeader.LastBlockID.Hash: %s != %s", tmHeader.Hash().String(), tmNextHeader.LastBlockID.Hash.String()) + } + + return nil +} + +type Verifier struct{} + +// VerifyHeaders verify that headers are valid tendermint headers, checks them on validity by trying call ibcClient.UpdateClient(header) +// to update light client's consensus state and checks that they are sequential (tl;dr header.Height + 1 == nextHeader.Height) +func (v Verifier) VerifyHeaders(ctx sdk.Context, clientKeeper clientkeeper.Keeper, clientID string, header, nextHeader exported.ClientMessage) error { + // this IBC handler updates the consensus state and the state root from a provided header. + // But more importantly in the current situation, it checks that header is valid. + // Honestly we need only to verify headers, but since the check functions are private, and we don't want to duplicate the code, + // we update consensus state at the same time (because why not?) + if err := clientKeeper.UpdateClient(ctx, clientID, header); err != nil { + return errors.Wrapf(err, "failed to update client: %v", err) + } + if err := clientKeeper.UpdateClient(ctx, clientID, nextHeader); err != nil { + return errors.Wrapf(err, "failed to update client: %v", err) + } + + tmHeader, ok := header.(*tendermintLightClientTypes.Header) + if !ok { + return errors.Wrapf(types.ErrInvalidType, "failed to cast header to tendermint Header") + } + + tmNextHeader, ok := nextHeader.(*tendermintLightClientTypes.Header) + if !ok { + return errors.Wrapf(types.ErrInvalidType, "failed to cast header to tendermint Header") + } + + // do some basic check to verify that tmNextHeader is next for the tmHeader + if err := checkHeadersOrder(tmHeader, tmNextHeader); err != nil { + return errors.Wrapf(types.ErrInvalidHeader, "block.NextBlockHeader is not next for the block.Header: %v", err) + } + + return nil +} + +func (v Verifier) UnpackHeader(any *codectypes.Any) (exported.ClientMessage, error) { + return ibcclienttypes.UnpackClientMessage(any) +} + +// ProcessBlock verifies headers and transaction in the block, and then passes the tx query result to +// the querying contract's sudo handler. +func (k Keeper) ProcessBlock(ctx sdk.Context, queryOwner sdk.AccAddress, queryID uint64, clientID string, block *types.Block) error { + header, err := k.headerVerifier.UnpackHeader(block.Header) + if err != nil { + ctx.Logger().Debug("ProcessBlock: failed to unpack block header", "error", err) + return errors.Wrapf(types.ErrProtoUnmarshal, "failed to unpack block header: %v", err) + } + + nextHeader, err := k.headerVerifier.UnpackHeader(block.NextBlockHeader) + if err != nil { + ctx.Logger().Debug("ProcessBlock: failed to unpack block header", "error", err) + return errors.Wrapf(types.ErrProtoUnmarshal, "failed to unpack next block header: %v", err) + } + + if err := k.headerVerifier.VerifyHeaders(ctx, k.ibcKeeper.ClientKeeper, clientID, header, nextHeader); err != nil { + ctx.Logger().Debug("ProcessBlock: failed to verify headers", "error", err) + return errors.Wrapf(types.ErrInvalidHeader, "failed to verify headers: %v", err) + } + + tmHeader, ok := header.(*tendermintLightClientTypes.Header) + if !ok { + ctx.Logger().Debug("ProcessBlock: failed to cast current header to tendermint Header", "query_id", queryID) + return errors.Wrap(types.ErrInvalidType, "failed to cast current header to tendermint Header") + } + + tmNextHeader, ok := nextHeader.(*tendermintLightClientTypes.Header) + if !ok { + ctx.Logger().Debug("ProcessBlock: failed to cast next header to tendermint Header", "query_id", queryID) + return errors.Wrap(types.ErrInvalidType, "failed to cast next header to tendermint header") + } + + var ( + tx = block.GetTx() + txData = tx.GetData() + txHash = tmtypes.Tx(txData).Hash() + ) + if !k.CheckTransactionIsAlreadyProcessed(ctx, queryID, txHash) { + // Check that cryptography is O.K. (tx is included in the block, tx was executed successfully) + if err = k.transactionVerifier.VerifyTransaction(tmHeader, tmNextHeader, tx); err != nil { + ctx.Logger().Debug("ProcessBlock: failed to verifyTransaction", + "error", err, "query_id", queryID, "tx_hash", hex.EncodeToString(txHash)) + return errors.Wrapf(types.ErrInternal, "failed to verifyTransaction %s: %v", hex.EncodeToString(txHash), err) + } + + // Let the query owner contract process the query result. + if _, err := k.contractManagerKeeper.SudoTxQueryResult(ctx, queryOwner, queryID, ibcclienttypes.NewHeight(tmHeader.TrustedHeight.GetRevisionNumber(), uint64(tmHeader.Header.Height)), txData); err != nil { + ctx.Logger().Debug("ProcessBlock: failed to SudoTxQueryResult", + "error", err, "query_id", queryID, "tx_hash", hex.EncodeToString(txHash)) + return errors.Wrapf(err, "contract %s rejected transaction query result (tx_hash: %s)", + queryOwner, hex.EncodeToString(txHash)) + } + + k.SaveTransactionAsProcessed(ctx, queryID, txHash) + } else { + ctx.Logger().Debug("ProcessBlock: transaction was already submitted", + "query_id", queryID, "tx_hash", hex.EncodeToString(txHash)) + } + + return nil +} + +type TransactionVerifier struct{} + +// VerifyTransaction verifies that some transaction is included in block, and the transaction was executed successfully. +// The function checks: +// * transaction is included in block - header.DataHash merkle root contains transactions hash; +// * transactions was executed successfully - transaction's responseDeliveryTx.Code == 0; +// * transaction's responseDeliveryTx is legitimate - nextHeaderLastResultsDataHash merkle root contains +// deterministicExecTxResult(ResponseDeliveryTx).Bytes() +func (v TransactionVerifier) VerifyTransaction( + header *tendermintLightClientTypes.Header, + nextHeader *tendermintLightClientTypes.Header, + tx *types.TxValue, +) error { + // verify inclusion proof + inclusionProof, err := merkle.ProofFromProto(tx.InclusionProof) + if err != nil { + return errors.Wrapf(types.ErrInvalidType, "failed to convert proto proof to merkle proof: %v", err) + } + + if err = inclusionProof.Verify(header.Header.DataHash, tmtypes.Tx(tx.Data).Hash()); err != nil { + return errors.Wrapf(types.ErrInvalidProof, "failed to verify inclusion proof: %v", err) + } + + // verify delivery proof + deliveryProof, err := merkle.ProofFromProto(tx.DeliveryProof) + if err != nil { + return errors.Wrapf(types.ErrInvalidType, "failed to convert proto proof to merkle proof: %v", err) + } + + responseTx := deterministicExecTxResult(tx.Response) + + responseTxBz, err := responseTx.Marshal() + if err != nil { + return errors.Wrapf(types.ErrProtoMarshal, "failed to marshal ResponseDeliveryTx: %v", err) + } + + if err = deliveryProof.Verify(nextHeader.Header.LastResultsHash, responseTxBz); err != nil { + return errors.Wrapf(types.ErrInvalidProof, "failed to verify delivery proof: %v", err) + } + + // check that transaction was successful + if tx.Response.Code != abci.CodeTypeOK { + return errors.Wrapf(types.ErrInternal, "tx %s is unsuccessful: ResponseDelivery.Code = %d", hex.EncodeToString(tmtypes.Tx(tx.Data).Hash()), tx.Response.Code) + } + + // check that inclusion proof and delivery proof are for the same transaction + if deliveryProof.Index != inclusionProof.Index { + return errors.Wrapf(types.ErrInvalidProof, "inclusion proof index and delivery proof index are not equal: %d != %d", inclusionProof.Index, deliveryProof.Index) + } + + return nil +} diff --git a/x/interchainqueries/keeper/process_block_results_test.go b/x/interchainqueries/keeper/process_block_results_test.go new file mode 100644 index 00000000..7d17d051 --- /dev/null +++ b/x/interchainqueries/keeper/process_block_results_test.go @@ -0,0 +1,398 @@ +package keeper_test + +import ( + "fmt" + "testing" + "time" + + abci "github.com/cometbft/cometbft/abci/types" + + ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" + "github.com/golang/mock/gomock" + + icqtestkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchainqueries/keeper" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/interchainqueries/types" + + "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/cometbft/cometbft/crypto/tmhash" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + tmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version" + tmtypes "github.com/cometbft/cometbft/types" + tmversion "github.com/cometbft/cometbft/version" + "github.com/cosmos/cosmos-sdk/types" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + "github.com/cosmos/ibc-go/v8/modules/core/exported" + ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + ibctesting "github.com/cosmos/ibc-go/v8/testing" + "github.com/stretchr/testify/require" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" + + "github.com/Nolus-Protocol/nolus-core/testutil" + iqkeeper "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/keeper" + iqtypes "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +// CreateTMClientHeader creates a TM header to update the TM client. Args are passed in to allow +// caller flexibility to use params that differ from the chain. +func CreateTMClientHeader(chain *ibctesting.TestChain, chainID string, blockHeight int64, trustedHeight ibcclienttypes.Height, timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator, previousHeader *tmtypes.Header) *ibctmtypes.Header { + var ( + valSet *tmproto.ValidatorSet + trustedVals *tmproto.ValidatorSet + ) + require.NotNil(chain.TB, tmValSet) + + vsetHash := tmValSet.Hash() + + tmHeader := tmtypes.Header{ + Version: tmprotoversion.Consensus{Block: tmversion.BlockProtocol, App: 2}, + ChainID: chainID, + Height: blockHeight, + Time: timestamp, + LastBlockID: ibctesting.MakeBlockID(previousHeader.Hash(), 10_000, make([]byte, tmhash.Size)), + LastCommitHash: chain.App.LastCommitID().Hash, + DataHash: tmhash.Sum([]byte("data_hash")), + ValidatorsHash: vsetHash, + NextValidatorsHash: vsetHash, + ConsensusHash: tmhash.Sum([]byte("consensus_hash")), + AppHash: chain.CurrentHeader.AppHash, + LastResultsHash: tmhash.Sum([]byte("last_results_hash")), + EvidenceHash: tmhash.Sum([]byte("evidence_hash")), + ProposerAddress: tmValSet.Proposer.Address, //nolint:staticcheck + } + + hhash := tmHeader.Hash() + blockID := ibctesting.MakeBlockID(hhash, 3, tmhash.Sum([]byte("part_set"))) + voteSet := tmtypes.NewVoteSet(chainID, blockHeight, 1, tmproto.PrecommitType, tmValSet) + + commit, err := tmtypes.MakeExtCommit(blockID, blockHeight, 1, voteSet, signers, timestamp, false) + require.NoError(chain.TB, err) + + signedHeader := &tmproto.SignedHeader{ + Header: tmHeader.ToProto(), + Commit: commit.ToCommit().ToProto(), + } + + if tmValSet != nil { //nolint:staticcheck // this checks if a pointer is nil, suggesting that it can be nil but we have this test all over the place + valSet, err = tmValSet.ToProto() + require.NoError(chain.TB, err) + } + + if tmTrustedVals != nil { + trustedVals, err = tmTrustedVals.ToProto() + require.NoError(chain.TB, err) + } + + // The trusted fields may be nil. They may be filled before relaying messages to a client. + // The relayer is responsible for querying client and injecting appropriate trusted fields. + return &ibctmtypes.Header{ + SignedHeader: signedHeader, + ValidatorSet: valSet, + TrustedHeight: trustedHeight, + TrustedValidators: trustedVals, + } +} + +func NextBlock(chain *ibctesting.TestChain) { + _, err := chain.App.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: chain.CurrentHeader.Height, + Time: chain.CurrentHeader.GetTime(), + NextValidatorsHash: chain.NextVals.Hash(), + }) + require.NoError(chain.TB, err) + + _, err = chain.App.Commit() + require.NoError(chain.TB, err) + + // set the last header to the current header + // use nil trusted fields + ph, err := tmtypes.HeaderFromProto(chain.LastHeader.Header) + require.NoError(chain.TB, err) + + var signers []tmtypes.PrivValidator + for _, val := range chain.Vals.Validators { + signers = append(signers, chain.Signers[val.PubKey.Address().String()]) + } + chain.LastHeader = CreateTMClientHeader(chain, chain.ChainID, chain.CurrentHeader.Height, ibcclienttypes.Height{}, chain.CurrentHeader.Time, chain.Vals, nil, signers, &ph) + + // increment the current header + chain.CurrentHeader = tmproto.Header{ + ChainID: chain.ChainID, + Height: chain.App.LastBlockHeight() + 1, + AppHash: chain.App.LastCommitID().Hash, + // NOTE: the time is increased by the coordinator to maintain time synchrony amongst + // chains. + Time: chain.CurrentHeader.Time, + ValidatorsHash: chain.Vals.Hash(), + NextValidatorsHash: chain.Vals.Hash(), + } +} + +// CommitBlock commits a block on the provided indexes and then increments the global time. +// +// CONTRACT: the passed in list of indexes must not contain duplicates +func CommitBlock(coord *ibctesting.Coordinator, chains ...*ibctesting.TestChain) { + for _, chain := range chains { + NextBlock(chain) + } + coord.IncrementTime() +} + +// UpdateClient updates the IBC client associated with the endpoint. +func UpdateClient(endpoint *ibctesting.Endpoint) (err error) { + var header exported.ClientMessage + + // ensure counterparty has committed state + CommitBlock(endpoint.Chain.Coordinator, endpoint.Counterparty.Chain) + + switch endpoint.ClientConfig.GetClientType() { + case exported.Tendermint: + header, err = endpoint.Chain.ConstructUpdateTMClientHeader(endpoint.Counterparty.Chain, endpoint.ClientID) + + default: + err = fmt.Errorf("client type %s is not supported", endpoint.ClientConfig.GetClientType()) + } + + if err != nil { + return err + } + + msg, err := ibcclienttypes.NewMsgUpdateClient( + endpoint.ClientID, header, + endpoint.Chain.SenderAccount.GetAddress().String(), + ) + require.NoError(endpoint.Chain.TB, err) + + _, err = endpoint.Chain.SendMsgs(msg) + + return err +} + +func (suite *KeeperTestSuite) TestUnpackAndVerifyHeaders() { + tests := []struct { + name string + run func() error + expectedErrorMsg string + }{ + { + "valid headers", + func() error { + suite.Require().NoError(suite.Path.EndpointA.UpdateClient()) + + clientID := suite.Path.EndpointA.ClientID + CommitBlock(suite.Coordinator, suite.ChainB) + header, err := suite.Path.EndpointA.Chain.ConstructUpdateTMClientHeader(suite.Path.EndpointA.Counterparty.Chain, suite.Path.EndpointB.ClientID) + suite.Require().NoError(err) + + CommitBlock(suite.Coordinator, suite.ChainB) + nextHeader, err := suite.Path.EndpointA.Chain.ConstructUpdateTMClientHeader(suite.Path.EndpointA.Counterparty.Chain, suite.Path.EndpointB.ClientID) + suite.Require().NoError(err) + + return iqkeeper.Verifier{}.VerifyHeaders(suite.ChainA.GetContext(), suite.GetNeutronZoneApp(suite.ChainA).IBCKeeper.ClientKeeper, clientID, header, nextHeader) + }, + "", + }, + { + "headers are not sequential", + func() error { + suite.Require().NoError(UpdateClient(suite.Path.EndpointA)) + + clientID := suite.Path.EndpointA.ClientID + CommitBlock(suite.Coordinator, suite.ChainB) + + header, err := suite.Path.EndpointA.Chain.ConstructUpdateTMClientHeader(suite.Path.EndpointA.Counterparty.Chain, suite.Path.EndpointB.ClientID) + suite.Require().NoError(err) + + // skip one block to set nextHeader's height + 2 + CommitBlock(suite.Coordinator, suite.ChainB) + CommitBlock(suite.Coordinator, suite.ChainB) + + nextHeader, err := suite.Path.EndpointA.Chain.ConstructUpdateTMClientHeader(suite.Path.EndpointA.Counterparty.Chain, suite.Path.EndpointB.ClientID) + suite.Require().NoError(err) + + return iqkeeper.Verifier{}.VerifyHeaders(suite.ChainA.GetContext(), suite.GetNeutronZoneApp(suite.ChainA).IBCKeeper.ClientKeeper, clientID, header, nextHeader) + }, + "block.NextBlockHeader is not next for the block.Header", + }, + { + "header has some malicious field", + func() error { + suite.Require().NoError(UpdateClient(suite.Path.EndpointA)) + + clientID := suite.Path.EndpointA.ClientID + CommitBlock(suite.Coordinator, suite.ChainB) + CommitBlock(suite.Coordinator, suite.ChainB) + + header, err := suite.Path.EndpointA.Chain.ConstructUpdateTMClientHeader(suite.Path.EndpointA.Counterparty.Chain, suite.Path.EndpointB.ClientID) + suite.Require().NoError(err) + + CommitBlock(suite.Coordinator, suite.ChainB) + + header.SignedHeader.Header.LastResultsHash = []byte("malicious hash with length 32!!!") + + nextHeader, err := suite.Path.EndpointA.Chain.ConstructUpdateTMClientHeader(suite.Path.EndpointA.Counterparty.Chain, suite.Path.EndpointB.ClientID) + suite.Require().NoError(err) + + return iqkeeper.Verifier{}.VerifyHeaders(suite.ChainA.GetContext(), suite.GetNeutronZoneApp(suite.ChainA).IBCKeeper.ClientKeeper, clientID, header, nextHeader) + }, + "invalid header: untrustedHeader.ValidateBasic failed: commit signs block", + }, + { + "headers from the past (when client on chain A has the most recent consensus state and relayer try to submit old headers from chain B)", + func() error { + suite.Require().NoError(UpdateClient(suite.Path.EndpointA)) + + clientID := suite.Path.EndpointA.ClientID + CommitBlock(suite.Coordinator, suite.ChainB) + + oldHeader := *suite.ChainB.LastHeader + CommitBlock(suite.Coordinator, suite.ChainB) + oldNextHeader := *suite.ChainB.LastHeader + + for i := 0; i < 30; i++ { + suite.Require().NoError(UpdateClient(suite.Path.EndpointA)) + } + headerWithTrustedHeight, err := suite.Path.EndpointA.Chain.ConstructUpdateTMClientHeaderWithTrustedHeight(suite.Path.EndpointA.Counterparty.Chain, suite.Path.EndpointB.ClientID, ibcclienttypes.Height{ + RevisionNumber: 0, + RevisionHeight: 28, + }) + suite.Require().NoError(err) + + oldHeader.TrustedHeight = headerWithTrustedHeight.TrustedHeight + oldHeader.TrustedValidators = headerWithTrustedHeight.TrustedValidators + + oldNextHeader.TrustedHeight = headerWithTrustedHeight.TrustedHeight + oldNextHeader.TrustedValidators = headerWithTrustedHeight.TrustedValidators + + return iqkeeper.Verifier{}.VerifyHeaders(suite.ChainA.GetContext(), suite.GetNeutronZoneApp(suite.ChainA).IBCKeeper.ClientKeeper, clientID, &oldHeader, &oldNextHeader) + }, + "", + }, + } + + for i, tc := range tests { + tt := tc + suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tt.name, i+1, len(tests)), func() { + suite.SetupTest() + + var ( + ctx = suite.ChainA.GetContext() + contractOwner = keeper.RandomAccountAddress(suite.T()) // We don't care what this address is + ) + + // Store code and instantiate reflect contract. + codeID := suite.StoreTestCode(ctx, contractOwner, reflectContractPath) + contractAddress := suite.InstantiateTestContract(ctx, contractOwner, codeID) + suite.Require().NotEmpty(contractAddress) + + err := testutil.SetupICAPath(suite.Path, contractAddress.String()) + suite.Require().NoError(err) + + err = tt.run() + if tt.expectedErrorMsg != "" { + suite.Require().ErrorContains(err, tt.expectedErrorMsg) + } else { + suite.Require().NoError(err) + } + }) + } +} + +func TestSudoHasAddress(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + hv := mock_types.NewMockHeaderVerifier(ctrl) + tv := mock_types.NewMockTransactionVerifier(ctrl) + cm := mock_types.NewMockContractManagerKeeper(ctrl) + ibck := ibckeeper.Keeper{ClientKeeper: clientkeeper.Keeper{}} + + k, ctx := icqtestkeeper.InterchainQueriesKeeper(t, &ibck, cm, hv, tv) + address := types.MustAccAddressFromBech32(testutil.TestOwnerAddress) + header := ibctmtypes.Header{ + SignedHeader: &tmproto.SignedHeader{ + Header: &tmproto.Header{Height: 1001}, + }, + TrustedHeight: ibcclienttypes.Height{ + RevisionNumber: 1, + RevisionHeight: 1001, + }, + } + nextHeader := ibctmtypes.Header{ + TrustedHeight: ibcclienttypes.Height{ + RevisionNumber: 1, + RevisionHeight: 1002, + }, + } + packedHeader, err := codectypes.NewAnyWithValue(&header) + require.NoError(t, err) + packedNextHeader, err := codectypes.NewAnyWithValue(&nextHeader) + require.NoError(t, err) + tx := iqtypes.TxValue{ + Response: nil, + DeliveryProof: nil, + InclusionProof: nil, + Data: []byte("txbody"), + } + block := iqtypes.Block{ + NextBlockHeader: packedNextHeader, + Header: packedHeader, + Tx: &tx, + } + + hv.EXPECT().UnpackHeader(packedHeader).Return(nil, fmt.Errorf("failed to unpack packedHeader")) + err = k.ProcessBlock(ctx, address, 1, "tendermint-07", &block) + require.ErrorContains(t, err, "failed to unpack block header") + + hv.EXPECT().UnpackHeader(packedHeader).Return(exported.ClientMessage(&header), nil) + hv.EXPECT().UnpackHeader(packedNextHeader).Return(nil, fmt.Errorf("failed to unpack packedHeader")) + err = k.ProcessBlock(ctx, address, 1, "tendermint-07", &block) + require.ErrorContains(t, err, "failed to unpack next block header") + + hv.EXPECT().UnpackHeader(packedHeader).Return(exported.ClientMessage(&header), nil) + hv.EXPECT().UnpackHeader(packedNextHeader).Return(exported.ClientMessage(&nextHeader), nil) + hv.EXPECT().VerifyHeaders(ctx, clientkeeper.Keeper{}, "tendermint-07", exported.ClientMessage(&header), exported.ClientMessage(&nextHeader)).Return(fmt.Errorf("failed to verify headers")) + err = k.ProcessBlock(ctx, address, 1, "tendermint-07", &block) + require.ErrorContains(t, err, "failed to verify headers") + + hv.EXPECT().UnpackHeader(packedHeader).Return(exported.ClientMessage(&header), nil) + hv.EXPECT().UnpackHeader(packedNextHeader).Return(exported.ClientMessage(&nextHeader), nil) + hv.EXPECT().VerifyHeaders(ctx, clientkeeper.Keeper{}, "tendermint-07", exported.ClientMessage(&header), exported.ClientMessage(&nextHeader)).Return(nil) + tv.EXPECT().VerifyTransaction(&header, &nextHeader, &tx).Return(fmt.Errorf("failed to verify transaction")) + err = k.ProcessBlock(ctx, address, 1, "tendermint-07", &block) + require.ErrorContains(t, err, "failed to verifyTransaction") + + hv.EXPECT().UnpackHeader(packedHeader).Return(exported.ClientMessage(&header), nil) + hv.EXPECT().UnpackHeader(packedNextHeader).Return(exported.ClientMessage(&nextHeader), nil) + hv.EXPECT().VerifyHeaders(ctx, clientkeeper.Keeper{}, "tendermint-07", exported.ClientMessage(&header), exported.ClientMessage(&nextHeader)).Return(nil) + tv.EXPECT().VerifyTransaction(&header, &nextHeader, &tx).Return(nil) + cm.EXPECT().SudoTxQueryResult(ctx, address, uint64(1), ibcclienttypes.NewHeight(1, uint64(header.Header.Height)), tx.GetData()).Return(nil, fmt.Errorf("contract error")) + err = k.ProcessBlock(ctx, address, 1, "tendermint-07", &block) + require.ErrorContains(t, err, "rejected transaction query result") + + // all error flows passed, time to success + hv.EXPECT().UnpackHeader(packedHeader).Return(exported.ClientMessage(&header), nil) + hv.EXPECT().UnpackHeader(packedNextHeader).Return(exported.ClientMessage(&nextHeader), nil) + hv.EXPECT().VerifyHeaders(ctx, clientkeeper.Keeper{}, "tendermint-07", exported.ClientMessage(&header), exported.ClientMessage(&nextHeader)).Return(nil) + tv.EXPECT().VerifyTransaction(&header, &nextHeader, &tx).Return(nil) + cm.EXPECT().SudoTxQueryResult(ctx, address, uint64(1), ibcclienttypes.NewHeight(1, uint64(header.Header.Height)), tx.GetData()).Return(nil, nil) + err = k.ProcessBlock(ctx, address, 1, "tendermint-07", &block) + require.NoError(t, err) + + // no functions calls after VerifyHeaders means we try to process tx second time + hv.EXPECT().UnpackHeader(packedHeader).Return(exported.ClientMessage(&header), nil) + hv.EXPECT().UnpackHeader(packedNextHeader).Return(exported.ClientMessage(&nextHeader), nil) + hv.EXPECT().VerifyHeaders(ctx, clientkeeper.Keeper{}, "tendermint-07", exported.ClientMessage(&header), exported.ClientMessage(&nextHeader)).Return(nil) + err = k.ProcessBlock(ctx, address, 1, "tendermint-07", &block) + require.NoError(t, err) + + // same tx + another queryID + hv.EXPECT().UnpackHeader(packedHeader).Return(exported.ClientMessage(&header), nil) + hv.EXPECT().UnpackHeader(packedNextHeader).Return(exported.ClientMessage(&nextHeader), nil) + hv.EXPECT().VerifyHeaders(ctx, clientkeeper.Keeper{}, "tendermint-07", exported.ClientMessage(&header), exported.ClientMessage(&nextHeader)).Return(nil) + tv.EXPECT().VerifyTransaction(&header, &nextHeader, &tx).Return(nil) + cm.EXPECT().SudoTxQueryResult(ctx, address, uint64(2), ibcclienttypes.NewHeight(1, uint64(header.Header.Height)), tx.GetData()).Return(nil, nil) + err = k.ProcessBlock(ctx, address, 2, "tendermint-07", &block) + require.NoError(t, err) +} diff --git a/x/interchainqueries/module.go b/x/interchainqueries/module.go new file mode 100644 index 00000000..603358a4 --- /dev/null +++ b/x/interchainqueries/module.go @@ -0,0 +1,181 @@ +package interchainqueries + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/client/cli" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +var ( + _ appmodule.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + return + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +var _ appmodule.AppModule = AppModule{} + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() { // marker +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() { // marker +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return types.ConsensusVersion } + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(_ sdk.Context) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(wctx context.Context) ([]abci.ValidatorUpdate, error) { + ctx := sdk.UnwrapSDKContext(wctx) + am.keeper.TxQueriesCleanup(ctx) + return []abci.ValidatorUpdate{}, nil +} diff --git a/x/interchainqueries/module_simulation.go b/x/interchainqueries/module_simulation.go new file mode 100644 index 00000000..53e02c20 --- /dev/null +++ b/x/interchainqueries/module_simulation.go @@ -0,0 +1,49 @@ +package interchainqueries + +import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/Nolus-Protocol/nolus-core/testutil/common/sample" + interchainqueriessimulation "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/simulation" + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +// avoid unused import issue +var ( + _ = sample.AccAddress + _ = interchainqueriessimulation.FindAccount + _ = sims.StakePerAccount + _ = simulation.MsgEntryKind + _ = baseapp.Paramspace +) + +// GenerateGenesisState creates a randomized GenState of the module +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + interchainqueriesGenesis := types.GenesisState{ + Params: types.DefaultParams(), + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&interchainqueriesGenesis) +} + +// ProposalContents doesn't return any content functions for governance proposals +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { + return nil +} + +// RegisterStoreDecoder registers a decoder +func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + + return operations +} diff --git a/x/interchainqueries/simulation/simap.go b/x/interchainqueries/simulation/simap.go new file mode 100644 index 00000000..92c437c0 --- /dev/null +++ b/x/interchainqueries/simulation/simap.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/interchainqueries/types/codec.go b/x/interchainqueries/types/codec.go new file mode 100644 index 00000000..985707a3 --- /dev/null +++ b/x/interchainqueries/types/codec.go @@ -0,0 +1,30 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgRegisterInterchainQuery{}, "interchainqueries/RegisterQuery", nil) + cdc.RegisterConcrete(&MsgUpdateParams{}, "interchainqueries/MsgUpdateParams", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgRegisterInterchainQuery{}, + &MsgSubmitQueryResult{}, + &MsgUpdateInterchainQueryRequest{}, + &MsgRemoveInterchainQueryRequest{}, + &MsgUpdateParams{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/interchainqueries/types/constants.go b/x/interchainqueries/types/constants.go new file mode 100644 index 00000000..4c93fbef --- /dev/null +++ b/x/interchainqueries/types/constants.go @@ -0,0 +1,3 @@ +package types + +const ConsensusVersion = 2 diff --git a/x/interchainqueries/types/errors.go b/x/interchainqueries/types/errors.go new file mode 100644 index 00000000..4a3213cc --- /dev/null +++ b/x/interchainqueries/types/errors.go @@ -0,0 +1,31 @@ +package types + +import ( + "cosmossdk.io/errors" +) + +// x/interchainqueries module sentinel errors +var ( + ErrInvalidQueryID = errors.Register(ModuleName, 1100, "invalid query id") + ErrEmptyResult = errors.Register(ModuleName, 1101, "empty result") + ErrInvalidClientID = errors.Register(ModuleName, 1102, "invalid client id") + ErrInvalidUpdatePeriod = errors.Register(ModuleName, 1103, "invalid update period") + ErrInvalidConnectionID = errors.Register(ModuleName, 1104, "invalid connection id") + ErrInvalidQueryType = errors.Register(ModuleName, 1105, "invalid query type") + ErrInvalidTransactionsFilter = errors.Register(ModuleName, 1106, "invalid transactions filter") + ErrInvalidSubmittedResult = errors.Register(ModuleName, 1107, "invalid result") + ErrProtoMarshal = errors.Register(ModuleName, 1108, "failed to marshal protobuf bytes") + ErrProtoUnmarshal = errors.Register(ModuleName, 1109, "failed to unmarshal protobuf bytes") + ErrInvalidType = errors.Register(ModuleName, 1110, "invalid type") + ErrInternal = errors.Register(ModuleName, 1111, "internal error") + ErrInvalidProof = errors.Register(ModuleName, 1112, "merkle proof is invalid") + ErrInvalidHeader = errors.Register(ModuleName, 1113, "header is invalid") + ErrInvalidHeight = errors.Register(ModuleName, 1114, "height is invalid") + ErrNoQueryResult = errors.Register(ModuleName, 1115, "no query result") + ErrNotContract = errors.Register(ModuleName, 1116, "not a contract") + ErrEmptyKeys = errors.Register(ModuleName, 1117, "keys are empty") + ErrEmptyKeyPath = errors.Register(ModuleName, 1118, "key path is empty") + ErrEmptyKeyID = errors.Register(ModuleName, 1119, "key id is empty") + ErrTooManyKVQueryKeys = errors.Register(ModuleName, 1120, "too many keys") + ErrUnexpectedQueryTypeGenesis = errors.Register(ModuleName, 1121, "unexpected query type") +) diff --git a/x/interchainqueries/types/expected_keepers.go b/x/interchainqueries/types/expected_keepers.go new file mode 100644 index 00000000..f1858160 --- /dev/null +++ b/x/interchainqueries/types/expected_keepers.go @@ -0,0 +1,28 @@ +package types + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins + SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + // Methods imported from bank should be defined here +} + +type ContractManagerKeeper interface { + HasContractInfo(ctx context.Context, contractAddress sdk.AccAddress) bool + SudoKVQueryResult(ctx context.Context, contractAddress sdk.AccAddress, queryID uint64) ([]byte, error) + SudoTxQueryResult(ctx context.Context, contractAddress sdk.AccAddress, queryID uint64, height ibcclienttypes.Height, data []byte) ([]byte, error) +} diff --git a/x/interchainqueries/types/genesis.go b/x/interchainqueries/types/genesis.go new file mode 100644 index 00000000..c00668e5 --- /dev/null +++ b/x/interchainqueries/types/genesis.go @@ -0,0 +1,52 @@ +package types + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + err := gs.Params.Validate() + if err != nil { + return err + } + seenIDs := map[uint64]bool{} + + for _, val := range gs.GetRegisteredQueries() { + if seenIDs[val.Id] { + return errors.Wrapf(ErrInvalidQueryID, "duplicate query id: %d", val.Id) + } + seenIDs[val.Id] = true + + _, err = sdk.AccAddressFromBech32(val.Owner) + if err != nil { + return errors.Wrapf(err, "Invalid owner address (%s)", err) + } + + switch val.QueryType { + case string(InterchainQueryTypeTX): + if err := ValidateTransactionsFilter(val.TransactionsFilter); err != nil { + return errors.Wrap(ErrInvalidTransactionsFilter, err.Error()) + } + case string(InterchainQueryTypeKV): + if len(val.Keys) == 0 { + return errors.Wrap(ErrEmptyKeys, "keys cannot be empty") + } + if err := validateKeys(val.GetKeys()); err != nil { + return err + } + default: + return errors.Wrapf(ErrUnexpectedQueryTypeGenesis, "Unexpected query type: %s", val.QueryType) + } + } + return nil +} diff --git a/x/interchainqueries/types/genesis.pb.go b/x/interchainqueries/types/genesis.pb.go new file mode 100644 index 00000000..ef69e7dd --- /dev/null +++ b/x/interchainqueries/types/genesis.pb.go @@ -0,0 +1,1336 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchainqueries/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + 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/v8/modules/core/02-client/types" +) + +// 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 + +type RegisteredQuery struct { + // The unique id of the registered query. + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + // The address that registered the query. + Owner string `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"` + // The query type identifier: `kv` or `tx` now + QueryType string `protobuf:"bytes,3,opt,name=query_type,json=queryType,proto3" json:"query_type,omitempty"` + // The KV-storage keys for which we want to get values from remote chain + Keys []*KVKey `protobuf:"bytes,4,rep,name=keys,proto3" json:"keys,omitempty"` + // The filter for transaction search ICQ + TransactionsFilter string `protobuf:"bytes,5,opt,name=transactions_filter,json=transactionsFilter,proto3" json:"transactions_filter,omitempty"` + // The IBC connection ID for getting ConsensusState to verify proofs + ConnectionId string `protobuf:"bytes,6,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + // Parameter that defines how often the query must be updated. + UpdatePeriod uint64 `protobuf:"varint,7,opt,name=update_period,json=updatePeriod,proto3" json:"update_period,omitempty"` + // The local chain last block height when the query result was updated. + LastSubmittedResultLocalHeight uint64 `protobuf:"varint,8,opt,name=last_submitted_result_local_height,json=lastSubmittedResultLocalHeight,proto3" json:"last_submitted_result_local_height,omitempty"` + // The remote chain last block height when the query result was updated. + LastSubmittedResultRemoteHeight *types.Height `protobuf:"bytes,9,opt,name=last_submitted_result_remote_height,json=lastSubmittedResultRemoteHeight,proto3" json:"last_submitted_result_remote_height,omitempty"` + // Amount of coins deposited for the query. + Deposit github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,10,rep,name=deposit,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"deposit"` + // Timeout before query becomes available for everybody to remove. + SubmitTimeout uint64 `protobuf:"varint,11,opt,name=submit_timeout,json=submitTimeout,proto3" json:"submit_timeout,omitempty"` + // The local chain height when the query was registered. + RegisteredAtHeight uint64 `protobuf:"varint,12,opt,name=registered_at_height,json=registeredAtHeight,proto3" json:"registered_at_height,omitempty"` +} + +func (m *RegisteredQuery) Reset() { *m = RegisteredQuery{} } +func (m *RegisteredQuery) String() string { return proto.CompactTextString(m) } +func (*RegisteredQuery) ProtoMessage() {} +func (*RegisteredQuery) Descriptor() ([]byte, []int) { + return fileDescriptor_ed312d37df0260a6, []int{0} +} +func (m *RegisteredQuery) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RegisteredQuery) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RegisteredQuery.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 *RegisteredQuery) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisteredQuery.Merge(m, src) +} +func (m *RegisteredQuery) XXX_Size() int { + return m.Size() +} +func (m *RegisteredQuery) XXX_DiscardUnknown() { + xxx_messageInfo_RegisteredQuery.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisteredQuery proto.InternalMessageInfo + +func (m *RegisteredQuery) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *RegisteredQuery) GetOwner() string { + if m != nil { + return m.Owner + } + return "" +} + +func (m *RegisteredQuery) GetQueryType() string { + if m != nil { + return m.QueryType + } + return "" +} + +func (m *RegisteredQuery) GetKeys() []*KVKey { + if m != nil { + return m.Keys + } + return nil +} + +func (m *RegisteredQuery) GetTransactionsFilter() string { + if m != nil { + return m.TransactionsFilter + } + return "" +} + +func (m *RegisteredQuery) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *RegisteredQuery) GetUpdatePeriod() uint64 { + if m != nil { + return m.UpdatePeriod + } + return 0 +} + +func (m *RegisteredQuery) GetLastSubmittedResultLocalHeight() uint64 { + if m != nil { + return m.LastSubmittedResultLocalHeight + } + return 0 +} + +func (m *RegisteredQuery) GetLastSubmittedResultRemoteHeight() *types.Height { + if m != nil { + return m.LastSubmittedResultRemoteHeight + } + return nil +} + +func (m *RegisteredQuery) GetDeposit() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Deposit + } + return nil +} + +func (m *RegisteredQuery) GetSubmitTimeout() uint64 { + if m != nil { + return m.SubmitTimeout + } + return 0 +} + +func (m *RegisteredQuery) GetRegisteredAtHeight() uint64 { + if m != nil { + return m.RegisteredAtHeight + } + return 0 +} + +type KVKey struct { + // Path (storage prefix) to the storage where you want to read value by key + // (usually name of cosmos-sdk module: 'staking', 'bank', etc.) + Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` + // Key you want to read from the storage + Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` +} + +func (m *KVKey) Reset() { *m = KVKey{} } +func (m *KVKey) String() string { return proto.CompactTextString(m) } +func (*KVKey) ProtoMessage() {} +func (*KVKey) Descriptor() ([]byte, []int) { + return fileDescriptor_ed312d37df0260a6, []int{1} +} +func (m *KVKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *KVKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_KVKey.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 *KVKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_KVKey.Merge(m, src) +} +func (m *KVKey) XXX_Size() int { + return m.Size() +} +func (m *KVKey) XXX_DiscardUnknown() { + xxx_messageInfo_KVKey.DiscardUnknown(m) +} + +var xxx_messageInfo_KVKey proto.InternalMessageInfo + +func (m *KVKey) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + +func (m *KVKey) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +// GenesisState defines the interchainqueries module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + RegisteredQueries []*RegisteredQuery `protobuf:"bytes,2,rep,name=registered_queries,json=registeredQueries,proto3" json:"registered_queries,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_ed312d37df0260a6, []int{2} +} +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) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetRegisteredQueries() []*RegisteredQuery { + if m != nil { + return m.RegisteredQueries + } + return nil +} + +func init() { + proto.RegisterType((*RegisteredQuery)(nil), "neutron.interchainqueries.RegisteredQuery") + proto.RegisterType((*KVKey)(nil), "neutron.interchainqueries.KVKey") + proto.RegisterType((*GenesisState)(nil), "neutron.interchainqueries.GenesisState") +} + +func init() { + proto.RegisterFile("neutron/interchainqueries/genesis.proto", fileDescriptor_ed312d37df0260a6) +} + +var fileDescriptor_ed312d37df0260a6 = []byte{ + // 638 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x53, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0xd3, 0xb4, 0x25, 0x9b, 0xb4, 0xc0, 0xd2, 0x83, 0x5b, 0x09, 0x27, 0xa4, 0x02, 0x22, + 0xa4, 0x7a, 0x9b, 0xd2, 0x1b, 0x07, 0x44, 0x91, 0xf8, 0x2b, 0x87, 0xe2, 0x16, 0x24, 0xb8, 0x58, + 0xfe, 0x19, 0x9c, 0x55, 0x93, 0x5d, 0xb3, 0xbb, 0x0e, 0xf8, 0x2d, 0x78, 0x8e, 0x3e, 0x49, 0x8f, + 0x3d, 0x72, 0x02, 0xd4, 0x3e, 0x07, 0x12, 0xf2, 0xd8, 0xa1, 0x05, 0xd2, 0x9e, 0x3c, 0xfe, 0xf6, + 0x9b, 0x6f, 0x67, 0x67, 0xbe, 0x21, 0xf7, 0x05, 0x64, 0x46, 0x49, 0xc1, 0xb8, 0x30, 0xa0, 0xa2, + 0x61, 0xc0, 0xc5, 0xa7, 0x0c, 0x14, 0x07, 0xcd, 0x12, 0x10, 0xa0, 0xb9, 0x76, 0x53, 0x25, 0x8d, + 0xa4, 0xab, 0x15, 0xd1, 0xfd, 0x8f, 0xb8, 0xe6, 0x44, 0x52, 0x8f, 0xa5, 0x66, 0x61, 0xa0, 0x81, + 0x4d, 0x06, 0x21, 0x98, 0x60, 0xc0, 0x22, 0xc9, 0x45, 0x99, 0xba, 0xb6, 0x92, 0xc8, 0x44, 0x62, + 0xc8, 0x8a, 0xa8, 0x42, 0x3b, 0x3c, 0x8c, 0x58, 0x24, 0x15, 0xb0, 0x68, 0xc4, 0x41, 0x18, 0x36, + 0x19, 0x54, 0x51, 0x45, 0xb8, 0x77, 0x79, 0x69, 0x69, 0xa0, 0x82, 0x71, 0x55, 0x59, 0xef, 0x57, + 0x83, 0x5c, 0xf7, 0x20, 0xe1, 0xda, 0x80, 0x82, 0xf8, 0x4d, 0x06, 0x2a, 0xa7, 0xcb, 0xa4, 0xce, + 0x63, 0xdb, 0xea, 0x5a, 0xfd, 0x86, 0x57, 0xe7, 0x31, 0x5d, 0x21, 0xf3, 0xf2, 0xb3, 0x00, 0x65, + 0xd7, 0xbb, 0x56, 0xbf, 0xe9, 0x95, 0x3f, 0xf4, 0x36, 0x21, 0x85, 0x62, 0xee, 0x9b, 0x3c, 0x05, + 0x7b, 0x0e, 0x8f, 0x9a, 0x88, 0x1c, 0xe4, 0x29, 0xd0, 0x6d, 0xd2, 0x38, 0x84, 0x5c, 0xdb, 0x8d, + 0xee, 0x5c, 0xbf, 0xb5, 0xd5, 0x75, 0x2f, 0xed, 0x80, 0xbb, 0xfb, 0x6e, 0x17, 0x72, 0x0f, 0xd9, + 0x94, 0x91, 0x5b, 0x46, 0x05, 0x42, 0x07, 0x91, 0xe1, 0x52, 0x68, 0xff, 0x23, 0x1f, 0x19, 0x50, + 0xf6, 0x3c, 0xaa, 0xd3, 0x8b, 0x47, 0xcf, 0xf0, 0x84, 0xae, 0x93, 0xa5, 0x48, 0x0a, 0x01, 0x08, + 0xfa, 0x3c, 0xb6, 0x17, 0x90, 0xda, 0x3e, 0x07, 0x5f, 0xc6, 0x05, 0x29, 0x4b, 0xe3, 0xc0, 0x80, + 0x9f, 0x82, 0xe2, 0x32, 0xb6, 0x17, 0xf1, 0x6d, 0xed, 0x12, 0xdc, 0x43, 0x8c, 0xbe, 0x22, 0xbd, + 0x51, 0xa0, 0x8d, 0xaf, 0xb3, 0x70, 0xcc, 0x8d, 0x81, 0xd8, 0x57, 0xa0, 0xb3, 0x91, 0xf1, 0x47, + 0x32, 0x0a, 0x46, 0xfe, 0x10, 0x78, 0x32, 0x34, 0xf6, 0x35, 0xcc, 0x74, 0x0a, 0xe6, 0xfe, 0x94, + 0xe8, 0x21, 0xef, 0x75, 0x41, 0x7b, 0x81, 0x2c, 0x3a, 0x24, 0xeb, 0xb3, 0xb5, 0x14, 0x8c, 0xa5, + 0x81, 0xa9, 0x58, 0xb3, 0x6b, 0xf5, 0x5b, 0x5b, 0x6b, 0x2e, 0x0f, 0x23, 0xb7, 0x18, 0xa6, 0x5b, + 0x8d, 0x70, 0x32, 0x70, 0x4b, 0x21, 0xaf, 0x33, 0xe3, 0x22, 0x0f, 0x35, 0xaa, 0x9b, 0x80, 0x2c, + 0xc6, 0x90, 0x4a, 0xcd, 0x8d, 0x4d, 0xb0, 0xd3, 0xab, 0x6e, 0x69, 0x28, 0xb7, 0x30, 0x94, 0x5b, + 0x19, 0xca, 0x7d, 0x2a, 0xb9, 0xd8, 0xd9, 0x3c, 0xfe, 0xde, 0xa9, 0x1d, 0xfd, 0xe8, 0xf4, 0x13, + 0x6e, 0x86, 0x59, 0xe8, 0x46, 0x72, 0xcc, 0x2a, 0xf7, 0x95, 0x9f, 0x0d, 0x1d, 0x1f, 0xb2, 0x62, + 0x9c, 0x1a, 0x13, 0xb4, 0x37, 0xd5, 0xa6, 0x77, 0xc9, 0x72, 0xf9, 0x16, 0xdf, 0xf0, 0x31, 0xc8, + 0xcc, 0xd8, 0x2d, 0x6c, 0xc4, 0x52, 0x89, 0x1e, 0x94, 0x20, 0xdd, 0x24, 0x2b, 0xea, 0x8f, 0x99, + 0xfc, 0xc0, 0x4c, 0x1f, 0xda, 0x46, 0x32, 0x3d, 0x3f, 0x7b, 0x62, 0xca, 0xfa, 0x7b, 0x1b, 0x64, + 0x1e, 0xe7, 0x4f, 0x29, 0x69, 0xa4, 0x81, 0x19, 0xa2, 0xed, 0x9a, 0x1e, 0xc6, 0xf4, 0x06, 0x99, + 0x3b, 0x84, 0x1c, 0x6d, 0xd7, 0xf6, 0x8a, 0xb0, 0x77, 0x64, 0x91, 0xf6, 0xf3, 0x72, 0xb5, 0xf6, + 0x4d, 0x60, 0x80, 0x3e, 0x26, 0x0b, 0xa5, 0x9f, 0x31, 0xb1, 0xb5, 0x75, 0xe7, 0x0a, 0xa3, 0xed, + 0x21, 0x71, 0xa7, 0x51, 0xb4, 0xc1, 0xab, 0xd2, 0xe8, 0x7b, 0x72, 0xa1, 0x2c, 0xbf, 0xa2, 0xda, + 0x75, 0xec, 0xe5, 0x83, 0x2b, 0xc4, 0xfe, 0x59, 0x1a, 0xef, 0xa6, 0xfa, 0x0b, 0xe0, 0xa0, 0x77, + 0xde, 0x1e, 0x9f, 0x3a, 0xd6, 0xc9, 0xa9, 0x63, 0xfd, 0x3c, 0x75, 0xac, 0xaf, 0x67, 0x4e, 0xed, + 0xe4, 0xcc, 0xa9, 0x7d, 0x3b, 0x73, 0x6a, 0x1f, 0x1e, 0x5d, 0x98, 0x40, 0x75, 0xc5, 0x86, 0x54, + 0xc9, 0x34, 0x66, 0x93, 0x6d, 0xf6, 0x65, 0xc6, 0xe6, 0xe2, 0x68, 0xc2, 0x05, 0xdc, 0xdc, 0x87, + 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x7b, 0x34, 0x51, 0x13, 0x7e, 0x04, 0x00, 0x00, +} + +func (m *RegisteredQuery) 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 *RegisteredQuery) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RegisteredQuery) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.RegisteredAtHeight != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.RegisteredAtHeight)) + i-- + dAtA[i] = 0x60 + } + if m.SubmitTimeout != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.SubmitTimeout)) + i-- + dAtA[i] = 0x58 + } + if len(m.Deposit) > 0 { + for iNdEx := len(m.Deposit) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Deposit[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + } + } + if m.LastSubmittedResultRemoteHeight != nil { + { + size, err := m.LastSubmittedResultRemoteHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + } + if m.LastSubmittedResultLocalHeight != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.LastSubmittedResultLocalHeight)) + i-- + dAtA[i] = 0x40 + } + if m.UpdatePeriod != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.UpdatePeriod)) + i-- + dAtA[i] = 0x38 + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x32 + } + if len(m.TransactionsFilter) > 0 { + i -= len(m.TransactionsFilter) + copy(dAtA[i:], m.TransactionsFilter) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.TransactionsFilter))) + i-- + dAtA[i] = 0x2a + } + if len(m.Keys) > 0 { + for iNdEx := len(m.Keys) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Keys[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.QueryType) > 0 { + i -= len(m.QueryType) + copy(dAtA[i:], m.QueryType) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.QueryType))) + i-- + dAtA[i] = 0x1a + } + if len(m.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Owner))) + i-- + dAtA[i] = 0x12 + } + if m.Id != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *KVKey) 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 *KVKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *KVKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0x12 + } + if len(m.Path) > 0 { + i -= len(m.Path) + copy(dAtA[i:], m.Path) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Path))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +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.RegisteredQueries) > 0 { + for iNdEx := len(m.RegisteredQueries) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RegisteredQueries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.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 *RegisteredQuery) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovGenesis(uint64(m.Id)) + } + l = len(m.Owner) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.QueryType) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Keys) > 0 { + for _, e := range m.Keys { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + l = len(m.TransactionsFilter) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.UpdatePeriod != 0 { + n += 1 + sovGenesis(uint64(m.UpdatePeriod)) + } + if m.LastSubmittedResultLocalHeight != 0 { + n += 1 + sovGenesis(uint64(m.LastSubmittedResultLocalHeight)) + } + if m.LastSubmittedResultRemoteHeight != nil { + l = m.LastSubmittedResultRemoteHeight.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Deposit) > 0 { + for _, e := range m.Deposit { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if m.SubmitTimeout != 0 { + n += 1 + sovGenesis(uint64(m.SubmitTimeout)) + } + if m.RegisteredAtHeight != 0 { + n += 1 + sovGenesis(uint64(m.RegisteredAtHeight)) + } + return n +} + +func (m *KVKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Path) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.Key) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.RegisteredQueries) > 0 { + for _, e := range m.RegisteredQueries { + l = e.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 *RegisteredQuery) 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: RegisteredQuery: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RegisteredQuery: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Owner", 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.Owner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryType", 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.QueryType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Keys", 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.Keys = append(m.Keys, &KVKey{}) + if err := m.Keys[len(m.Keys)-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 TransactionsFilter", 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.TransactionsFilter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", 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.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatePeriod", wireType) + } + m.UpdatePeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdatePeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LastSubmittedResultLocalHeight", wireType) + } + m.LastSubmittedResultLocalHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LastSubmittedResultLocalHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastSubmittedResultRemoteHeight", 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 m.LastSubmittedResultRemoteHeight == nil { + m.LastSubmittedResultRemoteHeight = &types.Height{} + } + if err := m.LastSubmittedResultRemoteHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Deposit", 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.Deposit = append(m.Deposit, types1.Coin{}) + if err := m.Deposit[len(m.Deposit)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SubmitTimeout", wireType) + } + m.SubmitTimeout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SubmitTimeout |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisteredAtHeight", wireType) + } + m.RegisteredAtHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RegisteredAtHeight |= 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 *KVKey) 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: KVKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: KVKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Path", 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.Path = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", 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.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) + if m.Key == nil { + m.Key = []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 *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 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 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisteredQueries", 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.RegisteredQueries = append(m.RegisteredQueries, &RegisteredQuery{}) + if err := m.RegisteredQueries[len(m.RegisteredQueries)-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 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/x/interchainqueries/types/genesis_test.go b/x/interchainqueries/types/genesis_test.go new file mode 100644 index 00000000..bfe5eca4 --- /dev/null +++ b/x/interchainqueries/types/genesis_test.go @@ -0,0 +1,37 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +func TestGenesisState_Validate(t *testing.T) { + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{}, + valid: true, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/interchainqueries/types/keys.go b/x/interchainqueries/types/keys.go new file mode 100644 index 00000000..7e422b47 --- /dev/null +++ b/x/interchainqueries/types/keys.go @@ -0,0 +1,71 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // ModuleName defines the module name + ModuleName = "interchainqueries" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for slashing + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_interchainqueries" +) + +const ( + prefixRegisteredQuery = iota + 1 + prefixRegisteredQueryResult + prefixSubmittedTx + prefixTxQueryToRemove + prefixParamsKey +) + +var ( + // RegisteredQueryKey is the store key for queries registered in the module. + RegisteredQueryKey = []byte{prefixRegisteredQuery} + // RegisteredQueryResultKey is the store key for KV query results. + RegisteredQueryResultKey = []byte{prefixRegisteredQueryResult} + // SubmittedTxKey is the store key for submitted transaction hashes. + SubmittedTxKey = []byte{prefixSubmittedTx} + // TxQueryToRemoveKey is the store key for TX queries marked to be removed. + TxQueryToRemoveKey = []byte{prefixTxQueryToRemove} + // ParamsKey is the store key for the module params + ParamsKey = []byte{prefixParamsKey} + // LastRegisteredQueryIDKey is the store key for last registered query ID. + LastRegisteredQueryIDKey = []byte{0x64} +) + +// GetRegisteredQueryByIDKey builds a store key to access a registered query by query ID. +func GetRegisteredQueryByIDKey(id uint64) []byte { + return append(RegisteredQueryKey, sdk.Uint64ToBigEndian(id)...) +} + +// GetSubmittedTransactionIDForQueryKeyPrefix builds a store key prefix to access TX query hashes by ID. +func GetSubmittedTransactionIDForQueryKeyPrefix(queryID uint64) []byte { + return append(SubmittedTxKey, sdk.Uint64ToBigEndian(queryID)...) +} + +// GetSubmittedTransactionIDForQueryKey builds a store key to access a submitted transaction hash +// by query ID and hash. +func GetSubmittedTransactionIDForQueryKey(queryID uint64, txHash []byte) []byte { + return append(GetSubmittedTransactionIDForQueryKeyPrefix(queryID), txHash...) +} + +// GetRegisteredQueryResultByIDKey builds a store key to access a KV query result by query ID. +func GetRegisteredQueryResultByIDKey(id uint64) []byte { + return append(RegisteredQueryResultKey, sdk.Uint64ToBigEndian(id)...) +} + +// GetTxQueryToRemoveByIDKey builds a store key to access a TX query marked to be removed. +func GetTxQueryToRemoveByIDKey(id uint64) []byte { + return append(TxQueryToRemoveKey, sdk.Uint64ToBigEndian(id)...) +} diff --git a/x/interchainqueries/types/message_remove_interchain_query.go b/x/interchainqueries/types/message_remove_interchain_query.go new file mode 100644 index 00000000..632c4a55 --- /dev/null +++ b/x/interchainqueries/types/message_remove_interchain_query.go @@ -0,0 +1,55 @@ +package types + +import ( + "strings" + + "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var _ sdk.Msg = &MsgRemoveInterchainQueryRequest{} + +func NewMsgRemoveInterchainQuery(sender string, queryID uint64) MsgRemoveInterchainQueryRequest { + return MsgRemoveInterchainQueryRequest{ + QueryId: queryID, + Sender: sender, + } +} + +func (msg MsgRemoveInterchainQueryRequest) Route() string { + return RouterKey +} + +func (msg MsgRemoveInterchainQueryRequest) Type() string { + return "remove-interchain-query" +} + +func (msg MsgRemoveInterchainQueryRequest) Validate() error { + if msg.GetQueryId() == 0 { + return errors.Wrap(ErrInvalidQueryID, "query_id cannot be empty or equal to 0") + } + + if strings.TrimSpace(msg.Sender) == "" { + return errors.Wrap(sdkerrors.ErrInvalidAddress, "missing sender address") + } + + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Sender) + } + + return nil +} + +func (msg MsgRemoveInterchainQueryRequest) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(&msg) +} + +func (msg MsgRemoveInterchainQueryRequest) GetSigners() []sdk.AccAddress { + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{senderAddr} +} diff --git a/x/interchainqueries/types/params.go b/x/interchainqueries/types/params.go new file mode 100644 index 00000000..e2699c9b --- /dev/null +++ b/x/interchainqueries/types/params.go @@ -0,0 +1,79 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" + + "github.com/Nolus-Protocol/nolus-core/app/params" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +var ( + KeyQuerySubmitTimeout = []byte("QuerySubmitTimeout") + DefaultQuerySubmitTimeout = uint64(1036800) // One month, with block_time = 2.5s + KeyQueryDeposit = []byte("QueryDeposit") + DefaultQueryDeposit = sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(int64(1_000_000)))) + KeyTxQueryRemovalLimit = []byte("TxQueryRemovalLimit") + DefaultTxQueryRemovalLimit = uint64(10_000) +) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable( + paramtypes.NewParamSetPair(KeyQuerySubmitTimeout, DefaultQuerySubmitTimeout, func(_ interface{}) error { return nil }), + paramtypes.NewParamSetPair(KeyQueryDeposit, sdk.Coins{}, validateCoins), + paramtypes.NewParamSetPair(KeyTxQueryRemovalLimit, DefaultTxQueryRemovalLimit, func(_ interface{}) error { return nil }), + ) +} + +// NewParams creates a new Params instance +func NewParams(querySubmitTimeout uint64, queryDeposit sdk.Coins, txQueryRemovalLimit uint64) Params { + return Params{ + QuerySubmitTimeout: querySubmitTimeout, + QueryDeposit: queryDeposit, + TxQueryRemovalLimit: txQueryRemovalLimit, + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams(DefaultQuerySubmitTimeout, DefaultQueryDeposit, DefaultTxQueryRemovalLimit) +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyQuerySubmitTimeout, &p.QuerySubmitTimeout, func(_ interface{}) error { return nil }), + paramtypes.NewParamSetPair(KeyQueryDeposit, &p.QueryDeposit, validateCoins), + paramtypes.NewParamSetPair(KeyTxQueryRemovalLimit, &p.TxQueryRemovalLimit, func(_ interface{}) error { return nil }), + } +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +func validateCoins(i interface{}) error { + v, ok := i.(sdk.Coins) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if !v.IsValid() { + return fmt.Errorf("invalid coins parameter: %s", v) + } + + return nil +} diff --git a/x/interchainqueries/types/params.pb.go b/x/interchainqueries/types/params.pb.go new file mode 100644 index 00000000..db88e900 --- /dev/null +++ b/x/interchainqueries/types/params.pb.go @@ -0,0 +1,418 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchainqueries/params.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 + +// Params defines the parameters for the module. +type Params struct { + // Defines amount of blocks required before query becomes available for + // removal by anybody + QuerySubmitTimeout uint64 `protobuf:"varint,1,opt,name=query_submit_timeout,json=querySubmitTimeout,proto3" json:"query_submit_timeout,omitempty"` + // Amount of coins deposited for the query. + QueryDeposit github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=query_deposit,json=queryDeposit,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"query_deposit"` + // Amount of tx hashes to be removed during a single EndBlock. Can vary to + // balance between network cleaning speed and EndBlock duration. A zero value + // means no limit. + TxQueryRemovalLimit uint64 `protobuf:"varint,3,opt,name=tx_query_removal_limit,json=txQueryRemovalLimit,proto3" json:"tx_query_removal_limit,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_752a5f3346da64b1, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetQuerySubmitTimeout() uint64 { + if m != nil { + return m.QuerySubmitTimeout + } + return 0 +} + +func (m *Params) GetQueryDeposit() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.QueryDeposit + } + return nil +} + +func (m *Params) GetTxQueryRemovalLimit() uint64 { + if m != nil { + return m.TxQueryRemovalLimit + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "neutron.interchainqueries.Params") +} + +func init() { + proto.RegisterFile("neutron/interchainqueries/params.proto", fileDescriptor_752a5f3346da64b1) +} + +var fileDescriptor_752a5f3346da64b1 = []byte{ + // 331 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xb1, 0x4e, 0xf3, 0x30, + 0x10, 0xc7, 0x93, 0xaf, 0x55, 0x87, 0x7c, 0xb0, 0x84, 0x0a, 0xb5, 0x1d, 0xdc, 0x8a, 0x01, 0x75, + 0xa9, 0xdd, 0x52, 0x26, 0xd8, 0x0a, 0x23, 0x03, 0x14, 0x58, 0x58, 0xa2, 0x24, 0xb5, 0x52, 0x8b, + 0x3a, 0x17, 0xec, 0x4b, 0xd5, 0xbe, 0x05, 0x23, 0x23, 0x33, 0x4f, 0xd2, 0xb1, 0x23, 0x13, 0xa0, + 0x76, 0xe0, 0x35, 0x50, 0xec, 0x20, 0x21, 0xc1, 0xe4, 0x93, 0x7f, 0x77, 0xfe, 0xff, 0x74, 0xf6, + 0x0e, 0x53, 0x9e, 0xa3, 0x82, 0x94, 0x89, 0x14, 0xb9, 0x8a, 0xa7, 0xa1, 0x48, 0x1f, 0x72, 0xae, + 0x04, 0xd7, 0x2c, 0x0b, 0x55, 0x28, 0x35, 0xcd, 0x14, 0x20, 0xf8, 0xcd, 0xb2, 0x8f, 0xfe, 0xea, + 0x6b, 0x91, 0x18, 0xb4, 0x04, 0xcd, 0xa2, 0x50, 0x73, 0x36, 0x1f, 0x44, 0x1c, 0xc3, 0x01, 0x8b, + 0x41, 0xa4, 0x76, 0xb4, 0x55, 0x4f, 0x20, 0x01, 0x53, 0xb2, 0xa2, 0xb2, 0xb7, 0x07, 0x9f, 0xae, + 0x57, 0xbb, 0x34, 0x09, 0x7e, 0xdf, 0xab, 0x17, 0x6f, 0x2d, 0x03, 0x9d, 0x47, 0x52, 0x60, 0x80, + 0x42, 0x72, 0xc8, 0xb1, 0xe1, 0x76, 0xdc, 0x6e, 0x75, 0xec, 0x1b, 0x76, 0x6d, 0xd0, 0x8d, 0x25, + 0x7e, 0xe6, 0xed, 0xda, 0x89, 0x09, 0xcf, 0x40, 0x0b, 0x6c, 0xfc, 0xeb, 0x54, 0xba, 0xff, 0x8f, + 0x9a, 0xd4, 0xaa, 0xd0, 0x42, 0x85, 0x96, 0x2a, 0xf4, 0x0c, 0x44, 0x3a, 0xea, 0xaf, 0xde, 0xda, + 0xce, 0xcb, 0x7b, 0xbb, 0x9b, 0x08, 0x9c, 0xe6, 0x11, 0x8d, 0x41, 0xb2, 0xd2, 0xdb, 0x1e, 0x3d, + 0x3d, 0xb9, 0x67, 0xb8, 0xcc, 0xb8, 0x36, 0x03, 0x7a, 0xbc, 0x63, 0x12, 0xce, 0x6d, 0x80, 0x3f, + 0xf4, 0xf6, 0x71, 0x11, 0xd8, 0x50, 0xc5, 0x25, 0xcc, 0xc3, 0x59, 0x30, 0x13, 0x52, 0x60, 0xa3, + 0x62, 0x2c, 0xf7, 0x70, 0x71, 0x55, 0xc0, 0xb1, 0x65, 0x17, 0x05, 0x3a, 0xa9, 0x3e, 0x3d, 0xb7, + 0x9d, 0xd1, 0xed, 0x6a, 0x43, 0xdc, 0xf5, 0x86, 0xb8, 0x1f, 0x1b, 0xe2, 0x3e, 0x6e, 0x89, 0xb3, + 0xde, 0x12, 0xe7, 0x75, 0x4b, 0x9c, 0xbb, 0xd3, 0x1f, 0x32, 0xe5, 0x7e, 0x7b, 0xa0, 0x92, 0xef, + 0x9a, 0xcd, 0x8f, 0xd9, 0xe2, 0x8f, 0x8f, 0x31, 0x96, 0x51, 0xcd, 0xec, 0x71, 0xf8, 0x15, 0x00, + 0x00, 0xff, 0xff, 0xc7, 0x61, 0x00, 0x43, 0xc2, 0x01, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TxQueryRemovalLimit != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TxQueryRemovalLimit)) + i-- + dAtA[i] = 0x18 + } + if len(m.QueryDeposit) > 0 { + for iNdEx := len(m.QueryDeposit) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.QueryDeposit[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.QuerySubmitTimeout != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.QuerySubmitTimeout)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.QuerySubmitTimeout != 0 { + n += 1 + sovParams(uint64(m.QuerySubmitTimeout)) + } + if len(m.QueryDeposit) > 0 { + for _, e := range m.QueryDeposit { + l = e.Size() + n += 1 + l + sovParams(uint64(l)) + } + } + if m.TxQueryRemovalLimit != 0 { + n += 1 + sovParams(uint64(m.TxQueryRemovalLimit)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QuerySubmitTimeout", wireType) + } + m.QuerySubmitTimeout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.QuerySubmitTimeout |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryDeposit", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QueryDeposit = append(m.QueryDeposit, types.Coin{}) + if err := m.QueryDeposit[len(m.QueryDeposit)-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 TxQueryRemovalLimit", wireType) + } + m.TxQueryRemovalLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxQueryRemovalLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/interchainqueries/types/query.pb.go b/x/interchainqueries/types/query.pb.go new file mode 100644 index 00000000..0f1972e0 --- /dev/null +++ b/x/interchainqueries/types/query.pb.go @@ -0,0 +1,2472 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchainqueries/query.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + 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" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// 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 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_2254be23ba3ff3b4, []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 response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +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_2254be23ba3ff3b4, []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() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type QueryRegisteredQueriesRequest struct { + Owners []string `protobuf:"bytes,1,rep,name=owners,proto3" json:"owners,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryRegisteredQueriesRequest) Reset() { *m = QueryRegisteredQueriesRequest{} } +func (m *QueryRegisteredQueriesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryRegisteredQueriesRequest) ProtoMessage() {} +func (*QueryRegisteredQueriesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{2} +} +func (m *QueryRegisteredQueriesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRegisteredQueriesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRegisteredQueriesRequest.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 *QueryRegisteredQueriesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRegisteredQueriesRequest.Merge(m, src) +} +func (m *QueryRegisteredQueriesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryRegisteredQueriesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRegisteredQueriesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRegisteredQueriesRequest proto.InternalMessageInfo + +func (m *QueryRegisteredQueriesRequest) GetOwners() []string { + if m != nil { + return m.Owners + } + return nil +} + +func (m *QueryRegisteredQueriesRequest) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *QueryRegisteredQueriesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryRegisteredQueriesResponse struct { + RegisteredQueries []RegisteredQuery `protobuf:"bytes,1,rep,name=registered_queries,json=registeredQueries,proto3" json:"registered_queries"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryRegisteredQueriesResponse) Reset() { *m = QueryRegisteredQueriesResponse{} } +func (m *QueryRegisteredQueriesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryRegisteredQueriesResponse) ProtoMessage() {} +func (*QueryRegisteredQueriesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{3} +} +func (m *QueryRegisteredQueriesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRegisteredQueriesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRegisteredQueriesResponse.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 *QueryRegisteredQueriesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRegisteredQueriesResponse.Merge(m, src) +} +func (m *QueryRegisteredQueriesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryRegisteredQueriesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRegisteredQueriesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRegisteredQueriesResponse proto.InternalMessageInfo + +func (m *QueryRegisteredQueriesResponse) GetRegisteredQueries() []RegisteredQuery { + if m != nil { + return m.RegisteredQueries + } + return nil +} + +func (m *QueryRegisteredQueriesResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryRegisteredQueryRequest struct { + QueryId uint64 `protobuf:"varint,1,opt,name=query_id,json=queryId,proto3" json:"query_id,omitempty"` +} + +func (m *QueryRegisteredQueryRequest) Reset() { *m = QueryRegisteredQueryRequest{} } +func (m *QueryRegisteredQueryRequest) String() string { return proto.CompactTextString(m) } +func (*QueryRegisteredQueryRequest) ProtoMessage() {} +func (*QueryRegisteredQueryRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{4} +} +func (m *QueryRegisteredQueryRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRegisteredQueryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRegisteredQueryRequest.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 *QueryRegisteredQueryRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRegisteredQueryRequest.Merge(m, src) +} +func (m *QueryRegisteredQueryRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryRegisteredQueryRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRegisteredQueryRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRegisteredQueryRequest proto.InternalMessageInfo + +func (m *QueryRegisteredQueryRequest) GetQueryId() uint64 { + if m != nil { + return m.QueryId + } + return 0 +} + +type QueryRegisteredQueryResponse struct { + RegisteredQuery *RegisteredQuery `protobuf:"bytes,1,opt,name=registered_query,json=registeredQuery,proto3" json:"registered_query,omitempty"` +} + +func (m *QueryRegisteredQueryResponse) Reset() { *m = QueryRegisteredQueryResponse{} } +func (m *QueryRegisteredQueryResponse) String() string { return proto.CompactTextString(m) } +func (*QueryRegisteredQueryResponse) ProtoMessage() {} +func (*QueryRegisteredQueryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{5} +} +func (m *QueryRegisteredQueryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRegisteredQueryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRegisteredQueryResponse.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 *QueryRegisteredQueryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRegisteredQueryResponse.Merge(m, src) +} +func (m *QueryRegisteredQueryResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryRegisteredQueryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRegisteredQueryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRegisteredQueryResponse proto.InternalMessageInfo + +func (m *QueryRegisteredQueryResponse) GetRegisteredQuery() *RegisteredQuery { + if m != nil { + return m.RegisteredQuery + } + return nil +} + +type QueryRegisteredQueryResultRequest struct { + QueryId uint64 `protobuf:"varint,1,opt,name=query_id,json=queryId,proto3" json:"query_id,omitempty"` +} + +func (m *QueryRegisteredQueryResultRequest) Reset() { *m = QueryRegisteredQueryResultRequest{} } +func (m *QueryRegisteredQueryResultRequest) String() string { return proto.CompactTextString(m) } +func (*QueryRegisteredQueryResultRequest) ProtoMessage() {} +func (*QueryRegisteredQueryResultRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{6} +} +func (m *QueryRegisteredQueryResultRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRegisteredQueryResultRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRegisteredQueryResultRequest.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 *QueryRegisteredQueryResultRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRegisteredQueryResultRequest.Merge(m, src) +} +func (m *QueryRegisteredQueryResultRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryRegisteredQueryResultRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRegisteredQueryResultRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRegisteredQueryResultRequest proto.InternalMessageInfo + +func (m *QueryRegisteredQueryResultRequest) GetQueryId() uint64 { + if m != nil { + return m.QueryId + } + return 0 +} + +type QueryRegisteredQueryResultResponse struct { + Result *QueryResult `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` +} + +func (m *QueryRegisteredQueryResultResponse) Reset() { *m = QueryRegisteredQueryResultResponse{} } +func (m *QueryRegisteredQueryResultResponse) String() string { return proto.CompactTextString(m) } +func (*QueryRegisteredQueryResultResponse) ProtoMessage() {} +func (*QueryRegisteredQueryResultResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{7} +} +func (m *QueryRegisteredQueryResultResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRegisteredQueryResultResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRegisteredQueryResultResponse.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 *QueryRegisteredQueryResultResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRegisteredQueryResultResponse.Merge(m, src) +} +func (m *QueryRegisteredQueryResultResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryRegisteredQueryResultResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRegisteredQueryResultResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRegisteredQueryResultResponse proto.InternalMessageInfo + +func (m *QueryRegisteredQueryResultResponse) GetResult() *QueryResult { + if m != nil { + return m.Result + } + return nil +} + +type Transaction struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *Transaction) Reset() { *m = Transaction{} } +func (m *Transaction) String() string { return proto.CompactTextString(m) } +func (*Transaction) ProtoMessage() {} +func (*Transaction) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{8} +} +func (m *Transaction) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Transaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Transaction.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 *Transaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_Transaction.Merge(m, src) +} +func (m *Transaction) XXX_Size() int { + return m.Size() +} +func (m *Transaction) XXX_DiscardUnknown() { + xxx_messageInfo_Transaction.DiscardUnknown(m) +} + +var xxx_messageInfo_Transaction proto.InternalMessageInfo + +func (m *Transaction) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *Transaction) GetHeight() uint64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *Transaction) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +type QueryLastRemoteHeight struct { + ConnectionId string `protobuf:"bytes,1,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` +} + +func (m *QueryLastRemoteHeight) Reset() { *m = QueryLastRemoteHeight{} } +func (m *QueryLastRemoteHeight) String() string { return proto.CompactTextString(m) } +func (*QueryLastRemoteHeight) ProtoMessage() {} +func (*QueryLastRemoteHeight) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{9} +} +func (m *QueryLastRemoteHeight) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryLastRemoteHeight) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryLastRemoteHeight.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 *QueryLastRemoteHeight) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryLastRemoteHeight.Merge(m, src) +} +func (m *QueryLastRemoteHeight) XXX_Size() int { + return m.Size() +} +func (m *QueryLastRemoteHeight) XXX_DiscardUnknown() { + xxx_messageInfo_QueryLastRemoteHeight.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryLastRemoteHeight proto.InternalMessageInfo + +func (m *QueryLastRemoteHeight) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +type QueryLastRemoteHeightResponse struct { + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *QueryLastRemoteHeightResponse) Reset() { *m = QueryLastRemoteHeightResponse{} } +func (m *QueryLastRemoteHeightResponse) String() string { return proto.CompactTextString(m) } +func (*QueryLastRemoteHeightResponse) ProtoMessage() {} +func (*QueryLastRemoteHeightResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2254be23ba3ff3b4, []int{10} +} +func (m *QueryLastRemoteHeightResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryLastRemoteHeightResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryLastRemoteHeightResponse.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 *QueryLastRemoteHeightResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryLastRemoteHeightResponse.Merge(m, src) +} +func (m *QueryLastRemoteHeightResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryLastRemoteHeightResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryLastRemoteHeightResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryLastRemoteHeightResponse proto.InternalMessageInfo + +func (m *QueryLastRemoteHeightResponse) GetHeight() uint64 { + if m != nil { + return m.Height + } + return 0 +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "neutron.interchainqueries.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "neutron.interchainqueries.QueryParamsResponse") + proto.RegisterType((*QueryRegisteredQueriesRequest)(nil), "neutron.interchainqueries.QueryRegisteredQueriesRequest") + proto.RegisterType((*QueryRegisteredQueriesResponse)(nil), "neutron.interchainqueries.QueryRegisteredQueriesResponse") + proto.RegisterType((*QueryRegisteredQueryRequest)(nil), "neutron.interchainqueries.QueryRegisteredQueryRequest") + proto.RegisterType((*QueryRegisteredQueryResponse)(nil), "neutron.interchainqueries.QueryRegisteredQueryResponse") + proto.RegisterType((*QueryRegisteredQueryResultRequest)(nil), "neutron.interchainqueries.QueryRegisteredQueryResultRequest") + proto.RegisterType((*QueryRegisteredQueryResultResponse)(nil), "neutron.interchainqueries.QueryRegisteredQueryResultResponse") + proto.RegisterType((*Transaction)(nil), "neutron.interchainqueries.Transaction") + proto.RegisterType((*QueryLastRemoteHeight)(nil), "neutron.interchainqueries.QueryLastRemoteHeight") + proto.RegisterType((*QueryLastRemoteHeightResponse)(nil), "neutron.interchainqueries.QueryLastRemoteHeightResponse") +} + +func init() { + proto.RegisterFile("neutron/interchainqueries/query.proto", fileDescriptor_2254be23ba3ff3b4) +} + +var fileDescriptor_2254be23ba3ff3b4 = []byte{ + // 758 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x4d, 0x4f, 0x14, 0x4d, + 0x10, 0xde, 0x5e, 0xf6, 0x5d, 0x5e, 0x6a, 0x79, 0x5f, 0xa0, 0x45, 0x03, 0x2b, 0xae, 0x30, 0x44, + 0x58, 0x30, 0x3b, 0xc3, 0x87, 0x0a, 0x46, 0xc4, 0x84, 0x83, 0x4a, 0xe2, 0x01, 0x26, 0xe2, 0xc1, + 0xcb, 0xa6, 0x77, 0xb7, 0x33, 0x3b, 0x09, 0xdb, 0xbd, 0xcc, 0xf4, 0x22, 0x73, 0xf5, 0xe6, 0xcd, + 0xe8, 0x5f, 0xf0, 0x07, 0x78, 0xf3, 0xe0, 0xc1, 0x2b, 0xf1, 0x44, 0xe2, 0xc5, 0x93, 0x31, 0xe0, + 0x0f, 0x31, 0xd3, 0xdd, 0xfb, 0xfd, 0xc5, 0x72, 0x9a, 0xee, 0x9e, 0x7a, 0xaa, 0x9e, 0x7a, 0xaa, + 0xaa, 0x1b, 0xee, 0x30, 0x5a, 0x11, 0x1e, 0x67, 0x96, 0xcb, 0x04, 0xf5, 0xf2, 0x45, 0xe2, 0xb2, + 0xa3, 0x0a, 0xf5, 0x5c, 0xea, 0x5b, 0xe1, 0x37, 0x30, 0xcb, 0x1e, 0x17, 0x1c, 0x4f, 0x6b, 0x33, + 0xb3, 0xcd, 0x2c, 0xb9, 0x9c, 0xe7, 0x7e, 0x89, 0xfb, 0x56, 0x8e, 0xf8, 0x54, 0x61, 0xac, 0xe3, + 0xd5, 0x1c, 0x15, 0x64, 0xd5, 0x2a, 0x13, 0xc7, 0x65, 0x44, 0xb8, 0x9c, 0x29, 0x37, 0xc9, 0x49, + 0x87, 0x3b, 0x5c, 0x2e, 0xad, 0x70, 0xa5, 0x4f, 0x67, 0x1c, 0xce, 0x9d, 0x43, 0x6a, 0x91, 0xb2, + 0x6b, 0x11, 0xc6, 0xb8, 0x90, 0x10, 0x5f, 0xff, 0x5d, 0xec, 0xce, 0xd0, 0xa1, 0x8c, 0xfa, 0x6e, + 0xd5, 0x70, 0xa1, 0xbb, 0x61, 0x99, 0x78, 0xa4, 0x54, 0xb5, 0x33, 0xba, 0xdb, 0x89, 0x13, 0x65, + 0x63, 0x4c, 0x02, 0xde, 0x0f, 0x53, 0xd9, 0x93, 0x40, 0x9b, 0x1e, 0x55, 0xa8, 0x2f, 0x8c, 0x57, + 0x70, 0xad, 0xe9, 0xd4, 0x2f, 0x73, 0xe6, 0x53, 0xfc, 0x04, 0xe2, 0x2a, 0xc0, 0x14, 0x9a, 0x45, + 0xe9, 0xc4, 0xda, 0x9c, 0xd9, 0x55, 0x2d, 0x53, 0x41, 0x77, 0x62, 0xa7, 0xbf, 0x6e, 0x47, 0x6c, + 0x0d, 0x33, 0x3e, 0x21, 0xb8, 0x25, 0x1d, 0xdb, 0xd4, 0x71, 0x7d, 0x41, 0x3d, 0x5a, 0xd8, 0x57, + 0xf6, 0x3a, 0x32, 0xbe, 0x01, 0x71, 0xfe, 0x86, 0x51, 0x2f, 0x0c, 0x31, 0x94, 0x1e, 0xb1, 0xf5, + 0x0e, 0xcf, 0xc3, 0x7f, 0x79, 0xce, 0x18, 0xcd, 0x87, 0x8a, 0x65, 0xdd, 0xc2, 0x54, 0x74, 0x16, + 0xa5, 0x47, 0xec, 0xd1, 0xfa, 0xe1, 0x6e, 0x01, 0x3f, 0x05, 0xa8, 0x57, 0x62, 0x6a, 0x48, 0x72, + 0x5c, 0x30, 0x55, 0xd9, 0xcc, 0xb0, 0x6c, 0xa6, 0x2a, 0xb5, 0x2e, 0x9b, 0xb9, 0x47, 0x1c, 0xaa, + 0x03, 0xdb, 0x0d, 0x48, 0xe3, 0x3b, 0x82, 0x54, 0x37, 0x9a, 0x5a, 0x8a, 0x2c, 0x60, 0xaf, 0xf6, + 0x33, 0xab, 0x93, 0x96, 0x9c, 0x13, 0x6b, 0xcb, 0x3d, 0x64, 0x69, 0xf6, 0x18, 0x68, 0x7d, 0x26, + 0xbc, 0xd6, 0x40, 0xf8, 0x59, 0x53, 0x2e, 0x51, 0x99, 0xcb, 0x62, 0xdf, 0x5c, 0x14, 0xbb, 0xa6, + 0x64, 0x36, 0xe1, 0x66, 0x87, 0x5c, 0x82, 0xaa, 0xe0, 0xd3, 0xf0, 0xaf, 0x74, 0x14, 0x6a, 0x1a, + 0x56, 0x35, 0x66, 0x0f, 0xcb, 0xfd, 0x6e, 0xc1, 0xa8, 0xc0, 0x4c, 0x67, 0xa4, 0xd6, 0xe0, 0x00, + 0xc6, 0x5b, 0x34, 0x08, 0x74, 0x63, 0x0c, 0xa0, 0x80, 0x3d, 0xd6, 0x9c, 0x7b, 0x60, 0x6c, 0xc3, + 0x5c, 0x97, 0xb0, 0x95, 0x43, 0x71, 0x09, 0xda, 0x05, 0x30, 0x7a, 0xe1, 0x35, 0xf9, 0x6d, 0x88, + 0x7b, 0xf2, 0x44, 0x53, 0x5e, 0xe8, 0x41, 0xb9, 0x11, 0xaf, 0x51, 0xc6, 0x2e, 0x24, 0x5e, 0x7a, + 0x84, 0xf9, 0x44, 0x36, 0x1f, 0xfe, 0x1f, 0xa2, 0x35, 0x26, 0x51, 0xb7, 0x10, 0xf6, 0x71, 0x91, + 0xba, 0x4e, 0x51, 0xc8, 0xd2, 0xc5, 0x6c, 0xbd, 0xc3, 0x18, 0x62, 0x05, 0x22, 0x88, 0x6c, 0xce, + 0x51, 0x5b, 0xae, 0x8d, 0x2d, 0xb8, 0x2e, 0x23, 0xbc, 0x20, 0xbe, 0xb0, 0x69, 0x89, 0x0b, 0xfa, + 0x5c, 0x19, 0xb7, 0x35, 0x3d, 0x6a, 0x6f, 0x7a, 0x63, 0x43, 0x8f, 0x54, 0x2b, 0xba, 0x96, 0x69, + 0x9d, 0x0a, 0x6a, 0xa4, 0xb2, 0xf6, 0x6e, 0x18, 0xfe, 0x91, 0x48, 0xfc, 0x01, 0x41, 0x5c, 0xcd, + 0x2b, 0xce, 0xf4, 0x93, 0xa1, 0xe9, 0xa2, 0x48, 0x9a, 0x97, 0x35, 0x57, 0x5c, 0x8c, 0xa5, 0xb7, + 0x3f, 0xfe, 0x7c, 0x8c, 0xce, 0xe3, 0x39, 0xab, 0xdf, 0x1d, 0x86, 0xbf, 0x21, 0x98, 0x68, 0x9b, + 0x3f, 0xbc, 0xd9, 0xbf, 0x4c, 0x9d, 0x6f, 0x96, 0xe4, 0xc3, 0x2b, 0x20, 0x35, 0xeb, 0xfb, 0x92, + 0xb5, 0x85, 0x33, 0x3d, 0x58, 0xb7, 0xdf, 0x06, 0xf8, 0x0b, 0x82, 0xb1, 0x96, 0x26, 0xc4, 0x0f, + 0x06, 0x63, 0x51, 0x1d, 0xd3, 0xe4, 0xc6, 0xc0, 0x38, 0xcd, 0x7d, 0x5d, 0x72, 0xcf, 0xe0, 0xbb, + 0x97, 0xe7, 0x1e, 0xe0, 0xaf, 0x08, 0x12, 0x0d, 0x4d, 0x8f, 0xb7, 0x06, 0x8f, 0x5e, 0x9f, 0xd5, + 0xe4, 0xe3, 0x2b, 0xa2, 0x75, 0x06, 0x96, 0xcc, 0x60, 0x09, 0x2f, 0x5a, 0x7d, 0x9e, 0xf0, 0xac, + 0x1a, 0x4d, 0xfc, 0x19, 0xc1, 0x78, 0xdb, 0x2c, 0xad, 0xf4, 0x23, 0xd1, 0x8a, 0x48, 0x6e, 0x0e, + 0x8a, 0xa8, 0x31, 0x5e, 0x91, 0x8c, 0x97, 0x71, 0xba, 0xa7, 0xe6, 0x21, 0x30, 0xab, 0x66, 0x71, + 0xe7, 0xe0, 0xf4, 0x3c, 0x85, 0xce, 0xce, 0x53, 0xe8, 0xf7, 0x79, 0x0a, 0xbd, 0xbf, 0x48, 0x45, + 0xce, 0x2e, 0x52, 0x91, 0x9f, 0x17, 0xa9, 0xc8, 0xeb, 0x47, 0x8e, 0x2b, 0x8a, 0x95, 0x9c, 0x99, + 0xe7, 0xa5, 0xaa, 0xb7, 0x0c, 0xf7, 0x9c, 0x9a, 0xe7, 0xe3, 0x7b, 0xd6, 0x49, 0xa7, 0x07, 0x3e, + 0x28, 0x53, 0x3f, 0x17, 0x97, 0x8f, 0xfc, 0xfa, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x60, 0x57, + 0x58, 0xcf, 0xfd, 0x08, 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 { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + RegisteredQueries(ctx context.Context, in *QueryRegisteredQueriesRequest, opts ...grpc.CallOption) (*QueryRegisteredQueriesResponse, error) + RegisteredQuery(ctx context.Context, in *QueryRegisteredQueryRequest, opts ...grpc.CallOption) (*QueryRegisteredQueryResponse, error) + QueryResult(ctx context.Context, in *QueryRegisteredQueryResultRequest, opts ...grpc.CallOption) (*QueryRegisteredQueryResultResponse, error) + LastRemoteHeight(ctx context.Context, in *QueryLastRemoteHeight, opts ...grpc.CallOption) (*QueryLastRemoteHeightResponse, 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, "/neutron.interchainqueries.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) RegisteredQueries(ctx context.Context, in *QueryRegisteredQueriesRequest, opts ...grpc.CallOption) (*QueryRegisteredQueriesResponse, error) { + out := new(QueryRegisteredQueriesResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Query/RegisteredQueries", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) RegisteredQuery(ctx context.Context, in *QueryRegisteredQueryRequest, opts ...grpc.CallOption) (*QueryRegisteredQueryResponse, error) { + out := new(QueryRegisteredQueryResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Query/RegisteredQuery", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryResult(ctx context.Context, in *QueryRegisteredQueryResultRequest, opts ...grpc.CallOption) (*QueryRegisteredQueryResultResponse, error) { + out := new(QueryRegisteredQueryResultResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Query/QueryResult", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) LastRemoteHeight(ctx context.Context, in *QueryLastRemoteHeight, opts ...grpc.CallOption) (*QueryLastRemoteHeightResponse, error) { + out := new(QueryLastRemoteHeightResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Query/LastRemoteHeight", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + RegisteredQueries(context.Context, *QueryRegisteredQueriesRequest) (*QueryRegisteredQueriesResponse, error) + RegisteredQuery(context.Context, *QueryRegisteredQueryRequest) (*QueryRegisteredQueryResponse, error) + QueryResult(context.Context, *QueryRegisteredQueryResultRequest) (*QueryRegisteredQueryResultResponse, error) + LastRemoteHeight(context.Context, *QueryLastRemoteHeight) (*QueryLastRemoteHeightResponse, 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) RegisteredQueries(ctx context.Context, req *QueryRegisteredQueriesRequest) (*QueryRegisteredQueriesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisteredQueries not implemented") +} +func (*UnimplementedQueryServer) RegisteredQuery(ctx context.Context, req *QueryRegisteredQueryRequest) (*QueryRegisteredQueryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisteredQuery not implemented") +} +func (*UnimplementedQueryServer) QueryResult(ctx context.Context, req *QueryRegisteredQueryResultRequest) (*QueryRegisteredQueryResultResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryResult not implemented") +} +func (*UnimplementedQueryServer) LastRemoteHeight(ctx context.Context, req *QueryLastRemoteHeight) (*QueryLastRemoteHeightResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method LastRemoteHeight 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: "/neutron.interchainqueries.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_RegisteredQueries_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryRegisteredQueriesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).RegisteredQueries(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Query/RegisteredQueries", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).RegisteredQueries(ctx, req.(*QueryRegisteredQueriesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_RegisteredQuery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryRegisteredQueryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).RegisteredQuery(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Query/RegisteredQuery", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).RegisteredQuery(ctx, req.(*QueryRegisteredQueryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryResult_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryRegisteredQueryResultRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryResult(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Query/QueryResult", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryResult(ctx, req.(*QueryRegisteredQueryResultRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_LastRemoteHeight_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryLastRemoteHeight) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).LastRemoteHeight(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Query/LastRemoteHeight", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).LastRemoteHeight(ctx, req.(*QueryLastRemoteHeight)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.interchainqueries.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "RegisteredQueries", + Handler: _Query_RegisteredQueries_Handler, + }, + { + MethodName: "RegisteredQuery", + Handler: _Query_RegisteredQuery_Handler, + }, + { + MethodName: "QueryResult", + Handler: _Query_QueryResult_Handler, + }, + { + MethodName: "LastRemoteHeight", + Handler: _Query_LastRemoteHeight_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/interchainqueries/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 + { + 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 *QueryRegisteredQueriesRequest) 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 *QueryRegisteredQueriesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRegisteredQueriesRequest) 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] = 0x1a + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x12 + } + if len(m.Owners) > 0 { + for iNdEx := len(m.Owners) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Owners[iNdEx]) + copy(dAtA[i:], m.Owners[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Owners[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryRegisteredQueriesResponse) 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 *QueryRegisteredQueriesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRegisteredQueriesResponse) 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.RegisteredQueries) > 0 { + for iNdEx := len(m.RegisteredQueries) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RegisteredQueries[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 *QueryRegisteredQueryRequest) 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 *QueryRegisteredQueryRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRegisteredQueryRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.QueryId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.QueryId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryRegisteredQueryResponse) 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 *QueryRegisteredQueryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRegisteredQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.RegisteredQuery != nil { + { + size, err := m.RegisteredQuery.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 *QueryRegisteredQueryResultRequest) 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 *QueryRegisteredQueryResultRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRegisteredQueryResultRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.QueryId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.QueryId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryRegisteredQueryResultResponse) 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 *QueryRegisteredQueryResultResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRegisteredQueryResultResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Result != nil { + { + size, err := m.Result.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 *Transaction) 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 *Transaction) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Transaction) 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 = encodeVarintQuery(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x1a + } + if m.Height != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if m.Id != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryLastRemoteHeight) 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 *QueryLastRemoteHeight) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryLastRemoteHeight) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryLastRemoteHeightResponse) 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 *QueryLastRemoteHeightResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryLastRemoteHeightResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + 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 + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryRegisteredQueriesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Owners) > 0 { + for _, s := range m.Owners { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } + } + l = len(m.ConnectionId) + 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 *QueryRegisteredQueriesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.RegisteredQueries) > 0 { + for _, e := range m.RegisteredQueries { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryRegisteredQueryRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.QueryId != 0 { + n += 1 + sovQuery(uint64(m.QueryId)) + } + return n +} + +func (m *QueryRegisteredQueryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.RegisteredQuery != nil { + l = m.RegisteredQuery.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryRegisteredQueryResultRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.QueryId != 0 { + n += 1 + sovQuery(uint64(m.QueryId)) + } + return n +} + +func (m *QueryRegisteredQueryResultResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Result != nil { + l = m.Result.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *Transaction) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovQuery(uint64(m.Id)) + } + if m.Height != 0 { + n += 1 + sovQuery(uint64(m.Height)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryLastRemoteHeight) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryLastRemoteHeightResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovQuery(uint64(m.Height)) + } + 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 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 *QueryRegisteredQueriesRequest) 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: QueryRegisteredQueriesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRegisteredQueriesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Owners", 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.Owners = append(m.Owners, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", 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.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + 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 *QueryRegisteredQueriesResponse) 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: QueryRegisteredQueriesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRegisteredQueriesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisteredQueries", 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.RegisteredQueries = append(m.RegisteredQueries, RegisteredQuery{}) + if err := m.RegisteredQueries[len(m.RegisteredQueries)-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 + 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 *QueryRegisteredQueryRequest) 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: QueryRegisteredQueryRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRegisteredQueryRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryId", wireType) + } + m.QueryId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.QueryId |= 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 *QueryRegisteredQueryResponse) 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: QueryRegisteredQueryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRegisteredQueryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisteredQuery", 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.RegisteredQuery == nil { + m.RegisteredQuery = &RegisteredQuery{} + } + if err := m.RegisteredQuery.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 *QueryRegisteredQueryResultRequest) 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: QueryRegisteredQueryResultRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRegisteredQueryResultRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryId", wireType) + } + m.QueryId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.QueryId |= 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 *QueryRegisteredQueryResultResponse) 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: QueryRegisteredQueryResultResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRegisteredQueryResultResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Result", 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.Result == nil { + m.Result = &QueryResult{} + } + if err := m.Result.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 *Transaction) 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: Transaction: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Transaction: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= 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 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.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + 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 *QueryLastRemoteHeight) 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: QueryLastRemoteHeight: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryLastRemoteHeight: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", 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.ConnectionId = 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 *QueryLastRemoteHeightResponse) 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: QueryLastRemoteHeightResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryLastRemoteHeightResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= 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 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/x/interchainqueries/types/query.pb.gw.go b/x/interchainqueries/types/query.pb.gw.go new file mode 100644 index 00000000..8cbfcdc6 --- /dev/null +++ b/x/interchainqueries/types/query.pb.gw.go @@ -0,0 +1,485 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: neutron/interchainqueries/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 + +} + +var ( + filter_Query_RegisteredQueries_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_RegisteredQueries_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRegisteredQueriesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RegisteredQueries_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.RegisteredQueries(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_RegisteredQueries_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRegisteredQueriesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RegisteredQueries_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.RegisteredQueries(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_RegisteredQuery_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_RegisteredQuery_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRegisteredQueryRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RegisteredQuery_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.RegisteredQuery(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_RegisteredQuery_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRegisteredQueryRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_RegisteredQuery_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.RegisteredQuery(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_QueryResult_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_QueryResult_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRegisteredQueryResultRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryResult_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.QueryResult(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryResult_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRegisteredQueryResultRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryResult_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.QueryResult(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_LastRemoteHeight_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_LastRemoteHeight_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryLastRemoteHeight + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_LastRemoteHeight_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.LastRemoteHeight(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_LastRemoteHeight_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryLastRemoteHeight + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_LastRemoteHeight_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.LastRemoteHeight(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_RegisteredQueries_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_RegisteredQueries_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_RegisteredQueries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_RegisteredQuery_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_RegisteredQuery_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_RegisteredQuery_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryResult_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_QueryResult_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_QueryResult_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_LastRemoteHeight_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_LastRemoteHeight_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_LastRemoteHeight_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_RegisteredQueries_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_RegisteredQueries_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_RegisteredQueries_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_RegisteredQuery_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_RegisteredQuery_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_RegisteredQuery_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryResult_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_QueryResult_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_QueryResult_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_LastRemoteHeight_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_LastRemoteHeight_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_LastRemoteHeight_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}, []string{"neutron", "interchainqueries", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_RegisteredQueries_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"neutron", "interchainqueries", "registered_queries"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_RegisteredQuery_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"neutron", "interchainqueries", "registered_query"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryResult_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"neutron", "interchainqueries", "query_result"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_LastRemoteHeight_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"neutron", "interchainqueries", "remote_height"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_RegisteredQueries_0 = runtime.ForwardResponseMessage + + forward_Query_RegisteredQuery_0 = runtime.ForwardResponseMessage + + forward_Query_QueryResult_0 = runtime.ForwardResponseMessage + + forward_Query_LastRemoteHeight_0 = runtime.ForwardResponseMessage +) diff --git a/x/interchainqueries/types/registered_query.go b/x/interchainqueries/types/registered_query.go new file mode 100644 index 00000000..1667b6db --- /dev/null +++ b/x/interchainqueries/types/registered_query.go @@ -0,0 +1,38 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func (q *RegisteredQuery) GetOwnerAddress() (creator sdk.AccAddress, err error) { + creator, err = sdk.AccAddressFromBech32(q.Owner) + if err != nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to decode owner address: %s", q.Owner) + } + + return creator, nil +} + +// ValidateRemoval checks whether the caller is authorized to remove the query in current +// circumstances. Valid cases are: +// 1. owner removes query at any time; +// 2. anyone removes query if there's been q.SubmitTimeout blocks since last result submission +// height and query registration height. +func (q *RegisteredQuery) ValidateRemoval(ctx sdk.Context, caller string) error { + if q.GetOwner() == caller { + return nil // query owner is authorized to remove their queries at any time + } + + registrationTimeoutBlock := q.RegisteredAtHeight + q.SubmitTimeout + submitTimeoutBlock := q.LastSubmittedResultLocalHeight + q.SubmitTimeout + currentBlock := uint64(ctx.BlockHeader().Height) + if currentBlock <= registrationTimeoutBlock || currentBlock <= submitTimeoutBlock { + return fmt.Errorf("only owner can remove a query within its service period") + } + return nil +} diff --git a/x/interchainqueries/types/tx.go b/x/interchainqueries/types/tx.go new file mode 100644 index 00000000..6bce7639 --- /dev/null +++ b/x/interchainqueries/types/tx.go @@ -0,0 +1,260 @@ +package types + +import ( + "strings" + + "cosmossdk.io/errors" + "github.com/cosmos/ibc-go/v8/modules/core/exported" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + MaxKVQueryKeysCount = 32 +) + +var ( + _ sdk.Msg = &MsgSubmitQueryResult{} + _ codectypes.UnpackInterfacesMessage = MsgSubmitQueryResult{} +) + +func (msg MsgSubmitQueryResult) Route() string { + return RouterKey +} + +func (msg MsgSubmitQueryResult) Type() string { + return "submit-query-result" +} + +func (msg MsgSubmitQueryResult) Validate() error { + if msg.Result == nil { + return errors.Wrap(ErrEmptyResult, "query result can't be empty") + } + + if len(msg.Result.KvResults) == 0 && msg.Result.Block == nil { + return errors.Wrap(ErrEmptyResult, "query result can't be empty") + } + + if msg.QueryId == 0 { + return errors.Wrap(ErrInvalidQueryID, "query id cannot be equal zero") + } + + if strings.TrimSpace(msg.Sender) == "" { + return errors.Wrap(sdkerrors.ErrInvalidAddress, "missing sender address") + } + + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Sender) + } + + if strings.TrimSpace(msg.ClientId) == "" { + return errors.Wrap(ErrInvalidClientID, "client id cannot be empty") + } + + return nil +} + +func (msg MsgSubmitQueryResult) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(&msg) +} + +func (msg MsgSubmitQueryResult) GetSigners() []sdk.AccAddress { + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{senderAddr} +} + +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (msg MsgSubmitQueryResult) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var header exported.ClientMessage + if err := unpacker.UnpackAny(msg.Result.GetBlock().GetHeader(), &header); err != nil { + return err + } + + return unpacker.UnpackAny(msg.Result.GetBlock().GetNextBlockHeader(), &header) +} + +//---------------------------------------------------------------- + +var _ sdk.Msg = &MsgRegisterInterchainQuery{} + +func (msg MsgRegisterInterchainQuery) Route() string { + return RouterKey +} + +func (msg MsgRegisterInterchainQuery) Type() string { + return "register-interchain-query" +} + +func (msg MsgRegisterInterchainQuery) Validate() error { + if msg.UpdatePeriod == 0 { + return errors.Wrap(ErrInvalidUpdatePeriod, "update period can not be equal to zero") + } + + if strings.TrimSpace(msg.Sender) == "" { + return errors.Wrap(sdkerrors.ErrInvalidAddress, "missing sender address") + } + + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Sender) + } + + if strings.TrimSpace(msg.ConnectionId) == "" { + return errors.Wrap(ErrInvalidConnectionID, "connection id cannot be empty") + } + + if !InterchainQueryType(msg.QueryType).IsValid() { + return errors.Wrap(ErrInvalidQueryType, "invalid query type") + } + + if InterchainQueryType(msg.QueryType).IsKV() { + if len(msg.Keys) == 0 { + return errors.Wrap(ErrEmptyKeys, "keys cannot be empty") + } + if err := validateKeys(msg.GetKeys()); err != nil { + return err + } + } + + if InterchainQueryType(msg.QueryType).IsTX() { + if err := ValidateTransactionsFilter(msg.TransactionsFilter); err != nil { + return errors.Wrap(ErrInvalidTransactionsFilter, err.Error()) + } + } + return nil +} + +func (msg MsgRegisterInterchainQuery) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(&msg) +} + +func (msg MsgRegisterInterchainQuery) GetSigners() []sdk.AccAddress { + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{senderAddr} +} + +//---------------------------------------------------------------- + +var _ sdk.Msg = &MsgUpdateInterchainQueryRequest{} + +func (msg MsgUpdateInterchainQueryRequest) Validate() error { + if msg.GetQueryId() == 0 { + return errors.Wrap(ErrInvalidQueryID, "query_id cannot be empty or equal to 0") + } + + newKeys := msg.GetNewKeys() + newTxFilter := msg.GetNewTransactionsFilter() + + if len(newKeys) == 0 && newTxFilter == "" && msg.GetNewUpdatePeriod() == 0 { + return errors.Wrap( + sdkerrors.ErrInvalidRequest, + "one of new_keys, new_transactions_filter or new_update_period should be set", + ) + } + + if len(newKeys) != 0 && newTxFilter != "" { + return errors.Wrap( + sdkerrors.ErrInvalidRequest, + "either new_keys or new_transactions_filter should be set", + ) + } + + if len(newKeys) != 0 { + if err := validateKeys(newKeys); err != nil { + return err + } + } + + if newTxFilter != "" { + if err := ValidateTransactionsFilter(newTxFilter); err != nil { + return errors.Wrap(ErrInvalidTransactionsFilter, err.Error()) + } + } + + if strings.TrimSpace(msg.Sender) == "" { + return errors.Wrap(sdkerrors.ErrInvalidAddress, "missing sender address") + } + if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Sender) + } + return nil +} + +func (msg MsgUpdateInterchainQueryRequest) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(&msg) +} + +func (msg MsgUpdateInterchainQueryRequest) GetSigners() []sdk.AccAddress { + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{senderAddr} +} + +//---------------------------------------------------------------- + +var _ sdk.Msg = &MsgUpdateParams{} + +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +func (msg *MsgUpdateParams) Type() string { + return "update-params" +} + +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgUpdateParams) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgUpdateParams) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "authority is invalid") + } + return nil +} + +func validateKeys(keys []*KVKey) error { + if uint64(len(keys)) > MaxKVQueryKeysCount { + return errors.Wrapf(ErrTooManyKVQueryKeys, "keys count cannot be more than %d", MaxKVQueryKeysCount) + } + + duplicates := make(map[string]struct{}) + for _, key := range keys { + if key == nil { + return errors.Wrap(sdkerrors.ErrInvalidType, "key cannot be nil") + } + + if _, ok := duplicates[key.ToString()]; ok { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "keys cannot be duplicated") + } + + if len(key.Path) == 0 { + return errors.Wrap(ErrEmptyKeyPath, "keys path cannot be empty") + } + + if len(key.Key) == 0 { + return errors.Wrap(ErrEmptyKeyID, "keys id cannot be empty") + } + + duplicates[key.ToString()] = struct{}{} + } + + return nil +} diff --git a/x/interchainqueries/types/tx.pb.go b/x/interchainqueries/types/tx.pb.go new file mode 100644 index 00000000..a4a4ca2d --- /dev/null +++ b/x/interchainqueries/types/tx.pb.go @@ -0,0 +1,3966 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchainqueries/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + types1 "github.com/cometbft/cometbft/abci/types" + crypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/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" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// 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 + +type MsgRegisterInterchainQuery struct { + // defines a query type: `kv` or `tx` now + QueryType string `protobuf:"bytes,1,opt,name=query_type,json=queryType,proto3" json:"query_type,omitempty"` + // is used to define KV-storage keys for which we want to get values from + // remote chain + Keys []*KVKey `protobuf:"bytes,2,rep,name=keys,proto3" json:"keys,omitempty"` + // is used to define a filter for transaction search ICQ + TransactionsFilter string `protobuf:"bytes,3,opt,name=transactions_filter,json=transactionsFilter,proto3" json:"transactions_filter,omitempty"` + // is IBC connection ID for getting ConsensusState to verify proofs + ConnectionId string `protobuf:"bytes,4,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + // is used to specify how often (in neutron blocks) the query must be updated + UpdatePeriod uint64 `protobuf:"varint,5,opt,name=update_period,json=updatePeriod,proto3" json:"update_period,omitempty"` + // is the signer of the message + Sender string `protobuf:"bytes,6,opt,name=sender,proto3" json:"sender,omitempty"` +} + +func (m *MsgRegisterInterchainQuery) Reset() { *m = MsgRegisterInterchainQuery{} } +func (m *MsgRegisterInterchainQuery) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterInterchainQuery) ProtoMessage() {} +func (*MsgRegisterInterchainQuery) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{0} +} +func (m *MsgRegisterInterchainQuery) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterInterchainQuery) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterInterchainQuery.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 *MsgRegisterInterchainQuery) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterInterchainQuery.Merge(m, src) +} +func (m *MsgRegisterInterchainQuery) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterInterchainQuery) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterInterchainQuery.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterInterchainQuery proto.InternalMessageInfo + +func (m *MsgRegisterInterchainQuery) GetQueryType() string { + if m != nil { + return m.QueryType + } + return "" +} + +func (m *MsgRegisterInterchainQuery) GetKeys() []*KVKey { + if m != nil { + return m.Keys + } + return nil +} + +func (m *MsgRegisterInterchainQuery) GetTransactionsFilter() string { + if m != nil { + return m.TransactionsFilter + } + return "" +} + +func (m *MsgRegisterInterchainQuery) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *MsgRegisterInterchainQuery) GetUpdatePeriod() uint64 { + if m != nil { + return m.UpdatePeriod + } + return 0 +} + +func (m *MsgRegisterInterchainQuery) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +type MsgRegisterInterchainQueryResponse struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *MsgRegisterInterchainQueryResponse) Reset() { *m = MsgRegisterInterchainQueryResponse{} } +func (m *MsgRegisterInterchainQueryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterInterchainQueryResponse) ProtoMessage() {} +func (*MsgRegisterInterchainQueryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{1} +} +func (m *MsgRegisterInterchainQueryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterInterchainQueryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterInterchainQueryResponse.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 *MsgRegisterInterchainQueryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterInterchainQueryResponse.Merge(m, src) +} +func (m *MsgRegisterInterchainQueryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterInterchainQueryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterInterchainQueryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterInterchainQueryResponse proto.InternalMessageInfo + +func (m *MsgRegisterInterchainQueryResponse) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +type MsgSubmitQueryResult struct { + QueryId uint64 `protobuf:"varint,1,opt,name=query_id,json=queryId,proto3" json:"query_id,omitempty"` + Sender string `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"` + // is the IBC client ID for an IBC connection between Neutron chain and target + // chain (where the result was obtained from) + ClientId string `protobuf:"bytes,3,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + Result *QueryResult `protobuf:"bytes,4,opt,name=result,proto3" json:"result,omitempty"` +} + +func (m *MsgSubmitQueryResult) Reset() { *m = MsgSubmitQueryResult{} } +func (m *MsgSubmitQueryResult) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitQueryResult) ProtoMessage() {} +func (*MsgSubmitQueryResult) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{2} +} +func (m *MsgSubmitQueryResult) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitQueryResult) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitQueryResult.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 *MsgSubmitQueryResult) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitQueryResult.Merge(m, src) +} +func (m *MsgSubmitQueryResult) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitQueryResult) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitQueryResult.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitQueryResult proto.InternalMessageInfo + +func (m *MsgSubmitQueryResult) GetQueryId() uint64 { + if m != nil { + return m.QueryId + } + return 0 +} + +func (m *MsgSubmitQueryResult) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgSubmitQueryResult) GetClientId() string { + if m != nil { + return m.ClientId + } + return "" +} + +func (m *MsgSubmitQueryResult) GetResult() *QueryResult { + if m != nil { + return m.Result + } + return nil +} + +type QueryResult struct { + KvResults []*StorageValue `protobuf:"bytes,1,rep,name=kv_results,json=kvResults,proto3" json:"kv_results,omitempty"` + Block *Block `protobuf:"bytes,2,opt,name=block,proto3" json:"block,omitempty"` + Height uint64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"` + Revision uint64 `protobuf:"varint,4,opt,name=revision,proto3" json:"revision,omitempty"` + AllowKvCallbacks bool `protobuf:"varint,5,opt,name=allow_kv_callbacks,json=allowKvCallbacks,proto3" json:"allow_kv_callbacks,omitempty"` +} + +func (m *QueryResult) Reset() { *m = QueryResult{} } +func (m *QueryResult) String() string { return proto.CompactTextString(m) } +func (*QueryResult) ProtoMessage() {} +func (*QueryResult) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{3} +} +func (m *QueryResult) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryResult) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryResult.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 *QueryResult) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryResult.Merge(m, src) +} +func (m *QueryResult) XXX_Size() int { + return m.Size() +} +func (m *QueryResult) XXX_DiscardUnknown() { + xxx_messageInfo_QueryResult.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryResult proto.InternalMessageInfo + +func (m *QueryResult) GetKvResults() []*StorageValue { + if m != nil { + return m.KvResults + } + return nil +} + +func (m *QueryResult) GetBlock() *Block { + if m != nil { + return m.Block + } + return nil +} + +func (m *QueryResult) GetHeight() uint64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *QueryResult) GetRevision() uint64 { + if m != nil { + return m.Revision + } + return 0 +} + +func (m *QueryResult) GetAllowKvCallbacks() bool { + if m != nil { + return m.AllowKvCallbacks + } + return false +} + +type StorageValue struct { + // is the substore name (acc, staking, etc.) + StoragePrefix string `protobuf:"bytes,1,opt,name=storage_prefix,json=storagePrefix,proto3" json:"storage_prefix,omitempty"` + // is the key in IAVL store + Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + // is the value in IAVL store + Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` + // is the Merkle Proof which proves existence of key-value pair in IAVL + // storage + Proof *crypto.ProofOps `protobuf:"bytes,4,opt,name=Proof,proto3" json:"Proof,omitempty"` +} + +func (m *StorageValue) Reset() { *m = StorageValue{} } +func (m *StorageValue) String() string { return proto.CompactTextString(m) } +func (*StorageValue) ProtoMessage() {} +func (*StorageValue) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{4} +} +func (m *StorageValue) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StorageValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StorageValue.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 *StorageValue) XXX_Merge(src proto.Message) { + xxx_messageInfo_StorageValue.Merge(m, src) +} +func (m *StorageValue) XXX_Size() int { + return m.Size() +} +func (m *StorageValue) XXX_DiscardUnknown() { + xxx_messageInfo_StorageValue.DiscardUnknown(m) +} + +var xxx_messageInfo_StorageValue proto.InternalMessageInfo + +func (m *StorageValue) GetStoragePrefix() string { + if m != nil { + return m.StoragePrefix + } + return "" +} + +func (m *StorageValue) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *StorageValue) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +func (m *StorageValue) GetProof() *crypto.ProofOps { + if m != nil { + return m.Proof + } + return nil +} + +type Block struct { + // We need to know block X+1 to verify response of transaction for block X + // since LastResultsHash is root hash of all results from the txs from the + // previous block + NextBlockHeader *types.Any `protobuf:"bytes,1,opt,name=next_block_header,json=nextBlockHeader,proto3" json:"next_block_header,omitempty"` + // We need to know block X to verify inclusion of transaction for block X + Header *types.Any `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` + Tx *TxValue `protobuf:"bytes,3,opt,name=tx,proto3" json:"tx,omitempty"` +} + +func (m *Block) Reset() { *m = Block{} } +func (m *Block) String() string { return proto.CompactTextString(m) } +func (*Block) ProtoMessage() {} +func (*Block) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{5} +} +func (m *Block) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Block) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Block.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 *Block) XXX_Merge(src proto.Message) { + xxx_messageInfo_Block.Merge(m, src) +} +func (m *Block) XXX_Size() int { + return m.Size() +} +func (m *Block) XXX_DiscardUnknown() { + xxx_messageInfo_Block.DiscardUnknown(m) +} + +var xxx_messageInfo_Block proto.InternalMessageInfo + +func (m *Block) GetNextBlockHeader() *types.Any { + if m != nil { + return m.NextBlockHeader + } + return nil +} + +func (m *Block) GetHeader() *types.Any { + if m != nil { + return m.Header + } + return nil +} + +func (m *Block) GetTx() *TxValue { + if m != nil { + return m.Tx + } + return nil +} + +type TxValue struct { + Response *types1.ExecTxResult `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` + // is the Merkle Proof which proves existence of response in block with height + // next_block_header.Height + DeliveryProof *crypto.Proof `protobuf:"bytes,2,opt,name=delivery_proof,json=deliveryProof,proto3" json:"delivery_proof,omitempty"` + // is the Merkle Proof which proves existence of data in block with height + // header.Height + InclusionProof *crypto.Proof `protobuf:"bytes,3,opt,name=inclusion_proof,json=inclusionProof,proto3" json:"inclusion_proof,omitempty"` + // is body of the transaction + Data []byte `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *TxValue) Reset() { *m = TxValue{} } +func (m *TxValue) String() string { return proto.CompactTextString(m) } +func (*TxValue) ProtoMessage() {} +func (*TxValue) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{6} +} +func (m *TxValue) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TxValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TxValue.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 *TxValue) XXX_Merge(src proto.Message) { + xxx_messageInfo_TxValue.Merge(m, src) +} +func (m *TxValue) XXX_Size() int { + return m.Size() +} +func (m *TxValue) XXX_DiscardUnknown() { + xxx_messageInfo_TxValue.DiscardUnknown(m) +} + +var xxx_messageInfo_TxValue proto.InternalMessageInfo + +func (m *TxValue) GetResponse() *types1.ExecTxResult { + if m != nil { + return m.Response + } + return nil +} + +func (m *TxValue) GetDeliveryProof() *crypto.Proof { + if m != nil { + return m.DeliveryProof + } + return nil +} + +func (m *TxValue) GetInclusionProof() *crypto.Proof { + if m != nil { + return m.InclusionProof + } + return nil +} + +func (m *TxValue) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +type MsgSubmitQueryResultResponse struct { +} + +func (m *MsgSubmitQueryResultResponse) Reset() { *m = MsgSubmitQueryResultResponse{} } +func (m *MsgSubmitQueryResultResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitQueryResultResponse) ProtoMessage() {} +func (*MsgSubmitQueryResultResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{7} +} +func (m *MsgSubmitQueryResultResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitQueryResultResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitQueryResultResponse.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 *MsgSubmitQueryResultResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitQueryResultResponse.Merge(m, src) +} +func (m *MsgSubmitQueryResultResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitQueryResultResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitQueryResultResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitQueryResultResponse proto.InternalMessageInfo + +type MsgRemoveInterchainQueryRequest struct { + QueryId uint64 `protobuf:"varint,1,opt,name=query_id,json=queryId,proto3" json:"query_id,omitempty"` + Sender string `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"` +} + +func (m *MsgRemoveInterchainQueryRequest) Reset() { *m = MsgRemoveInterchainQueryRequest{} } +func (m *MsgRemoveInterchainQueryRequest) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveInterchainQueryRequest) ProtoMessage() {} +func (*MsgRemoveInterchainQueryRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{8} +} +func (m *MsgRemoveInterchainQueryRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveInterchainQueryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveInterchainQueryRequest.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 *MsgRemoveInterchainQueryRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveInterchainQueryRequest.Merge(m, src) +} +func (m *MsgRemoveInterchainQueryRequest) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveInterchainQueryRequest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveInterchainQueryRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveInterchainQueryRequest proto.InternalMessageInfo + +func (m *MsgRemoveInterchainQueryRequest) GetQueryId() uint64 { + if m != nil { + return m.QueryId + } + return 0 +} + +func (m *MsgRemoveInterchainQueryRequest) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +type MsgRemoveInterchainQueryResponse struct { +} + +func (m *MsgRemoveInterchainQueryResponse) Reset() { *m = MsgRemoveInterchainQueryResponse{} } +func (m *MsgRemoveInterchainQueryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveInterchainQueryResponse) ProtoMessage() {} +func (*MsgRemoveInterchainQueryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{9} +} +func (m *MsgRemoveInterchainQueryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveInterchainQueryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveInterchainQueryResponse.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 *MsgRemoveInterchainQueryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveInterchainQueryResponse.Merge(m, src) +} +func (m *MsgRemoveInterchainQueryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveInterchainQueryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveInterchainQueryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveInterchainQueryResponse proto.InternalMessageInfo + +type MsgUpdateInterchainQueryRequest struct { + QueryId uint64 `protobuf:"varint,1,opt,name=query_id,json=queryId,proto3" json:"query_id,omitempty"` + NewKeys []*KVKey `protobuf:"bytes,2,rep,name=new_keys,json=newKeys,proto3" json:"new_keys,omitempty"` + NewUpdatePeriod uint64 `protobuf:"varint,3,opt,name=new_update_period,json=newUpdatePeriod,proto3" json:"new_update_period,omitempty"` + NewTransactionsFilter string `protobuf:"bytes,4,opt,name=new_transactions_filter,json=newTransactionsFilter,proto3" json:"new_transactions_filter,omitempty"` + Sender string `protobuf:"bytes,5,opt,name=sender,proto3" json:"sender,omitempty"` +} + +func (m *MsgUpdateInterchainQueryRequest) Reset() { *m = MsgUpdateInterchainQueryRequest{} } +func (m *MsgUpdateInterchainQueryRequest) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateInterchainQueryRequest) ProtoMessage() {} +func (*MsgUpdateInterchainQueryRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{10} +} +func (m *MsgUpdateInterchainQueryRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateInterchainQueryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateInterchainQueryRequest.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 *MsgUpdateInterchainQueryRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateInterchainQueryRequest.Merge(m, src) +} +func (m *MsgUpdateInterchainQueryRequest) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateInterchainQueryRequest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateInterchainQueryRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateInterchainQueryRequest proto.InternalMessageInfo + +func (m *MsgUpdateInterchainQueryRequest) GetQueryId() uint64 { + if m != nil { + return m.QueryId + } + return 0 +} + +func (m *MsgUpdateInterchainQueryRequest) GetNewKeys() []*KVKey { + if m != nil { + return m.NewKeys + } + return nil +} + +func (m *MsgUpdateInterchainQueryRequest) GetNewUpdatePeriod() uint64 { + if m != nil { + return m.NewUpdatePeriod + } + return 0 +} + +func (m *MsgUpdateInterchainQueryRequest) GetNewTransactionsFilter() string { + if m != nil { + return m.NewTransactionsFilter + } + return "" +} + +func (m *MsgUpdateInterchainQueryRequest) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +type MsgUpdateInterchainQueryResponse struct { +} + +func (m *MsgUpdateInterchainQueryResponse) Reset() { *m = MsgUpdateInterchainQueryResponse{} } +func (m *MsgUpdateInterchainQueryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateInterchainQueryResponse) ProtoMessage() {} +func (*MsgUpdateInterchainQueryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{11} +} +func (m *MsgUpdateInterchainQueryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateInterchainQueryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateInterchainQueryResponse.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 *MsgUpdateInterchainQueryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateInterchainQueryResponse.Merge(m, src) +} +func (m *MsgUpdateInterchainQueryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateInterchainQueryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateInterchainQueryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateInterchainQueryResponse proto.InternalMessageInfo + +// MsgUpdateParams is the MsgUpdateParams request type. +// +// Since: 0.47 +type MsgUpdateParams struct { + // Authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/interchainqueries parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{12} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d4793837a316491e, []int{13} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgRegisterInterchainQuery)(nil), "neutron.interchainqueries.MsgRegisterInterchainQuery") + proto.RegisterType((*MsgRegisterInterchainQueryResponse)(nil), "neutron.interchainqueries.MsgRegisterInterchainQueryResponse") + proto.RegisterType((*MsgSubmitQueryResult)(nil), "neutron.interchainqueries.MsgSubmitQueryResult") + proto.RegisterType((*QueryResult)(nil), "neutron.interchainqueries.QueryResult") + proto.RegisterType((*StorageValue)(nil), "neutron.interchainqueries.StorageValue") + proto.RegisterType((*Block)(nil), "neutron.interchainqueries.Block") + proto.RegisterType((*TxValue)(nil), "neutron.interchainqueries.TxValue") + proto.RegisterType((*MsgSubmitQueryResultResponse)(nil), "neutron.interchainqueries.MsgSubmitQueryResultResponse") + proto.RegisterType((*MsgRemoveInterchainQueryRequest)(nil), "neutron.interchainqueries.MsgRemoveInterchainQueryRequest") + proto.RegisterType((*MsgRemoveInterchainQueryResponse)(nil), "neutron.interchainqueries.MsgRemoveInterchainQueryResponse") + proto.RegisterType((*MsgUpdateInterchainQueryRequest)(nil), "neutron.interchainqueries.MsgUpdateInterchainQueryRequest") + proto.RegisterType((*MsgUpdateInterchainQueryResponse)(nil), "neutron.interchainqueries.MsgUpdateInterchainQueryResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "neutron.interchainqueries.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "neutron.interchainqueries.MsgUpdateParamsResponse") +} + +func init() { + proto.RegisterFile("neutron/interchainqueries/tx.proto", fileDescriptor_d4793837a316491e) +} + +var fileDescriptor_d4793837a316491e = []byte{ + // 1164 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4f, 0x4f, 0x1b, 0x47, + 0x14, 0x67, 0x8d, 0x4d, 0xf0, 0xe0, 0x40, 0x32, 0x25, 0xc5, 0x38, 0x8d, 0x43, 0xb6, 0x6a, 0x12, + 0xa1, 0x64, 0x57, 0x71, 0x29, 0x55, 0x41, 0xfd, 0x03, 0x6d, 0xa3, 0x22, 0x84, 0x4a, 0x17, 0xc8, + 0xa1, 0x97, 0xd5, 0x7a, 0x77, 0x58, 0x8f, 0xbc, 0x9e, 0x71, 0x76, 0x66, 0xfd, 0xe7, 0x50, 0xa9, + 0xca, 0xb1, 0x97, 0xd2, 0x6f, 0x51, 0xa9, 0x17, 0xa4, 0xf4, 0x2b, 0x54, 0xca, 0x31, 0xea, 0xa9, + 0x87, 0xaa, 0xaa, 0xe0, 0xc0, 0xb1, 0x5f, 0xa1, 0x9a, 0x3f, 0x6b, 0x4c, 0x8c, 0x4d, 0xe0, 0x02, + 0xfb, 0xde, 0xfb, 0xbd, 0x37, 0xbf, 0xf9, 0xcd, 0xbc, 0x37, 0x06, 0x26, 0x41, 0x09, 0x8f, 0x29, + 0xb1, 0x31, 0xe1, 0x28, 0xf6, 0x6b, 0x1e, 0x26, 0xcf, 0x13, 0x14, 0x63, 0xc4, 0x6c, 0xde, 0xb1, + 0x9a, 0x31, 0xe5, 0x14, 0xce, 0x6b, 0x8c, 0x35, 0x80, 0x29, 0xdd, 0xf4, 0x1a, 0x98, 0x50, 0x5b, + 0xfe, 0x55, 0xe8, 0xd2, 0x9c, 0x4f, 0x59, 0x83, 0x32, 0xbb, 0xc1, 0x42, 0xbb, 0xf5, 0x44, 0xfc, + 0xd3, 0x81, 0x79, 0x15, 0x70, 0xa5, 0x65, 0x2b, 0x43, 0x87, 0x66, 0x43, 0x1a, 0x52, 0xe5, 0x17, + 0x5f, 0x69, 0x42, 0x48, 0x69, 0x18, 0x21, 0x5b, 0x5a, 0xd5, 0x64, 0xdf, 0xf6, 0x48, 0x57, 0x87, + 0x1e, 0x0c, 0xa7, 0x1d, 0x22, 0x82, 0x18, 0x4e, 0x2b, 0xdf, 0x1f, 0x0e, 0x6c, 0x7a, 0xb1, 0xd7, + 0x48, 0x71, 0xb7, 0x39, 0x22, 0x01, 0x8a, 0x1b, 0x98, 0x70, 0xdb, 0xab, 0xfa, 0xd8, 0xe6, 0xdd, + 0x26, 0x4a, 0x83, 0x77, 0xfa, 0x82, 0x7e, 0xdc, 0x6d, 0x72, 0x2a, 0x38, 0xd1, 0x7d, 0x15, 0x36, + 0x7f, 0xc9, 0x80, 0xd2, 0x16, 0x0b, 0x1d, 0x14, 0x62, 0xc6, 0x51, 0xbc, 0xd1, 0x5b, 0xe9, 0xbb, + 0x04, 0xc5, 0x5d, 0x78, 0x07, 0x00, 0xb1, 0x64, 0xd7, 0x15, 0x25, 0x8b, 0xc6, 0x82, 0xf1, 0x30, + 0xef, 0xe4, 0xa5, 0x67, 0xb7, 0xdb, 0x44, 0x70, 0x09, 0x64, 0xeb, 0xa8, 0xcb, 0x8a, 0x99, 0x85, + 0xf1, 0x87, 0x53, 0x95, 0x05, 0x6b, 0xa8, 0xd8, 0xd6, 0xe6, 0xb3, 0x4d, 0xd4, 0x75, 0x24, 0x1a, + 0xda, 0xe0, 0x1d, 0x1e, 0x7b, 0x84, 0x79, 0x3e, 0xc7, 0x94, 0x30, 0x77, 0x1f, 0x47, 0x1c, 0xc5, + 0xc5, 0x71, 0x59, 0x1d, 0xf6, 0x87, 0x9e, 0xca, 0x08, 0x7c, 0x1f, 0x5c, 0xf7, 0x29, 0x21, 0x48, + 0x3a, 0x5d, 0x1c, 0x14, 0xb3, 0x12, 0x5a, 0x38, 0x75, 0x6e, 0x04, 0x02, 0x94, 0x34, 0x03, 0x8f, + 0x23, 0xb7, 0x89, 0x62, 0x4c, 0x83, 0x62, 0x6e, 0xc1, 0x78, 0x98, 0x75, 0x0a, 0xca, 0xb9, 0x2d, + 0x7d, 0xf0, 0x5d, 0x30, 0xc1, 0xa4, 0x1e, 0xc5, 0x09, 0x59, 0x42, 0x5b, 0x2b, 0x53, 0x2f, 0x4e, + 0x0e, 0x17, 0xb5, 0x61, 0x2e, 0x01, 0x73, 0xb8, 0x24, 0x0e, 0x62, 0x4d, 0x4a, 0x18, 0x82, 0xd3, + 0x20, 0x83, 0x03, 0x29, 0x49, 0xd6, 0xc9, 0xe0, 0xc0, 0x7c, 0x69, 0x80, 0xd9, 0x2d, 0x16, 0xee, + 0x24, 0xd5, 0x06, 0xe6, 0x29, 0x34, 0x89, 0x38, 0x9c, 0x07, 0x93, 0x4a, 0xc3, 0x1e, 0xfc, 0x9a, + 0xb4, 0x37, 0xfa, 0xe9, 0x64, 0xfa, 0xe9, 0xc0, 0xdb, 0x20, 0xef, 0x47, 0x18, 0x11, 0x2e, 0x72, + 0x94, 0x2e, 0x93, 0xca, 0xb1, 0x11, 0xc0, 0xcf, 0xc0, 0x44, 0x2c, 0x2b, 0x4b, 0x19, 0xa6, 0x2a, + 0xf7, 0x47, 0xc8, 0xde, 0xc7, 0xc3, 0xd1, 0x59, 0x67, 0xf7, 0xfa, 0x9f, 0x01, 0xa6, 0xfa, 0xc9, + 0x3e, 0x05, 0xa0, 0xde, 0x72, 0x15, 0x92, 0x15, 0x0d, 0x79, 0xae, 0x0f, 0x46, 0x2c, 0xb0, 0xc3, + 0x69, 0xec, 0x85, 0xe8, 0x99, 0x17, 0x25, 0xc8, 0xc9, 0xd7, 0x5b, 0xaa, 0x0c, 0x83, 0xcb, 0x20, + 0x57, 0x8d, 0xa8, 0x5f, 0x97, 0x1b, 0x1b, 0x7d, 0x35, 0xd6, 0x05, 0xce, 0x51, 0x70, 0xa1, 0x48, + 0x0d, 0xe1, 0xb0, 0xc6, 0xe5, 0xb6, 0xb3, 0x8e, 0xb6, 0x60, 0x09, 0x4c, 0xc6, 0xa8, 0x85, 0x19, + 0xa6, 0x44, 0x6e, 0x3b, 0xeb, 0xf4, 0x6c, 0xf8, 0x08, 0x40, 0x2f, 0x8a, 0x68, 0xdb, 0xad, 0xb7, + 0x5c, 0xdf, 0x8b, 0xa2, 0xaa, 0xe7, 0xd7, 0x99, 0x3c, 0xfe, 0x49, 0xe7, 0x86, 0x8c, 0x6c, 0xb6, + 0xbe, 0x4c, 0xfd, 0xe6, 0x81, 0x01, 0x0a, 0xfd, 0xac, 0xe1, 0x07, 0x60, 0x9a, 0x29, 0xdb, 0x6d, + 0xc6, 0x68, 0x1f, 0x77, 0xf4, 0x3d, 0xbf, 0xae, 0xbd, 0xdb, 0xd2, 0x09, 0x6f, 0x80, 0xf1, 0x3a, + 0xea, 0xca, 0xfd, 0x14, 0x1c, 0xf1, 0x09, 0x67, 0x41, 0xae, 0x25, 0x2a, 0x48, 0xaa, 0x05, 0x47, + 0x19, 0xf0, 0x09, 0xc8, 0x6d, 0x8b, 0x06, 0xd3, 0xa7, 0x73, 0xdb, 0x3a, 0x6d, 0x40, 0x4b, 0x35, + 0xa0, 0x25, 0xe3, 0xdf, 0x36, 0x99, 0xa3, 0x90, 0xe6, 0x6f, 0x06, 0xc8, 0x49, 0x15, 0xe0, 0x17, + 0xe0, 0x26, 0x41, 0x1d, 0xee, 0x4a, 0x31, 0xdc, 0x1a, 0xf2, 0xc4, 0xdd, 0x30, 0x64, 0xa1, 0x59, + 0x4b, 0x8d, 0x14, 0x2b, 0x1d, 0x29, 0xd6, 0x1a, 0xe9, 0x3a, 0x33, 0x02, 0x2e, 0x73, 0xbf, 0x91, + 0x60, 0xf8, 0x48, 0x08, 0xe8, 0xa5, 0x57, 0x6a, 0x58, 0x9a, 0xc6, 0xc0, 0x0a, 0xc8, 0xf0, 0x8e, + 0xe4, 0x3f, 0x55, 0x31, 0x47, 0x9c, 0xd1, 0x6e, 0x47, 0x9d, 0x70, 0x86, 0x77, 0xcc, 0xbf, 0x0d, + 0x70, 0x4d, 0xdb, 0xf0, 0x13, 0x71, 0x2c, 0xaa, 0x21, 0x34, 0xcd, 0x3b, 0xfd, 0xfb, 0x15, 0xd3, + 0xc8, 0xfa, 0xba, 0x83, 0xfc, 0xdd, 0x8e, 0xbe, 0x84, 0x3d, 0x38, 0xfc, 0x1c, 0x4c, 0x07, 0x28, + 0xc2, 0x2d, 0xd1, 0x19, 0x72, 0x22, 0x69, 0xc2, 0xc5, 0x61, 0x82, 0x39, 0xd7, 0x53, 0xbc, 0x34, + 0xe1, 0x1a, 0x98, 0xc1, 0xc4, 0x8f, 0x12, 0x71, 0x07, 0x74, 0x85, 0xf1, 0x0b, 0x2a, 0x4c, 0xf7, + 0x12, 0x54, 0x09, 0x08, 0xb2, 0x81, 0xc7, 0x3d, 0x79, 0x54, 0x05, 0x47, 0x7e, 0x9b, 0x65, 0xf0, + 0xde, 0x79, 0x6d, 0x9c, 0xf6, 0xbd, 0xe9, 0x81, 0xbb, 0x72, 0x3a, 0x34, 0x68, 0x0b, 0x0d, 0xcc, + 0x86, 0xe7, 0x09, 0x62, 0x57, 0xe9, 0xf8, 0xb3, 0x4d, 0x69, 0x82, 0x85, 0xe1, 0x4b, 0x68, 0x1a, + 0x2f, 0x32, 0x92, 0xc7, 0x9e, 0x9c, 0x6e, 0x97, 0xe7, 0xb1, 0x0a, 0x26, 0x09, 0x6a, 0xbb, 0x97, + 0x9a, 0xde, 0xd7, 0x08, 0x6a, 0x6f, 0x8a, 0x01, 0xbe, 0x28, 0x6e, 0x69, 0xdb, 0x3d, 0x3b, 0x6e, + 0x55, 0xbf, 0xce, 0x10, 0xd4, 0xde, 0xeb, 0x9f, 0xb8, 0xcb, 0x60, 0x4e, 0x60, 0xcf, 0x1b, 0xf8, + 0x6a, 0x8a, 0xdf, 0x22, 0xa8, 0xbd, 0x3b, 0x38, 0xf3, 0x4f, 0x85, 0xca, 0x5d, 0x24, 0xd4, 0x10, + 0x0d, 0xb4, 0x50, 0x7f, 0x18, 0x60, 0xa6, 0x07, 0xda, 0x96, 0xef, 0x26, 0x5c, 0x06, 0x79, 0x2f, + 0xe1, 0x35, 0x1a, 0x63, 0xde, 0x55, 0xdd, 0xbe, 0x5e, 0xfc, 0xf3, 0xf7, 0xc7, 0xb3, 0xfa, 0x61, + 0x5f, 0x0b, 0x82, 0x18, 0x31, 0xb6, 0xc3, 0x63, 0x4c, 0x42, 0xe7, 0x14, 0x0a, 0xbf, 0x02, 0x13, + 0xea, 0xe5, 0xd5, 0x77, 0xf5, 0xde, 0x08, 0xcd, 0xd4, 0x52, 0xeb, 0xf9, 0x57, 0xff, 0xdc, 0x1d, + 0xfb, 0xf5, 0xe4, 0x70, 0xd1, 0x70, 0x74, 0xee, 0xca, 0x92, 0xd8, 0xc2, 0x69, 0xd5, 0x9f, 0x4e, + 0x0e, 0x17, 0xef, 0x0d, 0x3e, 0xf1, 0x6f, 0x70, 0x36, 0xe7, 0xc1, 0xdc, 0x1b, 0xae, 0x74, 0x8b, + 0x95, 0x97, 0x39, 0x30, 0xbe, 0xc5, 0x42, 0xf8, 0xb3, 0x01, 0xe6, 0x86, 0xbd, 0xe4, 0x1f, 0x8d, + 0xa0, 0x3a, 0xfc, 0xb5, 0x2b, 0x7d, 0x7a, 0xa5, 0xb4, 0xde, 0x23, 0xf9, 0x03, 0xb8, 0x39, 0xf8, + 0x20, 0xda, 0xa3, 0x6b, 0x0e, 0x24, 0x94, 0x3e, 0xbe, 0x64, 0x42, 0x6f, 0xf9, 0x03, 0x03, 0xdc, + 0x3a, 0xb7, 0x8d, 0xe0, 0xca, 0x45, 0xfb, 0x1a, 0xde, 0xde, 0xa5, 0xd5, 0x2b, 0xe5, 0xf6, 0x51, + 0x3a, 0xf7, 0xc2, 0x5e, 0x44, 0x69, 0x54, 0xa7, 0x5f, 0x44, 0x69, 0x64, 0x87, 0x40, 0x02, 0x0a, + 0x67, 0xba, 0x63, 0xf1, 0x6d, 0x8a, 0x29, 0x6c, 0xa9, 0xf2, 0xf6, 0xd8, 0x74, 0xbd, 0x52, 0xee, + 0x47, 0xd1, 0x0e, 0xeb, 0x7b, 0xaf, 0x8e, 0xca, 0xc6, 0xeb, 0xa3, 0xb2, 0xf1, 0xef, 0x51, 0xd9, + 0x38, 0x38, 0x2e, 0x8f, 0xbd, 0x3e, 0x2e, 0x8f, 0xfd, 0x75, 0x5c, 0x1e, 0xfb, 0x7e, 0x35, 0xc4, + 0xbc, 0x96, 0x54, 0x2d, 0x9f, 0x36, 0x6c, 0x5d, 0xfe, 0x31, 0x8d, 0xc3, 0xf4, 0xdb, 0x6e, 0x2d, + 0xd9, 0x9d, 0xf3, 0x7e, 0xf4, 0x8b, 0x9f, 0xbd, 0xd5, 0x09, 0xf9, 0xd0, 0x7d, 0xf8, 0x7f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xaf, 0x02, 0x2b, 0xa7, 0x1e, 0x0c, 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 { + RegisterInterchainQuery(ctx context.Context, in *MsgRegisterInterchainQuery, opts ...grpc.CallOption) (*MsgRegisterInterchainQueryResponse, error) + SubmitQueryResult(ctx context.Context, in *MsgSubmitQueryResult, opts ...grpc.CallOption) (*MsgSubmitQueryResultResponse, error) + RemoveInterchainQuery(ctx context.Context, in *MsgRemoveInterchainQueryRequest, opts ...grpc.CallOption) (*MsgRemoveInterchainQueryResponse, error) + UpdateInterchainQuery(ctx context.Context, in *MsgUpdateInterchainQueryRequest, opts ...grpc.CallOption) (*MsgUpdateInterchainQueryResponse, error) + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) RegisterInterchainQuery(ctx context.Context, in *MsgRegisterInterchainQuery, opts ...grpc.CallOption) (*MsgRegisterInterchainQueryResponse, error) { + out := new(MsgRegisterInterchainQueryResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Msg/RegisterInterchainQuery", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) SubmitQueryResult(ctx context.Context, in *MsgSubmitQueryResult, opts ...grpc.CallOption) (*MsgSubmitQueryResultResponse, error) { + out := new(MsgSubmitQueryResultResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Msg/SubmitQueryResult", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveInterchainQuery(ctx context.Context, in *MsgRemoveInterchainQueryRequest, opts ...grpc.CallOption) (*MsgRemoveInterchainQueryResponse, error) { + out := new(MsgRemoveInterchainQueryResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Msg/RemoveInterchainQuery", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateInterchainQuery(ctx context.Context, in *MsgUpdateInterchainQueryRequest, opts ...grpc.CallOption) (*MsgUpdateInterchainQueryResponse, error) { + out := new(MsgUpdateInterchainQueryResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Msg/UpdateInterchainQuery", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/neutron.interchainqueries.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + RegisterInterchainQuery(context.Context, *MsgRegisterInterchainQuery) (*MsgRegisterInterchainQueryResponse, error) + SubmitQueryResult(context.Context, *MsgSubmitQueryResult) (*MsgSubmitQueryResultResponse, error) + RemoveInterchainQuery(context.Context, *MsgRemoveInterchainQueryRequest) (*MsgRemoveInterchainQueryResponse, error) + UpdateInterchainQuery(context.Context, *MsgUpdateInterchainQueryRequest) (*MsgUpdateInterchainQueryResponse, error) + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) RegisterInterchainQuery(ctx context.Context, req *MsgRegisterInterchainQuery) (*MsgRegisterInterchainQueryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterInterchainQuery not implemented") +} +func (*UnimplementedMsgServer) SubmitQueryResult(ctx context.Context, req *MsgSubmitQueryResult) (*MsgSubmitQueryResultResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SubmitQueryResult not implemented") +} +func (*UnimplementedMsgServer) RemoveInterchainQuery(ctx context.Context, req *MsgRemoveInterchainQueryRequest) (*MsgRemoveInterchainQueryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveInterchainQuery not implemented") +} +func (*UnimplementedMsgServer) UpdateInterchainQuery(ctx context.Context, req *MsgUpdateInterchainQueryRequest) (*MsgUpdateInterchainQueryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateInterchainQuery not implemented") +} +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_RegisterInterchainQuery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRegisterInterchainQuery) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RegisterInterchainQuery(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Msg/RegisterInterchainQuery", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RegisterInterchainQuery(ctx, req.(*MsgRegisterInterchainQuery)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_SubmitQueryResult_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSubmitQueryResult) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SubmitQueryResult(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Msg/SubmitQueryResult", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SubmitQueryResult(ctx, req.(*MsgSubmitQueryResult)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveInterchainQuery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveInterchainQueryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveInterchainQuery(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Msg/RemoveInterchainQuery", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveInterchainQuery(ctx, req.(*MsgRemoveInterchainQueryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateInterchainQuery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateInterchainQueryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateInterchainQuery(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Msg/UpdateInterchainQuery", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateInterchainQuery(ctx, req.(*MsgUpdateInterchainQueryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchainqueries.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.interchainqueries.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterInterchainQuery", + Handler: _Msg_RegisterInterchainQuery_Handler, + }, + { + MethodName: "SubmitQueryResult", + Handler: _Msg_SubmitQueryResult_Handler, + }, + { + MethodName: "RemoveInterchainQuery", + Handler: _Msg_RemoveInterchainQuery_Handler, + }, + { + MethodName: "UpdateInterchainQuery", + Handler: _Msg_UpdateInterchainQuery_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/interchainqueries/tx.proto", +} + +func (m *MsgRegisterInterchainQuery) 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 *MsgRegisterInterchainQuery) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterInterchainQuery) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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 m.UpdatePeriod != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.UpdatePeriod)) + i-- + dAtA[i] = 0x28 + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x22 + } + if len(m.TransactionsFilter) > 0 { + i -= len(m.TransactionsFilter) + copy(dAtA[i:], m.TransactionsFilter) + i = encodeVarintTx(dAtA, i, uint64(len(m.TransactionsFilter))) + i-- + dAtA[i] = 0x1a + } + if len(m.Keys) > 0 { + for iNdEx := len(m.Keys) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Keys[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.QueryType) > 0 { + i -= len(m.QueryType) + copy(dAtA[i:], m.QueryType) + i = encodeVarintTx(dAtA, i, uint64(len(m.QueryType))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterInterchainQueryResponse) 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 *MsgRegisterInterchainQueryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterInterchainQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Id != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgSubmitQueryResult) 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 *MsgSubmitQueryResult) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitQueryResult) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Result != nil { + { + size, err := m.Result.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + 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] = 0x1a + } + 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] = 0x12 + } + if m.QueryId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.QueryId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryResult) 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 *QueryResult) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryResult) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.AllowKvCallbacks { + i-- + if m.AllowKvCallbacks { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if m.Revision != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Revision)) + i-- + dAtA[i] = 0x20 + } + if m.Height != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x18 + } + if m.Block != nil { + { + size, err := m.Block.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.KvResults) > 0 { + for iNdEx := len(m.KvResults) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.KvResults[iNdEx].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 *StorageValue) 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 *StorageValue) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StorageValue) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Proof != nil { + { + size, err := m.Proof.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintTx(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x1a + } + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintTx(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0x12 + } + if len(m.StoragePrefix) > 0 { + i -= len(m.StoragePrefix) + copy(dAtA[i:], m.StoragePrefix) + i = encodeVarintTx(dAtA, i, uint64(len(m.StoragePrefix))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Block) 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 *Block) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Block) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Tx != nil { + { + size, err := m.Tx.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.NextBlockHeader != nil { + { + size, err := m.NextBlockHeader.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 *TxValue) 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 *TxValue) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TxValue) 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 = encodeVarintTx(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x22 + } + if m.InclusionProof != nil { + { + size, err := m.InclusionProof.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.DeliveryProof != nil { + { + size, err := m.DeliveryProof.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Response != nil { + { + size, err := m.Response.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 *MsgSubmitQueryResultResponse) 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 *MsgSubmitQueryResultResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitQueryResultResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgRemoveInterchainQueryRequest) 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 *MsgRemoveInterchainQueryRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveInterchainQueryRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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] = 0x12 + } + if m.QueryId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.QueryId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgRemoveInterchainQueryResponse) 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 *MsgRemoveInterchainQueryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveInterchainQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateInterchainQueryRequest) 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 *MsgUpdateInterchainQueryRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateInterchainQueryRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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] = 0x2a + } + if len(m.NewTransactionsFilter) > 0 { + i -= len(m.NewTransactionsFilter) + copy(dAtA[i:], m.NewTransactionsFilter) + i = encodeVarintTx(dAtA, i, uint64(len(m.NewTransactionsFilter))) + i-- + dAtA[i] = 0x22 + } + if m.NewUpdatePeriod != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.NewUpdatePeriod)) + i-- + dAtA[i] = 0x18 + } + if len(m.NewKeys) > 0 { + for iNdEx := len(m.NewKeys) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NewKeys[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.QueryId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.QueryId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateInterchainQueryResponse) 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 *MsgUpdateInterchainQueryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateInterchainQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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 *MsgRegisterInterchainQuery) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.QueryType) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Keys) > 0 { + for _, e := range m.Keys { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.TransactionsFilter) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.UpdatePeriod != 0 { + n += 1 + sovTx(uint64(m.UpdatePeriod)) + } + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRegisterInterchainQueryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovTx(uint64(m.Id)) + } + return n +} + +func (m *MsgSubmitQueryResult) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.QueryId != 0 { + n += 1 + sovTx(uint64(m.QueryId)) + } + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Result != nil { + l = m.Result.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *QueryResult) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.KvResults) > 0 { + for _, e := range m.KvResults { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if m.Block != nil { + l = m.Block.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovTx(uint64(m.Height)) + } + if m.Revision != 0 { + n += 1 + sovTx(uint64(m.Revision)) + } + if m.AllowKvCallbacks { + n += 2 + } + return n +} + +func (m *StorageValue) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.StoragePrefix) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Key) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Proof != nil { + l = m.Proof.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *Block) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.NextBlockHeader != nil { + l = m.NextBlockHeader.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.Tx != nil { + l = m.Tx.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *TxValue) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.DeliveryProof != nil { + l = m.DeliveryProof.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.InclusionProof != nil { + l = m.InclusionProof.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSubmitQueryResultResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveInterchainQueryRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.QueryId != 0 { + n += 1 + sovTx(uint64(m.QueryId)) + } + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveInterchainQueryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateInterchainQueryRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.QueryId != 0 { + n += 1 + sovTx(uint64(m.QueryId)) + } + if len(m.NewKeys) > 0 { + for _, e := range m.NewKeys { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if m.NewUpdatePeriod != 0 { + n += 1 + sovTx(uint64(m.NewUpdatePeriod)) + } + l = len(m.NewTransactionsFilter) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateInterchainQueryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + 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 *MsgRegisterInterchainQuery) 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: MsgRegisterInterchainQuery: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterInterchainQuery: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryType", 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.QueryType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Keys", 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.Keys = append(m.Keys, &KVKey{}) + if err := m.Keys[len(m.Keys)-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 TransactionsFilter", 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.TransactionsFilter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", 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.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatePeriod", wireType) + } + m.UpdatePeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdatePeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 + 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 *MsgRegisterInterchainQueryResponse) 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: MsgRegisterInterchainQueryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterInterchainQueryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= 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 *MsgSubmitQueryResult) 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: MsgSubmitQueryResult: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitQueryResult: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryId", wireType) + } + m.QueryId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.QueryId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 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 3: + 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 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Result", 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.Result == nil { + m.Result = &QueryResult{} + } + if err := m.Result.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 *QueryResult) 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: QueryResult: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryResult: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KvResults", 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.KvResults = append(m.KvResults, &StorageValue{}) + if err := m.KvResults[len(m.KvResults)-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 Block", 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.Block == nil { + m.Block = &Block{} + } + if err := m.Block.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Revision", wireType) + } + m.Revision = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Revision |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowKvCallbacks", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.AllowKvCallbacks = bool(v != 0) + 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 *StorageValue) 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: StorageValue: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StorageValue: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StoragePrefix", 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.StoragePrefix = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", 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.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) + if m.Key == nil { + m.Key = []byte{} + } + iNdEx = postIndex + case 3: + 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 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.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) + if m.Value == nil { + m.Value = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", 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.Proof == nil { + m.Proof = &crypto.ProofOps{} + } + if err := m.Proof.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 *Block) 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: Block: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Block: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NextBlockHeader", 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.NextBlockHeader == nil { + m.NextBlockHeader = &types.Any{} + } + if err := m.NextBlockHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", 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.Header == nil { + m.Header = &types.Any{} + } + if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tx", 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.Tx == nil { + m.Tx = &TxValue{} + } + if err := m.Tx.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 *TxValue) 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: TxValue: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TxValue: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", 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.Response == nil { + m.Response = &types1.ExecTxResult{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeliveryProof", 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.DeliveryProof == nil { + m.DeliveryProof = &crypto.Proof{} + } + if err := m.DeliveryProof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InclusionProof", 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.InclusionProof == nil { + m.InclusionProof = &crypto.Proof{} + } + if err := m.InclusionProof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + 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 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.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + 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 *MsgSubmitQueryResultResponse) 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: MsgSubmitQueryResultResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitQueryResultResponse: 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 *MsgRemoveInterchainQueryRequest) 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: MsgRemoveInterchainQueryRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveInterchainQueryRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryId", wireType) + } + m.QueryId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.QueryId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 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 + 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 *MsgRemoveInterchainQueryResponse) 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: MsgRemoveInterchainQueryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveInterchainQueryResponse: 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 *MsgUpdateInterchainQueryRequest) 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: MsgUpdateInterchainQueryRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateInterchainQueryRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryId", wireType) + } + m.QueryId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.QueryId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewKeys", 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.NewKeys = append(m.NewKeys, &KVKey{}) + if err := m.NewKeys[len(m.NewKeys)-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 NewUpdatePeriod", wireType) + } + m.NewUpdatePeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NewUpdatePeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewTransactionsFilter", 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.NewTransactionsFilter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + 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 + 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 *MsgUpdateInterchainQueryResponse) 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: MsgUpdateInterchainQueryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateInterchainQueryResponse: 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 *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 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.Params.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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 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/x/interchainqueries/types/tx_test.go b/x/interchainqueries/types/tx_test.go new file mode 100644 index 00000000..258d4eeb --- /dev/null +++ b/x/interchainqueries/types/tx_test.go @@ -0,0 +1,126 @@ +package types_test + +import ( + "testing" + + "github.com/cometbft/cometbft/proto/tendermint/crypto" + sdktypes "github.com/cosmos/cosmos-sdk/types" + ibchost "github.com/cosmos/ibc-go/v8/modules/core/exported" + "github.com/stretchr/testify/require" + + iqtypes "github.com/Nolus-Protocol/nolus-core/x/interchainqueries/types" +) + +const TestAddress = "cosmos10h9stc5v6ntgeygf5xf945njqq5h32r53uquvw" + +func TestMsgRegisterInterchainQueryGetSigners(t *testing.T) { + tests := []struct { + name string + malleate func() sdktypes.LegacyMsg + }{ + { + "valid_signer", + func() sdktypes.LegacyMsg { + return &iqtypes.MsgRegisterInterchainQuery{ + ConnectionId: "connection-0", + TransactionsFilter: "{}", + Keys: nil, + QueryType: string(iqtypes.InterchainQueryTypeTX), + UpdatePeriod: 1, + Sender: TestAddress, + } + }, + }, + } + + for _, tt := range tests { + msg := tt.malleate() + addr, _ := sdktypes.AccAddressFromBech32(TestAddress) + require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + } +} + +func TestMsgSubmitQueryResultGetSigners(t *testing.T) { + tests := []struct { + name string + malleate func() sdktypes.LegacyMsg + }{ + { + "valid_signer", + func() sdktypes.LegacyMsg { + return &iqtypes.MsgSubmitQueryResult{ + QueryId: 1, + Sender: TestAddress, + ClientId: "client-id", + Result: &iqtypes.QueryResult{ + KvResults: []*iqtypes.StorageValue{{ + Key: []byte{10}, + Proof: &crypto.ProofOps{Ops: []crypto.ProofOp{ + { + Type: "type", + Key: []byte{10}, + Data: []byte{10}, + }, + }}, + Value: []byte{10}, + StoragePrefix: ibchost.StoreKey, + }}, + Block: nil, + Height: 100, + Revision: 1, + }, + } + }, + }, + } + + for _, tt := range tests { + msg := tt.malleate() + addr, _ := sdktypes.AccAddressFromBech32(TestAddress) + require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + } +} + +func TestMsgUpdateQueryGetSigners(t *testing.T) { + tests := []struct { + name string + malleate func() sdktypes.LegacyMsg + }{ + { + "valid_signer", + func() sdktypes.LegacyMsg { + return &iqtypes.MsgUpdateInterchainQueryRequest{ + Sender: TestAddress, + } + }, + }, + } + + for _, tt := range tests { + msg := tt.malleate() + addr, _ := sdktypes.AccAddressFromBech32(TestAddress) + require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + } +} + +func TestMsgRemoveQueryGetSigners(t *testing.T) { + tests := []struct { + name string + malleate func() sdktypes.LegacyMsg + }{ + { + "valid_signer", + func() sdktypes.LegacyMsg { + return &iqtypes.MsgRemoveInterchainQueryRequest{ + Sender: TestAddress, + } + }, + }, + } + + for _, tt := range tests { + msg := tt.malleate() + addr, _ := sdktypes.AccAddressFromBech32(TestAddress) + require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + } +} diff --git a/x/interchainqueries/types/types.go b/x/interchainqueries/types/types.go new file mode 100644 index 00000000..dafa661f --- /dev/null +++ b/x/interchainqueries/types/types.go @@ -0,0 +1,144 @@ +package types + +import ( + "encoding/hex" + "encoding/json" + "fmt" + "strings" +) + +const ( + // EventTypeNeutronMessage defines the event type used by the Interchain Queries module events. + EventTypeNeutronMessage = "neutron" + + // AttributeKeyQueryID represents the key for event attribute delivering the query ID of a + // registered interchain query. + AttributeKeyQueryID = "query_id" + + // AttributeKeyOwner represents the key for event attribute delivering the address of the + // registrator of an interchain query. + AttributeKeyOwner = "owner" + + // AttributeKeyConnectionID represents the key for event attribute delivering the connection ID + // of an interchain query. + AttributeKeyConnectionID = "connection_id" + + // AttributeKeyQueryType represents the key for event attribute delivering the query type + // identifier (e.g. 'kv' or 'tx') + AttributeKeyQueryType = "type" + + // AttributeKeyKVQuery represents the keys of the storage we want to get from remote chain for event attribute delivering the keys + // of an interchain query. + AttributeKeyKVQuery = "kv_key" + + // AttributeTransactionsFilterQuery represents the transactions filter for event attribute delivering the filter + // of an interchain query. + AttributeTransactionsFilterQuery = "tx_filter" + + // AttributeValueCategory represents the value for the 'module' event attribute. + AttributeValueCategory = ModuleName + + // AttributeValueQueryUpdated represents the value for the 'action' event attribute. + AttributeValueQueryUpdated = "query_updated" + + // AttributeValueQueryRemoved represents the value for the 'action' event attribute. + AttributeValueQueryRemoved = "query_removed" + + // maxTransactionsFilters defines maximum allowed amount of tx filters in msgRegisterInterchainQuery + maxTransactionsFilters = 32 +) + +const ( + InterchainQueryTypeKV InterchainQueryType = "kv" + InterchainQueryTypeTX InterchainQueryType = "tx" + + kvPathKeyDelimiter = "/" + kvKeysDelimiter = "," +) + +type InterchainQueryType string + +func (icqt InterchainQueryType) IsValid() bool { + return icqt.IsTX() || icqt.IsKV() +} + +func (icqt InterchainQueryType) IsKV() bool { + return icqt == InterchainQueryTypeKV +} + +func (icqt InterchainQueryType) IsTX() bool { + return icqt == InterchainQueryTypeTX +} + +func (kv KVKey) ToString() string { + return kv.Path + kvPathKeyDelimiter + hex.EncodeToString(kv.Key) +} + +type KVKeys []*KVKey + +func (keys KVKeys) String() string { + if len(keys) == 0 { + return "" + } + + var b strings.Builder + b.WriteString(keys[0].ToString()) + + for _, key := range keys[1:] { + b.WriteString(kvKeysDelimiter) + b.WriteString(key.ToString()) + } + + return b.String() +} + +// TransactionsFilter represents the model of transactions filter parameter used in interchain +// queries of type TX. +type TransactionsFilter []TransactionsFilterItem + +// TransactionsFilterItem is a single condition for filtering transactions in search. +type TransactionsFilterItem struct { + // Field is the field used in condition, e.g. tx.height or transfer.recipient. + Field string `json:"field"` + // Op is the operation for filtering, one of the following: eq, gt, gte, lt, lte. + Op string `json:"op"` + // Value is the value for comparison. + Value interface{} `json:"value"` +} + +// ValidateTransactionsFilter checks if the passed string is a valid TransactionsFilter value. +func ValidateTransactionsFilter(s string) error { + const forbiddenCharacters = "\t\n\r\\()\"'=><" + filters := TransactionsFilter{} + if err := json.Unmarshal([]byte(s), &filters); err != nil { + return fmt.Errorf("failed to unmarshal transactions filter: %w", err) + } + if len(filters) > maxTransactionsFilters { + return fmt.Errorf("too many transactions filters, provided=%d, max=%d", len(filters), maxTransactionsFilters) + } + + for idx, f := range filters { + if strings.ContainsAny(f.Field, forbiddenCharacters) { + return fmt.Errorf("transactions filter condition idx=%d is invalid: special symbols %s are not allowed", idx, forbiddenCharacters) + } + if f.Field == "" { + return fmt.Errorf("transactions filter condition idx=%d is invalid: field couldn't be empty", idx) + } + switch value := f.Value.(type) { + case string: + case float64: + // despite json turns numbers into float, decimals are not allowed by tendermint API + if value != float64(int64(value)) { + return fmt.Errorf("transactions filter condition idx=%d is invalid: value %v can't be a decimal number", idx, value) + } + default: + return fmt.Errorf("transactions filter condition idx=%d is invalid: value '%v' is expected to be on of: string, number", idx, f.Value) + } + switch strings.ToLower(f.Op) { + case "eq", "gt", "gte", "lt", "lte": + default: + return fmt.Errorf("transactions filter condition idx=%d is invalid: op '%s' is expected to be one of: eq, gt, gte, lt, lte", idx, f.Op) + } + } + return nil +} diff --git a/x/interchainqueries/types/types_test.go b/x/interchainqueries/types/types_test.go new file mode 100644 index 00000000..202c8c53 --- /dev/null +++ b/x/interchainqueries/types/types_test.go @@ -0,0 +1,59 @@ +package types + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTransactionFilterValidation(t *testing.T) { + t.Run("Valid", func(t *testing.T) { + // several conditions + assert.NoError(t, ValidateTransactionsFilter(`[{"field":"transfer.recipient","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"},{"field":"tx.height","op":"Gte","value":100}]`)) + // all supported operations with a whole operand + assert.NoError(t, ValidateTransactionsFilter(`[{"field":"tx.height","op":"Eq","value":1000}]`)) + assert.NoError(t, ValidateTransactionsFilter(`[{"field":"tx.height","op":"Gt","value":1000}]`)) + assert.NoError(t, ValidateTransactionsFilter(`[{"field":"tx.height","op":"Gte","value":1000}]`)) + assert.NoError(t, ValidateTransactionsFilter(`[{"field":"tx.height","op":"Lt","value":1000}]`)) + assert.NoError(t, ValidateTransactionsFilter(`[{"field":"tx.height","op":"Lte","value":1000}]`)) + }) + t.Run("Invalid", func(t *testing.T) { + // invalid json + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.recipient","op":"Eq","value":`), "unexpected end of JSON input") + // empty operation + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.recipient","op":"","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), "op '' is expected to be one of: eq, gt, gte, lt, lte") + // empty field + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), "field couldn't be empty") + // field with forbidden symbols + const specialSymbolsAreNotAllowed = "special symbols \t\n\r\\()\"'=>< are not allowed" + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.\t","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.\n","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.\r","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.\\","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.(","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.)","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.\"","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.'","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.=","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.>","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"transfer.<","op":"Eq","value":"neutron1mjk79fjjgpplak5wq838w0yd982gzkyf8fxu8u"}]`), specialSymbolsAreNotAllowed) + // decimal number + assert.ErrorContains(t, ValidateTransactionsFilter(`[{"field":"tx.height","op":"Gte","value":15.5}]`), "can't be a decimal number") + assert.ErrorContains(t, ValidateTransactionsFilter(lotsOfTxFilters(t, 40)), "too many transactions filters") + }) +} + +func lotsOfTxFilters(t *testing.T, amount int) string { + filters := make([]TransactionsFilterItem, 0, amount) + for i := 0; i < amount; i++ { + filters = append(filters, TransactionsFilterItem{ + Field: "tx.height", + Op: "Eq", + Value: 1000, + }) + } + filtersStr, err := json.Marshal(filters) + assert.NoError(t, err) + return string(filtersStr) +} diff --git a/x/interchainqueries/types/verify.go b/x/interchainqueries/types/verify.go new file mode 100644 index 00000000..6e906770 --- /dev/null +++ b/x/interchainqueries/types/verify.go @@ -0,0 +1,22 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" + "github.com/cosmos/ibc-go/v8/modules/core/exported" + tendermintLightClientTypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" +) + +type HeaderVerifier interface { + VerifyHeaders(ctx sdk.Context, cleintkeeper clientkeeper.Keeper, clientID string, header, nextHeader exported.ClientMessage) error + UnpackHeader(any *codectypes.Any) (exported.ClientMessage, error) +} + +type TransactionVerifier interface { + VerifyTransaction( + header *tendermintLightClientTypes.Header, + nextHeader *tendermintLightClientTypes.Header, + tx *TxValue, + ) error +} diff --git a/x/interchaintxs/client/cli/query.go b/x/interchaintxs/client/cli/query.go new file mode 100644 index 00000000..bfa2d6d3 --- /dev/null +++ b/x/interchaintxs/client/cli/query.go @@ -0,0 +1,27 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group interchaintxs queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 1, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdInterchainAccountCmd()) + + return cmd +} diff --git a/x/interchaintxs/client/cli/query_interchainaccounts.go b/x/interchaintxs/client/cli/query_interchainaccounts.go new file mode 100644 index 00000000..a443e846 --- /dev/null +++ b/x/interchaintxs/client/cli/query_interchainaccounts.go @@ -0,0 +1,39 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func CmdInterchainAccountCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "interchain-account [owner-address] [connection-id] [interchain-account-id]", + Short: "get the interchain account address for a specific combination of owner-address, connection-id and interchain-account-id", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.InterchainAccountAddress(cmd.Context(), &types.QueryInterchainAccountAddressRequest{ + OwnerAddress: args[0], + ConnectionId: args[1], + InterchainAccountId: args[2], + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/interchaintxs/client/cli/query_params.go b/x/interchaintxs/client/cli/query_params.go new file mode 100644 index 00000000..90624e22 --- /dev/null +++ b/x/interchaintxs/client/cli/query_params.go @@ -0,0 +1,35 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/interchaintxs/client/cli/tx.go b/x/interchaintxs/client/cli/tx.go new file mode 100644 index 00000000..713a2d96 --- /dev/null +++ b/x/interchaintxs/client/cli/tx.go @@ -0,0 +1,23 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + return cmd +} diff --git a/x/interchaintxs/genesis.go b/x/interchaintxs/genesis.go new file mode 100644 index 00000000..e96f128c --- /dev/null +++ b/x/interchaintxs/genesis.go @@ -0,0 +1,25 @@ +package interchaintxs + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + err := k.SetParams(ctx, genState.Params) + if err != nil { + panic(err) + } +} + +// ExportGenesis returns the capability module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + return genesis +} diff --git a/x/interchaintxs/genesis_test.go b/x/interchaintxs/genesis_test.go new file mode 100644 index 00000000..ac2043b9 --- /dev/null +++ b/x/interchaintxs/genesis_test.go @@ -0,0 +1,26 @@ +package interchaintxs_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil/common/nullify" + keepertest "github.com/Nolus-Protocol/nolus-core/testutil/interchaintxs/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + } + + k, ctx := keepertest.InterchainTxsKeeper(t, nil, nil, nil, nil, nil, nil, nil) + interchaintxs.InitGenesis(ctx, *k, genesisState) + got := interchaintxs.ExportGenesis(ctx, *k) + require.NotNil(t, got) + + nullify.Fill(&genesisState) + nullify.Fill(got) +} diff --git a/x/interchaintxs/ibc_module.go b/x/interchaintxs/ibc_module.go new file mode 100644 index 00000000..a21033de --- /dev/null +++ b/x/interchaintxs/ibc_module.go @@ -0,0 +1,126 @@ +package interchaintxs + +import ( + "errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/keeper" +) + +var _ porttypes.IBCModule = IBCModule{} + +// IBCModule implements the ICS26 interface for interchain accounts controller chains +type IBCModule struct { + keeper keeper.Keeper +} + +// NewIBCModule creates a new IBCModule given the keeper +func NewIBCModule(k keeper.Keeper) IBCModule { + return IBCModule{ + keeper: k, + } +} + +// OnChanOpenInit implements the IBCModule interface. We don't need to implement this handler. +func (im IBCModule) OnChanOpenInit( + _ sdk.Context, + _ channeltypes.Order, + _ []string, + _ string, + _ string, + _ *capabilitytypes.Capability, + _ channeltypes.Counterparty, + version string, +) (string, error) { + // FIXME: always returning plain version is probably a bad idea! + return version, nil +} + +// OnChanOpenTry implements the IBCModule interface. We don't need to implement this handler. +func (im IBCModule) OnChanOpenTry( + _ sdk.Context, + _ channeltypes.Order, + _ []string, + _, + _ string, + _ *capabilitytypes.Capability, + _ channeltypes.Counterparty, + _ string, +) (string, error) { + return "", nil +} + +// OnChanOpenAck implements the IBCModule interface. This handler is called after we create an +// account on a remote zone (because icaControllerKeeper.RegisterInterchainAccount opens a channel). +func (im IBCModule) OnChanOpenAck( + ctx sdk.Context, + portID, + channelID string, + counterPartyChannelID string, + counterpartyVersion string, +) error { + return im.keeper.HandleChanOpenAck(ctx, portID, channelID, counterPartyChannelID, counterpartyVersion) +} + +// OnChanOpenConfirm implements the IBCModule interface. We don't need to implement this handler. +func (im IBCModule) OnChanOpenConfirm( + _ sdk.Context, + _, + _ string, +) error { + return nil +} + +// OnChanCloseInit implements the IBCModule interface. We don't need to implement this handler. +// Handler will be implemented in https://p2pvalidator.atlassian.net/browse/LSC-137 +func (im IBCModule) OnChanCloseInit( + _ sdk.Context, + _, + _ string, +) error { + return nil +} + +// OnChanCloseConfirm implements the IBCModule interface. We don't need to implement this handler. +func (im IBCModule) OnChanCloseConfirm( + _ sdk.Context, + _, + _ string, +) error { + return nil +} + +// OnRecvPacket implements the IBCModule interface. A successful acknowledgement +// is returned if the packet data is successfully decoded and the receiving application +// logic returns without error. +func (im IBCModule) OnRecvPacket( + _ sdk.Context, + _ channeltypes.Packet, + _ sdk.AccAddress, +) ibcexported.Acknowledgement { + return channeltypes.NewErrorAcknowledgement(errors.New("cannot receive packet via interchain accounts authentication module")) +} + +// OnAcknowledgementPacket implements the IBCModule interface. +func (im IBCModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + return im.keeper.HandleAcknowledgement(ctx, packet, acknowledgement, relayer) +} + +// OnTimeoutPacket implements the IBCModule interface. +func (im IBCModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) error { + return im.keeper.HandleTimeout(ctx, packet, relayer) +} diff --git a/x/interchaintxs/keeper/grpc_query.go b/x/interchaintxs/keeper/grpc_query.go new file mode 100644 index 00000000..0886e7e7 --- /dev/null +++ b/x/interchaintxs/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/interchaintxs/keeper/grpc_query_interchainaccount.go b/x/interchaintxs/keeper/grpc_query_interchainaccount.go new file mode 100644 index 00000000..3f8d062a --- /dev/null +++ b/x/interchaintxs/keeper/grpc_query_interchainaccount.go @@ -0,0 +1,37 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func (k Keeper) InterchainAccountAddress(c context.Context, req *types.QueryInterchainAccountAddressRequest) (*types.QueryInterchainAccountAddressResponse, error) { + if req == nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + icaOwner, err := types.NewICAOwner(req.OwnerAddress, req.InterchainAccountId) + if err != nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to create ica owner: %s", err) + } + + portID, err := icatypes.NewControllerPortID(icaOwner.String()) + if err != nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to get controller portID: %s", err) + } + + addr, found := k.icaControllerKeeper.GetInterchainAccountAddress(ctx, req.ConnectionId, portID) + if !found { + return nil, errors.Wrapf(types.ErrInterchainAccountNotFound, "no interchain account found for portID %s", portID) + } + + return &types.QueryInterchainAccountAddressResponse{InterchainAccountAddress: addr}, nil +} diff --git a/x/interchaintxs/keeper/grpc_query_interchainaccount_test.go b/x/interchaintxs/keeper/grpc_query_interchainaccount_test.go new file mode 100644 index 00000000..bb270be6 --- /dev/null +++ b/x/interchaintxs/keeper/grpc_query_interchainaccount_test.go @@ -0,0 +1,55 @@ +package keeper_test + +import ( + "fmt" + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + types2 "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil" + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchaintxs/keeper" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/interchaintxs/types" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func TestKeeper_InterchainAccountAddress(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + icaKeeper := mock_types.NewMockICAControllerKeeper(ctrl) + keeper, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, icaKeeper, nil, nil, nil, nil) + + resp, err := keeper.InterchainAccountAddress(ctx, nil) + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.Nil(t, resp) + + resp, err = keeper.InterchainAccountAddress(ctx, &types.QueryInterchainAccountAddressRequest{ + OwnerAddress: "nonbetch32", + InterchainAccountId: "test1", + ConnectionId: "connection-0", + }) + require.ErrorContains(t, err, "failed to create ica owner") + require.Nil(t, resp) + + portID := fmt.Sprintf("%s%s.%s", types2.ControllerPortPrefix, testutil.TestOwnerAddress, "test1") + icaKeeper.EXPECT().GetInterchainAccountAddress(ctx, "connection-0", portID).Return("", false) + resp, err = keeper.InterchainAccountAddress(ctx, &types.QueryInterchainAccountAddressRequest{ + OwnerAddress: testutil.TestOwnerAddress, + InterchainAccountId: "test1", + ConnectionId: "connection-0", + }) + require.ErrorContains(t, err, "no interchain account found for portID") + require.Nil(t, resp) + + portID = fmt.Sprintf("%s%s.%s", types2.ControllerPortPrefix, testutil.TestOwnerAddress, "test1") + icaKeeper.EXPECT().GetInterchainAccountAddress(ctx, "connection-0", portID).Return("neutron1interchainaccountaddress", true) + resp, err = keeper.InterchainAccountAddress(ctx, &types.QueryInterchainAccountAddressRequest{ + OwnerAddress: testutil.TestOwnerAddress, + InterchainAccountId: "test1", + ConnectionId: "connection-0", + }) + require.NoError(t, err) + require.Equal(t, &types.QueryInterchainAccountAddressResponse{InterchainAccountAddress: "neutron1interchainaccountaddress"}, resp) +} diff --git a/x/interchaintxs/keeper/grpc_query_params.go b/x/interchaintxs/keeper/grpc_query_params.go new file mode 100644 index 00000000..bcc60861 --- /dev/null +++ b/x/interchaintxs/keeper/grpc_query_params.go @@ -0,0 +1,20 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/interchaintxs/keeper/grpc_query_params_test.go b/x/interchaintxs/keeper/grpc_query_params_test.go new file mode 100644 index 00000000..3f7eb747 --- /dev/null +++ b/x/interchaintxs/keeper/grpc_query_params_test.go @@ -0,0 +1,25 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchaintxs/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func TestParamsQuery(t *testing.T) { + keeper, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, nil, nil, nil, nil, nil) + params := types.DefaultParams() + err := keeper.SetParams(ctx, params) + require.NoError(t, err) + + response, err := keeper.Params(ctx, nil) + require.Error(t, err) + require.Nil(t, response) + + response, err = keeper.Params(ctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) +} diff --git a/x/interchaintxs/keeper/ibc_handlers.go b/x/interchaintxs/keeper/ibc_handlers.go new file mode 100644 index 00000000..cb50b14e --- /dev/null +++ b/x/interchaintxs/keeper/ibc_handlers.go @@ -0,0 +1,114 @@ +package keeper + +import ( + "time" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + + "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + contractmanagertypes "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" + feetypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +// HandleAcknowledgement passes the acknowledgement data to the appropriate contract via a sudo call. +func (k *Keeper) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelHandleAcknowledgment) + k.Logger(ctx).Debug("Handling acknowledgement") + icaOwner, err := types.ICAOwnerFromPort(packet.SourcePort) + if err != nil { + k.Logger(ctx).Error("HandleAcknowledgement: failed to get ica owner from source port", "error", err) + return errors.Wrap(err, "failed to get ica owner from port") + } + + var ack channeltypes.Acknowledgement + if err := channeltypes.SubModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { + k.Logger(ctx).Error("HandleAcknowledgement: cannot unmarshal ICS-27 packet acknowledgement", "error", err) + return errors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 packet acknowledgement: %v", err) + } + msg, err := keeper.PrepareSudoCallbackMessage(packet, &ack) + if err != nil { + return errors.Wrapf(sdkerrors.ErrJSONMarshal, "failed to marshal Packet/Acknowledgment: %v", err) + } + + k.feeKeeper.DistributeAcknowledgementFee(ctx, relayer, feetypes.NewPacketID(packet.SourcePort, packet.SourceChannel, packet.Sequence)) + + // Actually we have only one kind of error returned from acknowledgement + // maybe later we'll retrieve actual errors from events + _, err = k.sudoKeeper.Sudo(ctx, icaOwner.GetContract(), msg) + if err != nil { + k.Logger(ctx).Debug("HandleAcknowledgement: failed to Sudo contract on packet acknowledgement", "error", err) + } + + return nil +} + +// HandleTimeout passes the timeout data to the appropriate contract via a sudo call. +// Since all ICA channels are ORDERED, a single timeout shuts down a channel. +func (k *Keeper) HandleTimeout(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelHandleTimeout) + k.Logger(ctx).Debug("HandleTimeout") + icaOwner, err := types.ICAOwnerFromPort(packet.SourcePort) + if err != nil { + k.Logger(ctx).Error("HandleTimeout: failed to get ica owner from source port", "error", err) + return errors.Wrap(err, "failed to get ica owner from port") + } + + msg, err := keeper.PrepareSudoCallbackMessage(packet, nil) + if err != nil { + return errors.Wrapf(sdkerrors.ErrJSONMarshal, "failed to marshal Packet: %v", err) + } + + k.feeKeeper.DistributeTimeoutFee(ctx, relayer, feetypes.NewPacketID(packet.SourcePort, packet.SourceChannel, packet.Sequence)) + + _, err = k.sudoKeeper.Sudo(ctx, icaOwner.GetContract(), msg) + if err != nil { + k.Logger(ctx).Debug("HandleTimeout: failed to Sudo contract on packet timeout", "error", err) + } + + return nil +} + +// HandleChanOpenAck passes the data about a successfully created channel to the appropriate contract +// (== the data about a successfully registered interchain account). +// Notice that in the case of an ICA channel - it is not yet in OPEN state here +// the last step of channel opening(confirm) happens on the host chain. +func (k *Keeper) HandleChanOpenAck( + ctx sdk.Context, + portID, + channelID, + counterpartyChannelID, + counterpartyVersion string, +) error { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelLabelHandleChanOpenAck) + + k.Logger(ctx).Debug("HandleChanOpenAck", "port_id", portID, "channel_id", channelID, "counterparty_channel_id", counterpartyChannelID, "counterparty_version", counterpartyVersion) + icaOwner, err := types.ICAOwnerFromPort(portID) + if err != nil { + k.Logger(ctx).Error("HandleChanOpenAck: failed to get ica owner from source port", "error", err) + return errors.Wrap(err, "failed to get ica owner from port") + } + + payload, err := keeper.PrepareOpenAckCallbackMessage(contractmanagertypes.OpenAckDetails{ + PortID: portID, + ChannelID: channelID, + CounterpartyChannelID: counterpartyChannelID, + CounterpartyVersion: counterpartyVersion, + }) + if err != nil { + return errors.Wrapf(sdkerrors.ErrJSONMarshal, "failed to marshal OpenAckDetails: %v", err) + } + + _, err = k.sudoKeeper.Sudo(ctx, icaOwner.GetContract(), payload) + if err != nil { + k.Logger(ctx).Debug("HandleChanOpenAck: failed to sudo contract on channel open acknowledgement", "error", err) + } + + return nil +} diff --git a/x/interchaintxs/keeper/ibc_handlers_test.go b/x/interchaintxs/keeper/ibc_handlers_test.go new file mode 100644 index 00000000..41168a68 --- /dev/null +++ b/x/interchaintxs/keeper/ibc_handlers_test.go @@ -0,0 +1,148 @@ +package keeper_test + +import ( + "fmt" + "testing" + + types2 "cosmossdk.io/store/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + + sdk "github.com/cosmos/cosmos-sdk/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil" + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchaintxs/keeper" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/interchaintxs/types" + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/types" + feetypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +const ICAId = ".ica0" + +func TestHandleAcknowledgement(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + feeKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl) + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + icak, infCtx := testkeeper.InterchainTxsKeeper(t, wmKeeper, feeKeeper, nil, nil, nil, bankKeeper, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + ctx := infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + + resACK := channeltypes.Acknowledgement{ + Response: &channeltypes.Acknowledgement_Result{Result: []byte("Result")}, + } + resAckData, err := channeltypes.SubModuleCdc.MarshalJSON(&resACK) + require.NoError(t, err) + p := channeltypes.Packet{ + Sequence: 100, + SourcePort: icatypes.ControllerPortPrefix + testutil.TestOwnerAddress + ICAId, + SourceChannel: "channel-0", + } + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + relayerBech32 := "neutron1fxudpred77a0grgh69u0j7y84yks5ev4n5050z45kecz792jnd6scqu98z" + relayerAddress := sdk.MustAccAddressFromBech32(relayerBech32) + + err = icak.HandleAcknowledgement(ctx, channeltypes.Packet{}, nil, relayerAddress) + require.ErrorContains(t, err, "failed to get ica owner from port") + + err = icak.HandleAcknowledgement(ctx, p, nil, relayerAddress) + require.ErrorContains(t, err, "cannot unmarshal ICS-27 packet acknowledgement") + + msgAck, err := keeper.PrepareSudoCallbackMessage(p, &resACK) + require.NoError(t, err) + + // success contract SudoResponse + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msgAck) + err = icak.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) + require.NoError(t, err) + + // error contract SudoResponse + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msgAck).Return(nil, fmt.Errorf("error sudoResponse")) + err = icak.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) + require.NoError(t, err) +} + +func TestHandleTimeout(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + feeKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl) + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + icak, infCtx := testkeeper.InterchainTxsKeeper(t, wmKeeper, feeKeeper, nil, nil, nil, bankKeeper, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + ctx := infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + relayerBech32 := "neutron1fxudpred77a0grgh69u0j7y84yks5ev4n5050z45kecz792jnd6scqu98z" + relayerAddress := sdk.MustAccAddressFromBech32(relayerBech32) + p := channeltypes.Packet{ + Sequence: 100, + SourcePort: icatypes.ControllerPortPrefix + testutil.TestOwnerAddress + ICAId, + SourceChannel: "channel-0", + } + + msgAck, err := keeper.PrepareSudoCallbackMessage(p, nil) + require.NoError(t, err) + + err = icak.HandleTimeout(ctx, channeltypes.Packet{}, relayerAddress) + require.ErrorContains(t, err, "failed to get ica owner from port") + + // contract success + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msgAck) + err = icak.HandleTimeout(ctx, p, relayerAddress) + require.NoError(t, err) + + // contract error + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msgAck).Return(nil, fmt.Errorf("SudoTimeout error")) + err = icak.HandleTimeout(ctx, p, relayerAddress) + require.NoError(t, err) +} + +func TestHandleChanOpenAck(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, nil, nil, nil, nil, bankKeeper, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + portID := icatypes.ControllerPortPrefix + testutil.TestOwnerAddress + ICAId + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + const channelID = "channel-0" + counterpartyChannelID := "channel-1" + + err := icak.HandleChanOpenAck(ctx, "", channelID, counterpartyChannelID, "1") + require.ErrorContains(t, err, "failed to get ica owner from port") + + msg, err := keeper.PrepareOpenAckCallbackMessage(types.OpenAckDetails{ + PortID: portID, + ChannelID: channelID, + CounterpartyChannelID: counterpartyChannelID, + CounterpartyVersion: "1", + }) + require.NoError(t, err) + + // sudo error + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msg).Return(nil, fmt.Errorf("SudoOnChanOpenAck error")) + err = icak.HandleChanOpenAck(ctx, portID, channelID, counterpartyChannelID, "1") + require.NoError(t, err) + + // sudo success + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msg) + err = icak.HandleChanOpenAck(ctx, portID, channelID, counterpartyChannelID, "1") + require.NoError(t, err) +} diff --git a/x/interchaintxs/keeper/keeper.go b/x/interchaintxs/keeper/keeper.go new file mode 100644 index 00000000..125b04ae --- /dev/null +++ b/x/interchaintxs/keeper/keeper.go @@ -0,0 +1,109 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/errors" + "cosmossdk.io/log" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +const ( + LabelSubmitTx = "submit_tx" + LabelHandleAcknowledgment = "handle_ack" + LabelLabelHandleChanOpenAck = "handle_chan_open_ack" + LabelRegisterInterchainAccount = "register_interchain_account" + LabelHandleTimeout = "handle_timeout" +) + +type ( + Keeper struct { + Codec codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + channelKeeper types.ChannelKeeper + feeKeeper types.FeeRefunderKeeper + icaControllerKeeper types.ICAControllerKeeper + icaControllerMsgServer types.ICAControllerMsgServer + sudoKeeper types.WasmKeeper + bankKeeper types.BankKeeper + getFeeCollectorAddr types.GetFeeCollectorAddr + authority string + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + channelKeeper types.ChannelKeeper, + icaControllerKeeper types.ICAControllerKeeper, + icaControllerMsgServer types.ICAControllerMsgServer, + sudoKeeper types.WasmKeeper, + feeKeeper types.FeeRefunderKeeper, + bankKeeper types.BankKeeper, + getFeeCollectorAddr types.GetFeeCollectorAddr, + authority string, +) *Keeper { + return &Keeper{ + Codec: cdc, + storeKey: storeKey, + memKey: memKey, + channelKeeper: channelKeeper, + icaControllerKeeper: icaControllerKeeper, + icaControllerMsgServer: icaControllerMsgServer, + sudoKeeper: sudoKeeper, + feeKeeper: feeKeeper, + bankKeeper: bankKeeper, + getFeeCollectorAddr: getFeeCollectorAddr, + authority: authority, + } +} + +func (k *Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +func (k Keeper) ChargeFee(ctx sdk.Context, payer sdk.AccAddress, fee sdk.Coins) error { + k.Logger(ctx).Debug("Trying to change fees", "payer", payer, "fee", fee) + + params := k.GetParams(ctx) + + if !fee.IsAnyGTE(params.RegisterFee) { + return errors.Wrapf(sdkerrors.ErrInsufficientFee, "provided fee is less than min governance set ack fee: %s < %s", fee, params.RegisterFee) + } + + feeCollector := k.getFeeCollectorAddr(ctx) + feeCollectorAddress, err := sdk.AccAddressFromBech32(feeCollector) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to convert fee collector, bech32 to AccAddress: %s: %s", feeCollector, err.Error()) + } + + err = k.bankKeeper.SendCoins(ctx, payer, feeCollectorAddress, fee) + if err != nil { + return errors.Wrapf(err, "failed send fee(%s) from %s to %s", fee, payer, feeCollectorAddress) + } + return nil +} + +func (k Keeper) GetAuthority() string { + return k.authority +} + +// GetICARegistrationFeeFirstCodeID returns code id, starting from which we charge fee for ICA registration +func (k Keeper) GetICARegistrationFeeFirstCodeID(ctx sdk.Context) (codeID uint64) { + store := ctx.KVStore(k.storeKey) + bytes := store.Get(types.ICARegistrationFeeFirstCodeID) + if bytes == nil { + k.Logger(ctx).Debug("Fee register ICA code id key don't exists, GetLastCodeID returns 0") + return 0 + } + return sdk.BigEndianToUint64(bytes) +} diff --git a/x/interchaintxs/keeper/msg_server.go b/x/interchaintxs/keeper/msg_server.go new file mode 100644 index 00000000..3cb59915 --- /dev/null +++ b/x/interchaintxs/keeper/msg_server.go @@ -0,0 +1,218 @@ +package keeper + +import ( + "context" + "fmt" + "time" + + "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + feetypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + ictxtypes "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +type msgServer struct { + Keeper +} + +var _ ictxtypes.MsgServer = msgServer{} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) ictxtypes.MsgServer { + return &msgServer{Keeper: keeper} +} + +func (k Keeper) RegisterInterchainAccount(goCtx context.Context, msg *ictxtypes.MsgRegisterInterchainAccount) (*ictxtypes.MsgRegisterInterchainAccountResponse, error) { + defer telemetry.ModuleMeasureSince(ictxtypes.ModuleName, time.Now(), LabelRegisterInterchainAccount) + + if err := msg.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgRegisterInterchainAccount") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + k.Logger(ctx).Debug("RegisterInterchainAccount", "connection_id", msg.ConnectionId, "from_address", msg.FromAddress, "interchain_account_id", msg.InterchainAccountId) + + senderAddr, err := sdk.AccAddressFromBech32(msg.FromAddress) + if err != nil { + k.Logger(ctx).Debug("RegisterInterchainAccount: failed to parse sender address", "from_address", msg.FromAddress) + return nil, errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.FromAddress) + } + + if !k.sudoKeeper.HasContractInfo(ctx, senderAddr) { + k.Logger(ctx).Debug("RegisterInterchainAccount: contract not found", "from_address", msg.FromAddress) + return nil, errors.Wrapf(ictxtypes.ErrNotContract, "%s is not a contract address", msg.FromAddress) + } + + // if contract is stored before [last] upgrade, we're not going charge fees for register ICA + if k.sudoKeeper.GetContractInfo(ctx, senderAddr).CodeID >= k.GetICARegistrationFeeFirstCodeID(ctx) { + if err := k.ChargeFee(ctx, senderAddr, msg.RegisterFee); err != nil { + return nil, errors.Wrapf(err, "failed to charge fees to pay for RegisterInterchainAccount msg: %s", msg) + } + } + + icaOwner := ictxtypes.NewICAOwnerFromAddress(senderAddr, msg.InterchainAccountId).String() + + resp, err := k.icaControllerMsgServer.RegisterInterchainAccount(ctx, &icacontrollertypes.MsgRegisterInterchainAccount{ + Owner: icaOwner, + ConnectionId: msg.ConnectionId, + Version: "", // FIXME: empty version string doesn't look good + Ordering: channeltypes.ORDERED, + }) + if err != nil { + k.Logger(ctx).Debug("RegisterInterchainAccount: failed to RegisterInterchainAccount:", "error", err, "owner", icaOwner, "msg", &msg) + return nil, errors.Wrap(err, "failed to RegisterInterchainAccount") + } + + k.icaControllerKeeper.SetMiddlewareEnabled(ctx, resp.PortId, msg.ConnectionId) + + return &ictxtypes.MsgRegisterInterchainAccountResponse{ + ChannelId: resp.ChannelId, + PortId: resp.PortId, + }, nil +} + +func (k Keeper) SubmitTx(goCtx context.Context, msg *ictxtypes.MsgSubmitTx) (*ictxtypes.MsgSubmitTxResponse, error) { + defer telemetry.ModuleMeasureSince(ictxtypes.ModuleName, time.Now(), LabelSubmitTx) + + if msg == nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "nil msg is prohibited") + } + + if err := msg.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgSubmitTx") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + k.Logger(ctx).Debug("SubmitTx", "connection_id", msg.ConnectionId, "from_address", msg.FromAddress, "interchain_account_id", msg.InterchainAccountId) + + senderAddr, err := sdk.AccAddressFromBech32(msg.FromAddress) + if err != nil { + k.Logger(ctx).Debug("SubmitTx: failed to parse sender address", "from_address", msg.FromAddress) + return nil, errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.FromAddress) + } + + if !k.sudoKeeper.HasContractInfo(ctx, senderAddr) { + k.Logger(ctx).Debug("SubmitTx: contract not found", "from_address", msg.FromAddress) + return nil, errors.Wrapf(ictxtypes.ErrNotContract, "%s is not a contract address", msg.FromAddress) + } + + params := k.GetParams(ctx) + if uint64(len(msg.Msgs)) > params.GetMsgSubmitTxMaxMessages() { + k.Logger(ctx).Debug("SubmitTx: provided MsgSubmitTx contains more messages than allowed", + "msg", msg, + "has", len(msg.Msgs), + "max", params.GetMsgSubmitTxMaxMessages(), + ) + return nil, fmt.Errorf( + "MsgSubmitTx contains more messages than allowed, has=%d, max=%d", + len(msg.Msgs), + params.GetMsgSubmitTxMaxMessages(), + ) + } + + icaOwner := ictxtypes.NewICAOwnerFromAddress(senderAddr, msg.InterchainAccountId).String() + + portID, err := icatypes.NewControllerPortID(icaOwner) + if err != nil { + k.Logger(ctx).Error("SubmitTx: failed to create NewControllerPortID:", "error", err, "owner", icaOwner) + return nil, errors.Wrap(err, "failed to create NewControllerPortID") + } + + channelID, found := k.icaControllerKeeper.GetActiveChannelID(ctx, msg.ConnectionId, portID) + if !found { + k.Logger(ctx).Debug("SubmitTx: failed to GetActiveChannelID", "connection_id", msg.ConnectionId, "port_id", portID) + return nil, errors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to GetActiveChannelID for port %s", portID) + } + + data, err := SerializeCosmosTx(k.Codec, msg.Msgs) + if err != nil { + k.Logger(ctx).Debug("SubmitTx: failed to SerializeCosmosTx", "error", err, "connection_id", msg.ConnectionId, "port_id", portID, "channel_id", channelID) + return nil, errors.Wrap(err, "failed to SerializeCosmosTx") + } + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: data, + Memo: msg.Memo, + } + + sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, portID, channelID) + if !found { + return nil, errors.Wrapf( + channeltypes.ErrSequenceSendNotFound, + "source port: %s, source channel: %s", portID, channelID, + ) + } + + if err := k.feeKeeper.LockFees(ctx, senderAddr, feetypes.NewPacketID(portID, channelID, sequence), msg.Fee); err != nil { + return nil, errors.Wrapf(err, "failed to lock fees to pay for SubmitTx msg: %s", msg) + } + + resp, err := k.icaControllerMsgServer.SendTx(ctx, &icacontrollertypes.MsgSendTx{ + Owner: icaOwner, + ConnectionId: msg.ConnectionId, + PacketData: packetData, + RelativeTimeout: uint64(time.Duration(msg.Timeout) * time.Second), + }) + if err != nil { + // usually we use DEBUG level for such errors, but in this case we have checked full input before running SendTX, so error here may be critical + k.Logger(ctx).Error("SubmitTx", "error", err, "owner", icaOwner, "connection_id", msg.ConnectionId, "channel_id", channelID) + return nil, errors.Wrap(err, "failed to SendTx") + } + + return &ictxtypes.MsgSubmitTxResponse{ + SequenceId: resp.Sequence, + Channel: channelID, + }, nil +} + +// SerializeCosmosTx serializes a slice of *types.Any messages using the CosmosTx type. The proto marshaled CosmosTx +// bytes are returned. This differs from icatypes.SerializeCosmosTx in that it does not serialize sdk.Msgs, but +// simply uses the already serialized values. +func SerializeCosmosTx(cdc codec.BinaryCodec, msgs []*codectypes.Any) (bz []byte, err error) { + // only ProtoCodec is supported + if _, ok := cdc.(*codec.ProtoCodec); !ok { + return nil, errors.Wrap(icatypes.ErrInvalidCodec, + "only ProtoCodec is supported for receiving messages on the host chain") + } + + cosmosTx := &icatypes.CosmosTx{ + Messages: msgs, + } + + bz, err = cdc.Marshal(cosmosTx) + if err != nil { + return nil, err + } + + return bz, nil +} + +// UpdateParams updates the module parameters +func (k Keeper) UpdateParams(goCtx context.Context, req *ictxtypes.MsgUpdateParams) (*ictxtypes.MsgUpdateParamsResponse, error) { + if err := req.Validate(); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgUpdateParams") + } + + authority := k.GetAuthority() + if authority != req.Authority { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.SetParams(ctx, req.Params); err != nil { + return nil, err + } + + return &ictxtypes.MsgUpdateParamsResponse{}, nil +} diff --git a/x/interchaintxs/keeper/msg_server_test.go b/x/interchaintxs/keeper/msg_server_test.go new file mode 100644 index 00000000..54c6d506 --- /dev/null +++ b/x/interchaintxs/keeper/msg_server_test.go @@ -0,0 +1,546 @@ +package keeper_test + +import ( + "fmt" + "testing" + "time" + + "cosmossdk.io/math" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + feerefundertypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/keeper" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + + "github.com/Nolus-Protocol/nolus-core/testutil" + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchaintxs/keeper" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/interchaintxs/types" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +const TestFeeCollectorAddr = "neutron1dua3d89szsmd3vwg0y5a2689ah0g4x68ps8vew" + +func TestMsgRegisterInterchainAccountValidate(t *testing.T) { + icak, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, nil, nil, nil, nil, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + + tests := []struct { + name string + msg types.MsgRegisterInterchainAccount + expectedErr error + }{ + { + "empty connection id", + types.MsgRegisterInterchainAccount{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "", + InterchainAccountId: "1", + }, + types.ErrEmptyConnectionID, + }, + { + "empty fromAddress", + types.MsgRegisterInterchainAccount{ + FromAddress: "", + ConnectionId: "connection-id", + InterchainAccountId: "1", + }, + sdkerrors.ErrInvalidAddress, + }, + { + "invalid fromAddress", + types.MsgRegisterInterchainAccount{ + FromAddress: "invalid address", + ConnectionId: "connection-id", + InterchainAccountId: "1", + }, + sdkerrors.ErrInvalidAddress, + }, + { + "empty interchain account id", + types.MsgRegisterInterchainAccount{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "", + }, + types.ErrEmptyInterchainAccountID, + }, + { + "long interchain account id", + types.MsgRegisterInterchainAccount{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: string(make([]byte, 48)), + }, + types.ErrLongInterchainAccountID, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := icak.RegisterInterchainAccount(ctx, &tt.msg) + require.ErrorIs(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + +func TestRegisterInterchainAccount(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + icaKeeper := mock_types.NewMockICAControllerKeeper(ctrl) + icaMsgServer := mock_types.NewMockICAControllerMsgServer(ctrl) + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, nil, icaKeeper, icaMsgServer, nil, bankKeeper, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + + msgRegAcc := types.MsgRegisterInterchainAccount{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-0", + InterchainAccountId: "ica0", + } + contractAddress := sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress) + icaOwner := types.NewICAOwnerFromAddress(contractAddress, msgRegAcc.InterchainAccountId) + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(false) + resp, err := icak.RegisterInterchainAccount(ctx, &msgRegAcc) + require.ErrorContains(t, err, "is not a contract address") + require.Nil(t, resp) + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + wmKeeper.EXPECT().GetContractInfo(ctx, contractAddress).Return(&wasmtypes.ContractInfo{CodeID: 1}) + resp, err = icak.RegisterInterchainAccount(ctx, &msgRegAcc) + require.ErrorContains(t, err, "failed to charge fees to pay for RegisterInterchainAccount msg") + require.Nil(t, resp) + + msgRegAcc.RegisterFee = sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(1_000_000))) + + msgRegICA := &icacontrollertypes.MsgRegisterInterchainAccount{ + Owner: icaOwner.String(), + ConnectionId: msgRegAcc.ConnectionId, + Version: "", + Ordering: channeltypes.ORDERED, + } + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + wmKeeper.EXPECT().GetContractInfo(ctx, contractAddress).Return(&wasmtypes.ContractInfo{CodeID: 1}) + bankKeeper.EXPECT().SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestFeeCollectorAddr), msgRegAcc.RegisterFee) + icaMsgServer.EXPECT().RegisterInterchainAccount(ctx, msgRegICA).Return(nil, fmt.Errorf("failed to register ica")) + resp, err = icak.RegisterInterchainAccount(ctx, &msgRegAcc) + require.ErrorContains(t, err, "failed to RegisterInterchainAccount") + require.Nil(t, resp) + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + wmKeeper.EXPECT().GetContractInfo(ctx, contractAddress).Return(&wasmtypes.ContractInfo{CodeID: 1}) + bankKeeper.EXPECT(). + SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestFeeCollectorAddr), msgRegAcc.RegisterFee). + Return(fmt.Errorf("failed to send coins")) + resp, err = icak.RegisterInterchainAccount(ctx, &msgRegAcc) + require.ErrorContains(t, err, "failed to charge fees to pay for RegisterInterchainAccount msg") + require.Nil(t, resp) + + channelID := "channel-0" + portID := "icacontroller-" + testutil.TestOwnerAddress + ICAId + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + wmKeeper.EXPECT().GetContractInfo(ctx, contractAddress).Return(&wasmtypes.ContractInfo{CodeID: 1}) + bankKeeper.EXPECT().SendCoins(ctx, sdk.MustAccAddressFromBech32(msgRegAcc.FromAddress), sdk.MustAccAddressFromBech32(TestFeeCollectorAddr), msgRegAcc.RegisterFee) + icaMsgServer.EXPECT().RegisterInterchainAccount(ctx, msgRegICA).Return(&icacontrollertypes.MsgRegisterInterchainAccountResponse{ + ChannelId: channelID, + PortId: portID, + }, nil) + icaKeeper.EXPECT().SetMiddlewareEnabled(ctx, portID, msgRegAcc.ConnectionId) + resp, err = icak.RegisterInterchainAccount(ctx, &msgRegAcc) + require.NoError(t, err) + require.Equal(t, types.MsgRegisterInterchainAccountResponse{ + ChannelId: channelID, + PortId: portID, + }, *resp) +} + +func TestMsgSubmitTXValidate(t *testing.T) { + icak, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, nil, nil, nil, nil, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + + cosmosMsg := codectypes.Any{ + TypeUrl: "msg", + Value: []byte{100}, // just check that values are not nil + } + + tests := []struct { + name string + msg types.MsgSubmitTx + expectedErr error + }{ + { + "invalid ack fee", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.Coins{ + { + Denom: "{}!@#a", + Amount: math.NewInt(100), + }, + }, + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + sdkerrors.ErrInvalidCoins, + }, + { + "invalid timeout fee", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.Coins{ + { + Denom: params.DefaultBondDenom, + Amount: math.NewInt(-100), + }, + }, + }, + }, + sdkerrors.ErrInvalidCoins, + }, + { + "non-zero recv fee", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + sdkerrors.ErrInvalidCoins, + }, + { + "zero ack fee", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: nil, + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + sdkerrors.ErrInvalidCoins, + }, + { + "zero timeout fee", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: nil, + }, + }, + sdkerrors.ErrInvalidCoins, + }, + { + "empty connection id", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + types.ErrEmptyConnectionID, + }, + { + "empty FromAddress", + types.MsgSubmitTx{ + FromAddress: "", + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + sdkerrors.ErrInvalidAddress, + }, + { + "invalid FromAddress", + types.MsgSubmitTx{ + FromAddress: "invalid_address", + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + sdkerrors.ErrInvalidAddress, + }, + { + "empty interchain account id", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + types.ErrEmptyInterchainAccountID, + }, + { + "no messages", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: nil, + Timeout: 1, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + types.ErrNoMessages, + }, + { + "invalid timeout", + types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*codectypes.Any{&cosmosMsg}, + Timeout: 0, + Fee: feerefundertypes.Fee{ + RecvFee: nil, + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + types.ErrInvalidTimeout, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := icak.SubmitTx(ctx, &tt.msg) + require.ErrorIs(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} + +func TestSubmitTx(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + icaKeeper := mock_types.NewMockICAControllerKeeper(ctrl) + icaMsgServer := mock_types.NewMockICAControllerMsgServer(ctrl) + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + refundKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl) + channelKeeper := mock_types.NewMockChannelKeeper(ctrl) + bankKeeper := mock_types.NewMockBankKeeper(ctrl) + icak, ctx := testkeeper.InterchainTxsKeeper(t, wmKeeper, refundKeeper, icaKeeper, icaMsgServer, channelKeeper, bankKeeper, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + + cosmosMsg := codectypes.Any{ + TypeUrl: "/cosmos.staking.v1beta1.MsgDelegate", + Value: []byte{26, 10, 10, 5, 115, 116, 97, 107, 101, 18, 1, 48}, + } + submitMsg := types.MsgSubmitTx{ + FromAddress: testutil.TestOwnerAddress, + InterchainAccountId: "ica0", + ConnectionId: "connection-0", + Msgs: []*codectypes.Any{&cosmosMsg}, + Memo: "memo", + Timeout: 100, + Fee: feerefundertypes.Fee{ + RecvFee: sdk.NewCoins(), + AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + } + + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + icaOwner := types.NewICAOwnerFromAddress(contractAddress, submitMsg.InterchainAccountId) + + resp, err := icak.SubmitTx(ctx, nil) + require.Nil(t, resp) + require.ErrorContains(t, err, "nil msg is prohibited") + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(false) + resp, err = icak.SubmitTx(ctx, &submitMsg) + require.Nil(t, resp) + require.ErrorContains(t, err, "is not a contract address") + + params := icak.GetParams(ctx) + maxMsgs := params.GetMsgSubmitTxMaxMessages() + submitMsg.Msgs = make([]*codectypes.Any, maxMsgs+1) + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + resp, err = icak.SubmitTx(ctx, &submitMsg) + require.Nil(t, resp) + require.ErrorContains(t, err, "MsgSubmitTx contains more messages than allowed") + submitMsg.Msgs = []*codectypes.Any{&cosmosMsg} + + portID := "icacontroller-" + testutil.TestOwnerAddress + ICAId + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + icaKeeper.EXPECT().GetActiveChannelID(ctx, "connection-0", portID).Return("", false) + resp, err = icak.SubmitTx(ctx, &submitMsg) + require.Nil(t, resp) + require.ErrorContains(t, err, "failed to GetActiveChannelID for port") + + activeChannel := "channel-0" + // wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + // icaKeeper.EXPECT().GetActiveChannelID(ctx, "connection-0", portID).Return(activeChannel, true) + // currCodec := icak.Codec + // icak.Codec = &codec.AminoCodec{} + // resp, err = icak.SubmitTx(ctx, &submitMsg) + // icak.Codec = currCodec + // require.Nil(t, resp) + // require.ErrorContains(t, err, "only ProtoCodec is supported for receiving messages on the host chain") + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + icaKeeper.EXPECT().GetActiveChannelID(ctx, "connection-0", portID).Return(activeChannel, true) + channelKeeper.EXPECT().GetNextSequenceSend(ctx, portID, activeChannel).Return(uint64(0), false) + resp, err = icak.SubmitTx(ctx, &submitMsg) + require.Nil(t, resp) + require.ErrorContains(t, err, "sequence send not found") + + sequence := uint64(100) + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + icaKeeper.EXPECT().GetActiveChannelID(ctx, "connection-0", portID).Return(activeChannel, true) + channelKeeper.EXPECT().GetNextSequenceSend(ctx, portID, activeChannel).Return(sequence, true) + refundKeeper.EXPECT().LockFees(ctx, contractAddress, feerefundertypes.NewPacketID(portID, activeChannel, sequence), submitMsg.Fee).Return(fmt.Errorf("failed to lock fees")) + resp, err = icak.SubmitTx(ctx, &submitMsg) + require.Nil(t, resp) + require.ErrorContains(t, err, "failed to lock fees to pay for SubmitTx msg") + + data, err := keeper.SerializeCosmosTx(icak.Codec, submitMsg.Msgs) + require.NoError(t, err) + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: data, + Memo: submitMsg.Memo, + } + + msgSendTx := &icacontrollertypes.MsgSendTx{ + Owner: icaOwner.String(), + ConnectionId: submitMsg.ConnectionId, + PacketData: packetData, + RelativeTimeout: uint64(time.Duration(submitMsg.Timeout) * time.Second), + } + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + icaKeeper.EXPECT().GetActiveChannelID(ctx, "connection-0", portID).Return(activeChannel, true) + channelKeeper.EXPECT().GetNextSequenceSend(ctx, portID, activeChannel).Return(sequence, true) + refundKeeper.EXPECT().LockFees(ctx, contractAddress, feerefundertypes.NewPacketID(portID, activeChannel, sequence), submitMsg.Fee).Return(nil) + icaMsgServer.EXPECT().SendTx(ctx, msgSendTx).Return(nil, fmt.Errorf("failed to send tx")) + resp, err = icak.SubmitTx(ctx, &submitMsg) + require.Nil(t, resp) + require.ErrorContains(t, err, "failed to SendTx") + + wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true) + icaKeeper.EXPECT().GetActiveChannelID(ctx, "connection-0", portID).Return(activeChannel, true) + channelKeeper.EXPECT().GetNextSequenceSend(ctx, portID, activeChannel).Return(sequence, true) + refundKeeper.EXPECT().LockFees(ctx, contractAddress, feerefundertypes.NewPacketID(portID, activeChannel, sequence), submitMsg.Fee).Return(nil) + icaMsgServer.EXPECT().SendTx(ctx, msgSendTx).Return(&icacontrollertypes.MsgSendTxResponse{Sequence: sequence}, nil) + resp, err = icak.SubmitTx(ctx, &submitMsg) + require.Equal(t, types.MsgSubmitTxResponse{ + SequenceId: sequence, + Channel: activeChannel, + }, *resp) + require.NoError(t, err) +} + +func TestMsgUpdateParamsValidate(t *testing.T) { + icak, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, nil, nil, nil, nil, func(_ sdk.Context) string { + return TestFeeCollectorAddr + }) + + tests := []struct { + name string + msg types.MsgUpdateParams + expectedErr string + }{ + { + "empty authority", + types.MsgUpdateParams{ + Authority: "", + }, + "authority is invalid", + }, + { + "invalid authority", + types.MsgUpdateParams{ + Authority: "invalid authority", + }, + "authority is invalid", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := icak.UpdateParams(ctx, &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} diff --git a/x/interchaintxs/keeper/params.go b/x/interchaintxs/keeper/params.go new file mode 100644 index 00000000..dec4f951 --- /dev/null +++ b/x/interchaintxs/keeper/params.go @@ -0,0 +1,31 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.Codec.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.Codec.Marshal(¶ms) + if err != nil { + return err + } + + store.Set(types.ParamsKey, bz) + return nil +} diff --git a/x/interchaintxs/keeper/params_test.go b/x/interchaintxs/keeper/params_test.go new file mode 100644 index 00000000..7a71d1f8 --- /dev/null +++ b/x/interchaintxs/keeper/params_test.go @@ -0,0 +1,20 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/interchaintxs/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func TestGetParams(t *testing.T) { + k, ctx := testkeeper.InterchainTxsKeeper(t, nil, nil, nil, nil, nil, nil, nil) + params := types.DefaultParams() + + err := k.SetParams(ctx, params) + require.NoError(t, err) + + require.EqualValues(t, params, k.GetParams(ctx)) +} diff --git a/x/interchaintxs/module.go b/x/interchaintxs/module.go new file mode 100644 index 00000000..eacdeec7 --- /dev/null +++ b/x/interchaintxs/module.go @@ -0,0 +1,179 @@ +package interchaintxs + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/client/cli" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/keeper" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +var ( + _ appmodule.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + return + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +var _ appmodule.AppModule = AppModule{} + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() { // marker +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() { // marker +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return types.ConsensusVersion } + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(_ sdk.Context) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(_ sdk.Context) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/interchaintxs/module_simulation.go b/x/interchaintxs/module_simulation.go new file mode 100644 index 00000000..cde1f5fa --- /dev/null +++ b/x/interchaintxs/module_simulation.go @@ -0,0 +1,47 @@ +package interchaintxs + +import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + interchaintxssimulation "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/simulation" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +// avoid unused import issue +var ( + _ = interchaintxssimulation.FindAccount + _ = sims.StakePerAccount + _ = simulation.MsgEntryKind + _ = baseapp.Paramspace +) + +// GenerateGenesisState creates a randomized GenState of the module +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + interchaintxsGenesis := types.GenesisState{ + Params: types.DefaultParams(), + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&interchaintxsGenesis) +} + +// ProposalContents doesn't return any content functions for governance proposals +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { + return nil +} + +// RegisterStoreDecoder registers a decoder +func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + + return operations +} diff --git a/x/interchaintxs/simulation/simap.go b/x/interchaintxs/simulation/simap.go new file mode 100644 index 00000000..92c437c0 --- /dev/null +++ b/x/interchaintxs/simulation/simap.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/interchaintxs/types/codec.go b/x/interchaintxs/types/codec.go new file mode 100644 index 00000000..e780becc --- /dev/null +++ b/x/interchaintxs/types/codec.go @@ -0,0 +1,52 @@ +package types + +import ( + "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/cosmos/gogoproto/proto" +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgRegisterInterchainAccount{}, "/neutron.interchaintxs.v1.MsgRegisterInterchainAccount", nil) + cdc.RegisterConcrete(&MsgSubmitTx{}, "/neutron.interchaintxs.v1.MsgSubmitTx", nil) + cdc.RegisterConcrete(&MsgUpdateParams{}, "/neutron.interchaintxs.v1.MsgUpdateParams", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgRegisterInterchainAccount{}, + &MsgSubmitTx{}, + &MsgUpdateParams{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc *codec.ProtoCodec +) + +func init() { + RegisterLegacyAminoCodec(legacy.Cdc) + reg, err := cdctypes.NewInterfaceRegistryWithOptions(cdctypes.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + SigningOptions: signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, + }, + }) + if err != nil { + panic(err) + } + ModuleCdc = codec.NewProtoCodec(reg) +} diff --git a/x/interchaintxs/types/constants.go b/x/interchaintxs/types/constants.go new file mode 100644 index 00000000..4c93fbef --- /dev/null +++ b/x/interchaintxs/types/constants.go @@ -0,0 +1,3 @@ +package types + +const ConsensusVersion = 2 diff --git a/x/interchaintxs/types/errors.go b/x/interchaintxs/types/errors.go new file mode 100644 index 00000000..f32e3980 --- /dev/null +++ b/x/interchaintxs/types/errors.go @@ -0,0 +1,20 @@ +package types + +import ( + "cosmossdk.io/errors" +) + +// x/interchaintxs module sentinel errors +var ( + ErrInvalidICAOwner = errors.Register(ModuleName, 1100, "invalid interchain account interchainAccountID") + ErrInvalidAccountAddress = errors.Register(ModuleName, 1101, "invalid account address") + ErrInterchainAccountNotFound = errors.Register(ModuleName, 1102, "interchain account not found") + ErrNotContract = errors.Register(ModuleName, 1103, "not a contract") + ErrEmptyInterchainAccountID = errors.Register(ModuleName, 1104, "empty interchain account id") + ErrEmptyConnectionID = errors.Register(ModuleName, 1105, "empty connection id") + ErrNoMessages = errors.Register(ModuleName, 1106, "no messages provided") + ErrInvalidTimeout = errors.Register(ModuleName, 1107, "invalid timeout") + ErrInvalidPayerFee = errors.Register(ModuleName, 1108, "invalid payer feerefunder") + ErrLongInterchainAccountID = errors.Register(ModuleName, 1109, "interchain account id is too long") + ErrInvalidType = errors.Register(ModuleName, 1110, "invalid type") +) diff --git a/x/interchaintxs/types/expected_keepers.go b/x/interchaintxs/types/expected_keepers.go new file mode 100644 index 00000000..8d90457c --- /dev/null +++ b/x/interchaintxs/types/expected_keepers.go @@ -0,0 +1,55 @@ +package types + +import ( + "context" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" + + feerefundertypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins + SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error +} + +type WasmKeeper interface { + HasContractInfo(ctx context.Context, contractAddress sdk.AccAddress) bool + GetContractInfo(ctx context.Context, contractAddress sdk.AccAddress) *wasmtypes.ContractInfo + Sudo(ctx context.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) +} + +type ICAControllerKeeper interface { + GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) + GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) + SetMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) +} + +type ICAControllerMsgServer interface { + RegisterInterchainAccount(context.Context, *icacontrollertypes.MsgRegisterInterchainAccount) (*icacontrollertypes.MsgRegisterInterchainAccountResponse, error) + SendTx(context.Context, *icacontrollertypes.MsgSendTx) (*icacontrollertypes.MsgSendTxResponse, error) +} + +type FeeRefunderKeeper interface { + LockFees(ctx context.Context, payer sdk.AccAddress, packetID feerefundertypes.PacketID, fee feerefundertypes.Fee) error + DistributeAcknowledgementFee(ctx context.Context, receiver sdk.AccAddress, packetID feerefundertypes.PacketID) + DistributeTimeoutFee(ctx context.Context, receiver sdk.AccAddress, packetID feerefundertypes.PacketID) +} + +// ChannelKeeper defines the expected IBC channel keeper +type ChannelKeeper interface { + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) + GetConnection(ctx sdk.Context, connectionID string) (ibcexported.ConnectionI, error) +} diff --git a/x/interchaintxs/types/genesis.go b/x/interchaintxs/types/genesis.go new file mode 100644 index 00000000..ffd96d1a --- /dev/null +++ b/x/interchaintxs/types/genesis.go @@ -0,0 +1,14 @@ +package types + +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + return gs.Params.Validate() +} diff --git a/x/interchaintxs/types/genesis.pb.go b/x/interchaintxs/types/genesis.pb.go new file mode 100644 index 00000000..85e6a2c7 --- /dev/null +++ b/x/interchaintxs/types/genesis.pb.go @@ -0,0 +1,324 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchaintxs/v1/genesis.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 interchaintxs module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +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_d16558b72a810826, []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) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "neutron.interchaintxs.v1.GenesisState") +} + +func init() { + proto.RegisterFile("neutron/interchaintxs/v1/genesis.proto", fileDescriptor_d16558b72a810826) +} + +var fileDescriptor_d16558b72a810826 = []byte{ + // 207 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcb, 0x4b, 0x2d, 0x2d, + 0x29, 0xca, 0xcf, 0xd3, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0x2b, 0xa9, + 0x28, 0xd6, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, + 0x2f, 0xc9, 0x17, 0x92, 0x80, 0xaa, 0xd3, 0x43, 0x51, 0xa7, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, + 0x9f, 0x9e, 0x0f, 0x56, 0xa4, 0x0f, 0x62, 0x41, 0xd4, 0x4b, 0xa9, 0xe2, 0x34, 0xb7, 0x20, 0xb1, + 0x28, 0x31, 0x17, 0x6a, 0xac, 0x92, 0x1f, 0x17, 0x8f, 0x3b, 0xc4, 0x9e, 0xe0, 0x92, 0xc4, 0x92, + 0x54, 0x21, 0x3b, 0x2e, 0x36, 0x88, 0xbc, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x82, 0x1e, + 0x2e, 0x7b, 0xf5, 0x02, 0xc0, 0xea, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xea, 0x72, + 0x0a, 0x3c, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, + 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xf3, 0xf4, 0xcc, 0x92, + 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0xa8, 0x99, 0xba, 0xf9, 0x45, 0xe9, 0x30, 0xb6, + 0x7e, 0x99, 0x89, 0x7e, 0x05, 0x9a, 0x63, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x2e, + 0x35, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x02, 0x5d, 0x4b, 0x80, 0x2a, 0x01, 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 + { + size, err := m.Params.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 = m.Params.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 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 + 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/x/interchaintxs/types/genesis_test.go b/x/interchaintxs/types/genesis_test.go new file mode 100644 index 00000000..c2b93a56 --- /dev/null +++ b/x/interchaintxs/types/genesis_test.go @@ -0,0 +1,50 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +func TestGenesisState_Validate(t *testing.T) { + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "MsgSubmitTxMaxMessages must be greater than zero", + genState: &types.GenesisState{ + Params: types.Params{ + MsgSubmitTxMaxMessages: 0, + }, + }, + valid: false, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + Params: types.Params{ + MsgSubmitTxMaxMessages: 10, + }, + }, + valid: true, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/interchaintxs/types/keys.go b/x/interchaintxs/types/keys.go new file mode 100644 index 00000000..ba4019d8 --- /dev/null +++ b/x/interchaintxs/types/keys.go @@ -0,0 +1,30 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "interchaintxs" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for slashing + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_interchaintxs" +) + +const ( + // parameters key + prefixParamsKey = iota + 1 + // prefix of code id, starting from which we charge fee for ICA registration + prefixICARegistrationFeeFirstCodeID = iota + 2 +) + +var ( + ParamsKey = []byte{prefixParamsKey} + ICARegistrationFeeFirstCodeID = []byte{prefixICARegistrationFeeFirstCodeID} +) diff --git a/x/interchaintxs/types/params.go b/x/interchaintxs/types/params.go new file mode 100644 index 00000000..ceb568d6 --- /dev/null +++ b/x/interchaintxs/types/params.go @@ -0,0 +1,79 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +var ( + KeyMsgSubmitTxMaxMessages = []byte("MsgSubmitTxMaxMessages") + DefaultMsgSubmitTxMaxMessages = uint64(16) + DefaultRegisterFee = sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, math.NewInt(1_000_000))) +) + +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable( + paramtypes.NewParamSetPair( + KeyMsgSubmitTxMaxMessages, + DefaultMsgSubmitTxMaxMessages, + validateMsgSubmitTxMaxMessages, + ), + ) +} + +// NewParams creates a new Params instance +func NewParams(msgSubmitTxMaxMessages uint64, registerFee sdk.Coins) Params { + return Params{ + MsgSubmitTxMaxMessages: msgSubmitTxMaxMessages, + RegisterFee: registerFee, + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams(DefaultMsgSubmitTxMaxMessages, DefaultRegisterFee) +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair( + KeyMsgSubmitTxMaxMessages, + &p.MsgSubmitTxMaxMessages, + validateMsgSubmitTxMaxMessages, + ), + } +} + +// Validate validates the set of params +func (p Params) Validate() error { + return validateMsgSubmitTxMaxMessages(p.GetMsgSubmitTxMaxMessages()) +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +func validateMsgSubmitTxMaxMessages(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("MsgSubmitTxMaxMessages must be greater than zero") + } + + return nil +} diff --git a/x/interchaintxs/types/params.pb.go b/x/interchaintxs/types/params.pb.go new file mode 100644 index 00000000..3012954b --- /dev/null +++ b/x/interchaintxs/types/params.pb.go @@ -0,0 +1,376 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchaintxs/v1/params.proto + +package types + +import ( + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" +) + +// 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 + +// Params defines the parameters for the module. +type Params struct { + // Defines maximum amount of messages to be passed in MsgSubmitTx + MsgSubmitTxMaxMessages uint64 `protobuf:"varint,1,opt,name=msg_submit_tx_max_messages,json=msgSubmitTxMaxMessages,proto3" json:"msg_submit_tx_max_messages,omitempty"` + // Defines a minimum fee required to register interchain account + RegisterFee []types.Coin `protobuf:"bytes,2,rep,name=register_fee,json=registerFee,proto3" json:"register_fee"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_52b0ced89d3fa9c6, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMsgSubmitTxMaxMessages() uint64 { + if m != nil { + return m.MsgSubmitTxMaxMessages + } + return 0 +} + +func (m *Params) GetRegisterFee() []types.Coin { + if m != nil { + return m.RegisterFee + } + return nil +} + +func init() { + proto.RegisterType((*Params)(nil), "neutron.interchaintxs.v1.Params") +} + +func init() { + proto.RegisterFile("neutron/interchaintxs/v1/params.proto", fileDescriptor_52b0ced89d3fa9c6) +} + +var fileDescriptor_52b0ced89d3fa9c6 = []byte{ + // 291 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0x31, 0x4b, 0x03, 0x41, + 0x10, 0x85, 0x6f, 0x35, 0xa4, 0xb8, 0x58, 0x05, 0x91, 0x98, 0x62, 0x13, 0x04, 0x21, 0x8d, 0xbb, + 0x9c, 0x0a, 0x42, 0xca, 0x08, 0x76, 0x01, 0x8d, 0x56, 0x36, 0xc7, 0xde, 0x31, 0x6e, 0xb6, 0xd8, + 0xdd, 0xb0, 0xb3, 0x39, 0xd6, 0x3f, 0x21, 0x96, 0x96, 0xfe, 0x9c, 0x94, 0x29, 0xad, 0x44, 0xee, + 0xfe, 0x88, 0xe4, 0xee, 0x52, 0x68, 0xf7, 0x98, 0x79, 0x8f, 0xf9, 0xe6, 0xc5, 0xe7, 0x06, 0xd6, + 0xde, 0x59, 0xc3, 0x95, 0xf1, 0xe0, 0xf2, 0xa5, 0x50, 0xc6, 0x07, 0xe4, 0x45, 0xc2, 0x57, 0xc2, + 0x09, 0x8d, 0x6c, 0xe5, 0xac, 0xb7, 0xfd, 0x41, 0x6b, 0x63, 0x7f, 0x6c, 0xac, 0x48, 0x86, 0x34, + 0xb7, 0xa8, 0x2d, 0xf2, 0x4c, 0x20, 0xf0, 0x22, 0xc9, 0xc0, 0x8b, 0x84, 0xe7, 0x56, 0x99, 0x26, + 0x39, 0x3c, 0x96, 0x56, 0xda, 0x5a, 0xf2, 0x9d, 0x6a, 0xa6, 0x67, 0x6f, 0x24, 0xee, 0xde, 0xd7, + 0x07, 0xfa, 0xd3, 0x78, 0xa8, 0x51, 0xa6, 0xb8, 0xce, 0xb4, 0xf2, 0xa9, 0x0f, 0xa9, 0x16, 0x21, + 0xd5, 0x80, 0x28, 0x24, 0xe0, 0x80, 0x8c, 0xc9, 0xa4, 0xb3, 0x38, 0xd1, 0x28, 0x1f, 0x6b, 0xc3, + 0x53, 0x98, 0x8b, 0x30, 0x6f, 0xb7, 0xfd, 0x59, 0x7c, 0xe4, 0x40, 0x2a, 0xf4, 0xe0, 0xd2, 0x17, + 0x80, 0xc1, 0xc1, 0xf8, 0x70, 0xd2, 0xbb, 0x3c, 0x65, 0x0d, 0x13, 0xdb, 0x31, 0xb1, 0x96, 0x89, + 0xdd, 0x5a, 0x65, 0x66, 0x9d, 0xcd, 0xf7, 0x28, 0x5a, 0xf4, 0xf6, 0xa1, 0x3b, 0x80, 0x69, 0xe7, + 0xe3, 0x73, 0x14, 0xcd, 0x1e, 0x36, 0x25, 0x25, 0xdb, 0x92, 0x92, 0x9f, 0x92, 0x92, 0xf7, 0x8a, + 0x46, 0xdb, 0x8a, 0x46, 0x5f, 0x15, 0x8d, 0x9e, 0x6f, 0xa4, 0xf2, 0xcb, 0x75, 0xc6, 0x72, 0xab, + 0x79, 0xdb, 0xc2, 0x85, 0x75, 0x72, 0xaf, 0x79, 0x71, 0xcd, 0xc3, 0xbf, 0xf6, 0xfc, 0xeb, 0x0a, + 0x30, 0xeb, 0xd6, 0xaf, 0x5e, 0xfd, 0x06, 0x00, 0x00, 0xff, 0xff, 0x40, 0x55, 0x79, 0xd9, 0x63, + 0x01, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.RegisterFee) > 0 { + for iNdEx := len(m.RegisterFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RegisterFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.MsgSubmitTxMaxMessages != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MsgSubmitTxMaxMessages)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MsgSubmitTxMaxMessages != 0 { + n += 1 + sovParams(uint64(m.MsgSubmitTxMaxMessages)) + } + if len(m.RegisterFee) > 0 { + for _, e := range m.RegisterFee { + l = e.Size() + n += 1 + l + sovParams(uint64(l)) + } + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgSubmitTxMaxMessages", wireType) + } + m.MsgSubmitTxMaxMessages = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgSubmitTxMaxMessages |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisterFee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RegisterFee = append(m.RegisterFee, types.Coin{}) + if err := m.RegisterFee[len(m.RegisterFee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/interchaintxs/types/query.pb.go b/x/interchaintxs/types/query.pb.go new file mode 100644 index 00000000..1518bda6 --- /dev/null +++ b/x/interchaintxs/types/query.pb.go @@ -0,0 +1,1017 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchaintxs/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// 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 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_6130c5f6c54e2428, []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 response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +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_6130c5f6c54e2428, []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() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type QueryInterchainAccountAddressRequest struct { + // owner_address is the owner of the interchain account on the controller + // chain + OwnerAddress string `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"` + // interchain_account_id is an identifier of your interchain account from + // which you want to execute msgs + InterchainAccountId string `protobuf:"bytes,2,opt,name=interchain_account_id,json=interchainAccountId,proto3" json:"interchain_account_id,omitempty"` + // connection_id is an IBC connection identifier between Neutron and remote + // chain + ConnectionId string `protobuf:"bytes,3,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` +} + +func (m *QueryInterchainAccountAddressRequest) Reset() { *m = QueryInterchainAccountAddressRequest{} } +func (m *QueryInterchainAccountAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryInterchainAccountAddressRequest) ProtoMessage() {} +func (*QueryInterchainAccountAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_6130c5f6c54e2428, []int{2} +} +func (m *QueryInterchainAccountAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryInterchainAccountAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryInterchainAccountAddressRequest.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 *QueryInterchainAccountAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryInterchainAccountAddressRequest.Merge(m, src) +} +func (m *QueryInterchainAccountAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryInterchainAccountAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryInterchainAccountAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryInterchainAccountAddressRequest proto.InternalMessageInfo + +// Query response for an interchain account address +type QueryInterchainAccountAddressResponse struct { + // The corresponding interchain account address on the host chain + InterchainAccountAddress string `protobuf:"bytes,1,opt,name=interchain_account_address,json=interchainAccountAddress,proto3" json:"interchain_account_address,omitempty"` +} + +func (m *QueryInterchainAccountAddressResponse) Reset() { *m = QueryInterchainAccountAddressResponse{} } +func (m *QueryInterchainAccountAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryInterchainAccountAddressResponse) ProtoMessage() {} +func (*QueryInterchainAccountAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6130c5f6c54e2428, []int{3} +} +func (m *QueryInterchainAccountAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryInterchainAccountAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryInterchainAccountAddressResponse.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 *QueryInterchainAccountAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryInterchainAccountAddressResponse.Merge(m, src) +} +func (m *QueryInterchainAccountAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryInterchainAccountAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryInterchainAccountAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryInterchainAccountAddressResponse proto.InternalMessageInfo + +func (m *QueryInterchainAccountAddressResponse) GetInterchainAccountAddress() string { + if m != nil { + return m.InterchainAccountAddress + } + return "" +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "neutron.interchaintxs.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "neutron.interchaintxs.v1.QueryParamsResponse") + proto.RegisterType((*QueryInterchainAccountAddressRequest)(nil), "neutron.interchaintxs.v1.QueryInterchainAccountAddressRequest") + proto.RegisterType((*QueryInterchainAccountAddressResponse)(nil), "neutron.interchaintxs.v1.QueryInterchainAccountAddressResponse") +} + +func init() { + proto.RegisterFile("neutron/interchaintxs/v1/query.proto", fileDescriptor_6130c5f6c54e2428) +} + +var fileDescriptor_6130c5f6c54e2428 = []byte{ + // 483 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xcf, 0x6a, 0x13, 0x41, + 0x18, 0xdf, 0x4d, 0x35, 0xe8, 0xa8, 0x97, 0x69, 0x85, 0x65, 0xd1, 0x4d, 0x59, 0x1b, 0x10, 0xb1, + 0x3b, 0x24, 0x0a, 0x82, 0x48, 0xa5, 0xbd, 0xe5, 0x66, 0x03, 0x5e, 0xbc, 0x84, 0xc9, 0xee, 0xb0, + 0x1d, 0x34, 0xf3, 0x6d, 0x76, 0x66, 0x63, 0x4b, 0xc8, 0xc5, 0x93, 0x07, 0x11, 0xc1, 0x17, 0xe8, + 0xcd, 0x9b, 0xcf, 0xd1, 0x63, 0xc1, 0x8b, 0x27, 0x91, 0xc4, 0x83, 0x8f, 0x21, 0x3b, 0x33, 0x6d, + 0xd9, 0x9a, 0x25, 0xe2, 0x6d, 0xf8, 0xf6, 0xf7, 0xef, 0xfb, 0xb3, 0x68, 0x4b, 0xb0, 0x42, 0xe5, + 0x20, 0x08, 0x17, 0x8a, 0xe5, 0xf1, 0x01, 0xe5, 0x42, 0x1d, 0x4a, 0x32, 0xe9, 0x90, 0x71, 0xc1, + 0xf2, 0xa3, 0x28, 0xcb, 0x41, 0x01, 0xf6, 0x2c, 0x2a, 0xaa, 0xa0, 0xa2, 0x49, 0xc7, 0x7f, 0x10, + 0x83, 0x1c, 0x81, 0x24, 0x43, 0x2a, 0x99, 0xa1, 0x90, 0x49, 0x67, 0xc8, 0x14, 0xed, 0x90, 0x8c, + 0xa6, 0x5c, 0x50, 0xc5, 0x41, 0x18, 0x15, 0x7f, 0x23, 0x85, 0x14, 0xf4, 0x93, 0x94, 0x2f, 0x5b, + 0xbd, 0x93, 0x02, 0xa4, 0x6f, 0x18, 0xa1, 0x19, 0x27, 0x54, 0x08, 0x50, 0x9a, 0x22, 0xed, 0xd7, + 0x76, 0x6d, 0xbe, 0x8c, 0xe6, 0x74, 0x64, 0x61, 0xe1, 0x06, 0xc2, 0xfb, 0xa5, 0xf9, 0x0b, 0x5d, + 0xec, 0xb3, 0x71, 0xc1, 0xa4, 0x0a, 0x5f, 0xa2, 0xf5, 0x4a, 0x55, 0x66, 0x20, 0x24, 0xc3, 0x3b, + 0xa8, 0x69, 0xc8, 0x9e, 0xbb, 0xe9, 0xde, 0xbf, 0xd1, 0xdd, 0x8c, 0xea, 0xda, 0x8b, 0x0c, 0x73, + 0xef, 0xca, 0xc9, 0x8f, 0x96, 0xd3, 0xb7, 0xac, 0xf0, 0xab, 0x8b, 0xb6, 0xb4, 0x6e, 0xef, 0x1c, + 0xbe, 0x1b, 0xc7, 0x50, 0x08, 0xb5, 0x9b, 0x24, 0x39, 0x93, 0x67, 0xfe, 0xf8, 0x1e, 0xba, 0x05, + 0x6f, 0x05, 0xcb, 0x07, 0xd4, 0xd4, 0xb5, 0xdf, 0xf5, 0xfe, 0x4d, 0x5d, 0xb4, 0x58, 0xdc, 0x45, + 0xb7, 0x2f, 0x6c, 0x07, 0xd4, 0x08, 0x0d, 0x78, 0xe2, 0x35, 0x34, 0x78, 0x9d, 0x5f, 0x36, 0xe9, + 0x25, 0xa5, 0x70, 0x0c, 0x42, 0xb0, 0xb8, 0x1c, 0x55, 0x89, 0x5d, 0x33, 0xc2, 0x17, 0xc5, 0x5e, + 0xf2, 0xf4, 0xda, 0xfb, 0xe3, 0x96, 0xf3, 0xfb, 0xb8, 0xe5, 0x84, 0x0c, 0xb5, 0x57, 0xe4, 0xb5, + 0x93, 0x79, 0x86, 0xfc, 0x25, 0x59, 0xaa, 0xe9, 0x3d, 0x5e, 0xa3, 0xd2, 0xfd, 0xb2, 0x86, 0xae, + 0x6a, 0x1f, 0xfc, 0xc1, 0x45, 0x4d, 0x33, 0x3a, 0xfc, 0xb0, 0x7e, 0xb8, 0x7f, 0x6f, 0xcc, 0xdf, + 0xfe, 0x47, 0xb4, 0xc9, 0x1b, 0xb6, 0xdf, 0x7d, 0xfb, 0xf5, 0xb9, 0xd1, 0xc2, 0x77, 0xc9, 0xf2, + 0x33, 0x31, 0x0b, 0xc3, 0x1f, 0x1b, 0xc8, 0xab, 0xeb, 0x1d, 0xef, 0xac, 0xb0, 0x5c, 0xb1, 0x64, + 0xff, 0xf9, 0x7f, 0xf3, 0x6d, 0x13, 0x63, 0xdd, 0xc4, 0x6b, 0xcc, 0x6b, 0x9a, 0x98, 0x56, 0x6e, + 0x68, 0x46, 0xa6, 0x4b, 0xcf, 0x65, 0x46, 0xa6, 0x95, 0x93, 0x98, 0x91, 0xfa, 0x4d, 0xee, 0xed, + 0x9f, 0xcc, 0x03, 0xf7, 0x74, 0x1e, 0xb8, 0x3f, 0xe7, 0x81, 0xfb, 0x69, 0x11, 0x38, 0xa7, 0x8b, + 0xc0, 0xf9, 0xbe, 0x08, 0x9c, 0x57, 0x4f, 0x52, 0xae, 0x0e, 0x8a, 0x61, 0x14, 0xc3, 0xe8, 0x2c, + 0xce, 0x36, 0xe4, 0xe9, 0x79, 0xb4, 0xc9, 0x63, 0x72, 0x78, 0x29, 0x9f, 0x3a, 0xca, 0x98, 0x1c, + 0x36, 0xf5, 0x8f, 0xf8, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x16, 0x40, 0xec, 0x47, 0x51, + 0x04, 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 { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + InterchainAccountAddress(ctx context.Context, in *QueryInterchainAccountAddressRequest, opts ...grpc.CallOption) (*QueryInterchainAccountAddressResponse, 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, "/neutron.interchaintxs.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) InterchainAccountAddress(ctx context.Context, in *QueryInterchainAccountAddressRequest, opts ...grpc.CallOption) (*QueryInterchainAccountAddressResponse, error) { + out := new(QueryInterchainAccountAddressResponse) + err := c.cc.Invoke(ctx, "/neutron.interchaintxs.v1.Query/InterchainAccountAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + InterchainAccountAddress(context.Context, *QueryInterchainAccountAddressRequest) (*QueryInterchainAccountAddressResponse, 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) InterchainAccountAddress(ctx context.Context, req *QueryInterchainAccountAddressRequest) (*QueryInterchainAccountAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method InterchainAccountAddress 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: "/neutron.interchaintxs.v1.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_InterchainAccountAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryInterchainAccountAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).InterchainAccountAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchaintxs.v1.Query/InterchainAccountAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).InterchainAccountAddress(ctx, req.(*QueryInterchainAccountAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.interchaintxs.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "InterchainAccountAddress", + Handler: _Query_InterchainAccountAddress_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/interchaintxs/v1/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 + { + 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 *QueryInterchainAccountAddressRequest) 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 *QueryInterchainAccountAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryInterchainAccountAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x1a + } + if len(m.InterchainAccountId) > 0 { + i -= len(m.InterchainAccountId) + copy(dAtA[i:], m.InterchainAccountId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.InterchainAccountId))) + i-- + dAtA[i] = 0x12 + } + if len(m.OwnerAddress) > 0 { + i -= len(m.OwnerAddress) + copy(dAtA[i:], m.OwnerAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.OwnerAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryInterchainAccountAddressResponse) 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 *QueryInterchainAccountAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryInterchainAccountAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.InterchainAccountAddress) > 0 { + i -= len(m.InterchainAccountAddress) + copy(dAtA[i:], m.InterchainAccountAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.InterchainAccountAddress))) + 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 + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryInterchainAccountAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OwnerAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.InterchainAccountId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryInterchainAccountAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.InterchainAccountAddress) + if l > 0 { + 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 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 *QueryInterchainAccountAddressRequest) 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: QueryInterchainAccountAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryInterchainAccountAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OwnerAddress", 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.OwnerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InterchainAccountId", 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.InterchainAccountId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", 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.ConnectionId = 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 *QueryInterchainAccountAddressResponse) 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: QueryInterchainAccountAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryInterchainAccountAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InterchainAccountAddress", 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.InterchainAccountAddress = 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 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/x/interchaintxs/types/query.pb.gw.go b/x/interchaintxs/types/query.pb.gw.go new file mode 100644 index 00000000..943b58aa --- /dev/null +++ b/x/interchaintxs/types/query.pb.gw.go @@ -0,0 +1,298 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: neutron/interchaintxs/v1/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_InterchainAccountAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryInterchainAccountAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["owner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "owner_address") + } + + protoReq.OwnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "owner_address", err) + } + + val, ok = pathParams["interchain_account_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "interchain_account_id") + } + + protoReq.InterchainAccountId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "interchain_account_id", err) + } + + val, ok = pathParams["connection_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id") + } + + protoReq.ConnectionId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err) + } + + msg, err := client.InterchainAccountAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_InterchainAccountAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryInterchainAccountAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["owner_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "owner_address") + } + + protoReq.OwnerAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "owner_address", err) + } + + val, ok = pathParams["interchain_account_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "interchain_account_id") + } + + protoReq.InterchainAccountId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "interchain_account_id", err) + } + + val, ok = pathParams["connection_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id") + } + + protoReq.ConnectionId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err) + } + + msg, err := server.InterchainAccountAddress(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_InterchainAccountAddress_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_InterchainAccountAddress_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_InterchainAccountAddress_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_InterchainAccountAddress_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_InterchainAccountAddress_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_InterchainAccountAddress_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}, []string{"neutron", "interchaintxs", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_InterchainAccountAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"neutron", "interchaintxs", "owner_address", "interchain_account_id", "connection_id", "interchain_account_address"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_InterchainAccountAddress_0 = runtime.ForwardResponseMessage +) diff --git a/x/interchaintxs/types/tx.go b/x/interchaintxs/types/tx.go new file mode 100644 index 00000000..26f31e4b --- /dev/null +++ b/x/interchaintxs/types/tx.go @@ -0,0 +1,162 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/errors" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/gogo/protobuf/proto" +) + +// const interchainAccountIDLimit = 47 +const interchainAccountIDLimit = 128 - + len("icacontroller-") - + len("neutron1unyuj8qnmygvzuex3dwmg9yzt9alhvyeat0uu0jedg2wj33efl5qmysp02") - // just a random contract address + len(".") + +var _ codectypes.UnpackInterfacesMessage = &MsgSubmitTx{} + +func (msg *MsgRegisterInterchainAccount) Validate() error { + if len(msg.ConnectionId) == 0 { + return ErrEmptyConnectionID + } + + if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse FromAddress: %s", msg.FromAddress) + } + + if len(msg.InterchainAccountId) == 0 { + return ErrEmptyInterchainAccountID + } + + if len(msg.InterchainAccountId) > interchainAccountIDLimit { + return errors.Wrapf(ErrLongInterchainAccountID, "max length is %d, got %d", interchainAccountIDLimit, len(msg.InterchainAccountId)) + } + + return nil +} + +func (msg *MsgRegisterInterchainAccount) GetSigners() []sdk.AccAddress { + fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress) + return []sdk.AccAddress{fromAddress} +} + +func (msg *MsgRegisterInterchainAccount) Route() string { + return RouterKey +} + +func (msg *MsgRegisterInterchainAccount) Type() string { + return "register-interchain-account" +} + +func (msg *MsgRegisterInterchainAccount) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +//---------------------------------------------------------------- + +func (msg *MsgSubmitTx) Validate() error { + if err := msg.Fee.Validate(); err != nil { + return err + } + + if len(msg.ConnectionId) == 0 { + return ErrEmptyConnectionID + } + + if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse FromAddress: %s", msg.FromAddress) + } + + if len(msg.InterchainAccountId) == 0 { + return ErrEmptyInterchainAccountID + } + + if len(msg.Msgs) == 0 { + return ErrNoMessages + } + + if msg.Timeout <= 0 { + return errors.Wrapf(ErrInvalidTimeout, "timeout must be greater than zero") + } + + return nil +} + +func (msg *MsgSubmitTx) GetSigners() []sdk.AccAddress { + fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress) + return []sdk.AccAddress{fromAddress} +} + +func (msg *MsgSubmitTx) Route() string { + return RouterKey +} + +func (msg *MsgSubmitTx) Type() string { + return "submit-tx" +} + +func (msg *MsgSubmitTx) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +// PackTxMsgAny marshals the sdk.Msg payload to a protobuf Any type +func PackTxMsgAny(sdkMsg sdk.Msg) (*codectypes.Any, error) { + msg, ok := sdkMsg.(proto.Message) + if !ok { + return nil, fmt.Errorf("can't proto marshal %T", sdkMsg) + } + + value, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + + return value, nil +} + +// implements UnpackInterfacesMessage.UnpackInterfaces (https://github.com/cosmos/cosmos-sdk/blob/d07d35f29e0a0824b489c552753e8798710ff5a8/codec/types/interface_registry.go#L60) +func (msg *MsgSubmitTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var sdkMsg sdk.Msg + for _, m := range msg.Msgs { + if err := unpacker.UnpackAny(m, &sdkMsg); err != nil { + return err + } + } + return nil +} + +//---------------------------------------------------------------- + +var _ sdk.Msg = &MsgUpdateParams{} + +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +func (msg *MsgUpdateParams) Type() string { + return "update-params" +} + +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgUpdateParams) GetSignBytes() []byte { + return ModuleCdc.MustMarshalJSON(msg) +} + +func (msg *MsgUpdateParams) Validate() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "authority is invalid") + } + return nil +} diff --git a/x/interchaintxs/types/tx.pb.go b/x/interchaintxs/types/tx.pb.go new file mode 100644 index 00000000..b16ea116 --- /dev/null +++ b/x/interchaintxs/types/tx.pb.go @@ -0,0 +1,1862 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/interchaintxs/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + _ "github.com/cosmos/cosmos-proto" + types1 "github.com/cosmos/cosmos-sdk/codec/types" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + 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" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + + types2 "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +// 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 + +// MsgRegisterInterchainAccount is used to register an account on a remote zone. +type MsgRegisterInterchainAccount struct { + FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + InterchainAccountId string `protobuf:"bytes,3,opt,name=interchain_account_id,json=interchainAccountId,proto3" json:"interchain_account_id,omitempty" yaml:"interchain_account_id"` + RegisterFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=register_fee,json=registerFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"register_fee"` +} + +func (m *MsgRegisterInterchainAccount) Reset() { *m = MsgRegisterInterchainAccount{} } +func (m *MsgRegisterInterchainAccount) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterInterchainAccount) ProtoMessage() {} +func (*MsgRegisterInterchainAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_50f087790e59c806, []int{0} +} +func (m *MsgRegisterInterchainAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterInterchainAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterInterchainAccount.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 *MsgRegisterInterchainAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterInterchainAccount.Merge(m, src) +} +func (m *MsgRegisterInterchainAccount) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterInterchainAccount) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterInterchainAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterInterchainAccount proto.InternalMessageInfo + +// MsgRegisterInterchainAccountResponse is the response type for +// MsgRegisterInterchainAccount. +type MsgRegisterInterchainAccountResponse struct { + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + PortId string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` +} + +func (m *MsgRegisterInterchainAccountResponse) Reset() { *m = MsgRegisterInterchainAccountResponse{} } +func (m *MsgRegisterInterchainAccountResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterInterchainAccountResponse) ProtoMessage() {} +func (*MsgRegisterInterchainAccountResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_50f087790e59c806, []int{1} +} +func (m *MsgRegisterInterchainAccountResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterInterchainAccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterInterchainAccountResponse.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 *MsgRegisterInterchainAccountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterInterchainAccountResponse.Merge(m, src) +} +func (m *MsgRegisterInterchainAccountResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterInterchainAccountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterInterchainAccountResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterInterchainAccountResponse proto.InternalMessageInfo + +// MsgSubmitTx defines the payload for Msg/SubmitTx +type MsgSubmitTx struct { + FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` + // interchain_account_id is supposed to be the unique identifier, e.g., + // lido/kava. This allows contracts to have more than one interchain accounts + // on remote zone This identifier will be a part of the portID that we'll + // claim our capability for. + InterchainAccountId string `protobuf:"bytes,2,opt,name=interchain_account_id,json=interchainAccountId,proto3" json:"interchain_account_id,omitempty"` + ConnectionId string `protobuf:"bytes,3,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty"` + Msgs []*types1.Any `protobuf:"bytes,4,rep,name=msgs,proto3" json:"msgs,omitempty"` + Memo string `protobuf:"bytes,5,opt,name=memo,proto3" json:"memo,omitempty"` + // timeout in seconds after which the packet times out + Timeout uint64 `protobuf:"varint,6,opt,name=timeout,proto3" json:"timeout,omitempty"` + Fee types2.Fee `protobuf:"bytes,7,opt,name=fee,proto3" json:"fee"` +} + +func (m *MsgSubmitTx) Reset() { *m = MsgSubmitTx{} } +func (m *MsgSubmitTx) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitTx) ProtoMessage() {} +func (*MsgSubmitTx) Descriptor() ([]byte, []int) { + return fileDescriptor_50f087790e59c806, []int{2} +} +func (m *MsgSubmitTx) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitTx) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitTx.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 *MsgSubmitTx) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitTx.Merge(m, src) +} +func (m *MsgSubmitTx) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitTx) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitTx.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitTx proto.InternalMessageInfo + +// MsgSubmitTxResponse defines the response for Msg/SubmitTx +type MsgSubmitTxResponse struct { + // channel's sequence_id for outgoing ibc packet. Unique per a channel. + SequenceId uint64 `protobuf:"varint,1,opt,name=sequence_id,json=sequenceId,proto3" json:"sequence_id,omitempty"` + // channel src channel on neutron side transaction was submitted from + Channel string `protobuf:"bytes,2,opt,name=channel,proto3" json:"channel,omitempty"` +} + +func (m *MsgSubmitTxResponse) Reset() { *m = MsgSubmitTxResponse{} } +func (m *MsgSubmitTxResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitTxResponse) ProtoMessage() {} +func (*MsgSubmitTxResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_50f087790e59c806, []int{3} +} +func (m *MsgSubmitTxResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitTxResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitTxResponse.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 *MsgSubmitTxResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitTxResponse.Merge(m, src) +} +func (m *MsgSubmitTxResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitTxResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitTxResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitTxResponse proto.InternalMessageInfo + +func (m *MsgSubmitTxResponse) GetSequenceId() uint64 { + if m != nil { + return m.SequenceId + } + return 0 +} + +func (m *MsgSubmitTxResponse) GetChannel() string { + if m != nil { + return m.Channel + } + return "" +} + +// MsgUpdateParams is the MsgUpdateParams request type. +// +// Since: 0.47 +type MsgUpdateParams struct { + // Authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/interchaintxs parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_50f087790e59c806, []int{4} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_50f087790e59c806, []int{5} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgRegisterInterchainAccount)(nil), "neutron.interchaintxs.v1.MsgRegisterInterchainAccount") + proto.RegisterType((*MsgRegisterInterchainAccountResponse)(nil), "neutron.interchaintxs.v1.MsgRegisterInterchainAccountResponse") + proto.RegisterType((*MsgSubmitTx)(nil), "neutron.interchaintxs.v1.MsgSubmitTx") + proto.RegisterType((*MsgSubmitTxResponse)(nil), "neutron.interchaintxs.v1.MsgSubmitTxResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "neutron.interchaintxs.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "neutron.interchaintxs.v1.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("neutron/interchaintxs/v1/tx.proto", fileDescriptor_50f087790e59c806) } + +var fileDescriptor_50f087790e59c806 = []byte{ + // 839 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xbf, 0x6f, 0xfb, 0x44, + 0x14, 0x8f, 0x93, 0x7c, 0x53, 0x72, 0x09, 0x42, 0xb8, 0xa9, 0xea, 0x44, 0x6d, 0x92, 0x1a, 0x2a, + 0x85, 0x4a, 0xb1, 0x9b, 0x80, 0x8a, 0x14, 0x09, 0xa4, 0xa6, 0x52, 0xa5, 0x0c, 0x91, 0x8a, 0x5b, + 0x16, 0x96, 0xe8, 0x62, 0x5f, 0x1c, 0x8b, 0xf8, 0xce, 0xf8, 0xce, 0x51, 0xb2, 0x21, 0x26, 0xc4, + 0xc4, 0xc2, 0xde, 0x11, 0x31, 0xa0, 0x0e, 0xfc, 0x01, 0x8c, 0x1d, 0x2b, 0x26, 0xa6, 0x02, 0xed, + 0x50, 0xe6, 0x0e, 0xcc, 0xe8, 0xec, 0x73, 0x7e, 0xa9, 0x89, 0xaa, 0xef, 0x92, 0xdc, 0x7b, 0xef, + 0x73, 0xef, 0xbd, 0xfb, 0x7c, 0xee, 0x9d, 0xc1, 0x01, 0x46, 0x01, 0xf3, 0x09, 0xd6, 0x1d, 0xcc, + 0x90, 0x6f, 0x0e, 0xa1, 0x83, 0xd9, 0x84, 0xea, 0xe3, 0x86, 0xce, 0x26, 0x9a, 0xe7, 0x13, 0x46, + 0x64, 0x45, 0x40, 0xb4, 0x25, 0x88, 0x36, 0x6e, 0x94, 0xde, 0x87, 0xae, 0x83, 0x89, 0x1e, 0xfe, + 0x46, 0xe0, 0x52, 0xd9, 0x24, 0xd4, 0x25, 0x54, 0xef, 0x43, 0x8a, 0xf4, 0x71, 0xa3, 0x8f, 0x18, + 0x6c, 0xe8, 0x26, 0x71, 0xb0, 0x88, 0xef, 0x8a, 0xb8, 0x4b, 0x6d, 0x5e, 0xc4, 0xa5, 0xb6, 0x08, + 0x14, 0xa3, 0x40, 0x2f, 0xb4, 0xf4, 0xc8, 0x10, 0xa1, 0x82, 0x4d, 0x6c, 0x12, 0xf9, 0xf9, 0x4a, + 0x78, 0xf7, 0x6c, 0x42, 0xec, 0x11, 0xd2, 0xa1, 0xe7, 0xe8, 0x10, 0x63, 0xc2, 0x20, 0x73, 0x08, + 0x8e, 0xf7, 0xec, 0x2c, 0x44, 0x87, 0x8c, 0x79, 0x71, 0x15, 0xe1, 0x0e, 0xad, 0x7e, 0x30, 0xd0, + 0x21, 0x9e, 0x8a, 0xd0, 0x7e, 0xcc, 0xc4, 0x00, 0x21, 0x1f, 0x0d, 0x02, 0x6c, 0x21, 0x9f, 0xaf, + 0x45, 0xf8, 0x70, 0x2d, 0x51, 0x1e, 0xf4, 0xa1, 0x2b, 0xea, 0xaa, 0xff, 0x24, 0xc1, 0x5e, 0x97, + 0xda, 0x06, 0xb2, 0x1d, 0xca, 0x90, 0xdf, 0x99, 0x81, 0x4f, 0x4d, 0x93, 0x04, 0x98, 0xc9, 0x07, + 0x20, 0x3f, 0xf0, 0x89, 0xdb, 0x83, 0x96, 0xe5, 0x23, 0x4a, 0x15, 0xa9, 0x2a, 0xd5, 0xb2, 0x46, + 0x8e, 0xfb, 0x4e, 0x23, 0x97, 0xfc, 0x19, 0x78, 0xd7, 0x24, 0x18, 0x23, 0x93, 0x1f, 0xa8, 0xe7, + 0x58, 0x4a, 0x92, 0x63, 0xda, 0xca, 0xf3, 0x7d, 0xa5, 0x30, 0x85, 0xee, 0xa8, 0xa5, 0x2e, 0x85, + 0x55, 0x23, 0x3f, 0xb7, 0x3b, 0x96, 0x7c, 0x05, 0x76, 0xe6, 0x3d, 0xf6, 0x60, 0x54, 0x97, 0xa7, + 0x49, 0x85, 0x69, 0xaa, 0xcf, 0xf7, 0x95, 0xbd, 0x28, 0xcd, 0x8b, 0x30, 0xd5, 0xd8, 0x76, 0x56, + 0xbb, 0xee, 0x58, 0x32, 0x06, 0x79, 0x5f, 0x1c, 0xaa, 0x37, 0x40, 0x48, 0x49, 0x57, 0x53, 0xb5, + 0x5c, 0xb3, 0xa8, 0x09, 0xa5, 0xb8, 0xde, 0x9a, 0xd0, 0x5b, 0x3b, 0x23, 0x0e, 0x6e, 0x1f, 0xdf, + 0xde, 0x57, 0x12, 0xbf, 0xfc, 0x55, 0xa9, 0xd9, 0x0e, 0x1b, 0x06, 0x7d, 0xcd, 0x24, 0xae, 0x90, + 0x55, 0xfc, 0xd5, 0xa9, 0xf5, 0xb5, 0xce, 0xa6, 0x1e, 0xa2, 0xe1, 0x06, 0x6a, 0xe4, 0xe2, 0x02, + 0xe7, 0x08, 0xb5, 0x8a, 0xdf, 0x5f, 0x57, 0x12, 0xff, 0x5e, 0x57, 0x12, 0xdf, 0x3d, 0xdd, 0x1c, + 0x2d, 0x51, 0xa6, 0x5a, 0xe0, 0xc3, 0x4d, 0x14, 0x1b, 0x88, 0x7a, 0x04, 0x53, 0x24, 0xef, 0x03, + 0x60, 0x0e, 0x21, 0xc6, 0x68, 0xc4, 0x4f, 0x1f, 0x11, 0x9d, 0x15, 0x9e, 0x8e, 0x25, 0xef, 0x82, + 0x2d, 0x8f, 0xf8, 0x6c, 0x46, 0xb0, 0x91, 0xe1, 0x66, 0xc7, 0x6a, 0xa5, 0x79, 0x69, 0xf5, 0xd7, + 0x24, 0xc8, 0x75, 0xa9, 0x7d, 0x19, 0xf4, 0x5d, 0x87, 0x5d, 0x4d, 0x5e, 0x23, 0x5c, 0x73, 0x1d, + 0xf3, 0x51, 0xfe, 0x17, 0x79, 0xfd, 0x60, 0x55, 0xec, 0x50, 0xa5, 0x15, 0x49, 0x6b, 0x20, 0xed, + 0x52, 0x9b, 0x0a, 0xd2, 0x0b, 0x5a, 0x74, 0x8b, 0xb5, 0xf8, 0x16, 0x6b, 0xa7, 0x78, 0x6a, 0x84, + 0x08, 0x59, 0x06, 0x69, 0x17, 0xb9, 0x44, 0x79, 0x13, 0x66, 0x09, 0xd7, 0xb2, 0x02, 0xb6, 0x98, + 0xe3, 0x22, 0x12, 0x30, 0x25, 0x53, 0x95, 0x6a, 0x69, 0x23, 0x36, 0xe5, 0x63, 0x90, 0xe2, 0x5a, + 0x6e, 0x55, 0xa5, 0x5a, 0xae, 0xa9, 0x68, 0xf1, 0xa0, 0x2f, 0x4c, 0x80, 0x76, 0x8e, 0x50, 0x3b, + 0xcd, 0xa5, 0x34, 0x38, 0x74, 0x93, 0x2c, 0x17, 0x60, 0x7b, 0x81, 0xaf, 0x99, 0x0a, 0x15, 0x90, + 0xa3, 0xe8, 0x9b, 0x00, 0x61, 0x13, 0xc5, 0x32, 0xa4, 0x0d, 0x10, 0xbb, 0x3a, 0x16, 0x6f, 0x4f, + 0x88, 0x22, 0x78, 0x8a, 0x4d, 0xf5, 0x77, 0x09, 0xbc, 0xd7, 0xa5, 0xf6, 0x97, 0x9e, 0x05, 0x19, + 0xba, 0x08, 0xc7, 0x4c, 0x3e, 0x01, 0x59, 0x18, 0xb0, 0x21, 0xf1, 0x1d, 0x36, 0x8d, 0x34, 0x68, + 0x2b, 0x7f, 0xfc, 0x56, 0x2f, 0x88, 0x7b, 0x28, 0xa4, 0xb8, 0x64, 0xbe, 0x83, 0x6d, 0x63, 0x0e, + 0x95, 0xcf, 0x40, 0x26, 0x1a, 0xd4, 0xb0, 0x48, 0xae, 0x59, 0xd5, 0xd6, 0x3d, 0x6b, 0x5a, 0x54, + 0xa9, 0x9d, 0xe5, 0xa7, 0xfe, 0xf9, 0xe9, 0xe6, 0x48, 0x32, 0xc4, 0xd6, 0xd6, 0x31, 0x3f, 0xf5, + 0x3c, 0xe9, 0x0f, 0x4f, 0x37, 0x47, 0xfb, 0xcb, 0xef, 0xc1, 0x4a, 0xbb, 0x6a, 0x11, 0xec, 0xae, + 0xb8, 0x62, 0x62, 0x9a, 0xff, 0x25, 0x41, 0xaa, 0x4b, 0x6d, 0xf9, 0x27, 0x09, 0x14, 0xd7, 0xbf, + 0x17, 0x27, 0xeb, 0xfb, 0xdc, 0x34, 0x04, 0xa5, 0xcf, 0xdf, 0x6e, 0x5f, 0xdc, 0x9d, 0x9a, 0x90, + 0xfb, 0xe0, 0x9d, 0xd9, 0xe5, 0x3f, 0xdc, 0x98, 0x2d, 0x86, 0x95, 0xea, 0xaf, 0x82, 0x2d, 0xd4, + 0x18, 0x81, 0xfc, 0x92, 0xba, 0x1f, 0x6d, 0x4c, 0xb0, 0x08, 0x2d, 0x35, 0x5e, 0x0d, 0x8d, 0xeb, + 0x95, 0xde, 0x7c, 0xcb, 0xd5, 0x6c, 0x7f, 0x71, 0xfb, 0x50, 0x96, 0xee, 0x1e, 0xca, 0xd2, 0xdf, + 0x0f, 0x65, 0xe9, 0xc7, 0xc7, 0x72, 0xe2, 0xee, 0xb1, 0x9c, 0xf8, 0xf3, 0xb1, 0x9c, 0xf8, 0xea, + 0xd3, 0x85, 0xb7, 0x4a, 0x64, 0xaf, 0x13, 0xdf, 0x8e, 0xd7, 0xfa, 0xf8, 0x13, 0x7d, 0xb2, 0xf2, + 0x01, 0x08, 0x1f, 0xb0, 0x7e, 0x26, 0x1c, 0xc5, 0x8f, 0xff, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xd9, + 0x95, 0xf0, 0x9e, 0x4f, 0x07, 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 { + RegisterInterchainAccount(ctx context.Context, in *MsgRegisterInterchainAccount, opts ...grpc.CallOption) (*MsgRegisterInterchainAccountResponse, error) + SubmitTx(ctx context.Context, in *MsgSubmitTx, opts ...grpc.CallOption) (*MsgSubmitTxResponse, error) + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) RegisterInterchainAccount(ctx context.Context, in *MsgRegisterInterchainAccount, opts ...grpc.CallOption) (*MsgRegisterInterchainAccountResponse, error) { + out := new(MsgRegisterInterchainAccountResponse) + err := c.cc.Invoke(ctx, "/neutron.interchaintxs.v1.Msg/RegisterInterchainAccount", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) SubmitTx(ctx context.Context, in *MsgSubmitTx, opts ...grpc.CallOption) (*MsgSubmitTxResponse, error) { + out := new(MsgSubmitTxResponse) + err := c.cc.Invoke(ctx, "/neutron.interchaintxs.v1.Msg/SubmitTx", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/neutron.interchaintxs.v1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + RegisterInterchainAccount(context.Context, *MsgRegisterInterchainAccount) (*MsgRegisterInterchainAccountResponse, error) + SubmitTx(context.Context, *MsgSubmitTx) (*MsgSubmitTxResponse, error) + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) RegisterInterchainAccount(ctx context.Context, req *MsgRegisterInterchainAccount) (*MsgRegisterInterchainAccountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterInterchainAccount not implemented") +} +func (*UnimplementedMsgServer) SubmitTx(ctx context.Context, req *MsgSubmitTx) (*MsgSubmitTxResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SubmitTx not implemented") +} +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_RegisterInterchainAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRegisterInterchainAccount) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RegisterInterchainAccount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchaintxs.v1.Msg/RegisterInterchainAccount", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RegisterInterchainAccount(ctx, req.(*MsgRegisterInterchainAccount)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_SubmitTx_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSubmitTx) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SubmitTx(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchaintxs.v1.Msg/SubmitTx", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SubmitTx(ctx, req.(*MsgSubmitTx)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.interchaintxs.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.interchaintxs.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterInterchainAccount", + Handler: _Msg_RegisterInterchainAccount_Handler, + }, + { + MethodName: "SubmitTx", + Handler: _Msg_SubmitTx_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/interchaintxs/v1/tx.proto", +} + +func (m *MsgRegisterInterchainAccount) 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 *MsgRegisterInterchainAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterInterchainAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.RegisterFee) > 0 { + for iNdEx := len(m.RegisterFee) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RegisterFee[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.InterchainAccountId) > 0 { + i -= len(m.InterchainAccountId) + copy(dAtA[i:], m.InterchainAccountId) + i = encodeVarintTx(dAtA, i, uint64(len(m.InterchainAccountId))) + i-- + dAtA[i] = 0x1a + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x12 + } + if len(m.FromAddress) > 0 { + i -= len(m.FromAddress) + copy(dAtA[i:], m.FromAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterInterchainAccountResponse) 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 *MsgRegisterInterchainAccountResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterInterchainAccountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintTx(dAtA, i, uint64(len(m.PortId))) + 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 *MsgSubmitTx) 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 *MsgSubmitTx) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitTx) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + if m.Timeout != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Timeout)) + i-- + dAtA[i] = 0x30 + } + 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] = 0x2a + } + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.ConnectionId) > 0 { + i -= len(m.ConnectionId) + copy(dAtA[i:], m.ConnectionId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ConnectionId))) + i-- + dAtA[i] = 0x1a + } + if len(m.InterchainAccountId) > 0 { + i -= len(m.InterchainAccountId) + copy(dAtA[i:], m.InterchainAccountId) + i = encodeVarintTx(dAtA, i, uint64(len(m.InterchainAccountId))) + i-- + dAtA[i] = 0x12 + } + if len(m.FromAddress) > 0 { + i -= len(m.FromAddress) + copy(dAtA[i:], m.FromAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSubmitTxResponse) 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 *MsgSubmitTxResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitTxResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Channel) > 0 { + i -= len(m.Channel) + copy(dAtA[i:], m.Channel) + i = encodeVarintTx(dAtA, i, uint64(len(m.Channel))) + i-- + dAtA[i] = 0x12 + } + if m.SequenceId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.SequenceId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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 *MsgRegisterInterchainAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FromAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.InterchainAccountId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.RegisterFee) > 0 { + for _, e := range m.RegisterFee { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgRegisterInterchainAccountResponse) 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.PortId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSubmitTx) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FromAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.InterchainAccountId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ConnectionId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Timeout != 0 { + n += 1 + sovTx(uint64(m.Timeout)) + } + l = m.Fee.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgSubmitTxResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SequenceId != 0 { + n += 1 + sovTx(uint64(m.SequenceId)) + } + l = len(m.Channel) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + 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 *MsgRegisterInterchainAccount) 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: MsgRegisterInterchainAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterInterchainAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", 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.FromAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", 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.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InterchainAccountId", 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.InterchainAccountId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RegisterFee", 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.RegisterFee = append(m.RegisterFee, types.Coin{}) + if err := m.RegisterFee[len(m.RegisterFee)-1].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 *MsgRegisterInterchainAccountResponse) 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: MsgRegisterInterchainAccountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterInterchainAccountResponse: 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 PortId", 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.PortId = 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 *MsgSubmitTx) 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: MsgSubmitTx: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitTx: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", 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.FromAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InterchainAccountId", 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.InterchainAccountId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConnectionId", 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.ConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", 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.Msgs = append(m.Msgs, &types1.Any{}) + if err := m.Msgs[len(m.Msgs)-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 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 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Timeout", wireType) + } + m.Timeout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Timeout |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Fee", 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.Fee.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 *MsgSubmitTxResponse) 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: MsgSubmitTxResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitTxResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SequenceId", wireType) + } + m.SequenceId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SequenceId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channel", 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.Channel = 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 *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 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.Params.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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 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/x/interchaintxs/types/tx_test.go b/x/interchaintxs/types/tx_test.go new file mode 100644 index 00000000..062fe332 --- /dev/null +++ b/x/interchaintxs/types/tx_test.go @@ -0,0 +1,65 @@ +package types_test + +import ( + "testing" + + cosmosTypes "github.com/cosmos/cosmos-sdk/codec/types" + sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +const TestAddress = "neutron1m9l358xunhhwds0568za49mzhvuxx9ux8xafx2" + +func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { + tests := []struct { + name string + malleate func() sdktypes.LegacyMsg + }{ + { + "valid_signer", + func() sdktypes.LegacyMsg { + return &types.MsgRegisterInterchainAccount{ + FromAddress: TestAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + } + }, + }, + } + + for _, tt := range tests { + msg := tt.malleate() + addr, _ := sdktypes.AccAddressFromBech32(TestAddress) + require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + } +} + +func TestMsgSubmitTXGetSigners(t *testing.T) { + tests := []struct { + name string + malleate func() sdktypes.LegacyMsg + }{ + { + "valid_signer", + func() sdktypes.LegacyMsg { + return &types.MsgSubmitTx{ + FromAddress: TestAddress, + ConnectionId: "connection-id", + InterchainAccountId: "1", + Msgs: []*cosmosTypes.Any{{ + TypeUrl: "msg", + Value: []byte{100}, // just check that values are not nil + }}, + } + }, + }, + } + + for _, tt := range tests { + msg := tt.malleate() + addr, _ := sdktypes.AccAddressFromBech32(TestAddress) + require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + } +} diff --git a/x/interchaintxs/types/types.go b/x/interchaintxs/types/types.go new file mode 100644 index 00000000..47a918e7 --- /dev/null +++ b/x/interchaintxs/types/types.go @@ -0,0 +1,59 @@ +package types + +import ( + "strings" + + "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" +) + +const Delimiter = "." + +type ICAOwner struct { + contractAddress sdk.AccAddress + interchainAccountID string +} + +func (i ICAOwner) String() string { + return i.contractAddress.String() + Delimiter + i.interchainAccountID +} + +func NewICAOwner(contractAddressBech32, interchainAccountID string) (ICAOwner, error) { + sdkContractAddress, err := sdk.AccAddressFromBech32(contractAddressBech32) + if err != nil { + return ICAOwner{}, errors.Wrapf(ErrInvalidAccountAddress, "failed to decode address from bech32: %v", err) + } + + return ICAOwner{contractAddress: sdkContractAddress, interchainAccountID: interchainAccountID}, nil +} + +func NewICAOwnerFromAddress(address sdk.AccAddress, interchainAccountID string) ICAOwner { + return ICAOwner{contractAddress: address, interchainAccountID: interchainAccountID} +} + +func ICAOwnerFromPort(port string) (ICAOwner, error) { + splitOwner := strings.SplitN(strings.TrimPrefix(port, icatypes.ControllerPortPrefix), Delimiter, 2) + if len(splitOwner) < 2 { + return ICAOwner{}, errors.Wrap(ErrInvalidICAOwner, "invalid ICA interchainAccountID format") + } + + contractAddress, err := sdk.AccAddressFromBech32(splitOwner[0]) + if err != nil { + return ICAOwner{}, errors.Wrapf(ErrInvalidAccountAddress, "failed to decode address from bech32: %v", err) + } + + return ICAOwner{contractAddress: contractAddress, interchainAccountID: splitOwner[1]}, nil +} + +func (i ICAOwner) GetContract() sdk.AccAddress { + return i.contractAddress +} + +func (i ICAOwner) GetInterchainAccountID() string { + return i.interchainAccountID +} + +// GetFeeCollectorAddr is a function to return the current fee collector address +type GetFeeCollectorAddr func(ctx sdk.Context) string diff --git a/x/interchaintxs/types/types_test.go b/x/interchaintxs/types/types_test.go new file mode 100644 index 00000000..731a736e --- /dev/null +++ b/x/interchaintxs/types/types_test.go @@ -0,0 +1,80 @@ +package types_test + +import ( + "testing" + + "github.com/Nolus-Protocol/nolus-core/app/params" + + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +const ( + ICAId = "id_1" + ContractAddr = "nolus17dtl0mjt3t77kpuhg2edqzjpszulwhgzcdvagh" +) + +func TestICAOwner(t *testing.T) { + var ( + contractAddress string + interchainAccountID string + ) + + cfg := params.GetDefaultConfig() + cfg.Seal() + + for _, tc := range []struct { + desc string + malleate func() (types.ICAOwner, error) + expectedStringRepresentation string + expectedErr error + }{ + { + desc: "valid", + expectedErr: nil, + expectedStringRepresentation: ContractAddr + types.Delimiter + ICAId, + malleate: func() (types.ICAOwner, error) { + contractAddress = ContractAddr + interchainAccountID = ICAId + return types.NewICAOwner(contractAddress, interchainAccountID) + }, + }, + { + desc: "Delimiter in the middle of the interchain account id", + expectedErr: nil, + expectedStringRepresentation: ContractAddr + types.Delimiter + + (ICAId + types.Delimiter + "another_data"), + malleate: func() (types.ICAOwner, error) { + contractAddress = ContractAddr + interchainAccountID = ICAId + types.Delimiter + "another_data" + + portID := contractAddress + types.Delimiter + interchainAccountID + + return types.ICAOwnerFromPort(portID) + }, + }, + { + desc: "invalid", + expectedErr: types.ErrInvalidAccountAddress, + malleate: func() (types.ICAOwner, error) { + contractAddress = "invalid_account_address" + interchainAccountID = ICAId + return types.NewICAOwner(contractAddress, interchainAccountID) + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + icaOwner, err := tc.malleate() + if tc.expectedErr == nil { + require.NoError(t, err) + require.Equal(t, contractAddress, icaOwner.GetContract().String()) + require.Equal(t, interchainAccountID, icaOwner.GetInterchainAccountID()) + require.Equal(t, tc.expectedStringRepresentation, icaOwner.String()) + } else { + require.Error(t, err) + require.ErrorIs(t, tc.expectedErr, err) + } + }) + } +} diff --git a/x/transfer/ibc_handlers.go b/x/transfer/ibc_handlers.go new file mode 100644 index 00000000..5e134bfc --- /dev/null +++ b/x/transfer/ibc_handlers.go @@ -0,0 +1,79 @@ +package transfer + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + feetypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" +) + +// HandleAcknowledgement passes the acknowledgement data to the appropriate contract via a sudo call. +func (im IBCModule) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { + var ack channeltypes.Acknowledgement + if err := channeltypes.SubModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { + return errors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) + } + var data transfertypes.FungibleTokenPacketData + if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { + return errors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + } + + senderAddress, err := sdk.AccAddressFromBech32(data.GetSender()) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to decode address from bech32: %v", err) + } + if !im.sudoKeeper.HasContractInfo(ctx, senderAddress) { + return nil + } + + im.wrappedKeeper.FeeKeeper.DistributeAcknowledgementFee(ctx, relayer, feetypes.NewPacketID(packet.SourcePort, packet.SourceChannel, packet.Sequence)) + + msg, err := keeper.PrepareSudoCallbackMessage(packet, &ack) + if err != nil { + return errors.Wrapf(sdkerrors.ErrJSONMarshal, "failed to marshal Packet/Acknowledgment: %v", err) + } + + _, err = im.sudoKeeper.Sudo(ctx, senderAddress, msg) + if err != nil { + im.keeper.Logger(ctx).Debug("HandleAcknowledgement: failed to Sudo contract on packet acknowledgement", "error", err) + } + + im.keeper.Logger(ctx).Debug("acknowledgement received", "Packet data", data, "CheckTx", ctx.IsCheckTx()) + + return nil +} + +// HandleTimeout passes the timeout data to the appropriate contract via a sudo call. +func (im IBCModule) HandleTimeout(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error { + var data transfertypes.FungibleTokenPacketData + if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { + return errors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + } + + senderAddress, err := sdk.AccAddressFromBech32(data.GetSender()) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to decode address from bech32: %v", err) + } + if !im.sudoKeeper.HasContractInfo(ctx, senderAddress) { + return nil + } + + msg, err := keeper.PrepareSudoCallbackMessage(packet, nil) + if err != nil { + return errors.Wrapf(sdkerrors.ErrJSONMarshal, "failed to marshal Packet: %v", err) + } + + im.wrappedKeeper.FeeKeeper.DistributeTimeoutFee(ctx, relayer, feetypes.NewPacketID(packet.SourcePort, packet.SourceChannel, packet.Sequence)) + + _, err = im.sudoKeeper.Sudo(ctx, senderAddress, msg) + if err != nil { + im.keeper.Logger(ctx).Debug("HandleAcknowledgement: failed to Sudo contract on packet timeout", "error", err) + } + + return nil +} diff --git a/x/transfer/ibc_handlers_test.go b/x/transfer/ibc_handlers_test.go new file mode 100644 index 00000000..18a12371 --- /dev/null +++ b/x/transfer/ibc_handlers_test.go @@ -0,0 +1,180 @@ +package transfer_test + +import ( + "fmt" + "testing" + + types2 "cosmossdk.io/store/types" + + "github.com/Nolus-Protocol/nolus-core/x/contractmanager/keeper" + + sdk "github.com/cosmos/cosmos-sdk/types" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/Nolus-Protocol/nolus-core/testutil" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/transfer/types" + testkeeper "github.com/Nolus-Protocol/nolus-core/testutil/transfer/keeper" + feetypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + ictxtypes "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types" + "github.com/Nolus-Protocol/nolus-core/x/transfer" +) + +const TestCosmosAddress = "cosmos10h9stc5v6ntgeygf5xf945njqq5h32r53uquvw" + +func TestHandleAcknowledgement(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + feeKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl) + chanKeeper := mock_types.NewMockChannelKeeper(ctrl) + authKeeper := mock_types.NewMockAccountKeeper(ctrl) + // required to initialize keeper + authKeeper.EXPECT().GetModuleAddress(transfertypes.ModuleName).Return([]byte("address")) + txKeeper, infCtx, _ := testkeeper.TransferKeeper(t, wmKeeper, feeKeeper, chanKeeper, authKeeper) + txModule := transfer.NewIBCModule(*txKeeper, wmKeeper) + ctx := infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + + resACK := channeltypes.Acknowledgement{ + Response: &channeltypes.Acknowledgement_Result{Result: []byte("Result")}, + } + resAckData, err := channeltypes.SubModuleCdc.MarshalJSON(&resACK) + require.NoError(t, err) + p := channeltypes.Packet{ + Sequence: 100, + SourcePort: "transfer", + SourceChannel: "channel-0", + } + + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + relayerBech32 := "neutron1fxudpred77a0grgh69u0j7y84yks5ev4n5050z45kecz792jnd6scqu98z" + relayerAddress := sdk.MustAccAddressFromBech32(relayerBech32) + + err = txModule.HandleAcknowledgement(ctx, channeltypes.Packet{}, nil, relayerAddress) + require.ErrorContains(t, err, "cannot unmarshal ICS-20 transfer packet acknowledgement") + + err = txModule.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) + require.ErrorContains(t, err, "cannot unmarshal ICS-20 transfer packet data") + + token := transfertypes.FungibleTokenPacketData{ + Denom: "stake", + Amount: "1000", + Sender: "nonbech32", + Receiver: TestCosmosAddress, + } + tokenBz, err := ictxtypes.ModuleCdc.MarshalJSON(&token) + require.NoError(t, err) + p.Data = tokenBz + + err = txModule.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) + require.ErrorContains(t, err, "failed to decode address from bech32") + + token = transfertypes.FungibleTokenPacketData{ + Denom: "stake", + Amount: "1000", + Sender: testutil.TestOwnerAddress, + Receiver: TestCosmosAddress, + } + tokenBz, err = ictxtypes.ModuleCdc.MarshalJSON(&token) + require.NoError(t, err) + p.Data = tokenBz + + msgAck, err := keeper.PrepareSudoCallbackMessage(p, &resACK) + require.NoError(t, err) + + // non contract + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + wmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(false) + err = txModule.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) + require.NoError(t, err) + + // error during Sudo contract + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + wmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) + feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msgAck).Return(nil, fmt.Errorf("SudoResponse error")) + err = txModule.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) + require.NoError(t, err) + + // success during Sudo contract + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + wmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) + feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msgAck) + err = txModule.HandleAcknowledgement(ctx, p, resAckData, relayerAddress) + require.NoError(t, err) +} + +func TestHandleTimeout(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + feeKeeper := mock_types.NewMockFeeRefunderKeeper(ctrl) + chanKeeper := mock_types.NewMockChannelKeeper(ctrl) + authKeeper := mock_types.NewMockAccountKeeper(ctrl) + // required to initialize keeper + authKeeper.EXPECT().GetModuleAddress(transfertypes.ModuleName).Return([]byte("address")) + txKeeper, infCtx, _ := testkeeper.TransferKeeper(t, wmKeeper, feeKeeper, chanKeeper, authKeeper) + txModule := transfer.NewIBCModule(*txKeeper, wmKeeper) + ctx := infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + contractAddress := sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress) + relayerBech32 := "neutron1fxudpred77a0grgh69u0j7y84yks5ev4n5050z45kecz792jnd6scqu98z" + relayerAddress := sdk.MustAccAddressFromBech32(relayerBech32) + p := channeltypes.Packet{ + Sequence: 100, + SourcePort: "transfer", + SourceChannel: "channel-0", + } + + err := txModule.HandleTimeout(ctx, channeltypes.Packet{}, relayerAddress) + require.ErrorContains(t, err, "cannot unmarshal ICS-20 transfer packet data") + + token := transfertypes.FungibleTokenPacketData{ + Denom: "stake", + Amount: "1000", + Sender: "nonbech32", + Receiver: TestCosmosAddress, + } + tokenBz, err := ictxtypes.ModuleCdc.MarshalJSON(&token) + require.NoError(t, err) + p.Data = tokenBz + err = txModule.HandleTimeout(ctx, p, relayerAddress) + require.ErrorContains(t, err, "failed to decode address from bech32") + + token = transfertypes.FungibleTokenPacketData{ + Denom: "stake", + Amount: "1000", + Sender: testutil.TestOwnerAddress, + Receiver: TestCosmosAddress, + } + tokenBz, err = ictxtypes.ModuleCdc.MarshalJSON(&token) + require.NoError(t, err) + p.Data = tokenBz + + msg, err := keeper.PrepareSudoCallbackMessage(p, nil) + require.NoError(t, err) + + // success non contract + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + wmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(false) + err = txModule.HandleTimeout(ctx, p, relayerAddress) + require.NoError(t, err) + + // success contract + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + wmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) + feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msg).Return(nil, nil) + err = txModule.HandleTimeout(ctx, p, relayerAddress) + require.NoError(t, err) + + // error during SudoTimeOut contract + ctx = infCtx.WithGasMeter(types2.NewGasMeter(1_000_000_000_000)) + wmKeeper.EXPECT().HasContractInfo(ctx, sdk.MustAccAddressFromBech32(testutil.TestOwnerAddress)).Return(true) + feeKeeper.EXPECT().DistributeTimeoutFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) + wmKeeper.EXPECT().Sudo(ctx, contractAddress, msg).Return(nil, fmt.Errorf("SudoTimeout error")) + err = txModule.HandleTimeout(ctx, p, relayerAddress) + require.NoError(t, err) +} diff --git a/x/transfer/keeper/keeper.go b/x/transfer/keeper/keeper.go new file mode 100644 index 00000000..c4753d9d --- /dev/null +++ b/x/transfer/keeper/keeper.go @@ -0,0 +1,100 @@ +package transfer + +import ( + "context" + + "cosmossdk.io/errors" + storetypes "cosmossdk.io/store/types" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" + + feetypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + wrappedtypes "github.com/Nolus-Protocol/nolus-core/x/transfer/types" +) + +// KeeperTransferWrapper is a wrapper for original ibc keeper to override response for "Transfer" method +type KeeperTransferWrapper struct { + keeper.Keeper + channelKeeper wrappedtypes.ChannelKeeper + FeeKeeper wrappedtypes.FeeRefunderKeeper + SudoKeeper wrappedtypes.WasmKeeper +} + +func (k KeeperTransferWrapper) Transfer(goCtx context.Context, msg *wrappedtypes.MsgTransfer) (*wrappedtypes.MsgTransferResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + k.Logger(ctx).Debug("Transfer: failed to parse sender address", "sender", msg.Sender) + return nil, errors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse address: %s", msg.Sender) + } + + isContract := k.SudoKeeper.HasContractInfo(ctx, senderAddr) + + if err := msg.Validate(isContract); err != nil { + return nil, errors.Wrap(err, "failed to validate MsgTransfer") + } + + sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, msg.SourcePort, msg.SourceChannel) + if !found { + return nil, errors.Wrapf( + channeltypes.ErrSequenceSendNotFound, + "source port: %s, source channel: %s", msg.SourcePort, msg.SourceChannel, + ) + } + + // if the sender is a contract, lock fees. + // Because contracts are required to pay fees for the acknowledgements + if isContract { + if err := k.FeeKeeper.LockFees(ctx, senderAddr, feetypes.NewPacketID(msg.SourcePort, msg.SourceChannel, sequence), msg.Fee); err != nil { + return nil, errors.Wrapf(err, "failed to lock fees to pay for transfer msg: %v", msg) + } + } + + transferMsg := types.NewMsgTransfer(msg.SourcePort, msg.SourceChannel, msg.Token, msg.Sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, msg.Memo) + if _, err := k.Keeper.Transfer(goCtx, transferMsg); err != nil { + return nil, err + } + + return &wrappedtypes.MsgTransferResponse{ + SequenceId: sequence, + Channel: msg.SourceChannel, + }, nil +} + +func (k KeeperTransferWrapper) UpdateParams(goCtx context.Context, msg *wrappedtypes.MsgUpdateParams) (*wrappedtypes.MsgUpdateParamsResponse, error) { + newMsg := &types.MsgUpdateParams{ + Signer: msg.Signer, + Params: msg.Params, + } + if _, err := k.Keeper.UpdateParams(goCtx, newMsg); err != nil { + return nil, err + } + + return &wrappedtypes.MsgUpdateParamsResponse{}, nil +} + +// NewKeeper creates a new IBC transfer Keeper(KeeperTransferWrapper) instance +func NewKeeper( + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, + ics4Wrapper porttypes.ICS4Wrapper, channelKeeper wrappedtypes.ChannelKeeper, portKeeper types.PortKeeper, + authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, + feeKeeper wrappedtypes.FeeRefunderKeeper, + sudoKeeper wrappedtypes.WasmKeeper, authority string, +) KeeperTransferWrapper { + return KeeperTransferWrapper{ + channelKeeper: channelKeeper, + Keeper: keeper.NewKeeper(cdc, key, paramSpace, ics4Wrapper, channelKeeper, portKeeper, + authKeeper, bankKeeper, scopedKeeper, authority), + FeeKeeper: feeKeeper, + SudoKeeper: sudoKeeper, + } +} diff --git a/x/transfer/keeper/keeper_test.go b/x/transfer/keeper/keeper_test.go new file mode 100644 index 00000000..15caca54 --- /dev/null +++ b/x/transfer/keeper/keeper_test.go @@ -0,0 +1,597 @@ +package transfer_test + +import ( + "testing" + + "cosmossdk.io/math" + sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v8/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/Nolus-Protocol/nolus-core/app/params" + "github.com/Nolus-Protocol/nolus-core/testutil" + mock_types "github.com/Nolus-Protocol/nolus-core/testutil/mocks/transfer/types" + "github.com/Nolus-Protocol/nolus-core/testutil/transfer/keeper" + feetypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + "github.com/Nolus-Protocol/nolus-core/x/transfer/types" +) + +const ( + TestAddress = "cosmos10h9stc5v6ntgeygf5xf945njqq5h32r53uquvw" + + reflectContractPath = "../../../wasmbinding/testdata/reflect.wasm" +) + +type KeeperTestSuite struct { + testutil.IBCConnectionTestSuite +} + +func (suite KeeperTestSuite) TestTransfer() { //nolint:govet // it's a test so it's okay to copy locks + suite.ConfigureTransferChannel() + + msgSrv := suite.GetNeutronZoneApp(suite.ChainA).TransferKeeper + + ctx := suite.ChainA.GetContext() + resp, err := msgSrv.Transfer(ctx, &types.MsgTransfer{ + Sender: "nonbech32", + }) + suite.Nil(resp) + suite.ErrorIs(err, errors.ErrInvalidAddress) + + ctx = suite.ChainA.GetContext() + resp, err = msgSrv.Transfer(ctx, &types.MsgTransfer{ + SourcePort: "nonexistent_port", + SourceChannel: suite.TransferPath.EndpointA.ChannelID, + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + TimeoutHeight: clienttypes.Height{ + RevisionNumber: 10, + RevisionHeight: 10000, + }, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + }, + }) + suite.Nil(resp) + suite.ErrorIs(err, channeltypes.ErrSequenceSendNotFound) + + // sender is a non contract account + ctx = suite.ChainA.GetContext() + resp, err = msgSrv.Transfer(ctx, &types.MsgTransfer{ + SourcePort: suite.TransferPath.EndpointA.ChannelConfig.PortID, + SourceChannel: suite.TransferPath.EndpointA.ChannelID, + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + TimeoutHeight: clienttypes.Height{ + RevisionNumber: 10, + RevisionHeight: 10000, + }, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + }, + }) + suite.Nil(resp) + suite.ErrorIs(err, errors.ErrInsufficientFunds) + + // sender is a non contract account + senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress() + suite.TopUpWallet(ctx, senderAddress, sdktypes.MustAccAddressFromBech32(testutil.TestOwnerAddress)) + ctx = suite.ChainA.GetContext() + resp, err = msgSrv.Transfer(ctx, &types.MsgTransfer{ + SourcePort: suite.TransferPath.EndpointA.ChannelConfig.PortID, + SourceChannel: suite.TransferPath.EndpointA.ChannelID, + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + TimeoutHeight: clienttypes.Height{ + RevisionNumber: 10, + RevisionHeight: 10000, + }, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + }, + }) + suite.Equal(types.MsgTransferResponse{ + SequenceId: 1, + Channel: suite.TransferPath.EndpointA.ChannelID, + }, *resp) + suite.NoError(err) + + testOwner := sdktypes.MustAccAddressFromBech32(testutil.TestOwnerAddress) + + // Store code and instantiate reflect contract. + codeID := suite.StoreTestCode(ctx, testOwner, reflectContractPath) + contractAddress := suite.InstantiateTestContract(ctx, testOwner, codeID) + suite.Require().NotEmpty(contractAddress) + + ctx = suite.ChainA.GetContext() + resp, err = msgSrv.Transfer(ctx, &types.MsgTransfer{ + SourcePort: suite.TransferPath.EndpointA.ChannelConfig.PortID, + SourceChannel: suite.TransferPath.EndpointA.ChannelID, + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000)), + Sender: contractAddress.String(), + Receiver: TestAddress, + TimeoutHeight: clienttypes.Height{ + RevisionNumber: 10, + RevisionHeight: 10000, + }, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + }, + }) + suite.Nil(resp) + suite.ErrorContains(err, "failed to lock fees") + + suite.TopUpWallet(ctx, senderAddress, contractAddress) + ctx = suite.ChainA.GetContext() + resp, err = msgSrv.Transfer(ctx, &types.MsgTransfer{ + SourcePort: suite.TransferPath.EndpointA.ChannelConfig.PortID, + SourceChannel: suite.TransferPath.EndpointA.ChannelID, + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000)), + Sender: contractAddress.String(), + Receiver: TestAddress, + TimeoutHeight: clienttypes.Height{ + RevisionNumber: 10, + RevisionHeight: 10000, + }, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(1000))), + }, + }) + suite.Equal(types.MsgTransferResponse{ + SequenceId: 2, + Channel: suite.TransferPath.EndpointA.ChannelID, + }, *resp) + suite.NoError(err) +} + +func (suite *KeeperTestSuite) TopUpWallet(ctx sdktypes.Context, sender, contractAddress sdktypes.AccAddress) { + coinsAmnt := sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(int64(1_000_000)))) + bankKeeper := suite.GetNeutronZoneApp(suite.ChainA).BankKeeper + err := bankKeeper.SendCoins(ctx, sender, contractAddress, coinsAmnt) + suite.Require().NoError(err) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +func TestMsgTransferValidate(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + authKeeper := mock_types.NewMockAccountKeeper(ctrl) + wmKeeper := mock_types.NewMockWasmKeeper(ctrl) + // required to initialize keeper + authKeeper.EXPECT().GetModuleAddress(transfertypes.ModuleName).Return([]byte("address")) + k, ctx, _ := keeper.TransferKeeper(t, wmKeeper, nil, nil, authKeeper) + + wmKeeper.EXPECT().HasContractInfo(ctx, gomock.Any()).Return(true).AnyTimes() + + tests := []struct { + name string + msg types.MsgTransfer + expectedErr error + }{ + { + "invalid ack fee", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.Coins{ + { + Denom: "{}!@#a", + Amount: math.NewInt(100), + }, + }, + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + errors.ErrInvalidCoins, + }, + { + "invalid timeout fee", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.Coins{ + { + Denom: params.DefaultBondDenom, + Amount: math.NewInt(-100), + }, + }, + }, + }, + errors.ErrInvalidCoins, + }, + { + "non-zero recv fee", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + errors.ErrInvalidCoins, + }, + { + "zero ack fee", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: nil, + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + errors.ErrInvalidCoins, + }, + { + "zero timeout fee", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: nil, + }, + }, + errors.ErrInvalidCoins, + }, + { + "empty source port", + types.MsgTransfer{ + SourcePort: "", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "invalid source port separator", + types.MsgTransfer{ + SourcePort: "/transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "invalid source port length", + types.MsgTransfer{ + SourcePort: "t", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "invalid source port", + types.MsgTransfer{ + SourcePort: "nonexistent port", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "empty source channel", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "invalid source channel separator", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "/channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "invalid source channel length", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: string(make([]byte, host.DefaultMaxCharacterLength+1)), + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "invalid source channel", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel 2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + host.ErrInvalidID, + }, + { + "invalid token denom", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.Coin{ + Denom: "{}!@#a", + Amount: math.NewInt(100), + }, + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + ibcerrors.ErrInvalidCoins, + }, + { + "nil token amount", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.Coin{ + Denom: params.DefaultBondDenom, + }, + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + ibcerrors.ErrInvalidCoins, + }, + { + "negative token amount", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.Coin{ + Denom: params.DefaultBondDenom, + Amount: math.NewInt(-100), + }, + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + ibcerrors.ErrInvalidCoins, + }, + { + "empty sender", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: "", + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + errors.ErrInvalidAddress, + }, + { + "invalid sender", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: "invalid_sender", + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + errors.ErrInvalidAddress, + }, + { + "empty receiver", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: "", + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + ibcerrors.ErrInvalidAddress, + }, + { + "long receiver", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: string(make([]byte, transfertypes.MaximumReceiverLength+1)), + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + ibcerrors.ErrInvalidAddress, + }, + { + "long memo", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100)), + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Memo: string(make([]byte, transfertypes.MaximumMemoLength+1)), + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + transfertypes.ErrInvalidMemo, + }, + { + "invalid token denom prefix format", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.Coin{ + Denom: transfertypes.DenomPrefix, + Amount: math.NewInt(100), + }, + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + transfertypes.ErrInvalidDenomForTransfer, + }, + { + "invalid token denom prefix format with separator", + types.MsgTransfer{ + SourcePort: "transfer", + SourceChannel: "channel-2", + Token: sdktypes.Coin{ + Denom: transfertypes.DenomPrefix + "/", + Amount: math.NewInt(100), + }, + Sender: testutil.TestOwnerAddress, + Receiver: TestAddress, + Fee: feetypes.Fee{ + RecvFee: nil, + AckFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + TimeoutFee: sdktypes.NewCoins(sdktypes.NewCoin(params.DefaultBondDenom, math.NewInt(100))), + }, + }, + transfertypes.ErrInvalidDenomForTransfer, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resp, err := k.Transfer(ctx, &tt.msg) + require.ErrorIs(t, err, tt.expectedErr) + require.Nil(t, resp) + }) + } +} diff --git a/x/transfer/module.go b/x/transfer/module.go new file mode 100644 index 00000000..615ef8b0 --- /dev/null +++ b/x/transfer/module.go @@ -0,0 +1,146 @@ +package transfer + +import ( + "fmt" + + "cosmossdk.io/core/appmodule" + "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + wrapkeeper "github.com/Nolus-Protocol/nolus-core/x/transfer/keeper" + neutrontypes "github.com/Nolus-Protocol/nolus-core/x/transfer/types" +) + +/* + In addition to original ack processing of ibc transfer acknowledgement we want to pass the acknowledgement to originating wasm contract. + The package contains a code to achieve the purpose. +*/ + +type IBCModule struct { + wrappedKeeper wrapkeeper.KeeperTransferWrapper + keeper keeper.Keeper + sudoKeeper neutrontypes.WasmKeeper + transfer.IBCModule +} + +// NewIBCModule creates a new IBCModule given the keeper +func NewIBCModule(k wrapkeeper.KeeperTransferWrapper, sudoKeeper neutrontypes.WasmKeeper) IBCModule { + return IBCModule{ + wrappedKeeper: k, + keeper: k.Keeper, + sudoKeeper: sudoKeeper, + IBCModule: transfer.NewIBCModule(k.Keeper), + } +} + +// OnAcknowledgementPacket implements the IBCModule interface. +// Wrapper struct shadows(overrides) the OnAcknowledgementPacket method to achieve the package's purpose. +func (im IBCModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + err := im.IBCModule.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) + if err != nil { + return errors.Wrap(err, "failed to process original OnAcknowledgementPacket") + } + return im.HandleAcknowledgement(ctx, packet, acknowledgement, relayer) +} + +// OnTimeoutPacket implements the IBCModule interface. +func (im IBCModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) error { + err := im.IBCModule.OnTimeoutPacket(ctx, packet, relayer) + if err != nil { + return errors.Wrap(err, "failed to process original OnTimeoutPacket") + } + return im.HandleTimeout(ctx, packet, relayer) +} + +var _ appmodule.AppModule = AppModule{} + +type AppModule struct { + transfer.AppModule + keeper wrapkeeper.KeeperTransferWrapper +} + +// NewAppModule creates a new 20-transfer module +func NewAppModule(k wrapkeeper.KeeperTransferWrapper) AppModule { + return AppModule{ + AppModule: transfer.NewAppModule(k.Keeper), + keeper: k, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() { // marker +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() { // marker +} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + neutrontypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) + + cfg.MsgServer().RegisterService(&neutrontypes.MsgServiceDescOrig, am.keeper) + + m := keeper.NewMigrator(am.keeper.Keeper) + if err := cfg.RegisterMigration(types.ModuleName, 1, m.MigrateTraces); err != nil { + panic(fmt.Sprintf("failed to migrate transfer app from version 1 to 2: %v", err)) + } + + if err := cfg.RegisterMigration(types.ModuleName, 2, m.MigrateTotalEscrowForDenom); err != nil { + panic(fmt.Sprintf("failed to migrate transfer app from version 2 to 3: %v", err)) + } + + if err := cfg.RegisterMigration(types.ModuleName, 3, m.MigrateParams); err != nil { + panic(fmt.Sprintf("failed to migrate transfer app version 3 to 4: %v", err)) + } + + if err := cfg.RegisterMigration(types.ModuleName, 4, m.MigrateDenomMetadata); err != nil { + panic(fmt.Sprintf("failed to migrate transfer app from version 4 to 5: %v", err)) + } +} + +type AppModuleBasic struct { + transfer.AppModuleBasic +} + +func NewAppModuleBasic() AppModuleBasic { + return AppModuleBasic{AppModuleBasic: transfer.AppModuleBasic{}} +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + neutrontypes.RegisterLegacyAminoCodec(cdc) +} + +func (am AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + neutrontypes.RegisterLegacyAminoCodec(cdc) + am.AppModuleBasic.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (am AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + neutrontypes.RegisterInterfaces(reg) + am.AppModuleBasic.RegisterInterfaces(reg) +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} diff --git a/x/transfer/types/codec.go b/x/transfer/types/codec.go new file mode 100644 index 00000000..3e9e7a6f --- /dev/null +++ b/x/transfer/types/codec.go @@ -0,0 +1,25 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgTransfer{}, "/neutron.transfer.v1.Transfer", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgTransfer{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} diff --git a/x/transfer/types/expected_keepers.go b/x/transfer/types/expected_keepers.go new file mode 100644 index 00000000..0318f411 --- /dev/null +++ b/x/transfer/types/expected_keepers.go @@ -0,0 +1,34 @@ +package types + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + + feerefundertypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +type WasmKeeper interface { + HasContractInfo(ctx context.Context, contractAddress sdk.AccAddress) bool + Sudo(ctx context.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) +} + +type FeeRefunderKeeper interface { + LockFees(ctx context.Context, payer sdk.AccAddress, packetID feerefundertypes.PacketID, fee feerefundertypes.Fee) error + DistributeAcknowledgementFee(ctx context.Context, receiver sdk.AccAddress, packetID feerefundertypes.PacketID) + DistributeTimeoutFee(ctx context.Context, receiver sdk.AccAddress, packetID feerefundertypes.PacketID) +} + +// ChannelKeeper defines the expected IBC channel keeper +type ChannelKeeper interface { + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) + GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel +} + +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI +} diff --git a/x/transfer/types/query.pb.go b/x/transfer/types/query.pb.go new file mode 100644 index 00000000..49957658 --- /dev/null +++ b/x/transfer/types/query.pb.go @@ -0,0 +1,254 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/transfer/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + math "math" + + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v8/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" +) + +// 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 + +func init() { proto.RegisterFile("neutron/transfer/v1/query.proto", fileDescriptor_560cfedb574fdf6b) } + +var fileDescriptor_560cfedb574fdf6b = []byte{ + // 368 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x3f, 0x4b, 0x03, 0x31, + 0x18, 0xc6, 0x7b, 0x42, 0x0b, 0xc6, 0x45, 0x32, 0x96, 0x12, 0xa1, 0x74, 0xd0, 0xaa, 0x89, 0xd7, + 0x56, 0x3f, 0x80, 0x38, 0x38, 0x38, 0xa8, 0x38, 0xb9, 0x48, 0xee, 0x8c, 0x77, 0x07, 0x6d, 0x92, + 0x26, 0xb9, 0x62, 0x91, 0x2e, 0x7e, 0x02, 0xa1, 0x5f, 0xc1, 0x41, 0xc4, 0x0f, 0xe2, 0x58, 0x70, + 0x71, 0x94, 0xd6, 0x0f, 0x22, 0x97, 0xbb, 0xb3, 0x0a, 0xfe, 0xe9, 0x6d, 0x49, 0x78, 0x9e, 0xe7, + 0xfd, 0xe5, 0x7d, 0x13, 0xb0, 0xc6, 0x59, 0x6c, 0x94, 0xe0, 0xc4, 0x28, 0xca, 0xf5, 0x15, 0x53, + 0x64, 0xe0, 0x92, 0x7e, 0xcc, 0xd4, 0x10, 0x4b, 0x25, 0x8c, 0x80, 0xab, 0x99, 0x00, 0xe7, 0x82, + 0x6a, 0x2d, 0x10, 0x22, 0xe8, 0x32, 0x42, 0x65, 0x44, 0x28, 0xe7, 0xc2, 0x50, 0x13, 0x09, 0xae, + 0x53, 0x7d, 0x75, 0x3d, 0xf2, 0x7c, 0x42, 0xa5, 0xec, 0x46, 0x7e, 0x7a, 0xfe, 0x5b, 0x72, 0xeb, + 0xbe, 0x0c, 0xca, 0x27, 0xc9, 0x1e, 0x3e, 0x39, 0x00, 0x1c, 0x30, 0x2e, 0x7a, 0x67, 0x8a, 0xfa, + 0x0c, 0x76, 0x70, 0xe4, 0xf9, 0xf8, 0x6b, 0xc6, 0x67, 0x71, 0x3c, 0x70, 0xb1, 0xf5, 0xcc, 0xe5, + 0xa7, 0xac, 0x1f, 0x33, 0x6d, 0xaa, 0xbb, 0x05, 0x5d, 0x5a, 0x0a, 0xae, 0x59, 0xdd, 0xbd, 0x7d, + 0x79, 0x1f, 0x2f, 0x6d, 0xc2, 0x0d, 0x92, 0x81, 0x7f, 0x07, 0xbe, 0x4c, 0x1c, 0x17, 0x26, 0xb1, + 0x68, 0x72, 0x13, 0x52, 0x1d, 0x8e, 0xe0, 0x83, 0x03, 0x56, 0xe6, 0x49, 0x1a, 0x16, 0xab, 0xac, + 0x73, 0xe0, 0xbd, 0xa2, 0xb6, 0x8c, 0xb8, 0x69, 0x89, 0x1b, 0xb0, 0xfe, 0x3f, 0x31, 0x1c, 0x3b, + 0xa0, 0x72, 0x4c, 0x15, 0xed, 0x69, 0xb8, 0xb3, 0x40, 0xb9, 0x54, 0x9a, 0x03, 0xba, 0x05, 0x1c, + 0x19, 0x5b, 0xc3, 0xb2, 0x21, 0x58, 0xfb, 0x99, 0x4d, 0xa6, 0x28, 0x8f, 0x0e, 0x58, 0xb6, 0x37, + 0x3b, 0xa4, 0x3a, 0x84, 0xed, 0x45, 0xfb, 0x90, 0xa8, 0x73, 0xb6, 0x4e, 0x31, 0x53, 0x86, 0xd7, + 0xb2, 0x78, 0x5b, 0xb0, 0xf9, 0x57, 0xeb, 0x92, 0x21, 0x27, 0xc3, 0xb6, 0x2d, 0x1c, 0xed, 0x1f, + 0x3d, 0x4f, 0x91, 0x33, 0x99, 0x22, 0xe7, 0x6d, 0x8a, 0x9c, 0xbb, 0x19, 0x2a, 0x4d, 0x66, 0xa8, + 0xf4, 0x3a, 0x43, 0xa5, 0xf3, 0x56, 0x10, 0x99, 0x30, 0xf6, 0xb0, 0x2f, 0x7a, 0x24, 0xfb, 0x25, + 0xdb, 0x42, 0x05, 0xf9, 0x9a, 0x0c, 0x3a, 0xe4, 0x7a, 0x9e, 0x6f, 0x86, 0x92, 0x69, 0xaf, 0x62, + 0xdf, 0x7e, 0xfb, 0x23, 0x00, 0x00, 0xff, 0xff, 0xf4, 0x46, 0x5b, 0xdc, 0x78, 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 + +// 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 { + // DenomTrace queries a denomination trace information. + DenomTrace(ctx context.Context, in *types.QueryDenomTraceRequest, opts ...grpc.CallOption) (*types.QueryDenomTraceResponse, error) + // DenomTraces queries all denomination traces. + DenomTraces(ctx context.Context, in *types.QueryDenomTracesRequest, opts ...grpc.CallOption) (*types.QueryDenomTracesResponse, error) + // Params queries all parameters of the ibc-transfer module. + Params(ctx context.Context, in *types.QueryParamsRequest, opts ...grpc.CallOption) (*types.QueryParamsResponse, error) + // DenomHash queries a denomination hash information. + DenomHash(ctx context.Context, in *types.QueryDenomHashRequest, opts ...grpc.CallOption) (*types.QueryDenomHashResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) DenomTrace(ctx context.Context, in *types.QueryDenomTraceRequest, opts ...grpc.CallOption) (*types.QueryDenomTraceResponse, error) { + out := new(types.QueryDenomTraceResponse) + err := c.cc.Invoke(ctx, "/neutron.transfer.Query/DenomTrace", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) DenomTraces(ctx context.Context, in *types.QueryDenomTracesRequest, opts ...grpc.CallOption) (*types.QueryDenomTracesResponse, error) { + out := new(types.QueryDenomTracesResponse) + err := c.cc.Invoke(ctx, "/neutron.transfer.Query/DenomTraces", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Params(ctx context.Context, in *types.QueryParamsRequest, opts ...grpc.CallOption) (*types.QueryParamsResponse, error) { + out := new(types.QueryParamsResponse) + err := c.cc.Invoke(ctx, "/neutron.transfer.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) DenomHash(ctx context.Context, in *types.QueryDenomHashRequest, opts ...grpc.CallOption) (*types.QueryDenomHashResponse, error) { + out := new(types.QueryDenomHashResponse) + err := c.cc.Invoke(ctx, "/neutron.transfer.Query/DenomHash", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // DenomTrace queries a denomination trace information. + DenomTrace(context.Context, *types.QueryDenomTraceRequest) (*types.QueryDenomTraceResponse, error) + // DenomTraces queries all denomination traces. + DenomTraces(context.Context, *types.QueryDenomTracesRequest) (*types.QueryDenomTracesResponse, error) + // Params queries all parameters of the ibc-transfer module. + Params(context.Context, *types.QueryParamsRequest) (*types.QueryParamsResponse, error) + // DenomHash queries a denomination hash information. + DenomHash(context.Context, *types.QueryDenomHashRequest) (*types.QueryDenomHashResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) DenomTrace(ctx context.Context, req *types.QueryDenomTraceRequest) (*types.QueryDenomTraceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DenomTrace not implemented") +} +func (*UnimplementedQueryServer) DenomTraces(ctx context.Context, req *types.QueryDenomTracesRequest) (*types.QueryDenomTracesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DenomTraces not implemented") +} +func (*UnimplementedQueryServer) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) DenomHash(ctx context.Context, req *types.QueryDenomHashRequest) (*types.QueryDenomHashResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DenomHash not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_DenomTrace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(types.QueryDenomTraceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DenomTrace(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.transfer.Query/DenomTrace", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DenomTrace(ctx, req.(*types.QueryDenomTraceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_DenomTraces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(types.QueryDenomTracesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DenomTraces(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.transfer.Query/DenomTraces", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DenomTraces(ctx, req.(*types.QueryDenomTracesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(types.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: "/neutron.transfer.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*types.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(types.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: "/neutron.transfer.Query/DenomHash", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DenomHash(ctx, req.(*types.QueryDenomHashRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.transfer.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "DenomTrace", + Handler: _Query_DenomTrace_Handler, + }, + { + MethodName: "DenomTraces", + Handler: _Query_DenomTraces_Handler, + }, + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "DenomHash", + Handler: _Query_DenomHash_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/transfer/v1/query.proto", +} diff --git a/x/transfer/types/query.pb.gw.go b/x/transfer/types/query.pb.gw.go new file mode 100644 index 00000000..05f06a00 --- /dev/null +++ b/x/transfer/types/query.pb.gw.go @@ -0,0 +1,439 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: neutron/transfer/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + types_0 "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + "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_DenomTrace_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types_0.QueryDenomTraceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") + } + + protoReq.Hash, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) + } + + msg, err := client.DenomTrace(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DenomTrace_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types_0.QueryDenomTraceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") + } + + protoReq.Hash, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) + } + + msg, err := server.DenomTrace(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_DenomTraces_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types_0.QueryDenomTracesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.DenomTraces(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types_0.QueryDenomTracesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.DenomTraces(ctx, &protoReq) + return msg, metadata, err + +} + +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 types_0.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 types_0.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 types_0.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 types_0.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 + +} + +// 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_DenomTrace_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_DenomTrace_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_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DenomTraces_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_DenomTraces_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_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + 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()...) + + }) + + 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_DenomTrace_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_DenomTrace_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_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DenomTraces_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_DenomTraces_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_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + 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()...) + + }) + + return nil +} + +var ( + pattern_Query_DenomTrace_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", "apps", "transfer", "v1", "denom_traces", "hash"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_DenomTraces_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"ibc", "apps", "transfer", "v1", "denom_traces"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"ibc", "apps", "transfer", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_DenomHash_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", "apps", "transfer", "v1", "denom_hashes", "trace"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_DenomTrace_0 = runtime.ForwardResponseMessage + + forward_Query_DenomTraces_0 = runtime.ForwardResponseMessage + + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_DenomHash_0 = runtime.ForwardResponseMessage +) diff --git a/x/transfer/types/query.pb.gw.go_old b/x/transfer/types/query.pb.gw.go_old new file mode 100644 index 00000000..a4eb86d6 --- /dev/null +++ b/x/transfer/types/query.pb.gw.go_old @@ -0,0 +1,439 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: transfer/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + "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_DenomTrace_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types.QueryDenomTraceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") + } + + protoReq.Hash, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) + } + + msg, err := client.DenomTrace(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DenomTrace_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types.QueryDenomTraceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") + } + + protoReq.Hash, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) + } + + msg, err := server.DenomTrace(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_DenomTraces_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types.QueryDenomTracesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.DenomTraces(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DenomTraces_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq types.QueryDenomTracesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_DenomTraces_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.DenomTraces(ctx, &protoReq) + return msg, metadata, err + +} + +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 types.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 types.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 types.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 types.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 + +} + +// 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_DenomTrace_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_DenomTrace_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_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DenomTraces_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_DenomTraces_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_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + 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()...) + + }) + + 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_DenomTrace_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_DenomTrace_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_DenomTrace_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_DenomTraces_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_DenomTraces_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_DenomTraces_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + 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()...) + + }) + + return nil +} + +var ( + pattern_Query_DenomTrace_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", "apps", "transfer", "v1", "denom_traces", "hash"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_DenomTraces_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"ibc", "apps", "transfer", "v1", "denom_traces"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"ibc", "apps", "transfer", "v1", "params"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_DenomHash_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", "apps", "transfer", "v1", "denom_hashes", "trace"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_DenomTrace_0 = runtime.ForwardResponseMessage + + forward_Query_DenomTraces_0 = runtime.ForwardResponseMessage + + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_DenomHash_0 = runtime.ForwardResponseMessage +) diff --git a/x/transfer/types/tx.go b/x/transfer/types/tx.go new file mode 100644 index 00000000..98f88ad8 --- /dev/null +++ b/x/transfer/types/tx.go @@ -0,0 +1,120 @@ +package types + +import ( + "context" + + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + "google.golang.org/grpc" + + feerefundertypes "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (msg *MsgTransfer) Validate(isContract bool) error { + if isContract { + if err := msg.Fee.Validate(); err != nil { + return err + } + } + + sdkMsg := types.NewMsgTransfer(msg.SourcePort, msg.SourceChannel, msg.Token, msg.Sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, msg.Memo) + return sdkMsg.ValidateBasic() +} + +func (msg *MsgTransfer) GetSigners() []sdk.AccAddress { + fromAddress, _ := sdk.AccAddressFromBech32(msg.Sender) + return []sdk.AccAddress{fromAddress} +} + +// MsgOrigTransferHandler - 1) helps to bind `/neutron.transfer.Msg/Transfer` as a handler for `ibc.applications.transfer.v1.MsgTransfer` +// 2) converts `ibc.applications.transfer.v1.MsgTransfer` into neutron.transfer.MsgTransfer` before processing. +// +//nolint:revive // we cant rearrange arguments since we need to meet the type requirement +func MsgOrigTransferHandler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(types.MsgTransfer) + if err := dec(in); err != nil { + return nil, err + } + conv := &MsgTransfer{ + SourcePort: in.SourcePort, + SourceChannel: in.SourceChannel, + Token: in.Token, + Sender: in.Sender, + Receiver: in.Receiver, + TimeoutHeight: in.TimeoutHeight, + TimeoutTimestamp: in.TimeoutTimestamp, + Memo: in.Memo, + Fee: feerefundertypes.Fee{}, + } + if interceptor == nil { + return srv.(MsgServer).Transfer(ctx, conv) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.transfer.Msg/Transfer", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + reqT := req.(*types.MsgTransfer) + convReq := &MsgTransfer{ + SourcePort: reqT.SourcePort, + SourceChannel: reqT.SourceChannel, + Token: reqT.Token, + Sender: reqT.Sender, + Receiver: reqT.Receiver, + TimeoutHeight: reqT.TimeoutHeight, + TimeoutTimestamp: reqT.TimeoutTimestamp, + Memo: reqT.Memo, + Fee: feerefundertypes.Fee{}, + } + return srv.(MsgServer).Transfer(ctx, convReq) + } + return interceptor(ctx, conv, info, handler) +} + +// MsgUpdateParamsHandler handler helps to bind `/ibc.applications.transfer.v1.Msg/UpdateParams`. +// +//nolint:revive // we cant rearrange arguments since we need to meet the type requirement +func MsgUpdateParamsHandler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(types.MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + conv := &MsgUpdateParams{ + Signer: in.Signer, + Params: in.Params, + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, conv) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.transfer.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + reqT := req.(*types.MsgUpdateParams) + convReq := &MsgUpdateParams{ + Signer: reqT.Signer, + Params: reqT.Params, + } + return srv.(MsgServer).UpdateParams(ctx, convReq) + } + return interceptor(ctx, in, info, handler) +} + +var MsgServiceDescOrig = grpc.ServiceDesc{ + ServiceName: "ibc.applications.transfer.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Transfer", + Handler: MsgOrigTransferHandler, + }, + { + MethodName: "UpdateParams", + Handler: MsgUpdateParamsHandler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/applications/transfer/v1/tx.proto", +} diff --git a/x/transfer/types/tx.pb.go b/x/transfer/types/tx.pb.go new file mode 100644 index 00000000..dd49c840 --- /dev/null +++ b/x/transfer/types/tx.pb.go @@ -0,0 +1,1368 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: neutron/transfer/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + types3 "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + types1 "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + + types2 "github.com/Nolus-Protocol/nolus-core/x/feerefunder/types" +) + +// 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 + +type MsgTransfer struct { + // the port on which the packet will be sent + SourcePort string `protobuf:"bytes,1,opt,name=source_port,json=sourcePort,proto3" json:"source_port,omitempty" yaml:"source_port"` + // the channel by which the packet will be sent + SourceChannel string `protobuf:"bytes,2,opt,name=source_channel,json=sourceChannel,proto3" json:"source_channel,omitempty" yaml:"source_channel"` + // the tokens to be transferred + Token types.Coin `protobuf:"bytes,3,opt,name=token,proto3" json:"token"` + // the sender address + Sender string `protobuf:"bytes,4,opt,name=sender,proto3" json:"sender,omitempty"` + // the recipient address on the destination chain + Receiver string `protobuf:"bytes,5,opt,name=receiver,proto3" json:"receiver,omitempty"` + // Timeout height relative to the current block height. + // The timeout is disabled when set to 0. + TimeoutHeight types1.Height `protobuf:"bytes,6,opt,name=timeout_height,json=timeoutHeight,proto3" json:"timeout_height" yaml:"timeout_height"` + // Timeout timestamp in absolute nanoseconds since unix epoch. + // The timeout is disabled when set to 0. + TimeoutTimestamp uint64 `protobuf:"varint,7,opt,name=timeout_timestamp,json=timeoutTimestamp,proto3" json:"timeout_timestamp,omitempty" yaml:"timeout_timestamp"` + Memo string `protobuf:"bytes,8,opt,name=memo,proto3" json:"memo,omitempty"` + Fee types2.Fee `protobuf:"bytes,9,opt,name=fee,proto3" json:"fee"` +} + +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_c44193c4a9c18e30, []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 is the modified response type for +// ibc-go MsgTransfer. +type MsgTransferResponse struct { + // channel's sequence_id for outgoing ibc packet. Unique per a channel. + SequenceId uint64 `protobuf:"varint,1,opt,name=sequence_id,json=sequenceId,proto3" json:"sequence_id,omitempty"` + // channel src channel on neutron side transaction was submitted from + Channel string `protobuf:"bytes,2,opt,name=channel,proto3" json:"channel,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_c44193c4a9c18e30, []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 (m *MsgTransferResponse) GetSequenceId() uint64 { + if m != nil { + return m.SequenceId + } + return 0 +} + +func (m *MsgTransferResponse) GetChannel() string { + if m != nil { + return m.Channel + } + return "" +} + +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // signer address + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + // params defines the transfer parameters to update. + // + // NOTE: All parameters must be supplied. + Params types3.Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_c44193c4a9c18e30, []int{2} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c44193c4a9c18e30, []int{3} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgTransfer)(nil), "neutron.transfer.MsgTransfer") + proto.RegisterType((*MsgTransferResponse)(nil), "neutron.transfer.MsgTransferResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "neutron.transfer.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "neutron.transfer.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("neutron/transfer/v1/tx.proto", fileDescriptor_c44193c4a9c18e30) } + +var fileDescriptor_c44193c4a9c18e30 = []byte{ + // 686 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0x4f, 0x6f, 0xd3, 0x4a, + 0x10, 0x8f, 0x5f, 0xd2, 0xb4, 0xdd, 0xbc, 0xfe, 0x79, 0xdb, 0xf7, 0x5a, 0x37, 0x6a, 0xed, 0x3e, + 0x0b, 0xa4, 0x52, 0xc4, 0x9a, 0x04, 0x10, 0x52, 0x4f, 0x28, 0x95, 0x10, 0x95, 0xa8, 0x14, 0x59, + 0xe5, 0x82, 0x90, 0x8a, 0xe3, 0x4c, 0x1c, 0x8b, 0x78, 0xd7, 0xec, 0x6e, 0xa2, 0xf6, 0x82, 0x10, + 0xa7, 0x1e, 0xf9, 0x08, 0xfd, 0x08, 0xfd, 0x00, 0x7c, 0x80, 0x1e, 0x7b, 0xe4, 0x14, 0xa1, 0xf6, + 0x50, 0xce, 0xbd, 0x72, 0x41, 0x5e, 0xaf, 0xd3, 0xa4, 0x42, 0x70, 0xca, 0xcc, 0xfc, 0x7e, 0x33, + 0xe3, 0xf9, 0xcd, 0x6c, 0xd0, 0x1a, 0x85, 0xbe, 0xe4, 0x8c, 0xba, 0x92, 0xfb, 0x54, 0x74, 0x80, + 0xbb, 0x83, 0x9a, 0x2b, 0x0f, 0x49, 0xc2, 0x99, 0x64, 0x78, 0x51, 0xa3, 0x24, 0x47, 0xab, 0x56, + 0xc0, 0x44, 0xcc, 0x84, 0xdb, 0xf2, 0x05, 0xb8, 0x83, 0x5a, 0x0b, 0xa4, 0x5f, 0x73, 0x03, 0x16, + 0xd1, 0x2c, 0xa3, 0xba, 0xa2, 0xf1, 0x58, 0x84, 0x69, 0xa5, 0x58, 0x84, 0x1a, 0xf8, 0x37, 0x64, + 0x21, 0x53, 0xa6, 0x9b, 0x5a, 0x3a, 0x7a, 0x3f, 0x6a, 0x05, 0xae, 0x9f, 0x24, 0xbd, 0x28, 0xf0, + 0x65, 0xc4, 0xa8, 0x98, 0xfc, 0x0e, 0x6d, 0x6b, 0xb2, 0x9d, 0x92, 0x03, 0xc6, 0xc1, 0x0d, 0x7a, + 0x11, 0x50, 0x99, 0x52, 0x32, 0x4b, 0x13, 0xd6, 0xf3, 0x61, 0x3a, 0x00, 0x1c, 0x3a, 0x7d, 0xda, + 0x06, 0x9e, 0xda, 0x19, 0xec, 0xfc, 0x28, 0xa2, 0xca, 0x9e, 0x08, 0xf7, 0x75, 0x55, 0xfc, 0x14, + 0x55, 0x04, 0xeb, 0xf3, 0x00, 0x0e, 0x12, 0xc6, 0xa5, 0x69, 0x6c, 0x18, 0x9b, 0xb3, 0x8d, 0xe5, + 0xeb, 0xa1, 0x8d, 0x8f, 0xfc, 0xb8, 0xb7, 0xed, 0x8c, 0x81, 0x8e, 0x87, 0x32, 0xaf, 0xc9, 0xb8, + 0xc4, 0xcf, 0xd0, 0xbc, 0xc6, 0x82, 0xae, 0x4f, 0x29, 0xf4, 0xcc, 0xbf, 0x54, 0xee, 0xea, 0xf5, + 0xd0, 0xfe, 0x6f, 0x22, 0x57, 0xe3, 0x8e, 0x37, 0x97, 0x05, 0x76, 0x32, 0x1f, 0x3f, 0x41, 0x53, + 0x92, 0xbd, 0x03, 0x6a, 0x16, 0x37, 0x8c, 0xcd, 0x4a, 0x7d, 0x95, 0x64, 0xb2, 0x91, 0x54, 0x56, + 0xa2, 0x65, 0x25, 0x3b, 0x2c, 0xa2, 0x8d, 0xd2, 0xd9, 0xd0, 0x2e, 0x78, 0x19, 0x1b, 0x2f, 0xa3, + 0xb2, 0x80, 0x74, 0x2a, 0xb3, 0x94, 0x36, 0xf4, 0xb4, 0x87, 0xab, 0x68, 0x86, 0x43, 0x00, 0xd1, + 0x00, 0xb8, 0x39, 0xa5, 0x90, 0x91, 0x8f, 0xdf, 0xa2, 0x79, 0x19, 0xc5, 0xc0, 0xfa, 0xf2, 0xa0, + 0x0b, 0x51, 0xd8, 0x95, 0x66, 0x59, 0xf5, 0xac, 0x92, 0xa8, 0x15, 0x90, 0x54, 0x4e, 0xa2, 0x45, + 0x1c, 0xd4, 0xc8, 0x0b, 0xc5, 0x68, 0xac, 0xa7, 0x4d, 0x6f, 0x86, 0x99, 0xcc, 0x77, 0xbc, 0x39, + 0x1d, 0xc8, 0xd8, 0x78, 0x17, 0xfd, 0x93, 0x33, 0xd2, 0x5f, 0x21, 0xfd, 0x38, 0x31, 0xa7, 0x37, + 0x8c, 0xcd, 0x52, 0x63, 0xed, 0x7a, 0x68, 0x9b, 0x93, 0x45, 0x46, 0x14, 0xc7, 0x5b, 0xd4, 0xb1, + 0xfd, 0x3c, 0x84, 0x31, 0x2a, 0xc5, 0x10, 0x33, 0x73, 0x46, 0x0d, 0xa1, 0x6c, 0xfc, 0x10, 0x15, + 0x3b, 0x00, 0xe6, 0xac, 0xfa, 0x6a, 0x93, 0xe4, 0x27, 0x39, 0xb6, 0x63, 0xf2, 0x1c, 0x40, 0x0b, + 0x95, 0x52, 0xb7, 0x97, 0x8e, 0x4f, 0xec, 0xc2, 0xf7, 0x13, 0xbb, 0xf0, 0xe9, 0xea, 0x74, 0x4b, + 0x6b, 0xe4, 0x34, 0xd1, 0xd2, 0xd8, 0xf2, 0x3d, 0x10, 0x09, 0xa3, 0x02, 0xb0, 0x8d, 0x2a, 0x02, + 0xde, 0xf7, 0x81, 0x06, 0x70, 0x10, 0xb5, 0xd5, 0x11, 0x94, 0x3c, 0x94, 0x87, 0x76, 0xdb, 0xd8, + 0x44, 0xd3, 0x13, 0x5b, 0xf6, 0x72, 0xd7, 0xf9, 0x80, 0x16, 0xf6, 0x44, 0xf8, 0x2a, 0x69, 0xfb, + 0x12, 0x9a, 0x3e, 0xf7, 0x63, 0xa1, 0x16, 0x14, 0x85, 0x14, 0x78, 0x76, 0x4d, 0x9e, 0xf6, 0x70, + 0x03, 0x95, 0x13, 0xc5, 0x50, 0x35, 0x2a, 0xf5, 0x3b, 0x4a, 0xfc, 0xf1, 0xc3, 0x1f, 0x3d, 0xb1, + 0x74, 0x0d, 0x59, 0x35, 0x3d, 0x92, 0xce, 0xdc, 0x5e, 0x38, 0x1e, 0x4d, 0xa4, 0x8a, 0x3a, 0xab, + 0x68, 0xe5, 0x56, 0xff, 0x7c, 0xaa, 0xfa, 0x17, 0x03, 0x15, 0xf7, 0x44, 0x88, 0x9b, 0x68, 0x66, + 0x74, 0xee, 0xeb, 0xe4, 0xf6, 0x6b, 0x26, 0x63, 0x82, 0x54, 0xef, 0xfe, 0x16, 0x1e, 0xe9, 0xf5, + 0x06, 0xfd, 0x3d, 0x31, 0xf1, 0xff, 0xbf, 0x4c, 0x1b, 0xa7, 0x54, 0xef, 0xfd, 0x91, 0x92, 0x57, + 0xaf, 0x4e, 0x7d, 0xbc, 0x3a, 0xdd, 0x32, 0x1a, 0x2f, 0xcf, 0x2e, 0x2c, 0xe3, 0xfc, 0xc2, 0x32, + 0xbe, 0x5d, 0x58, 0xc6, 0xe7, 0x4b, 0xab, 0x70, 0x7e, 0x69, 0x15, 0xbe, 0x5e, 0x5a, 0x85, 0xd7, + 0xf5, 0x30, 0x92, 0xdd, 0x7e, 0x8b, 0x04, 0x2c, 0x76, 0x75, 0xd5, 0x07, 0x8c, 0x87, 0xb9, 0xed, + 0x0e, 0x1e, 0xbb, 0x87, 0x37, 0xff, 0x21, 0xf2, 0x28, 0x01, 0xd1, 0x2a, 0xab, 0xe7, 0xff, 0xe8, + 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x33, 0x1a, 0x12, 0x42, 0xec, 0x04, 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) + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, 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, "/neutron.transfer.Msg/Transfer", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/neutron.transfer.Msg/UpdateParams", 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) + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, 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 (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams 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: "/neutron.transfer.Msg/Transfer", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Transfer(ctx, req.(*MsgTransfer)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/neutron.transfer.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "neutron.transfer.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Transfer", + Handler: _Msg_Transfer_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "neutron/transfer/v1/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 + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + 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] = 0x42 + } + if m.TimeoutTimestamp != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.TimeoutTimestamp)) + i-- + dAtA[i] = 0x38 + } + { + size, err := m.TimeoutHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + 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] = 0x2a + } + 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] = 0x22 + } + { + size, err := m.Token.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + 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] = 0x12 + } + 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] = 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 len(m.Channel) > 0 { + i -= len(m.Channel) + copy(dAtA[i:], m.Channel) + i = encodeVarintTx(dAtA, i, uint64(len(m.Channel))) + i-- + dAtA[i] = 0x12 + } + if m.SequenceId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.SequenceId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + 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] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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.SourcePort) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SourceChannel) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Token.Size() + 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)) + } + l = m.TimeoutHeight.Size() + 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)) + } + l = m.Fee.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.SequenceId != 0 { + n += 1 + sovTx(uint64(m.SequenceId)) + } + l = len(m.Channel) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + 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 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 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 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 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token", 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.Token.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + 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 5: + 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 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutHeight", 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.TimeoutHeight.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + 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 8: + 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 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Fee", 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.Fee.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 SequenceId", wireType) + } + m.SequenceId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SequenceId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channel", 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.Channel = 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 *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 + case 2: + 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 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.Params.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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 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") +)