From 6e0d1499c5758f9d265c877cf2706ab12d7aa9b2 Mon Sep 17 00:00:00 2001 From: victor118 Date: Fri, 23 Aug 2024 12:47:18 +0200 Subject: [PATCH] FIX : Init sdk cmd queries --- app/app.go | 34 +++++++++++++++++++++++++++++++++- cmd/chihuahuad/cmd/root.go | 25 ++++++++++++++++--------- go.mod | 3 ++- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index b6f6e82..87a373b 100644 --- a/app/app.go +++ b/app/app.go @@ -10,9 +10,13 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + "cosmossdk.io/client/v2/autocli" + "cosmossdk.io/core/appmodule" "cosmossdk.io/log" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/circuit" + circuitkeeper "cosmossdk.io/x/circuit/keeper" circuittypes "cosmossdk.io/x/circuit/types" abci "github.com/cometbft/cometbft/abci/types" tmos "github.com/cometbft/cometbft/libs/os" @@ -50,6 +54,7 @@ import ( "github.com/rakyll/statik/fs" sdkbank "github.com/cosmos/cosmos-sdk/x/bank" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" sdkbanktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/consensus" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" @@ -334,6 +339,7 @@ type App struct { GroupKeeper groupkeeper.Keeper NFTKeeper nftkeeper.Keeper ConsensusParamsKeeper consensuskeeper.Keeper + CircuitKeeper circuitkeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly IBCFeeKeeper ibcfeekeeper.Keeper @@ -460,6 +466,8 @@ func New( Bech32Prefix, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + app.CircuitKeeper = circuitkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[circuittypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AccountKeeper.AddressCodec()) + app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) app.AuthzKeeper = authzkeeper.NewKeeper( runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, @@ -786,6 +794,7 @@ func New( // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. app.mm = module.NewManager( + genutil.NewAppModule( app.AccountKeeper, app.StakingKeeper, @@ -794,7 +803,7 @@ func New( ), auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(sdkbanktypes.ModuleName)), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), @@ -819,6 +828,7 @@ func New( alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancemoduletypes.ModuleName)), tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(tokenfactorytypes.ModuleName)), liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper), + circuit.NewAppModule(appCodec, app.CircuitKeeper), ) // BasicModuleManager defines the module BasicManager is in charge of setting up basic, @@ -910,6 +920,7 @@ func New( wasmtypes.ModuleName, alliancemoduletypes.ModuleName, tokenfactorytypes.ModuleName, + circuittypes.ModuleName, } app.mm.SetOrderInitGenesis(genesisModuleOrder...) app.mm.SetOrderExportGenesis(genesisModuleOrder...) @@ -1315,3 +1326,24 @@ func (app *App) SimulationManager() *module.SimulationManager { func (a *App) DefaultGenesis() map[string]json.RawMessage { return a.BasicModuleManager.DefaultGenesis(a.appCodec) } + +// AutoCliOpts returns the autocli options for the app. +func (app *App) AutoCliOpts() autocli.AppOptions { + modules := make(map[string]appmodule.AppModule, 0) + for _, m := range app.mm.Modules { + if moduleWithName, ok := m.(module.HasName); ok { + moduleName := moduleWithName.Name() + if appModule, ok := moduleWithName.(appmodule.AppModule); ok { + modules[moduleName] = appModule + } + } + } + + return autocli.AppOptions{ + Modules: modules, + ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.mm.Modules), + AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), + ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), + } +} diff --git a/cmd/chihuahuad/cmd/root.go b/cmd/chihuahuad/cmd/root.go index 215e5ba..ff1423e 100644 --- a/cmd/chihuahuad/cmd/root.go +++ b/cmd/chihuahuad/cmd/root.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/math" "cosmossdk.io/math/unsafe" confixcmd "cosmossdk.io/tools/confix/cmd" + wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli" cmtconfig "github.com/cometbft/cometbft/config" tmcfg "github.com/cometbft/cometbft/config" cmttime "github.com/cometbft/cometbft/types/time" @@ -190,7 +191,15 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { } initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager) + // add keyring to autocli opts + autoCliOpts := tempApp.AutoCliOpts() + initClientCtx, _ = config.ReadFromClientConfig(initClientCtx) + autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring) + autoCliOpts.ClientCtx = initClientCtx + if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { + panic(err) + } return rootCmd, encodingConfig } @@ -698,7 +707,7 @@ Example: func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, basicManager module.BasicManager) { rootCmd.AddCommand( - genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), + genutilcli.InitCmd(basicManager, app.DefaultNodeHome), NewTestnetCmd(basicManager, banktypes.GenesisBalancesIterator{}), debug.Cmd(), confixcmd.ConfigCommand(), @@ -707,12 +716,12 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b ) server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, appExport, addModuleInitFlags) - + wasmcli.ExtendUnsafeResetAllCmd(rootCmd) // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( server.StatusCommand(), - genesisCommand(encodingConfig), - queryCommand(), + genesisCommand(encodingConfig.TxConfig, basicManager), + queryCommand(basicManager), txCommand(basicManager), keys.Commands(), ) @@ -725,8 +734,8 @@ func addModuleInitFlags(startCmd *cobra.Command) { } // genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter -func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command { - cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, app.ModuleBasics, app.DefaultNodeHome) +func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, cmds ...*cobra.Command) *cobra.Command { + cmd := genutilcli.Commands(txConfig, basicManager, app.DefaultNodeHome) for _, subCmd := range cmds { cmd.AddCommand(subCmd) @@ -734,7 +743,7 @@ func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command return cmd } -func queryCommand() *cobra.Command { +func queryCommand(basicManager module.BasicManager) *cobra.Command { cmd := &cobra.Command{ Use: "query", Aliases: []string{"q"}, @@ -753,7 +762,6 @@ func queryCommand() *cobra.Command { server.QueryBlockResultsCmd(), ) - app.ModuleBasics.AddQueryCommands(cmd) cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") return cmd @@ -780,7 +788,6 @@ func txCommand(bm module.BasicManager) *cobra.Command { authcmd.GetSimulateCmd(), ) - bm.AddTxCommands(cmd) cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") return cmd diff --git a/go.mod b/go.mod index 8c0efed..81e7fd8 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,8 @@ require ( require ( cosmossdk.io/api v0.7.5 + cosmossdk.io/client/v2 v2.0.0-beta.1 + cosmossdk.io/core v0.11.1 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 cosmossdk.io/math v1.3.0 @@ -59,7 +61,6 @@ require ( cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.38.0 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/core v0.11.1 // indirect cosmossdk.io/depinject v1.0.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect