2024-07-05 22:20:13 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
dbm "github.com/cosmos/cosmos-db"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"cosmossdk.io/log"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/config"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
|
|
"github.com/cosmos/cosmos-sdk/server"
|
|
|
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
|
|
|
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
|
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
|
|
|
|
"github.com/onsonr/hway/app"
|
|
|
|
"github.com/onsonr/hway/app/params"
|
|
|
|
// NewRootCmd creates a new root command for chain app. It is called once in the
|
|
|
|
// main function.
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewRootCmd() *cobra.Command {
|
|
|
|
cfg := sdk.GetConfig()
|
|
|
|
cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
|
|
|
|
cfg.SetBech32PrefixForValidator(app.Bech32PrefixValAddr, app.Bech32PrefixValPub)
|
|
|
|
cfg.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub)
|
|
|
|
cfg.Seal()
|
|
|
|
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
|
|
|
|
// note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go)
|
|
|
|
tempApp := app.NewChainApp(
|
|
|
|
log.NewNopLogger(), dbm.NewMemDB(), nil, false, simtestutil.NewAppOptionsWithFlagHome(tempDir()),
|
|
|
|
)
|
|
|
|
encodingConfig := params.EncodingConfig{
|
|
|
|
InterfaceRegistry: tempApp.InterfaceRegistry(),
|
|
|
|
Codec: tempApp.AppCodec(),
|
|
|
|
TxConfig: tempApp.TxConfig(),
|
|
|
|
Amino: tempApp.LegacyAmino(),
|
|
|
|
}
|
|
|
|
|
|
|
|
initClientCtx := client.Context{}.
|
|
|
|
WithCodec(encodingConfig.Codec).
|
|
|
|
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
|
|
|
WithTxConfig(encodingConfig.TxConfig).
|
|
|
|
WithLegacyAmino(encodingConfig.Amino).
|
|
|
|
WithInput(os.Stdin).
|
|
|
|
WithAccountRetriever(authtypes.AccountRetriever{}).
|
|
|
|
WithHomeDir(app.DefaultNodeHome).
|
|
|
|
WithViper("")
|
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
|
|
|
Use: version.AppName,
|
|
|
|
Short: version.AppName + " Daemon (server)",
|
|
|
|
SilenceErrors: true,
|
|
|
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
|
|
|
// set the default command outputs
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// This needs to go after ReadFromClientConfig, as that function
|
|
|
|
// sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode
|
|
|
|
// is only available if the client is online.
|
|
|
|
if !initClientCtx.Offline {
|
|
|
|
enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
|
|
|
|
txConfigOpts := tx.ConfigOptions{
|
|
|
|
EnabledSignModes: enabledSignModes,
|
|
|
|
TextualCoinMetadataQueryFn: txmodule.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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the context chain ID and validator address
|
2024-07-07 17:45:08 -04:00
|
|
|
app.SetLocalChainID(initClientCtx.ChainID)
|
|
|
|
app.SetLocalValidatorAddress(initClientCtx.FromAddress.String())
|
2024-07-05 22:20:13 -04:00
|
|
|
|
|
|
|
customAppTemplate, customAppConfig := initAppConfig()
|
|
|
|
customCMTConfig := initCometBFTConfig()
|
|
|
|
|
|
|
|
return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customCMTConfig)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
initRootCmd(rootCmd, encodingConfig.TxConfig, encodingConfig.InterfaceRegistry, 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
|
|
|
|
}
|