From d8388a19117dfabd7d06c01f83bd13fa93293e80 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 31 Aug 2023 17:35:00 +0800 Subject: [PATCH] Problem: interchain-accounts in ibc-go v6 is not integrated (#1147) * Problem: interchain-accounts in ibc-go v6 is not integrated add ica test * fix buf * fix upgrade * fix lint * cleanup --- CHANGELOG.md | 1 + app/app.go | 97 +- app/upgrades.go | 21 +- client/docs/swagger-ui/swagger.yaml | 8 +- docs/api/proto-docs.md | 99 +- go.mod | 4 +- integration_tests/cosmoscli.py | 30 +- integration_tests/test_ibc.py | 94 ++ proto/buf.gen.gogo.yaml | 2 +- proto/cronos/genesis.proto | 12 +- proto/cronos/query.proto | 108 +- proto/cronos/tx.proto | 14 +- proto/icaauth/v1/genesis.proto | 13 + proto/icaauth/v1/params.proto | 20 + proto/icaauth/v1/query.proto | 46 + proto/icaauth/v1/tx.proto | 57 + proto/memiavl/wal.proto | 2 +- x/cronos/client/cli/tx.go | 12 + x/cronos/types/query.pb.go | 12 +- x/cronos/types/tx.pb.go | 3 +- x/icaauth/client/cli/flags.go | 7 + x/icaauth/client/cli/query.go | 26 + .../cli/query_interchain_account_address.go | 47 + x/icaauth/client/cli/query_params.go | 34 + x/icaauth/client/cli/tx.go | 25 + x/icaauth/client/cli/tx_register_account.go | 48 + x/icaauth/client/cli/tx_submit_tx.go | 68 + x/icaauth/genesis.go | 25 + x/icaauth/handler.go | 32 + x/icaauth/keeper/grpc_query.go | 7 + .../grpc_query_interchain_account_address.go | 27 + x/icaauth/keeper/grpc_query_params.go | 19 + x/icaauth/keeper/keeper.go | 118 ++ x/icaauth/keeper/msg_server.go | 17 + .../keeper/msg_server_register_account.go | 18 + x/icaauth/keeper/msg_server_submit_tx.go | 26 + x/icaauth/keeper/params.go | 37 + x/icaauth/module.go | 164 +++ x/icaauth/module_ibc.go | 141 ++ x/icaauth/types/codec.go | 29 + x/icaauth/types/genesis.go | 14 + x/icaauth/types/genesis.pb.go | 322 +++++ x/icaauth/types/keys.go | 32 + x/icaauth/types/message_register_account.go | 48 + .../types/message_register_account_test.go | 39 + x/icaauth/types/message_submit_tx.go | 104 ++ x/icaauth/types/message_submit_tx_test.go | 39 + x/icaauth/types/params.go | 69 + x/icaauth/types/params.pb.go | 328 +++++ x/icaauth/types/query.pb.go | 980 ++++++++++++++ x/icaauth/types/query.pb.gw.go | 276 ++++ x/icaauth/types/tx.pb.go | 1163 +++++++++++++++++ x/icaauth/types/types.go | 13 + 53 files changed, 4844 insertions(+), 153 deletions(-) create mode 100644 proto/icaauth/v1/genesis.proto create mode 100644 proto/icaauth/v1/params.proto create mode 100644 proto/icaauth/v1/query.proto create mode 100644 proto/icaauth/v1/tx.proto create mode 100644 x/icaauth/client/cli/flags.go create mode 100644 x/icaauth/client/cli/query.go create mode 100644 x/icaauth/client/cli/query_interchain_account_address.go create mode 100644 x/icaauth/client/cli/query_params.go create mode 100644 x/icaauth/client/cli/tx.go create mode 100644 x/icaauth/client/cli/tx_register_account.go create mode 100644 x/icaauth/client/cli/tx_submit_tx.go create mode 100644 x/icaauth/genesis.go create mode 100644 x/icaauth/handler.go create mode 100644 x/icaauth/keeper/grpc_query.go create mode 100644 x/icaauth/keeper/grpc_query_interchain_account_address.go create mode 100644 x/icaauth/keeper/grpc_query_params.go create mode 100644 x/icaauth/keeper/keeper.go create mode 100644 x/icaauth/keeper/msg_server.go create mode 100644 x/icaauth/keeper/msg_server_register_account.go create mode 100644 x/icaauth/keeper/msg_server_submit_tx.go create mode 100644 x/icaauth/keeper/params.go create mode 100644 x/icaauth/module.go create mode 100644 x/icaauth/module_ibc.go create mode 100644 x/icaauth/types/codec.go create mode 100644 x/icaauth/types/genesis.go create mode 100644 x/icaauth/types/genesis.pb.go create mode 100644 x/icaauth/types/keys.go create mode 100644 x/icaauth/types/message_register_account.go create mode 100644 x/icaauth/types/message_register_account_test.go create mode 100644 x/icaauth/types/message_submit_tx.go create mode 100644 x/icaauth/types/message_submit_tx_test.go create mode 100644 x/icaauth/types/params.go create mode 100644 x/icaauth/types/params.pb.go create mode 100644 x/icaauth/types/query.pb.go create mode 100644 x/icaauth/types/query.pb.gw.go create mode 100644 x/icaauth/types/tx.pb.go create mode 100644 x/icaauth/types/types.go diff --git a/CHANGELOG.md b/CHANGELOG.md index f5fa4d84a9..9513367c05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - [cronos#997](https://github.com/crypto-org-chain/cronos/pull/997) Fix logic to support proxy contract for cronos originated crc20. - [cronos#1005](https://github.com/crypto-org-chain/cronos/pull/1005) Support specify channel id for send-to-ibc event in case of source token. - [cronos#1069](https://github.com/crypto-org-chain/cronos/pull/1069) Update ethermint to develop, go-ethereum to `v1.10.26` and ibc-go to `v6.2.0`. +- [cronos#1147](https://github.com/crypto-org-chain/cronos/pull/1147) integrate ica module. ### Bug Fixes diff --git a/app/app.go b/app/app.go index 607aa46d4a..458725f78c 100644 --- a/app/app.go +++ b/app/app.go @@ -106,6 +106,16 @@ import ( porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" + + ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" + icacontroller "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller" + icacontrollerkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/keeper" + icacontrollertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + icaauth "github.com/crypto-org-chain/cronos/v2/x/icaauth" + icaauthkeeper "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper" + icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + tmjson "github.com/tendermint/tendermint/libs/json" evmante "github.com/evmos/ethermint/app/ante" @@ -190,6 +200,7 @@ var ( govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, ibcfeetypes.ModuleName: nil, + icatypes.ModuleName: nil, evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, cronostypes.ModuleName: {authtypes.Minter, authtypes.Burner}, @@ -229,6 +240,8 @@ func GenModuleBasics() module.BasicManager { authzmodule.AppModuleBasic{}, ibc.AppModuleBasic{}, transfer.AppModuleBasic{}, + ica.AppModuleBasic{}, + icaauth.AppModuleBasic{}, vesting.AppModuleBasic{}, ibcfee.AppModuleBasic{}, evm.AppModuleBasic{}, @@ -254,6 +267,9 @@ func StoreKeys(skipGravity bool) ( // ibc keys ibchost.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey, + // ica keys + icacontrollertypes.StoreKey, + icaauthtypes.StoreKey, // ethermint keys evmtypes.StoreKey, feemarkettypes.StoreKey, // this line is used by starport scaffolding # stargate/app/storeKey @@ -289,27 +305,31 @@ type App struct { memKeys map[string]*storetypes.MemoryStoreKey // keepers - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper - CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - MintKeeper mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.Keeper - CrisisKeeper crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper - ParamsKeeper paramskeeper.Keeper - IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly - IBCFeeKeeper ibcfeekeeper.Keeper - EvidenceKeeper evidencekeeper.Keeper - TransferKeeper ibctransferkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - AuthzKeeper authzkeeper.Keeper + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + IBCFeeKeeper ibcfeekeeper.Keeper + ICAControllerKeeper icacontrollerkeeper.Keeper + ICAAuthKeeper icaauthkeeper.Keeper + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + AuthzKeeper authzkeeper.Keeper // make scoped keepers public for test purposes - ScopedIBCKeeper capabilitykeeper.ScopedKeeper - ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper + ScopedICAAuthKeeper capabilitykeeper.ScopedKeeper // Ethermint keepers EvmKeeper *evmkeeper.Keeper @@ -392,6 +412,9 @@ func New( // grant capabilities for the ibc and ibc-transfer modules scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) + scopedICAAuthKeeper := app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleName) + // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating // their scoped modules in `NewApp` with `ScopeToModule` app.CapabilityKeeper.Seal() @@ -442,6 +465,16 @@ func New( &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, ) + // ICA Controller keeper + app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( + appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), + app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + scopedICAControllerKeeper, app.MsgServiceRouter(), + ) + + icaModule := ica.NewAppModule(&app.ICAControllerKeeper, nil) + // Create Transfer Keepers app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), @@ -561,9 +594,21 @@ func New( } app.StakingKeeper = *stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(hooks...)) + app.ICAAuthKeeper = *icaauthkeeper.NewKeeper(appCodec, keys[icaauthtypes.StoreKey], keys[icaauthtypes.MemStoreKey], app.ICAControllerKeeper, scopedICAAuthKeeper) + icaAuthModule := icaauth.NewAppModule(appCodec, app.ICAAuthKeeper) + icaAuthIBCModule := icaauth.NewIBCModule(app.ICAAuthKeeper) + + icaControllerIBCModule := icacontroller.NewIBCMiddleware(icaAuthIBCModule, app.ICAControllerKeeper) + icaControllerStack := ibcfee.NewIBCMiddleware(icaControllerIBCModule, app.IBCFeeKeeper) + // Create static IBC router, add transfer route, then set and seal it ibcRouter := porttypes.NewRouter() - ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) + // Add ontroller & ica auth modules to IBC router + ibcRouter. + AddRoute(icaauthtypes.ModuleName, icaControllerStack). + AddRoute(icacontrollertypes.SubModuleName, icaControllerStack). + AddRoute(ibctransfertypes.ModuleName, transferStack) + // this line is used by starport scaffolding # ibc/app/router app.IBCKeeper.SetRouter(ibcRouter) @@ -598,6 +643,8 @@ func New( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), transferModule, + icaModule, + icaAuthModule, feeModule, evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmS), feemarket.NewAppModule(app.FeeMarketKeeper, feeMarketS), @@ -616,6 +663,8 @@ func New( evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, + icaauthtypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, @@ -634,6 +683,8 @@ func New( ibchost.ModuleName, ibctransfertypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, + icaauthtypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, @@ -674,6 +725,8 @@ func New( evidencetypes.ModuleName, ibctransfertypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, + icaauthtypes.ModuleName, authz.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, @@ -764,6 +817,8 @@ func New( app.ScopedIBCKeeper = scopedIBCKeeper app.ScopedTransferKeeper = scopedTransferKeeper + app.ScopedICAControllerKeeper = scopedICAControllerKeeper + app.ScopedICAAuthKeeper = scopedICAAuthKeeper // this line is used by starport scaffolding # stargate/app/beforeInitReturn return app @@ -967,6 +1022,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName) + paramsKeeper.Subspace(icaauthtypes.ModuleName) paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint: staticcheck paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable()) if !skipGravity { diff --git a/app/upgrades.go b/app/upgrades.go index 76d6de86cd..c0baad6775 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -7,11 +7,30 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" + icacontrollertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types" ) func (app *App) RegisterUpgradeHandlers() { upgradeHandlerV2 := func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + if icaModule, ok := app.mm.Modules[icatypes.ModuleName].(ica.AppModule); ok { + // set the ICS27 consensus version so InitGenesis is not run + version := icaModule.ConsensusVersion() + fromVM[icatypes.ModuleName] = version + + // create ICS27 Controller submodule params + controllerParams := icacontrollertypes.Params{ + ControllerEnabled: true, + } + + // initialize ICS27 module + icaModule.InitModule(ctx, controllerParams, icahosttypes.Params{}) + } + m, err := app.mm.RunMigrations(ctx, app.configurator, fromVM) if err != nil { return m, err @@ -36,7 +55,7 @@ func (app *App) RegisterUpgradeHandlers() { if !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { if upgradeInfo.Name == planName { storeUpgrades := storetypes.StoreUpgrades{ - Added: []string{gravitytypes.StoreKey}, + Added: []string{gravitytypes.StoreKey, icacontrollertypes.StoreKey, icaauthtypes.StoreKey}, } // configure store loader that checks if version == upgradeHeight and applies store upgrades diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index 6d369dc42d..fecba38046 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -662,7 +662,9 @@ paths: type: boolean description: >- QueryPermissionsResponse is the response type for the - Query/Permissions RPC method. + Query/Permissions RPC + + method. default: description: An unexpected error response. schema: @@ -41229,7 +41231,9 @@ definitions: type: boolean description: >- QueryPermissionsResponse is the response type for the Query/Permissions - RPC method. + RPC + + method. cronos.ReplayBlockResponse: type: object properties: diff --git a/docs/api/proto-docs.md b/docs/api/proto-docs.md index 34f71dceb9..5e0c21451a 100644 --- a/docs/api/proto-docs.md +++ b/docs/api/proto-docs.md @@ -32,27 +32,27 @@ - [Msg](#cronos.Msg) -- [icactl/v1/params.proto](#icactl/v1/params.proto) - - [Params](#cronos.icactl.v1.Params) +- [icaauth/v1/params.proto](#icaauth/v1/params.proto) + - [Params](#cronos.icaauth.v1.Params) -- [icactl/v1/genesis.proto](#icactl/v1/genesis.proto) - - [GenesisState](#cronos.icactl.v1.GenesisState) +- [icaauth/v1/genesis.proto](#icaauth/v1/genesis.proto) + - [GenesisState](#cronos.icaauth.v1.GenesisState) -- [icactl/v1/query.proto](#icactl/v1/query.proto) - - [QueryInterchainAccountAddressRequest](#cronos.icactl.v1.QueryInterchainAccountAddressRequest) - - [QueryInterchainAccountAddressResponse](#cronos.icactl.v1.QueryInterchainAccountAddressResponse) - - [QueryParamsRequest](#cronos.icactl.v1.QueryParamsRequest) - - [QueryParamsResponse](#cronos.icactl.v1.QueryParamsResponse) +- [icaauth/v1/query.proto](#icaauth/v1/query.proto) + - [QueryInterchainAccountAddressRequest](#cronos.icaauth.v1.QueryInterchainAccountAddressRequest) + - [QueryInterchainAccountAddressResponse](#cronos.icaauth.v1.QueryInterchainAccountAddressResponse) + - [QueryParamsRequest](#cronos.icaauth.v1.QueryParamsRequest) + - [QueryParamsResponse](#cronos.icaauth.v1.QueryParamsResponse) - - [Query](#cronos.icactl.v1.Query) + - [Query](#cronos.icaauth.v1.Query) -- [icactl/v1/tx.proto](#icactl/v1/tx.proto) - - [MsgRegisterAccount](#cronos.icactl.v1.MsgRegisterAccount) - - [MsgRegisterAccountResponse](#cronos.icactl.v1.MsgRegisterAccountResponse) - - [MsgSubmitTx](#cronos.icactl.v1.MsgSubmitTx) - - [MsgSubmitTxResponse](#cronos.icactl.v1.MsgSubmitTxResponse) +- [icaauth/v1/tx.proto](#icaauth/v1/tx.proto) + - [MsgRegisterAccount](#cronos.icaauth.v1.MsgRegisterAccount) + - [MsgRegisterAccountResponse](#cronos.icaauth.v1.MsgRegisterAccountResponse) + - [MsgSubmitTx](#cronos.icaauth.v1.MsgSubmitTx) + - [MsgSubmitTxResponse](#cronos.icaauth.v1.MsgSubmitTxResponse) - - [Msg](#cronos.icactl.v1.Msg) + - [Msg](#cronos.icaauth.v1.Msg) - [Scalar Value Types](#scalar-value-types) @@ -393,14 +393,14 @@ Msg defines the Cronos Msg service - +

Top

-## icactl/v1/params.proto +## icaauth/v1/params.proto - + ### Params Params defines the parameters for the module. @@ -408,7 +408,7 @@ Params defines the parameters for the module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `minTimeoutDuration` | [google.protobuf.Duration](#google.protobuf.Duration) | | minTimeoutDuration defines the minimum value of packet timeout when submitting transactions to host chain on behalf of interchain account | +| `min_timeout_duration` | [google.protobuf.Duration](#google.protobuf.Duration) | | min_timeout_duration defines the minimum value of packet timeout when submitting transactions to host chain on behalf of interchain account | @@ -424,22 +424,22 @@ Params defines the parameters for the module. - +

Top

-## icactl/v1/genesis.proto +## icaauth/v1/genesis.proto - + ### GenesisState -GenesisState defines the icactl module's genesis state. +GenesisState defines the icaauth module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#cronos.icactl.v1.Params) | | params defines the genesis parameters | +| `params` | [Params](#cronos.icaauth.v1.Params) | | params defines the genesis parameters | @@ -455,14 +455,14 @@ GenesisState defines the icactl module's genesis state. - +

Top

-## icactl/v1/query.proto +## icaauth/v1/query.proto - + ### QueryInterchainAccountAddressRequest QueryInterchainAccountAddressRequest defines the request for the InterchainAccountAddress query. @@ -470,7 +470,7 @@ QueryInterchainAccountAddressRequest defines the request for the InterchainAccou | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `connectionId` | [string](#string) | | | +| `connection_id` | [string](#string) | | | | `owner` | [string](#string) | | | @@ -478,7 +478,7 @@ QueryInterchainAccountAddressRequest defines the request for the InterchainAccou - + ### QueryInterchainAccountAddressResponse QueryInterchainAccountAddressResponse defines the response for the InterchainAccountAddress query. @@ -486,14 +486,14 @@ QueryInterchainAccountAddressResponse defines the response for the InterchainAcc | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `interchainAccountAddress` | [string](#string) | | | +| `interchain_account_address` | [string](#string) | | | - + ### QueryParamsRequest QueryParamsRequest is request type for the Query/Params RPC method. @@ -503,7 +503,7 @@ QueryParamsRequest is request type for the Query/Params RPC method. - + ### QueryParamsResponse QueryParamsResponse is response type for the Query/Params RPC method. @@ -511,7 +511,7 @@ QueryParamsResponse is response type for the Query/Params RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#cronos.icactl.v1.Params) | | params holds all the parameters of this module. | +| `params` | [Params](#cronos.icaauth.v1.Params) | | params holds all the parameters of this module. | @@ -524,28 +524,28 @@ QueryParamsResponse is response type for the Query/Params RPC method. - + ### Query Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Params` | [QueryParamsRequest](#cronos.icactl.v1.QueryParamsRequest) | [QueryParamsResponse](#cronos.icactl.v1.QueryParamsResponse) | Parameters queries the parameters of the module. | GET|/cronos/icactl/v1/params| -| `InterchainAccountAddress` | [QueryInterchainAccountAddressRequest](#cronos.icactl.v1.QueryInterchainAccountAddressRequest) | [QueryInterchainAccountAddressResponse](#cronos.icactl.v1.QueryInterchainAccountAddressResponse) | InterchainAccountAddress queries the interchain account address for given `connectionId` and `owner` | GET|/cronos/icactl/v1/interchain_account_address/{connectionId}/{owner}| +| `Params` | [QueryParamsRequest](#cronos.icaauth.v1.QueryParamsRequest) | [QueryParamsResponse](#cronos.icaauth.v1.QueryParamsResponse) | Parameters queries the parameters of the module. | GET|/cronos/icaauth/v1/params| +| `InterchainAccountAddress` | [QueryInterchainAccountAddressRequest](#cronos.icaauth.v1.QueryInterchainAccountAddressRequest) | [QueryInterchainAccountAddressResponse](#cronos.icaauth.v1.QueryInterchainAccountAddressResponse) | InterchainAccountAddress queries the interchain account address for given `connection_id` and `owner` | GET|/cronos/icaauth/v1/interchain_account_address/{connection_id}/{owner}| - +

Top

-## icactl/v1/tx.proto +## icaauth/v1/tx.proto - + ### MsgRegisterAccount MsgRegisterAccount defines the request message for MsgRegisterAccount @@ -554,14 +554,15 @@ MsgRegisterAccount defines the request message for MsgRegisterAccount | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `owner` | [string](#string) | | owner represents the owner of the interchain account | -| `connectionId` | [string](#string) | | connectionId represents the IBC `connectionId` of the host chain | +| `connection_id` | [string](#string) | | connection_id represents the IBC `connection_id` of the host chain | +| `version` | [string](#string) | | version represents the version of the ICA channel | - + ### MsgRegisterAccountResponse MsgRegisterAccountResponse defines the response message for MsgRegisterAccount @@ -571,7 +572,7 @@ MsgRegisterAccountResponse defines the response message for MsgRegisterAccount - + ### MsgSubmitTx MsgSubmitTx defines the request message for MsgSubmitTx @@ -580,16 +581,16 @@ MsgSubmitTx defines the request message for MsgSubmitTx | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `owner` | [string](#string) | | owner represents the owner of the interchain account | -| `connectionId` | [string](#string) | | connectionId represents the IBC `connectionId` of the host chain | +| `connection_id` | [string](#string) | | connection_id represents the IBC `connection_id` of the host chain | | `msgs` | [google.protobuf.Any](#google.protobuf.Any) | repeated | msgs represents the transactions to be submitted to the host chain | -| `timeoutDuration` | [google.protobuf.Duration](#google.protobuf.Duration) | | timeoutDuration represents the timeout duration for the IBC packet from last block | +| `timeout_duration` | [google.protobuf.Duration](#google.protobuf.Duration) | | timeout_duration represents the timeout duration for the IBC packet from last block | - + ### MsgSubmitTxResponse MsgSubmitTxResponse defines the response message for MsgSubmitTx @@ -605,15 +606,15 @@ MsgSubmitTxResponse defines the response message for MsgSubmitTx - + ### Msg Msg defines the Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `RegisterAccount` | [MsgRegisterAccount](#cronos.icactl.v1.MsgRegisterAccount) | [MsgRegisterAccountResponse](#cronos.icactl.v1.MsgRegisterAccountResponse) | RegisterAccount registers an interchain account on host chain with given `connectionId` | | -| `SubmitTx` | [MsgSubmitTx](#cronos.icactl.v1.MsgSubmitTx) | [MsgSubmitTxResponse](#cronos.icactl.v1.MsgSubmitTxResponse) | SubmitTx submits a transaction to the host chain on behalf of interchain account | | +| `RegisterAccount` | [MsgRegisterAccount](#cronos.icaauth.v1.MsgRegisterAccount) | [MsgRegisterAccountResponse](#cronos.icaauth.v1.MsgRegisterAccountResponse) | RegisterAccount registers an interchain account on host chain with given `connection_id` | | +| `SubmitTx` | [MsgSubmitTx](#cronos.icaauth.v1.MsgSubmitTx) | [MsgSubmitTxResponse](#cronos.icaauth.v1.MsgSubmitTxResponse) | SubmitTx submits a transaction to the host chain on behalf of interchain account | | diff --git a/go.mod b/go.mod index 6d34a7c489..434b506462 100644 --- a/go.mod +++ b/go.mod @@ -19,9 +19,11 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/linxGnu/grocksdb v1.8.0 github.com/peggyjv/gravity-bridge/module/v2 v2.0.0-20220420162017-838c0d25e974 + github.com/pkg/errors v0.9.1 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 + github.com/spf13/viper v1.14.0 github.com/stretchr/testify v1.8.3 github.com/tendermint/tendermint v0.34.29 github.com/tendermint/tm-db v0.6.7 @@ -156,7 +158,6 @@ require ( github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.14.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect @@ -174,7 +175,6 @@ require ( github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/spf13/afero v1.9.3 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/spf13/viper v1.14.0 // indirect github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index 6972d301d2..df6beaed30 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -1244,8 +1244,9 @@ def ica_register_account(self, connid, **kwargs): return json.loads( self.raw( "tx", - "icactl", - "register-account", + "ica", + "controller", + "register", connid, "-y", **(default_kwargs | kwargs), @@ -1262,8 +1263,9 @@ def ica_submit_tx(self, connid, tx, **kwargs): return json.loads( self.raw( "tx", - "icactl", - "submit-tx", + "ica", + "controller", + "send-tx", connid, tx, "-y", @@ -1279,7 +1281,7 @@ def ica_query_account(self, connid, owner, **kwargs): return json.loads( self.raw( "q", - "icactl", + "icaauth", "interchain-account-address", connid, owner, @@ -1287,6 +1289,20 @@ def ica_query_account(self, connid, owner, **kwargs): ) ) + def ica_generate_packet_data(self, tx, memo=None, **kwargs): + return json.loads( + self.raw( + "tx", + "interchain-accounts", + "host", + "generate-packet-data", + tx, + "--memo" if memo else None, + home=self.data_dir, + **kwargs, + ) + ) + def ibc_query_channels(self, connid, **kwargs): default_kwargs = { "node": self.node_rpc, @@ -1387,7 +1403,7 @@ def ibc_update_client_with_header(self, client_id, header, **kwargs): ) ) - def query_icactl_params(self, **kwargs): + def query_icaauth_params(self, **kwargs): default_kwargs = { "node": self.node_rpc, "output": "json", @@ -1395,7 +1411,7 @@ def query_icactl_params(self, **kwargs): return json.loads( self.raw( "q", - "icactl", + "icaauth", "params", **(default_kwargs | kwargs), ) diff --git a/integration_tests/test_ibc.py b/integration_tests/test_ibc.py index 98e55364ea..1d14243bb2 100644 --- a/integration_tests/test_ibc.py +++ b/integration_tests/test_ibc.py @@ -1,4 +1,6 @@ +import base64 import hashlib +import json import pytest @@ -433,3 +435,95 @@ def check_contract_balance_change(): def ibc_denom(channel, denom): h = hashlib.sha256(f"transfer/{channel}/{denom}".encode()).hexdigest().upper() return f"ibc/{h}" + + +def test_ica(ibc, tmp_path): + connid = "connection-0" + cli_host = ibc.chainmain.cosmos_cli() + cli_controller = ibc.cronos.cosmos_cli() + + print("register ica account") + rsp = cli_controller.ica_register_account( + connid, from_="signer2", gas="400000", fees="100000000basetcro" + ) + assert rsp["code"] == 0, rsp["raw_log"] + port_id, channel_id = next( + ( + base64.b64decode(evt["attributes"][0]["value"].encode()).decode(), + base64.b64decode(evt["attributes"][1]["value"].encode()).decode(), + ) + for evt in rsp["events"] + if evt["type"] == "channel_open_init" + ) + print("port-id", port_id, "channel-id", channel_id) + + print("wait for ica channel ready") + + def check_channel_ready(): + channels = cli_controller.ibc_query_channels(connid)["channels"] + try: + state = next( + channel["state"] + for channel in channels + if channel["channel_id"] == channel_id + ) + except StopIteration: + return False + return state == "STATE_OPEN" + + wait_for_fn("channel ready", check_channel_ready) + + print("query ica account") + ica_address = cli_controller.ica_query_account( + connid, cli_controller.address("signer2") + )["interchain_account_address"] + print("ica address", ica_address) + + # initial balance of interchain account should be zero + assert cli_host.balance(ica_address) == 0 + + # send some funds to interchain account + rsp = cli_host.transfer("signer2", ica_address, "1cro", gas_prices="1000000basecro") + assert rsp["code"] == 0, rsp["raw_log"] + wait_for_new_blocks(cli_host, 1) + + # check if the funds are received in interchain account + assert cli_host.balance(ica_address, denom="basecro") == 100000000 + + # generate a transaction to send to host chain + generated_tx = tmp_path / "generated_tx.txt" + generated_tx_msg = { + "@type": "/cosmos.bank.v1beta1.MsgSend", + "from_address": ica_address, + "to_address": cli_host.address("signer2"), + "amount": [{"denom": "basecro", "amount": "50000000"}], + } + str = json.dumps(generated_tx_msg) + generated_packet = cli_controller.ica_generate_packet_data(str) + print(generated_packet) + generated_tx.write_text(json.dumps(generated_packet)) + + num_txs = len(cli_host.query_all_txs(ica_address)["txs"]) + + # submit transaction on host chain on behalf of interchain account + rsp = cli_controller.ica_submit_tx( + connid, + generated_tx, + from_="signer2", + ) + assert rsp["code"] == 0, rsp["raw_log"] + packet_seq = next( + int(base64.b64decode(evt["attributes"][4]["value"].encode())) + for evt in rsp["events"] + if evt["type"] == "send_packet" + ) + print("packet sequence", packet_seq) + + def check_ica_tx(): + return len(cli_host.query_all_txs(ica_address)["txs"]) > num_txs + + print("wait for ica tx arrive") + wait_for_fn("ica transfer tx", check_ica_tx) + + # check if the funds are reduced in interchain account + assert cli_host.balance(ica_address, denom="basecro") == 50000000 diff --git a/proto/buf.gen.gogo.yaml b/proto/buf.gen.gogo.yaml index b9090bcdc2..9c8ba0a4b1 100644 --- a/proto/buf.gen.gogo.yaml +++ b/proto/buf.gen.gogo.yaml @@ -2,7 +2,7 @@ version: v1 plugins: - name: gocosmos out: .. - opt: plugins=grpc + opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types - name: grpc-gateway out: .. opt: logtostderr=true,allow_colon_final_segments=true diff --git a/proto/cronos/genesis.proto b/proto/cronos/genesis.proto index 2748aad3f5..66464344a8 100644 --- a/proto/cronos/genesis.proto +++ b/proto/cronos/genesis.proto @@ -10,10 +10,10 @@ option go_package = "github.com/crypto-org-chain/cronos/v2/x/cronos/types"; // GenesisState defines the cronos module's genesis state. message GenesisState { - // params defines all the paramaters of the module. - Params params = 1 [(gogoproto.nullable) = false]; - repeated TokenMapping external_contracts = 2 [(gogoproto.nullable) = false]; - repeated TokenMapping auto_contracts = 3 [(gogoproto.nullable) = false]; - // this line is used by starport scaffolding # genesis/proto/state - // this line is used by starport scaffolding # ibc/genesis/proto + // params defines all the paramaters of the module. + Params params = 1 [ (gogoproto.nullable) = false ]; + repeated TokenMapping external_contracts = 2 [ (gogoproto.nullable) = false ]; + repeated TokenMapping auto_contracts = 3 [ (gogoproto.nullable) = false ]; + // this line is used by starport scaffolding # genesis/proto/state + // this line is used by starport scaffolding # ibc/genesis/proto } diff --git a/proto/cronos/query.proto b/proto/cronos/query.proto index 56720629cb..ba4d936f55 100644 --- a/proto/cronos/query.proto +++ b/proto/cronos/query.proto @@ -12,72 +12,74 @@ option go_package = "github.com/crypto-org-chain/cronos/v2/x/cronos/types"; // Query defines the gRPC querier service. service Query { - // ContractByDenom queries contract addresses by native denom - rpc ContractByDenom(ContractByDenomRequest) returns (ContractByDenomResponse) { - option (google.api.http).get = "/cronos/v1/contract_by_denom/{denom}"; - } - - // DenomByContract queries native denom by contract address - rpc DenomByContract(DenomByContractRequest) returns (DenomByContractResponse) { - option (google.api.http).get = "/cronos/v1/denom_by_contract/{contract}"; - } - - // ReplayBlock replay the eth messages in the block to recover the results of false-failed txs. - rpc ReplayBlock(ReplayBlockRequest) returns (ReplayBlockResponse) { } - - // Params queries all parameters. - rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { - option (google.api.http).get = "/cronos/v1/params"; - } - - // Params queries permissions for a specific address.. - rpc Permissions(QueryPermissionsRequest) returns (QueryPermissionsResponse) { - option (google.api.http).get = "/cronos/v1/permissions"; - } - - // this line is used by starport scaffolding # 2 + // ContractByDenom queries contract addresses by native denom + rpc ContractByDenom(ContractByDenomRequest) + returns (ContractByDenomResponse) { + option (google.api.http).get = "/cronos/v1/contract_by_denom/{denom}"; + } + + // DenomByContract queries native denom by contract address + rpc DenomByContract(DenomByContractRequest) + returns (DenomByContractResponse) { + option (google.api.http).get = "/cronos/v1/denom_by_contract/{contract}"; + } + + // ReplayBlock replay the eth messages in the block to recover the results of + // false-failed txs. + rpc ReplayBlock(ReplayBlockRequest) returns (ReplayBlockResponse) {} + + // Params queries all parameters. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/cronos/v1/params"; + } + + // Params queries permissions for a specific address.. + rpc Permissions(QueryPermissionsRequest) returns (QueryPermissionsResponse) { + option (google.api.http).get = "/cronos/v1/permissions"; + } + + // this line is used by starport scaffolding # 2 } // ContractByDenomRequest is the request type of ContractByDenom call message ContractByDenomRequest { - option (gogoproto.equal) = false; - option (gogoproto.goproto_getters) = false; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; - string denom = 1; + string denom = 1; } // ContractByDenomRequest is the response type of ContractByDenom call message ContractByDenomResponse { - string contract = 1; - string auto_contract = 2; + string contract = 1; + string auto_contract = 2; } // DenomByContractRequest is the request type of DenomByContract call message DenomByContractRequest { - option (gogoproto.equal) = false; - option (gogoproto.goproto_getters) = false; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; - string contract = 1; + string contract = 1; } // DenomByContractResponse is the response type of DenomByContract call -message DenomByContractResponse { - string denom = 1; -} +message DenomByContractResponse { string denom = 1; } // ReplayBlockRequest message ReplayBlockRequest { - option (gogoproto.equal) = false; - option (gogoproto.goproto_getters) = false; - - // the eth messages in the block - repeated ethermint.evm.v1.MsgEthereumTx msgs = 1; - int64 block_number = 2; - string block_hash = 3; - google.protobuf.Timestamp block_time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // the eth messages in the block + repeated ethermint.evm.v1.MsgEthereumTx msgs = 1; + int64 block_number = 2; + string block_hash = 3; + google.protobuf.Timestamp block_time = 4 + [ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ]; } -// ReplayBlockResponse +// ReplayBlockResponse message ReplayBlockResponse { repeated ethermint.evm.v1.MsgEthereumTxResponse responses = 1; } @@ -87,19 +89,19 @@ message QueryParamsRequest {} // QueryParamsResponse is the response type for the Query/Params RPC method. message QueryParamsResponse { - // params defines the parameters of the module. - Params params = 1 [(gogoproto.nullable) = false]; + // params defines the parameters of the module. + Params params = 1 [ (gogoproto.nullable) = false ]; } -// QueryPermissionsRequest is the request type for the Query/Permissions RPC method. -message QueryPermissionsRequest { - string address = 1; -} +// QueryPermissionsRequest is the request type for the Query/Permissions RPC +// method. +message QueryPermissionsRequest { string address = 1; } -// QueryPermissionsResponse is the response type for the Query/Permissions RPC method. +// QueryPermissionsResponse is the response type for the Query/Permissions RPC +// method. message QueryPermissionsResponse { - bool can_change_token_mapping = 1; - bool can_turn_bridge = 2; + bool can_change_token_mapping = 1; + bool can_turn_bridge = 2; } // this line is used by starport scaffolding # 3 diff --git a/proto/cronos/tx.proto b/proto/cronos/tx.proto index 89116c6b21..3647b2e229 100644 --- a/proto/cronos/tx.proto +++ b/proto/cronos/tx.proto @@ -32,7 +32,8 @@ service Msg { rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); // UpdatePermissions defines a method to update cronos admins permissions - rpc UpdatePermissions(MsgUpdatePermissions) returns (MsgUpdatePermissionsResponse); + rpc UpdatePermissions(MsgUpdatePermissions) + returns (MsgUpdatePermissionsResponse); } // MsgConvertVouchers represents a message to convert ibc voucher coins to @@ -86,17 +87,18 @@ message MsgTurnBridgeResponse {} // MsgUpdateParams defines the request type for updating cronos params. message MsgUpdateParams { - // authority is the address of the governance account. - string authority = 1; + // authority is the address of the governance account. + string authority = 1; - // NOTE: All parameters must be supplied. - Params params = 2 [(gogoproto.nullable) = false]; + // NOTE: All parameters must be supplied. + Params params = 2 [ (gogoproto.nullable) = false ]; } // MsgUpdateParamsResponse defines the response type. message MsgUpdateParamsResponse {} -// MsgUpdatePermissions defines the request type for updating cronos permissions. +// MsgUpdatePermissions defines the request type for updating cronos +// permissions. message MsgUpdatePermissions { string from = 1; string address = 2; diff --git a/proto/icaauth/v1/genesis.proto b/proto/icaauth/v1/genesis.proto new file mode 100644 index 0000000000..861542afd2 --- /dev/null +++ b/proto/icaauth/v1/genesis.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package icaauth.v1; + +import "gogoproto/gogo.proto"; +import "icaauth/v1/params.proto"; + +option go_package = "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"; + +// GenesisState defines the icaauth module's genesis state. +message GenesisState { + // params defines the genesis parameters + Params params = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/icaauth/v1/params.proto b/proto/icaauth/v1/params.proto new file mode 100644 index 0000000000..2bdf5f280a --- /dev/null +++ b/proto/icaauth/v1/params.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package icaauth.v1; + +import "google/protobuf/duration.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"; + +// Params defines the parameters for the module. +message Params { + option (gogoproto.goproto_stringer) = false; + + // min_timeout_duration defines the minimum value of packet timeout when + // submitting transactions to host chain on behalf of interchain account + google.protobuf.Duration min_timeout_duration = 1 [ + (gogoproto.moretags) = "yaml:\"min_timeout_duration\"", + (gogoproto.stdduration) = true, + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/proto/icaauth/v1/query.proto b/proto/icaauth/v1/query.proto new file mode 100644 index 0000000000..ee15982e13 --- /dev/null +++ b/proto/icaauth/v1/query.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; +package icaauth.v1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "icaauth/v1/params.proto"; + +option go_package = "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"; + +// Query defines the gRPC querier service. +service Query { + // Parameters queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/cronos/icaauth/v1/params"; + } + + // InterchainAccountAddress queries the interchain account address for given + // `connection_id` and `owner` + rpc InterchainAccountAddress(QueryInterchainAccountAddressRequest) + returns (QueryInterchainAccountAddressResponse) { + option (google.api.http).get = + "/cronos/icaauth/v1/interchain_account_address/{connection_id}/{owner}"; + } +} + +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryInterchainAccountAddressRequest defines the request for the +// InterchainAccountAddress query. +message QueryInterchainAccountAddressRequest { + string connection_id = 1 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + string owner = 2; +} + +// QueryInterchainAccountAddressResponse defines the response for the +// InterchainAccountAddress query. +message QueryInterchainAccountAddressResponse { + string interchain_account_address = 1; +} diff --git a/proto/icaauth/v1/tx.proto b/proto/icaauth/v1/tx.proto new file mode 100644 index 0000000000..2512714436 --- /dev/null +++ b/proto/icaauth/v1/tx.proto @@ -0,0 +1,57 @@ +syntax = "proto3"; +package icaauth.v1; + +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/any.proto"; + +option go_package = "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"; + +// Msg defines the Msg service. +service Msg { + // RegisterAccount registers an interchain account on host chain with given + // `connection_id` + rpc RegisterAccount(MsgRegisterAccount) returns (MsgRegisterAccountResponse); + + // SubmitTx submits a transaction to the host chain on behalf of interchain + // account + rpc SubmitTx(MsgSubmitTx) returns (MsgSubmitTxResponse); +} + +// MsgRegisterAccount defines the request message for MsgRegisterAccount +message MsgRegisterAccount { + // owner represents the owner of the interchain account + string owner = 1; + + // connection_id represents the IBC `connection_id` of the host chain + string connection_id = 2 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + + // version represents the version of the ICA channel + string version = 3; +} + +// MsgRegisterAccountResponse defines the response message for +// MsgRegisterAccount +message MsgRegisterAccountResponse {} + +// MsgSubmitTx defines the request message for MsgSubmitTx +message MsgSubmitTx { + // owner represents the owner of the interchain account + string owner = 1; + + // connection_id represents the IBC `connection_id` of the host chain + string connection_id = 2 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + + // msgs represents the transactions to be submitted to the host chain + repeated google.protobuf.Any msgs = 3 + [ (cosmos_proto.accepts_interface) = "sdk.Msg" ]; + + // timeout_duration represents the timeout duration for the IBC packet from + // last block + google.protobuf.Duration timeout_duration = 4 + [ (gogoproto.stdduration) = true ]; +} + +// MsgSubmitTxResponse defines the response message for MsgSubmitTx +message MsgSubmitTxResponse {} \ No newline at end of file diff --git a/proto/memiavl/wal.proto b/proto/memiavl/wal.proto index 0b55ae85ce..efe500867f 100644 --- a/proto/memiavl/wal.proto +++ b/proto/memiavl/wal.proto @@ -9,7 +9,7 @@ import "cosmos/base/store/v1beta1/commit_info.proto"; // NamedChangeSet combine a tree name with the changeset message NamedChangeSet { - iavl.ChangeSet changeset = 1 [(gogoproto.nullable) = false]; + iavl.ChangeSet changeset = 1 [ (gogoproto.nullable) = false ]; string name = 2; } diff --git a/x/cronos/client/cli/tx.go b/x/cronos/client/cli/tx.go index 76096d16fe..af3bf56c60 100644 --- a/x/cronos/client/cli/tx.go +++ b/x/cronos/client/cli/tx.go @@ -22,8 +22,12 @@ import ( "github.com/cosmos/cosmos-sdk/client" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + + icagenesistypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/genesis/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" ibcfeetypes "github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types" "github.com/crypto-org-chain/cronos/v2/x/cronos/types" + icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" evmtypes "github.com/evmos/ethermint/x/evm/types" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types" @@ -408,6 +412,14 @@ func Migrate(appState genutiltypes.AppMap, clientCtx client.Context) genutiltype if appState[gravitytypes.ModuleName] == nil { appState[gravitytypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(gravitytypes.DefaultGenesisState()) } + // Add interchainaccounts with default genesis. + if appState[icatypes.ModuleName] == nil { + appState[icatypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(icagenesistypes.DefaultGenesis()) + } + // Add icaauth with default genesis. + if appState[icaauthtypes.ModuleName] == nil { + appState[icaauthtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(icaauthtypes.DefaultGenesis()) + } var evmState ExportEvmGenesisState err := json.Unmarshal(appState[evmtypes.ModuleName], &evmState) if err != nil { diff --git a/x/cronos/types/query.pb.go b/x/cronos/types/query.pb.go index c10e824ec5..2a29f01a76 100644 --- a/x/cronos/types/query.pb.go +++ b/x/cronos/types/query.pb.go @@ -378,7 +378,8 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } -// QueryPermissionsRequest is the request type for the Query/Permissions RPC method. +// QueryPermissionsRequest is the request type for the Query/Permissions RPC +// method. type QueryPermissionsRequest struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` } @@ -423,7 +424,8 @@ func (m *QueryPermissionsRequest) GetAddress() string { return "" } -// QueryPermissionsResponse is the response type for the Query/Permissions RPC method. +// QueryPermissionsResponse is the response type for the Query/Permissions RPC +// method. type QueryPermissionsResponse struct { CanChangeTokenMapping bool `protobuf:"varint,1,opt,name=can_change_token_mapping,json=canChangeTokenMapping,proto3" json:"can_change_token_mapping,omitempty"` CanTurnBridge bool `protobuf:"varint,2,opt,name=can_turn_bridge,json=canTurnBridge,proto3" json:"can_turn_bridge,omitempty"` @@ -560,7 +562,8 @@ type QueryClient interface { ContractByDenom(ctx context.Context, in *ContractByDenomRequest, opts ...grpc.CallOption) (*ContractByDenomResponse, error) // DenomByContract queries native denom by contract address DenomByContract(ctx context.Context, in *DenomByContractRequest, opts ...grpc.CallOption) (*DenomByContractResponse, error) - // ReplayBlock replay the eth messages in the block to recover the results of false-failed txs. + // ReplayBlock replay the eth messages in the block to recover the results of + // false-failed txs. ReplayBlock(ctx context.Context, in *ReplayBlockRequest, opts ...grpc.CallOption) (*ReplayBlockResponse, error) // Params queries all parameters. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) @@ -627,7 +630,8 @@ type QueryServer interface { ContractByDenom(context.Context, *ContractByDenomRequest) (*ContractByDenomResponse, error) // DenomByContract queries native denom by contract address DenomByContract(context.Context, *DenomByContractRequest) (*DenomByContractResponse, error) - // ReplayBlock replay the eth messages in the block to recover the results of false-failed txs. + // ReplayBlock replay the eth messages in the block to recover the results of + // false-failed txs. ReplayBlock(context.Context, *ReplayBlockRequest) (*ReplayBlockResponse, error) // Params queries all parameters. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) diff --git a/x/cronos/types/tx.pb.go b/x/cronos/types/tx.pb.go index 6dacd6669f..f46ebccf0c 100644 --- a/x/cronos/types/tx.pb.go +++ b/x/cronos/types/tx.pb.go @@ -517,7 +517,8 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo -// MsgUpdatePermissions defines the request type for updating cronos permissions. +// MsgUpdatePermissions defines the request type for updating cronos +// permissions. type MsgUpdatePermissions struct { From string `protobuf:"bytes,1,opt,name=from,proto3" json:"from,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` diff --git a/x/icaauth/client/cli/flags.go b/x/icaauth/client/cli/flags.go new file mode 100644 index 0000000000..73b5c17cef --- /dev/null +++ b/x/icaauth/client/cli/flags.go @@ -0,0 +1,7 @@ +package cli + +const ( + // The controller chain channel version + FlagVersion = "version" + FlagTimeoutDuration = "timeout-duration" +) diff --git a/x/icaauth/client/cli/query.go b/x/icaauth/client/cli/query.go new file mode 100644 index 0000000000..6f74b88f41 --- /dev/null +++ b/x/icaauth/client/cli/query.go @@ -0,0 +1,26 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/spf13/cobra" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + // Group icaauth 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(CmdInterchainAccountAddress()) + + return cmd +} diff --git a/x/icaauth/client/cli/query_interchain_account_address.go b/x/icaauth/client/cli/query_interchain_account_address.go new file mode 100644 index 0000000000..b4875a9cae --- /dev/null +++ b/x/icaauth/client/cli/query_interchain_account_address.go @@ -0,0 +1,47 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdInterchainAccountAddress() *cobra.Command { + cmd := &cobra.Command{ + Use: "interchain-account-address [connection-id] [owner]", + Short: "Gets interchain account address on host chain", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + reqConnectionID := args[0] + reqOwner := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryInterchainAccountAddressRequest{ + ConnectionId: reqConnectionID, + Owner: reqOwner, + } + + res, err := queryClient.InterchainAccountAddress(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/icaauth/client/cli/query_params.go b/x/icaauth/client/cli/query_params.go new file mode 100644 index 0000000000..583258fb27 --- /dev/null +++ b/x/icaauth/client/cli/query_params.go @@ -0,0 +1,34 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/spf13/cobra" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []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/icaauth/client/cli/tx.go b/x/icaauth/client/cli/tx.go new file mode 100644 index 0000000000..54891dad56 --- /dev/null +++ b/x/icaauth/client/cli/tx.go @@ -0,0 +1,25 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/spf13/cobra" +) + +// 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(CmdRegisterAccount()) + cmd.AddCommand(CmdSubmitTx()) + + return cmd +} diff --git a/x/icaauth/client/cli/tx_register_account.go b/x/icaauth/client/cli/tx_register_account.go new file mode 100644 index 0000000000..25ef06a369 --- /dev/null +++ b/x/icaauth/client/cli/tx_register_account.go @@ -0,0 +1,48 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdRegisterAccount() *cobra.Command { + cmd := &cobra.Command{ + Use: "register-account [connection-id]", + Short: "Registers an interchain account", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + argConnectionID := args[0] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + version, err := cmd.Flags().GetString(FlagVersion) + if err != nil { + return err + } + + msg := types.NewMsgRegisterAccount( + clientCtx.GetFromAddress().String(), + argConnectionID, + version, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/icaauth/client/cli/tx_submit_tx.go b/x/icaauth/client/cli/tx_submit_tx.go new file mode 100644 index 0000000000..5e9c32c44c --- /dev/null +++ b/x/icaauth/client/cli/tx_submit_tx.go @@ -0,0 +1,68 @@ +package cli + +import ( + "fmt" + "strconv" + "strings" + "time" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdSubmitTx() *cobra.Command { + cmd := &cobra.Command{ + Use: "submit-tx [connection-id] [msg_tx_json_file]", + Short: "Submit a transaction on host chain on behalf of the interchain account", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a transaction on host chain on behalf of the interchain account: +Example: + $ %s tx %s submit-tx connection-1 tx.json --from mykey + $ %s tx bank send --generate-only > tx.json && %s tx %s submit-tx connection-1 tx.json --from mykey + `, version.AppName, types.ModuleName, version.AppName, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + argConnectionID := args[0] + argMsg := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + theTx, err := authclient.ReadTxFromFile(clientCtx, argMsg) + if err != nil { + return err + } + + timeoutDuration, err := cmd.Flags().GetDuration(FlagTimeoutDuration) + if err != nil { + return err + } + + msg := types.NewMsgSubmitTx( + clientCtx.GetFromAddress().String(), + argConnectionID, + theTx.GetMsgs(), + &timeoutDuration, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + cmd.Flags().Duration(FlagTimeoutDuration, time.Minute*5, "Timeout duration for the transaction (default: 5 minutes)") + + return cmd +} diff --git a/x/icaauth/genesis.go b/x/icaauth/genesis.go new file mode 100644 index 0000000000..ef4c1e673c --- /dev/null +++ b/x/icaauth/genesis.go @@ -0,0 +1,25 @@ +package icaauth + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + if err := k.SetParams(ctx, genState.Params); err != nil { + panic(fmt.Sprintf("Invalid icaauth module params: %v\n", genState.Params)) + } +} + +// 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/icaauth/handler.go b/x/icaauth/handler.go new file mode 100644 index 0000000000..5c96c2bc3b --- /dev/null +++ b/x/icaauth/handler.go @@ -0,0 +1,32 @@ +package icaauth + +import ( + "fmt" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" +) + +// NewHandler ... +func NewHandler(k keeper.Keeper) sdk.Handler { + msgServer := keeper.NewMsgServerImpl(k) + + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + ctx = ctx.WithEventManager(sdk.NewEventManager()) + + switch msg := msg.(type) { + case *types.MsgRegisterAccount: + res, err := msgServer.RegisterAccount(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgSubmitTx: + res, err := msgServer.SubmitTx(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } + } +} diff --git a/x/icaauth/keeper/grpc_query.go b/x/icaauth/keeper/grpc_query.go new file mode 100644 index 0000000000..ba5a26a542 --- /dev/null +++ b/x/icaauth/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/icaauth/keeper/grpc_query_interchain_account_address.go b/x/icaauth/keeper/grpc_query_interchain_account_address.go new file mode 100644 index 0000000000..a7e502cccd --- /dev/null +++ b/x/icaauth/keeper/grpc_query_interchain_account_address.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) InterchainAccountAddress(goCtx context.Context, req *types.QueryInterchainAccountAddressRequest) (*types.QueryInterchainAccountAddressResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + icaAddress, err := k.GetInterchainAccountAddress(ctx, req.ConnectionId, req.Owner) + if err != nil { + return nil, err + } + + return &types.QueryInterchainAccountAddressResponse{ + InterchainAccountAddress: icaAddress, + }, nil +} diff --git a/x/icaauth/keeper/grpc_query_params.go b/x/icaauth/keeper/grpc_query_params.go new file mode 100644 index 0000000000..cea397862c --- /dev/null +++ b/x/icaauth/keeper/grpc_query_params.go @@ -0,0 +1,19 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +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/icaauth/keeper/keeper.go b/x/icaauth/keeper/keeper.go new file mode 100644 index 0000000000..05f4caa5b5 --- /dev/null +++ b/x/icaauth/keeper/keeper.go @@ -0,0 +1,118 @@ +package keeper + +import ( + "fmt" + "time" + + "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + icacontrollerkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/keeper" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/gogo/protobuf/proto" + "github.com/tendermint/tendermint/libs/log" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type ( + Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + + icaControllerKeeper icacontrollerkeeper.Keeper + scopedKeeper capabilitykeeper.ScopedKeeper + } +) + +func NewKeeper( + cdc codec.Codec, + storeKey, + memKey storetypes.StoreKey, + icaControllerKeeper icacontrollerkeeper.Keeper, + scopedKeeper capabilitykeeper.ScopedKeeper, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + + icaControllerKeeper: icaControllerKeeper, + scopedKeeper: scopedKeeper, + } +} + +// DoSubmitTx submits a transaction to the host chain on behalf of interchain account +func (k *Keeper) DoSubmitTx(ctx sdk.Context, connectionID, owner string, msgs []proto.Message, timeoutDuration time.Duration) error { + portID, err := icatypes.NewControllerPortID(owner) + if err != nil { + return err + } + + channelID, found := k.icaControllerKeeper.GetActiveChannelID(ctx, connectionID, portID) + if !found { + return errors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) + } + + channelCapability, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) + if !found { + return errors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } + + data, err := icatypes.SerializeCosmosTx(k.cdc, msgs) + if err != nil { + return err + } + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: data, + } + + // timeoutDuration should be constraited by MinTimeoutDuration parameter. + timeoutTimestamp := ctx.BlockTime().Add(timeoutDuration).UnixNano() + + _, err = k.icaControllerKeeper.SendTx(ctx, channelCapability, connectionID, portID, packetData, uint64(timeoutTimestamp)) //nolint:staticcheck + if err != nil { + return err + } + + return nil +} + +// RegisterInterchainAccount registers an interchain account with the given `connectionId` and `owner` on the host chain +func (k *Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, version string) error { + return k.icaControllerKeeper.RegisterInterchainAccount(ctx, connectionID, owner, version) +} + +// GetInterchainAccountAddress fetches the interchain account address for given `connectionId` and `owner` +func (k *Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, owner string) (string, error) { + portID, err := icatypes.NewControllerPortID(owner) + if err != nil { + return "", status.Errorf(codes.InvalidArgument, "invalid owner address: %s", err) + } + + icaAddress, found := k.icaControllerKeeper.GetInterchainAccountAddress(ctx, connectionID, portID) + + if !found { + return "", status.Errorf(codes.NotFound, "could not find account") + } + + return icaAddress, nil +} + +// ClaimCapability claims the channel capability passed via the OnOpenChanInit callback +func (k *Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { + return k.scopedKeeper.ClaimCapability(ctx, cap, name) +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} diff --git a/x/icaauth/keeper/msg_server.go b/x/icaauth/keeper/msg_server.go new file mode 100644 index 0000000000..d01fce99a6 --- /dev/null +++ b/x/icaauth/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/crypto-org-chain/cronos/v2/x/icaauth/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{} diff --git a/x/icaauth/keeper/msg_server_register_account.go b/x/icaauth/keeper/msg_server_register_account.go new file mode 100644 index 0000000000..45b1939d75 --- /dev/null +++ b/x/icaauth/keeper/msg_server_register_account.go @@ -0,0 +1,18 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" +) + +func (k msgServer) RegisterAccount(goCtx context.Context, msg *types.MsgRegisterAccount) (*types.MsgRegisterAccountResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if err := k.RegisterInterchainAccount(ctx, msg.ConnectionId, msg.Owner, msg.Version); err != nil { + return nil, err + } + + return &types.MsgRegisterAccountResponse{}, nil +} diff --git a/x/icaauth/keeper/msg_server_submit_tx.go b/x/icaauth/keeper/msg_server_submit_tx.go new file mode 100644 index 0000000000..b0ceba4e6e --- /dev/null +++ b/x/icaauth/keeper/msg_server_submit_tx.go @@ -0,0 +1,26 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" +) + +func (k msgServer) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + msgs, err := msg.GetMessages() + if err != nil { + return nil, err + } + + minTimeoutDuration := k.MinTimeoutDuration(ctx) + + err = k.DoSubmitTx(ctx, msg.ConnectionId, msg.Owner, msgs, msg.CalculateTimeoutDuration(minTimeoutDuration)) + if err != nil { + return nil, err + } + + return &types.MsgSubmitTxResponse{}, nil +} diff --git a/x/icaauth/keeper/params.go b/x/icaauth/keeper/params.go new file mode 100644 index 0000000000..39f7bd5387 --- /dev/null +++ b/x/icaauth/keeper/params.go @@ -0,0 +1,37 @@ +package keeper + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/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 { + if err := params.Validate(); err != nil { + return err + } + + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(¶ms) + store.Set(types.ParamsKey, bz) + + return nil +} + +// MinTimeoutDuration returns the MinTimeoutDuration param +func (k Keeper) MinTimeoutDuration(ctx sdk.Context) (res time.Duration) { + return k.GetParams(ctx).MinTimeoutDuration +} diff --git a/x/icaauth/module.go b/x/icaauth/module.go new file mode 100644 index 0000000000..a0df347a71 --- /dev/null +++ b/x/icaauth/module.go @@ -0,0 +1,164 @@ +package icaauth + +import ( + "encoding/json" + "fmt" + + "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/crypto-org-chain/cronos/v2/x/icaauth/client/cli" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" +) + +var ( + _ module.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, config 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(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {} + +// 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 +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.BinaryCodec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// Route returns the capability module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the capability module's Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return nil +} + +// 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) +} + +// 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 + + 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 1 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/icaauth/module_ibc.go b/x/icaauth/module_ibc.go new file mode 100644 index 0000000000..42580eafec --- /dev/null +++ b/x/icaauth/module_ibc.go @@ -0,0 +1,141 @@ +package icaauth + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/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 +func (am IBCModule) OnChanOpenInit( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID string, + channelID string, + chanCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + version string, +) (string, error) { + // Claim channel capability passed back by IBC module + if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { + return "", err + } + return version, nil +} + +// OnChanOpenTry implements the IBCModule interface +func (am IBCModule) OnChanOpenTry( + ctx sdk.Context, + order channeltypes.Order, + connectionHops []string, + portID, + channelID string, + channelCap *capabilitytypes.Capability, + counterparty channeltypes.Counterparty, + counterpartyVersion string, +) (string, error) { + // https://github.com/cosmos/ibc-go/blob/v3.0.0/docs/apps/interchain-accounts/auth-modules.md#ibcmodule-implementation + return "", errors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") +} + +// OnChanOpenAck implements the IBCModule interface +func (am IBCModule) OnChanOpenAck( + ctx sdk.Context, + portID, + channelID string, + counterpartyChannelID string, + counterpartyVersion string, +) error { + return nil +} + +// OnChanOpenConfirm implements the IBCModule interface +func (am IBCModule) OnChanOpenConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + // https://github.com/cosmos/ibc-go/blob/v3.0.0/docs/apps/interchain-accounts/auth-modules.md#ibcmodule-implementation + return errors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain") +} + +// OnChanCloseInit implements the IBCModule interface +func (am IBCModule) OnChanCloseInit( + ctx sdk.Context, + portID, + channelID string, +) error { + // https://github.com/cosmos/ibc-go/blob/v3.0.0/docs/apps/interchain-accounts/auth-modules.md#ibcmodule-implementation + return errors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") +} + +// OnChanCloseConfirm implements the IBCModule interface +func (am IBCModule) OnChanCloseConfirm( + ctx sdk.Context, + portID, + channelID string, +) error { + return nil +} + +// OnRecvPacket implements the IBCModule interface +func (am IBCModule) OnRecvPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) ibcexported.Acknowledgement { + // https://github.com/cosmos/ibc-go/blob/v3.0.0/docs/apps/interchain-accounts/auth-modules.md#ibcmodule-implementation + return channeltypes.NewErrorAcknowledgement(errors.Wrapf(sdkerrors.ErrInvalidRequest, "cannot receive packet via interchain accounts authentication module")) +} + +// OnAcknowledgementPacket implements the IBCModule interface +func (am IBCModule) OnAcknowledgementPacket( + ctx sdk.Context, + packet channeltypes.Packet, + acknowledgement []byte, + relayer sdk.AccAddress, +) error { + return nil +} + +// OnTimeoutPacket implements the IBCModule interface +func (am IBCModule) OnTimeoutPacket( + ctx sdk.Context, + packet channeltypes.Packet, + relayer sdk.AccAddress, +) error { + return nil +} + +func (am IBCModule) NegotiateAppVersion( + ctx sdk.Context, + order channeltypes.Order, + connectionID string, + portID string, + counterparty channeltypes.Counterparty, + proposedVersion string, +) (version string, err error) { + return proposedVersion, nil +} diff --git a/x/icaauth/types/codec.go b/x/icaauth/types/codec.go new file mode 100644 index 0000000000..46ff2552f4 --- /dev/null +++ b/x/icaauth/types/codec.go @@ -0,0 +1,29 @@ +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(&MsgRegisterAccount{}, "icaauth/RegisterAccount", nil) + cdc.RegisterConcrete(&MsgSubmitTx{}, "icaauth/SubmitTx", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgRegisterAccount{}, + ) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgSubmitTx{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/icaauth/types/genesis.go b/x/icaauth/types/genesis.go new file mode 100644 index 0000000000..ffd96d1aad --- /dev/null +++ b/x/icaauth/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/icaauth/types/genesis.pb.go b/x/icaauth/types/genesis.pb.go new file mode 100644 index 0000000000..ca656595c4 --- /dev/null +++ b/x/icaauth/types/genesis.pb.go @@ -0,0 +1,322 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: icaauth/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the icaauth module's genesis state. +type GenesisState struct { + // params defines the genesis parameters + 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_2ebfc8327b166956, []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), "icaauth.v1.GenesisState") +} + +func init() { proto.RegisterFile("icaauth/v1/genesis.proto", fileDescriptor_2ebfc8327b166956) } + +var fileDescriptor_2ebfc8327b166956 = []byte{ + // 205 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xc8, 0x4c, 0x4e, 0x4c, + 0x2c, 0x2d, 0xc9, 0xd0, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x82, 0xca, 0xe8, 0x95, 0x19, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, + 0xe7, 0x83, 0x85, 0xf5, 0x41, 0x2c, 0x88, 0x0a, 0x29, 0x71, 0x24, 0xbd, 0x05, 0x89, 0x45, 0x89, + 0xb9, 0x50, 0xad, 0x4a, 0x0e, 0x5c, 0x3c, 0xee, 0x10, 0xb3, 0x82, 0x4b, 0x12, 0x4b, 0x52, 0x85, + 0x0c, 0xb8, 0xd8, 0x20, 0xf2, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x42, 0x7a, 0x08, 0xb3, + 0xf5, 0x02, 0xc0, 0x32, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x41, 0xd5, 0x39, 0xf9, 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, 0x69, 0x7a, 0x66, 0x49, 0x46, 0x69, + 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x72, 0x51, 0x65, 0x41, 0x49, 0xbe, 0x6e, 0x7e, 0x51, 0xba, + 0x6e, 0x72, 0x46, 0x62, 0x66, 0x9e, 0x7e, 0x72, 0x51, 0x7e, 0x5e, 0x7e, 0xb1, 0x7e, 0x99, 0x91, + 0x7e, 0x85, 0x3e, 0xcc, 0x71, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x97, 0x19, 0x03, + 0x02, 0x00, 0x00, 0xff, 0xff, 0x84, 0x0c, 0xaf, 0x34, 0xf0, 0x00, 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/icaauth/types/keys.go b/x/icaauth/types/keys.go new file mode 100644 index 0000000000..a70f08e864 --- /dev/null +++ b/x/icaauth/types/keys.go @@ -0,0 +1,32 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "icaauth" + + // 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_icaauth" + + // Version defines the current version the IBC module supports + Version = "icaauth-1" +) + +// prefix bytes for the icaauth persistent store +const ( + paramsKey = iota + 1 +) + +// KVStore key prefixes +var ( + // ParamsKey is the key for params. + ParamsKey = []byte{paramsKey} +) diff --git a/x/icaauth/types/message_register_account.go b/x/icaauth/types/message_register_account.go new file mode 100644 index 0000000000..93c48808c4 --- /dev/null +++ b/x/icaauth/types/message_register_account.go @@ -0,0 +1,48 @@ +package types + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgRegisterAccount = "register_account" + +var _ sdk.Msg = &MsgRegisterAccount{} + +func NewMsgRegisterAccount(owner, connectionID, version string) *MsgRegisterAccount { + return &MsgRegisterAccount{ + Owner: owner, + ConnectionId: connectionID, + Version: version, + } +} + +func (msg *MsgRegisterAccount) Route() string { + return RouterKey +} + +func (msg *MsgRegisterAccount) Type() string { + return TypeMsgRegisterAccount +} + +func (msg *MsgRegisterAccount) GetSigners() []sdk.AccAddress { + owner, err := sdk.AccAddressFromBech32(msg.Owner) + if err != nil { + panic(err) + } + return []sdk.AccAddress{owner} +} + +func (msg *MsgRegisterAccount) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRegisterAccount) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Owner) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid owner address (%s)", err) + } + return nil +} diff --git a/x/icaauth/types/message_register_account_test.go b/x/icaauth/types/message_register_account_test.go new file mode 100644 index 0000000000..53ee4c929b --- /dev/null +++ b/x/icaauth/types/message_register_account_test.go @@ -0,0 +1,39 @@ +package types + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" +) + +func TestMsgRegisterAccount_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgRegisterAccount + err error + }{ + { + name: "invalid address", + msg: MsgRegisterAccount{ + Owner: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgRegisterAccount{ + Owner: AccAddress(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/icaauth/types/message_submit_tx.go b/x/icaauth/types/message_submit_tx.go new file mode 100644 index 0000000000..a8b61403bd --- /dev/null +++ b/x/icaauth/types/message_submit_tx.go @@ -0,0 +1,104 @@ +package types + +import ( + "time" + + "cosmossdk.io/errors" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + proto "github.com/gogo/protobuf/proto" +) + +const TypeMsgSubmitTx = "submit_tx" + +var ( + _ sdk.Msg = &MsgSubmitTx{} + _ cdctypes.UnpackInterfacesMessage = &MsgSubmitTx{} +) + +func NewMsgSubmitTx(owner string, connectionID string, msgs []sdk.Msg, timeoutDuration *time.Duration) *MsgSubmitTx { + msgsAny := make([]*cdctypes.Any, len(msgs)) + for i, msg := range msgs { + any, err := cdctypes.NewAnyWithValue(msg) + if err != nil { + panic(err) + } + + msgsAny[i] = any + } + + return &MsgSubmitTx{ + Owner: owner, + ConnectionId: connectionID, + Msgs: msgsAny, + TimeoutDuration: timeoutDuration, + } +} + +func (msg MsgSubmitTx) GetMessages() ([]proto.Message, error) { + msgs := make([]proto.Message, len(msg.Msgs)) + for i, msgAny := range msg.Msgs { + msg, ok := msgAny.GetCachedValue().(proto.Message) + if !ok { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "messages contains %T which is not a sdk.Msg", msgAny) + } + msgs[i] = msg + } + + return msgs, nil +} + +func (msg MsgSubmitTx) CalculateTimeoutDuration(minTimeoutDuration time.Duration) time.Duration { + var timeoutDuration time.Duration + + if msg.TimeoutDuration != nil && *msg.TimeoutDuration >= minTimeoutDuration { + timeoutDuration = *msg.TimeoutDuration + } else { + timeoutDuration = minTimeoutDuration + } + + return timeoutDuration +} + +func (msg *MsgSubmitTx) Route() string { + return RouterKey +} + +func (msg *MsgSubmitTx) Type() string { + return TypeMsgSubmitTx +} + +func (msg *MsgSubmitTx) GetSigners() []sdk.AccAddress { + owner, err := sdk.AccAddressFromBech32(msg.Owner) + if err != nil { + panic(err) + } + return []sdk.AccAddress{owner} +} + +func (msg *MsgSubmitTx) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgSubmitTx) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Owner) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid owner address (%s)", err) + } + return nil +} + +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (msg MsgSubmitTx) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error { + for _, x := range msg.Msgs { + var msg sdk.Msg + err := unpacker.UnpackAny(x, &msg) + if err != nil { + return err + } + } + + return nil +} diff --git a/x/icaauth/types/message_submit_tx_test.go b/x/icaauth/types/message_submit_tx_test.go new file mode 100644 index 0000000000..2418414bed --- /dev/null +++ b/x/icaauth/types/message_submit_tx_test.go @@ -0,0 +1,39 @@ +package types + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" +) + +func TestMsgSubmitTx_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgSubmitTx + err error + }{ + { + name: "invalid address", + msg: MsgSubmitTx{ + Owner: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgSubmitTx{ + Owner: AccAddress(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/icaauth/types/params.go b/x/icaauth/types/params.go new file mode 100644 index 0000000000..4a08bbbb64 --- /dev/null +++ b/x/icaauth/types/params.go @@ -0,0 +1,69 @@ +package types + +import ( + "fmt" + "time" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +var ( + KeyMinTimeoutDuration = []byte("MinTimeoutDuration") + DefaultMinTimeoutDuration = time.Hour +) + +// 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( + minTimeoutDuration time.Duration, +) Params { + return Params{ + MinTimeoutDuration: minTimeoutDuration, + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams( + DefaultMinTimeoutDuration, + ) +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMinTimeoutDuration, &p.MinTimeoutDuration, validateMinTimeoutDuration), + } +} + +// Validate validates the set of params +func (p Params) Validate() error { + if err := validateMinTimeoutDuration(p.MinTimeoutDuration); err != nil { + return err + } + + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) // nolint:errcheck + return string(out) +} + +// validateMinTimeoutDuration validates the MinTimeoutDuration param +func validateMinTimeoutDuration(v interface{}) error { + _, ok := v.(time.Duration) + if !ok { + return fmt.Errorf("invalid parameter type: %T", v) + } + + return nil +} diff --git a/x/icaauth/types/params.pb.go b/x/icaauth/types/params.pb.go new file mode 100644 index 0000000000..41ddbe9039 --- /dev/null +++ b/x/icaauth/types/params.pb.go @@ -0,0 +1,328 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: icaauth/v1/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 { + // min_timeout_duration defines the minimum value of packet timeout when + // submitting transactions to host chain on behalf of interchain account + MinTimeoutDuration time.Duration `protobuf:"bytes,1,opt,name=min_timeout_duration,json=minTimeoutDuration,proto3,stdduration" json:"min_timeout_duration" yaml:"min_timeout_duration"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_1d9da7e51e957114, []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) GetMinTimeoutDuration() time.Duration { + if m != nil { + return m.MinTimeoutDuration + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "icaauth.v1.Params") +} + +func init() { proto.RegisterFile("icaauth/v1/params.proto", fileDescriptor_1d9da7e51e957114) } + +var fileDescriptor_1d9da7e51e957114 = []byte{ + // 260 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0x4c, 0x4e, 0x4c, + 0x2c, 0x2d, 0xc9, 0xd0, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, + 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x82, 0x4a, 0xe8, 0x95, 0x19, 0x4a, 0xc9, 0xa5, 0xe7, 0xe7, 0xa7, + 0xe7, 0xa4, 0xea, 0x83, 0x65, 0x92, 0x4a, 0xd3, 0xf4, 0x53, 0x4a, 0x8b, 0x12, 0x4b, 0x32, 0xf3, + 0xf3, 0x20, 0x6a, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, + 0xd4, 0xc2, 0xc8, 0xc5, 0x16, 0x00, 0x36, 0x52, 0xa8, 0x84, 0x4b, 0x24, 0x37, 0x33, 0x2f, 0xbe, + 0x24, 0x33, 0x37, 0x35, 0xbf, 0xb4, 0x24, 0x1e, 0xa6, 0x5d, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, + 0x48, 0x52, 0x0f, 0x62, 0xbe, 0x1e, 0xcc, 0x7c, 0x3d, 0x17, 0xa8, 0x02, 0x27, 0xf5, 0x13, 0xf7, + 0xe4, 0x19, 0x3e, 0xdd, 0x93, 0x97, 0xae, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0xc2, 0x66, 0x88, 0xd2, + 0x8c, 0xfb, 0xf2, 0x8c, 0x41, 0x42, 0xb9, 0x99, 0x79, 0x21, 0x10, 0x19, 0x98, 0x66, 0x2b, 0x96, + 0x19, 0x0b, 0xe4, 0x19, 0x9c, 0xfc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, + 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, + 0xca, 0x34, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0xb9, 0xa8, 0xb2, + 0xa0, 0x24, 0x5f, 0x37, 0xbf, 0x28, 0x5d, 0x37, 0x39, 0x23, 0x31, 0x33, 0x4f, 0x3f, 0xb9, 0x28, + 0x3f, 0x2f, 0xbf, 0x58, 0xbf, 0xcc, 0x48, 0xbf, 0x42, 0x1f, 0x16, 0x46, 0x25, 0x95, 0x05, 0xa9, + 0xc5, 0x49, 0x6c, 0x60, 0x67, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x06, 0x25, 0x79, + 0x3b, 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 + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.MinTimeoutDuration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.MinTimeoutDuration):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintParams(dAtA, i, uint64(n1)) + 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 = github_com_gogo_protobuf_types.SizeOfStdDuration(m.MinTimeoutDuration) + 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 MinTimeoutDuration", 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 := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.MinTimeoutDuration, 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/icaauth/types/query.pb.go b/x/icaauth/types/query.pb.go new file mode 100644 index 0000000000..4979315eac --- /dev/null +++ b/x/icaauth/types/query.pb.go @@ -0,0 +1,980 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: icaauth/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/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" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is 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_b4ef18af0a32af09, []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_b4ef18af0a32af09, []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{} +} + +// QueryInterchainAccountAddressRequest defines the request for the +// InterchainAccountAddress query. +type QueryInterchainAccountAddressRequest struct { + ConnectionId string `protobuf:"bytes,1,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + Owner string `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,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_b4ef18af0a32af09, []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 + +func (m *QueryInterchainAccountAddressRequest) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *QueryInterchainAccountAddressRequest) GetOwner() string { + if m != nil { + return m.Owner + } + return "" +} + +// QueryInterchainAccountAddressResponse defines the response for the +// InterchainAccountAddress query. +type QueryInterchainAccountAddressResponse struct { + 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_b4ef18af0a32af09, []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), "icaauth.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "icaauth.v1.QueryParamsResponse") + proto.RegisterType((*QueryInterchainAccountAddressRequest)(nil), "icaauth.v1.QueryInterchainAccountAddressRequest") + proto.RegisterType((*QueryInterchainAccountAddressResponse)(nil), "icaauth.v1.QueryInterchainAccountAddressResponse") +} + +func init() { proto.RegisterFile("icaauth/v1/query.proto", fileDescriptor_b4ef18af0a32af09) } + +var fileDescriptor_b4ef18af0a32af09 = []byte{ + // 437 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x93, 0xe2, 0x16, 0x1c, 0xf5, 0x32, 0x06, 0x8d, 0x51, 0x52, 0x0d, 0x0a, 0x5e, 0x36, + 0xb3, 0xad, 0x78, 0x11, 0x3d, 0x6c, 0x41, 0x96, 0x3d, 0x88, 0x9a, 0xa3, 0x97, 0x32, 0x3b, 0x19, + 0xd2, 0x81, 0x76, 0x5e, 0x76, 0x32, 0xa9, 0x86, 0xb2, 0x17, 0x3f, 0x81, 0xe0, 0x77, 0x92, 0x3d, + 0xc9, 0x82, 0x17, 0x4f, 0x8b, 0xb4, 0x7e, 0x02, 0x3f, 0x81, 0x64, 0x26, 0xbb, 0xdb, 0x52, 0x43, + 0xf1, 0x96, 0x79, 0xef, 0xff, 0xde, 0xff, 0xf7, 0xde, 0x0b, 0xba, 0x23, 0x18, 0xa5, 0xa5, 0x1e, + 0x93, 0x59, 0x9f, 0x1c, 0x97, 0x5c, 0x55, 0x71, 0xae, 0x40, 0x03, 0x46, 0x4d, 0x3c, 0x9e, 0xf5, + 0x03, 0x2f, 0x83, 0x0c, 0x4c, 0x98, 0xd4, 0x5f, 0x56, 0x11, 0x3c, 0xc8, 0x00, 0xb2, 0x09, 0x27, + 0x34, 0x17, 0x84, 0x4a, 0x09, 0x9a, 0x6a, 0x01, 0xb2, 0x68, 0xb2, 0x77, 0x57, 0xfa, 0xe6, 0x54, + 0xd1, 0x69, 0x93, 0x88, 0x3c, 0x84, 0xdf, 0xd7, 0x3e, 0xef, 0x4c, 0x30, 0xe1, 0xc7, 0x25, 0x2f, + 0x74, 0x74, 0x80, 0x6e, 0xaf, 0x45, 0x8b, 0x1c, 0x64, 0xc1, 0xf1, 0x1e, 0xea, 0xda, 0x62, 0xdf, + 0x7d, 0xe8, 0x3e, 0xbd, 0x31, 0xc0, 0xf1, 0x15, 0x56, 0x6c, 0xb5, 0xc3, 0x6b, 0xa7, 0xe7, 0x3d, + 0x27, 0x69, 0x74, 0xd1, 0x1c, 0x3d, 0x36, 0x8d, 0x0e, 0xa5, 0xe6, 0x8a, 0x8d, 0xa9, 0x90, 0xfb, + 0x8c, 0x41, 0x29, 0xf5, 0x7e, 0x9a, 0x2a, 0x5e, 0x5c, 0x18, 0xe2, 0x57, 0xe8, 0x16, 0x03, 0x29, + 0x39, 0xab, 0xa1, 0x47, 0x22, 0x35, 0x06, 0xd7, 0x87, 0xfe, 0x9f, 0xf3, 0x9e, 0x57, 0xd1, 0xe9, + 0xe4, 0x45, 0xb4, 0x96, 0x8e, 0x92, 0x9b, 0x57, 0xef, 0xc3, 0x14, 0x7b, 0x68, 0x07, 0x3e, 0x4a, + 0xae, 0xfc, 0x4e, 0x5d, 0x96, 0xd8, 0x47, 0xc4, 0xd1, 0x93, 0x2d, 0xe6, 0xcd, 0x5c, 0x2f, 0x51, + 0x20, 0x2e, 0x35, 0x23, 0x6a, 0x45, 0x23, 0x6a, 0x55, 0x16, 0x25, 0xf1, 0x45, 0x4b, 0x97, 0xc1, + 0xb7, 0x0e, 0xda, 0x31, 0x3e, 0x78, 0x82, 0xba, 0x76, 0x0b, 0x38, 0x5c, 0xdd, 0xcc, 0xe6, 0x82, + 0x83, 0x5e, 0x6b, 0xde, 0x22, 0x45, 0x8f, 0x3e, 0xff, 0xf8, 0xfd, 0xb5, 0x73, 0x1f, 0xdf, 0x23, + 0x4c, 0x81, 0x84, 0x82, 0x6c, 0x1c, 0x10, 0x7f, 0x77, 0x91, 0xdf, 0x36, 0x1a, 0xde, 0xdb, 0x30, + 0xd8, 0x72, 0x82, 0xa0, 0xff, 0x1f, 0x15, 0x0d, 0xe4, 0x1b, 0x03, 0x79, 0x80, 0x5f, 0xff, 0x03, + 0xb2, 0x7d, 0xa1, 0x64, 0xbe, 0x76, 0xcb, 0x13, 0x32, 0x37, 0xe7, 0x3a, 0x19, 0xbe, 0x3d, 0x5d, + 0x84, 0xee, 0xd9, 0x22, 0x74, 0x7f, 0x2d, 0x42, 0xf7, 0xcb, 0x32, 0x74, 0xce, 0x96, 0xa1, 0xf3, + 0x73, 0x19, 0x3a, 0x1f, 0x9e, 0x67, 0x42, 0x8f, 0xcb, 0xa3, 0x98, 0xc1, 0x94, 0x30, 0x55, 0xe5, + 0x1a, 0x76, 0x41, 0x65, 0xbb, 0xa6, 0xfd, 0x85, 0xf7, 0x6c, 0x40, 0x3e, 0x5d, 0x02, 0xe8, 0x2a, + 0xe7, 0xc5, 0x51, 0xd7, 0xfc, 0xe3, 0xcf, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x46, 0xbd, + 0x8f, 0x56, 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) + // InterchainAccountAddress queries the interchain account address for given + // `connection_id` and `owner` + 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, "/icaauth.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, "/icaauth.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 queries the interchain account address for given + // `connection_id` and `owner` + 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: "/icaauth.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: "/icaauth.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: "icaauth.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "InterchainAccountAddress", + Handler: _Query_InterchainAccountAddress_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "icaauth/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.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Owner))) + i-- + dAtA[i] = 0x12 + } + 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 *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.ConnectionId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Owner) + 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 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 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 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.Owner = 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/icaauth/types/query.pb.gw.go b/x/icaauth/types/query.pb.gw.go new file mode 100644 index 0000000000..a11bc99e46 --- /dev/null +++ b/x/icaauth/types/query.pb.gw.go @@ -0,0 +1,276 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: icaauth/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["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) + } + + val, ok = pathParams["owner"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "owner") + } + + protoReq.Owner, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "owner", 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["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) + } + + val, ok = pathParams["owner"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "owner") + } + + protoReq.Owner, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "owner", 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, 2, 3}, []string{"cronos", "icaauth", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_InterchainAccountAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"cronos", "icaauth", "v1", "interchain_account_address", "connection_id", "owner"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_InterchainAccountAddress_0 = runtime.ForwardResponseMessage +) diff --git a/x/icaauth/types/tx.pb.go b/x/icaauth/types/tx.pb.go new file mode 100644 index 0000000000..bc31adf8fe --- /dev/null +++ b/x/icaauth/types/tx.pb.go @@ -0,0 +1,1163 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: icaauth/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 + +// MsgRegisterAccount defines the request message for MsgRegisterAccount +type MsgRegisterAccount struct { + // owner represents the owner of the interchain account + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + // connection_id represents the IBC `connection_id` of the host chain + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + // version represents the version of the ICA channel + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` +} + +func (m *MsgRegisterAccount) Reset() { *m = MsgRegisterAccount{} } +func (m *MsgRegisterAccount) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterAccount) ProtoMessage() {} +func (*MsgRegisterAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_09bf995a0c8f8b8c, []int{0} +} +func (m *MsgRegisterAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterAccount.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 *MsgRegisterAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterAccount.Merge(m, src) +} +func (m *MsgRegisterAccount) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterAccount) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterAccount proto.InternalMessageInfo + +func (m *MsgRegisterAccount) GetOwner() string { + if m != nil { + return m.Owner + } + return "" +} + +func (m *MsgRegisterAccount) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *MsgRegisterAccount) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +// MsgRegisterAccountResponse defines the response message for +// MsgRegisterAccount +type MsgRegisterAccountResponse struct { +} + +func (m *MsgRegisterAccountResponse) Reset() { *m = MsgRegisterAccountResponse{} } +func (m *MsgRegisterAccountResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterAccountResponse) ProtoMessage() {} +func (*MsgRegisterAccountResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_09bf995a0c8f8b8c, []int{1} +} +func (m *MsgRegisterAccountResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterAccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterAccountResponse.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 *MsgRegisterAccountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterAccountResponse.Merge(m, src) +} +func (m *MsgRegisterAccountResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterAccountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterAccountResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterAccountResponse proto.InternalMessageInfo + +// MsgSubmitTx defines the request message for MsgSubmitTx +type MsgSubmitTx struct { + // owner represents the owner of the interchain account + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + // connection_id represents the IBC `connection_id` of the host chain + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + // msgs represents the transactions to be submitted to the host chain + Msgs []*types.Any `protobuf:"bytes,3,rep,name=msgs,proto3" json:"msgs,omitempty"` + // timeout_duration represents the timeout duration for the IBC packet from + // last block + TimeoutDuration *time.Duration `protobuf:"bytes,4,opt,name=timeout_duration,json=timeoutDuration,proto3,stdduration" json:"timeout_duration,omitempty"` +} + +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_09bf995a0c8f8b8c, []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 + +func (m *MsgSubmitTx) GetOwner() string { + if m != nil { + return m.Owner + } + return "" +} + +func (m *MsgSubmitTx) GetConnectionId() string { + if m != nil { + return m.ConnectionId + } + return "" +} + +func (m *MsgSubmitTx) GetMsgs() []*types.Any { + if m != nil { + return m.Msgs + } + return nil +} + +func (m *MsgSubmitTx) GetTimeoutDuration() *time.Duration { + if m != nil { + return m.TimeoutDuration + } + return nil +} + +// MsgSubmitTxResponse defines the response message for MsgSubmitTx +type MsgSubmitTxResponse struct { +} + +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_09bf995a0c8f8b8c, []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 init() { + proto.RegisterType((*MsgRegisterAccount)(nil), "icaauth.v1.MsgRegisterAccount") + proto.RegisterType((*MsgRegisterAccountResponse)(nil), "icaauth.v1.MsgRegisterAccountResponse") + proto.RegisterType((*MsgSubmitTx)(nil), "icaauth.v1.MsgSubmitTx") + proto.RegisterType((*MsgSubmitTxResponse)(nil), "icaauth.v1.MsgSubmitTxResponse") +} + +func init() { proto.RegisterFile("icaauth/v1/tx.proto", fileDescriptor_09bf995a0c8f8b8c) } + +var fileDescriptor_09bf995a0c8f8b8c = []byte{ + // 449 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x41, 0x8e, 0xd3, 0x30, + 0x14, 0x86, 0x6b, 0x5a, 0x18, 0x70, 0x41, 0x83, 0x32, 0x45, 0xa4, 0x11, 0x4a, 0xab, 0x2c, 0x50, + 0x37, 0xb5, 0x35, 0x45, 0xb3, 0x41, 0x62, 0x31, 0xd5, 0x6c, 0x40, 0xaa, 0x90, 0x02, 0x1b, 0xd8, + 0x54, 0xa9, 0x6b, 0x5c, 0x8b, 0x89, 0x5f, 0x65, 0x3b, 0xa5, 0x59, 0x73, 0x01, 0x96, 0x9c, 0x80, + 0x13, 0x70, 0x08, 0xc4, 0x6a, 0x96, 0xac, 0x00, 0xb5, 0xe2, 0x02, 0x9c, 0x00, 0x35, 0x89, 0x29, + 0xb4, 0x82, 0xdd, 0xec, 0xf2, 0xbf, 0xef, 0xf9, 0xcf, 0x7b, 0x7f, 0x62, 0x7c, 0x24, 0x59, 0x92, + 0x64, 0x76, 0x46, 0x17, 0xc7, 0xd4, 0x2e, 0xc9, 0x5c, 0x83, 0x05, 0x0f, 0x57, 0x45, 0xb2, 0x38, + 0x0e, 0xda, 0x0c, 0x4c, 0x0a, 0x66, 0x5c, 0x10, 0x5a, 0x8a, 0xb2, 0x2d, 0x68, 0x09, 0x10, 0x50, + 0xd6, 0x37, 0x4f, 0x55, 0x35, 0x14, 0x00, 0xe2, 0x9c, 0xd3, 0x42, 0x4d, 0xb2, 0x57, 0x74, 0x9a, + 0xe9, 0xc4, 0x4a, 0x50, 0x15, 0x6f, 0xef, 0xf2, 0x44, 0xe5, 0x25, 0x8a, 0xde, 0x22, 0xec, 0x8d, + 0x8c, 0x88, 0xb9, 0x90, 0xc6, 0x72, 0x7d, 0xca, 0x18, 0x64, 0xca, 0x7a, 0x2d, 0x7c, 0x15, 0xde, + 0x28, 0xae, 0x7d, 0xd4, 0x45, 0xbd, 0x1b, 0x71, 0x29, 0xbc, 0x47, 0xf8, 0x16, 0x03, 0xa5, 0x38, + 0xdb, 0x78, 0x8f, 0xe5, 0xd4, 0xbf, 0xb2, 0xa1, 0x43, 0xff, 0xe7, 0xd7, 0x4e, 0x2b, 0x4f, 0xd2, + 0xf3, 0x87, 0xd1, 0x5f, 0x38, 0x8a, 0x6f, 0x6e, 0xf5, 0xe3, 0xa9, 0xe7, 0xe3, 0x83, 0x05, 0xd7, + 0x46, 0x82, 0xf2, 0xeb, 0x85, 0xad, 0x93, 0xd1, 0x3d, 0x1c, 0xec, 0x0f, 0x11, 0x73, 0x33, 0x07, + 0x65, 0x78, 0xf4, 0x03, 0xe1, 0xe6, 0xc8, 0x88, 0x67, 0xd9, 0x24, 0x95, 0xf6, 0xf9, 0xf2, 0x72, + 0x86, 0x3b, 0xc1, 0x8d, 0xd4, 0x08, 0xe3, 0xd7, 0xbb, 0xf5, 0x5e, 0x73, 0xd0, 0x22, 0x65, 0x64, + 0xc4, 0x45, 0x46, 0x4e, 0x55, 0x3e, 0x6c, 0x7e, 0xfe, 0xd8, 0x3f, 0x30, 0xd3, 0xd7, 0x64, 0x33, + 0x6c, 0xd1, 0xee, 0x3d, 0xc1, 0xb7, 0xad, 0x4c, 0x39, 0x64, 0x76, 0xec, 0x42, 0xf7, 0x1b, 0x5d, + 0xd4, 0x6b, 0x0e, 0xda, 0x7b, 0x16, 0x67, 0x55, 0xc3, 0xb0, 0xf1, 0xfe, 0x5b, 0x07, 0xc5, 0x87, + 0xd5, 0x41, 0x57, 0x8e, 0xee, 0xe0, 0xa3, 0x3f, 0xd6, 0x74, 0xeb, 0x0f, 0x3e, 0x20, 0x5c, 0x1f, + 0x19, 0xe1, 0xbd, 0xc0, 0x87, 0xbb, 0x9f, 0x29, 0x24, 0xdb, 0xdf, 0x86, 0xec, 0x27, 0x18, 0xdc, + 0xff, 0x3f, 0x77, 0xaf, 0xf0, 0xce, 0xf0, 0xf5, 0xdf, 0xe9, 0xde, 0xdd, 0x39, 0xe3, 0x40, 0xd0, + 0xf9, 0x07, 0x70, 0x2e, 0xc3, 0xa7, 0x9f, 0x56, 0x21, 0xba, 0x58, 0x85, 0xe8, 0xfb, 0x2a, 0x44, + 0xef, 0xd6, 0x61, 0xed, 0x62, 0x1d, 0xd6, 0xbe, 0xac, 0xc3, 0xda, 0xcb, 0x13, 0x21, 0xed, 0x2c, + 0x9b, 0x10, 0x06, 0x29, 0x65, 0x3a, 0x9f, 0x5b, 0xe8, 0x83, 0x16, 0x7d, 0x36, 0x4b, 0xa4, 0xa2, + 0x4c, 0x83, 0x02, 0x43, 0x17, 0x03, 0xba, 0xa4, 0xee, 0x6a, 0xd8, 0x7c, 0xce, 0xcd, 0xe4, 0x5a, + 0x11, 0xdd, 0x83, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa7, 0xdd, 0x5f, 0x85, 0x32, 0x03, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // RegisterAccount registers an interchain account on host chain with given + // `connection_id` + RegisterAccount(ctx context.Context, in *MsgRegisterAccount, opts ...grpc.CallOption) (*MsgRegisterAccountResponse, error) + // SubmitTx submits a transaction to the host chain on behalf of interchain + // account + SubmitTx(ctx context.Context, in *MsgSubmitTx, opts ...grpc.CallOption) (*MsgSubmitTxResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) RegisterAccount(ctx context.Context, in *MsgRegisterAccount, opts ...grpc.CallOption) (*MsgRegisterAccountResponse, error) { + out := new(MsgRegisterAccountResponse) + err := c.cc.Invoke(ctx, "/icaauth.v1.Msg/RegisterAccount", 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, "/icaauth.v1.Msg/SubmitTx", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // RegisterAccount registers an interchain account on host chain with given + // `connection_id` + RegisterAccount(context.Context, *MsgRegisterAccount) (*MsgRegisterAccountResponse, error) + // SubmitTx submits a transaction to the host chain on behalf of interchain + // account + SubmitTx(context.Context, *MsgSubmitTx) (*MsgSubmitTxResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) RegisterAccount(ctx context.Context, req *MsgRegisterAccount) (*MsgRegisterAccountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterAccount not implemented") +} +func (*UnimplementedMsgServer) SubmitTx(ctx context.Context, req *MsgSubmitTx) (*MsgSubmitTxResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SubmitTx not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_RegisterAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRegisterAccount) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RegisterAccount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/icaauth.v1.Msg/RegisterAccount", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RegisterAccount(ctx, req.(*MsgRegisterAccount)) + } + 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: "/icaauth.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) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "icaauth.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterAccount", + Handler: _Msg_RegisterAccount_Handler, + }, + { + MethodName: "SubmitTx", + Handler: _Msg_SubmitTx_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "icaauth/v1/tx.proto", +} + +func (m *MsgRegisterAccount) 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 *MsgRegisterAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Version) > 0 { + i -= len(m.Version) + copy(dAtA[i:], m.Version) + i = encodeVarintTx(dAtA, i, uint64(len(m.Version))) + i-- + dAtA[i] = 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.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintTx(dAtA, i, uint64(len(m.Owner))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterAccountResponse) 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 *MsgRegisterAccountResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterAccountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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 + if m.TimeoutDuration != nil { + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(*m.TimeoutDuration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(*m.TimeoutDuration):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTx(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + } + 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] = 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.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintTx(dAtA, i, uint64(len(m.Owner))) + 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 + 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 *MsgRegisterAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Owner) + 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.Version) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRegisterAccountResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgSubmitTx) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Owner) + 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)) + } + } + if m.TimeoutDuration != nil { + l = github_com_gogo_protobuf_types.SizeOfStdDuration(*m.TimeoutDuration) + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSubmitTxResponse) 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 *MsgRegisterAccount) 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: MsgRegisterAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 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.Owner = 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 Version", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Version = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + 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 *MsgRegisterAccountResponse) 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: MsgRegisterAccountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterAccountResponse: 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 *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 Owner", 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.Owner = 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 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, &types.Any{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutDuration", 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.TimeoutDuration == nil { + m.TimeoutDuration = new(time.Duration) + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(m.TimeoutDuration, 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 { + 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/icaauth/types/types.go b/x/icaauth/types/types.go new file mode 100644 index 0000000000..7aec2d129a --- /dev/null +++ b/x/icaauth/types/types.go @@ -0,0 +1,13 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/crypto/ed25519" +) + +// AccAddress returns a sample account address (for use in testing) +func AccAddress() string { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr).String() +}