From ba20a9d36e6736740af1cb63808ca3941c816e47 Mon Sep 17 00:00:00 2001 From: Hyoung-yoon Kim Date: Thu, 30 Nov 2023 14:17:28 -0500 Subject: [PATCH] fix: add query commands through auto cli --- app/app.go | 23 +++++++++++++++++++++++ cmd/seda-chaind/cmd/root.go | 21 ++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index 63782ae1..d21ea8b3 100644 --- a/app/app.go +++ b/app/app.go @@ -12,6 +12,8 @@ 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" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -945,6 +947,27 @@ func (app *App) TxConfig() client.TxConfig { return app.txConfig } +// 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()), + } +} + // GetKey returns the KVStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. diff --git a/cmd/seda-chaind/cmd/root.go b/cmd/seda-chaind/cmd/root.go index 5625b5b0..6e2970bf 100644 --- a/cmd/seda-chaind/cmd/root.go +++ b/cmd/seda-chaind/cmd/root.go @@ -5,7 +5,6 @@ import ( "io" "os" "path/filepath" - "strings" "github.com/spf13/cast" "github.com/spf13/cobra" @@ -27,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -113,10 +113,15 @@ func NewRootCmd() *cobra.Command { } initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager()) - overwriteFlagDefaults(rootCmd, map[string]string{ - flags.FlagChainID: strings.ReplaceAll(app.Name, "-", ""), - flags.FlagKeyringBackend: "test", - }) + + // TO-DO unnecessary once depinject is implemented + 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 } @@ -180,9 +185,6 @@ func queryCommand(basicManager module.BasicManager) *cobra.Command { server.QueryBlockResultsCmd(), ) - basicManager.AddQueryCommands(cmd) - cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") - return cmd } @@ -207,9 +209,6 @@ func txCommand(basicManager module.BasicManager) *cobra.Command { authcmd.GetDecodeCommand(), ) - basicManager.AddTxCommands(cmd) - cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") - return cmd }