2025-10-03 14:45:52 -04:00
|
|
|
package main
|
2024-07-05 22:20:13 -04:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
|
2024-09-07 18:12:58 -04:00
|
|
|
dbm "github.com/cosmos/cosmos-db"
|
2025-10-03 14:45:52 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
|
|
"cosmossdk.io/log"
|
|
|
|
|
|
2024-07-05 22:20:13 -04:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/config"
|
2025-10-03 14:45:52 -04:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2024-07-05 22:20:13 -04:00
|
|
|
"github.com/cosmos/cosmos-sdk/server"
|
|
|
|
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
|
|
|
|
"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"
|
|
|
|
|
|
2025-10-03 14:45:52 -04:00
|
|
|
evmoskeyring "github.com/cosmos/evm/crypto/keyring"
|
|
|
|
|
|
|
|
|
|
"github.com/sonr-io/sonr/app"
|
|
|
|
|
"github.com/sonr-io/sonr/app/params"
|
2024-07-05 22:20:13 -04:00
|
|
|
)
|
|
|
|
|
|
2025-10-03 14:45:52 -04:00
|
|
|
// NewRootCmd creates a new root command for chain app. It is called once in the
|
|
|
|
|
// main function.
|
2024-07-05 22:20:13 -04:00
|
|
|
func NewRootCmd() *cobra.Command {
|
|
|
|
|
// 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)
|
2025-10-03 14:45:52 -04:00
|
|
|
tempApp := app.NewChainApp(
|
|
|
|
|
log.NewNopLogger(),
|
|
|
|
|
dbm.NewMemDB(),
|
|
|
|
|
nil,
|
|
|
|
|
false,
|
|
|
|
|
simtestutil.NewAppOptionsWithFlagHome(tempDir()),
|
|
|
|
|
app.EVMAppOptions,
|
2024-07-05 22:20:13 -04:00
|
|
|
)
|
|
|
|
|
encodingConfig := params.EncodingConfig{
|
2025-10-03 14:45:52 -04:00
|
|
|
InterfaceRegistry: tempApp.InterfaceRegistry(),
|
|
|
|
|
Codec: tempApp.AppCodec(),
|
|
|
|
|
TxConfig: tempApp.TxConfig(),
|
|
|
|
|
Amino: tempApp.LegacyAmino(),
|
2024-07-05 22:20:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initClientCtx := client.Context{}.
|
|
|
|
|
WithCodec(encodingConfig.Codec).
|
|
|
|
|
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
|
|
|
|
WithTxConfig(encodingConfig.TxConfig).
|
|
|
|
|
WithLegacyAmino(encodingConfig.Amino).
|
|
|
|
|
WithInput(os.Stdin).
|
|
|
|
|
WithAccountRetriever(authtypes.AccountRetriever{}).
|
|
|
|
|
WithHomeDir(app.DefaultNodeHome).
|
2025-10-03 14:45:52 -04:00
|
|
|
WithBroadcastMode(flags.FlagBroadcastMode).
|
|
|
|
|
WithKeyringOptions(evmoskeyring.Option()).
|
|
|
|
|
WithLedgerHasProtobuf(true).
|
2024-07-05 22:20:13 -04:00
|
|
|
WithViper("")
|
|
|
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
|
|
|
|
Use: version.AppName,
|
|
|
|
|
Short: version.AppName + " Daemon (server)",
|
2025-11-18 12:19:21 -05:00
|
|
|
Long: sonrLogo(),
|
2024-07-05 22:20:13 -04:00
|
|
|
SilenceErrors: true,
|
|
|
|
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
|
|
|
|
// set the default command outputs
|
2025-10-03 14:45:52 -04:00
|
|
|
var err error
|
2024-07-05 22:20:13 -04:00
|
|
|
cmd.SetOut(cmd.OutOrStdout())
|
|
|
|
|
cmd.SetErr(cmd.ErrOrStderr())
|
|
|
|
|
|
|
|
|
|
initClientCtx = initClientCtx.WithCmdContext(cmd.Context())
|
2025-10-03 14:45:52 -04:00
|
|
|
initClientCtx, err = client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
|
2024-07-05 22:20:13 -04:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customAppTemplate, customAppConfig := initAppConfig()
|
|
|
|
|
customCMTConfig := initCometBFTConfig()
|
|
|
|
|
|
2025-10-03 14:45:52 -04:00
|
|
|
return server.InterceptConfigsPreRunHandler(
|
|
|
|
|
cmd,
|
|
|
|
|
customAppTemplate,
|
|
|
|
|
customAppConfig,
|
|
|
|
|
customCMTConfig,
|
|
|
|
|
)
|
2024-07-05 22:20:13 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 14:45:52 -04:00
|
|
|
initRootCmd(rootCmd, tempApp)
|
2024-07-05 22:20:13 -04:00
|
|
|
|
|
|
|
|
// add keyring to autocli opts
|
2025-10-03 14:45:52 -04:00
|
|
|
autoCliOpts := tempApp.AutoCliOpts()
|
2024-07-05 22:20:13 -04:00
|
|
|
initClientCtx, _ = config.ReadFromClientConfig(initClientCtx)
|
|
|
|
|
autoCliOpts.ClientCtx = initClientCtx
|
|
|
|
|
|
|
|
|
|
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 14:45:52 -04:00
|
|
|
// Return the root command
|
2024-07-05 22:20:13 -04:00
|
|
|
return rootCmd
|
|
|
|
|
}
|