From 88a5e0f3e5a089a738f08bf78e7c9444231e608f Mon Sep 17 00:00:00 2001 From: Lockwarr Date: Tue, 18 Jun 2024 15:45:49 +0300 Subject: [PATCH] fix: improve cli --- app/keepers/keepers.go | 3 --- cmd/nolusd/root.go | 38 ++++++++++++++++++++++++++++---------- go.mod | 1 + go.sum | 4 ++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 4dbcf995..42f0ce36 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -462,9 +462,6 @@ func (appKeepers *AppKeepers) NewAppKeepers( AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)). //nolint:staticcheck AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(*appKeepers.ParamsKeeper)) - // TODO: test these proposals and remove these legacy handler - // AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)). - // AddRoute(ibcexported.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)) //nolint:staticcheck govConfig := govtypes.DefaultConfig() // MaxMetadataLen defines the maximum proposal metadata length. diff --git a/cmd/nolusd/root.go b/cmd/nolusd/root.go index 58197093..fdf346ac 100644 --- a/cmd/nolusd/root.go +++ b/cmd/nolusd/root.go @@ -26,14 +26,19 @@ import ( "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/client/snapshot" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/tx/signing" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -122,7 +127,7 @@ func NewRootCmd( WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). WithBroadcastMode(flags.BroadcastSync). - WithHomeDir(defaultNodeHome). + WithHomeDir(app.DefaultNodeHome). WithViper("") rootCmd := &cobra.Command{ @@ -133,6 +138,7 @@ func NewRootCmd( cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.ErrOrStderr()) + initClientCtx = initClientCtx.WithCmdContext(cmd.Context()) initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) if err != nil { return err @@ -143,6 +149,23 @@ func NewRootCmd( return err } + if !initClientCtx.Offline { + enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := tx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx), + } + txConfig, err := tx.NewTxConfigWithOptions( + initClientCtx.Codec, + txConfigOpts, + ) + if err != nil { + return err + } + + initClientCtx = initClientCtx.WithTxConfig(txConfig) + } + if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } @@ -185,13 +208,13 @@ func initRootCmd( rootCmd *cobra.Command, encodingConfig app.EncodingConfig, ) { + a := appCreator{encodingConfig} + gentxModule := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic) rootCmd.AddCommand( genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()), - // TODO: Do we need MigrateGenesisCmd? - // genutilcli.MigrateGenesisCmd(), genutilcli.GenTxCmd( app.ModuleBasics, encodingConfig.TxConfig, @@ -205,14 +228,10 @@ func initRootCmd( tmcli.NewCompletionCmd(rootCmd, true), debug.Cmd(), confixcmd.ConfigCommand(), - - // TODO: test and decide if we need those two new pruning/snapshot commands - // pruning.Cmd(newApp, simapp.DefaultNodeHome), - // snapshot.Cmd(newApp), + pruning.Cmd(a.newApp, app.DefaultNodeHome), + snapshot.Cmd(a.newApp), ) - a := appCreator{encodingConfig} - // add server commands server.AddCommands( rootCmd, @@ -246,7 +265,6 @@ func queryCommand() *cobra.Command { } cmd.AddCommand( - // TODO: authcmd.GetAccountCmd(), rpc.ValidatorCommand(), server.QueryBlockResultsCmd(), server.QueryBlocksCmd(), diff --git a/go.mod b/go.mod index 3b890540..61c6d4e7 100644 --- a/go.mod +++ b/go.mod @@ -250,6 +250,7 @@ require ( ) replace ( + cosmossdk.io/client/v2 => cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79 github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 github.com/CosmWasm/wasmd => github.com/neutron-org/wasmd v0.51.0 diff --git a/go.sum b/go.sum index f23ab7dd..d92ee4a1 100644 --- a/go.sum +++ b/go.sum @@ -188,8 +188,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ= cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/client/v2 v2.0.0-beta.1 h1:XkHh1lhrLYIT9zKl7cIOXUXg2hdhtjTPBUfqERNA1/Q= -cosmossdk.io/client/v2 v2.0.0-beta.1/go.mod h1:JEUSu9moNZQ4kU3ir1DKD5eU4bllmAexrGWjmb9k8qU= +cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79 h1:Hr1t0fCq1nbFC7hLs0Xvy9WAiH7Iti5iVLXMM5C37F0= +cosmossdk.io/client/v2 v2.0.0-beta.1.0.20240124105859-5ad1805d0e79/go.mod h1:8pN6LSVReNnIxrC2QGcvuIJ/m1pJN6FNYn2kAYtYftI= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=