0g-chain/cmd/kava/cmd/root.go
Robert Pirtle 49812b6e7c
fix(cli): Resolve problem with assert-invariants cmd (#1624)
* remove no-op migrate command

* move assert-invariants from migrate -> cmd

* fix: don't modify validators for assert-invariants

Makes validator addition in TestApp initialization optional.

* update changelog
2023-06-09 16:52:52 -07:00

126 lines
3.7 KiB
Go

package cmd
import (
"os"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
ethermintclient "github.com/evmos/ethermint/client"
"github.com/evmos/ethermint/crypto/hd"
ethermintserver "github.com/evmos/ethermint/server"
servercfg "github.com/evmos/ethermint/server/config"
"github.com/spf13/cobra"
tmcfg "github.com/tendermint/tendermint/config"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/app/params"
kavaclient "github.com/kava-labs/kava/client"
)
// EnvPrefix is the prefix environment variables must have to configure the app.
const EnvPrefix = "KAVA"
// NewRootCmd creates a new root command for the kava blockchain.
func NewRootCmd() *cobra.Command {
app.SetSDKConfig().Seal()
encodingConfig := app.MakeEncodingConfig()
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(app.DefaultNodeHome).
WithKeyringOptions(hd.EthSecp256k1Option()).
WithViper(EnvPrefix)
rootCmd := &cobra.Command{
Use: "kava",
Short: "Daemon and CLI for the Kava blockchain.",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
if err != nil {
return err
}
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
if err != nil {
return err
}
if err = client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}
customAppTemplate, customAppConfig := servercfg.AppConfig("ukava")
return server.InterceptConfigsPreRunHandler(
cmd,
customAppTemplate,
customAppConfig,
tmcfg.DefaultConfig(),
)
},
}
addSubCmds(rootCmd, encodingConfig, app.DefaultNodeHome)
return rootCmd
}
// addSubCmds registers all the sub commands used by kava.
func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, defaultNodeHome string) {
rootCmd.AddCommand(
StatusCommand(),
ethermintclient.ValidateChainID(
genutilcli.InitCmd(app.ModuleBasics, defaultNodeHome),
),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome),
AssertInvariantsCmd(encodingConfig),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(defaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true), // TODO add other shells, drop tmcli dependency, unhide?
// testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), // TODO add
debug.Cmd(),
config.Cmd(),
)
ac := appCreator{
encodingConfig: encodingConfig,
}
// ethermintserver adds additional flags to start the JSON-RPC server for evm support
ethermintserver.AddCommands(
rootCmd,
ethermintserver.NewDefaultStartOptions(
ac.newApp,
app.DefaultNodeHome,
),
ac.appExport,
ac.addStartCmdFlags,
)
// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
newQueryCmd(),
newTxCmd(),
kavaclient.KeyCommands(app.DefaultNodeHome),
)
}