2024-05-01 04:26:39 +00:00
|
|
|
package main
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
import (
|
2024-02-06 22:54:10 +00:00
|
|
|
"fmt"
|
2022-01-08 00:39:27 +00:00
|
|
|
"os"
|
2024-07-11 13:23:31 +00:00
|
|
|
"path/filepath"
|
2022-01-08 00:39:27 +00:00
|
|
|
|
2024-07-11 13:23:31 +00:00
|
|
|
dbm "github.com/cometbft/cometbft-db"
|
|
|
|
tmcfg "github.com/cometbft/cometbft/config"
|
|
|
|
tmcli "github.com/cometbft/cometbft/libs/cli"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/config"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/debug"
|
2022-10-19 18:11:17 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2024-05-01 04:33:44 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/server"
|
2024-07-11 13:23:31 +00:00
|
|
|
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
2024-02-06 22:54:10 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
2022-01-08 00:39:27 +00:00
|
|
|
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
2024-02-06 22:54:10 +00:00
|
|
|
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
2023-04-04 00:08:45 +00:00
|
|
|
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"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2024-05-01 03:17:24 +00:00
|
|
|
"github.com/0glabs/0g-chain/app"
|
|
|
|
"github.com/0glabs/0g-chain/app/params"
|
|
|
|
"github.com/0glabs/0g-chain/cmd/kava/cmd/iavlviewer"
|
|
|
|
"github.com/0glabs/0g-chain/cmd/kava/cmd/rocksdb"
|
2024-07-11 13:23:31 +00:00
|
|
|
"github.com/Kava-Labs/opendb"
|
2022-01-08 00:39:27 +00:00
|
|
|
)
|
|
|
|
|
2024-05-01 04:33:44 +00:00
|
|
|
func customKeyringOptions() keyring.Option {
|
|
|
|
return func(options *keyring.Options) {
|
|
|
|
options.SupportedAlgos = append(hd.SupportedAlgorithms, vrf.VrfAlgo)
|
|
|
|
options.SupportedAlgosLedger = append(hd.SupportedAlgorithmsLedger, vrf.VrfAlgo)
|
|
|
|
}
|
|
|
|
}
|
2022-05-05 00:05:07 +00:00
|
|
|
|
2024-05-01 04:33:44 +00:00
|
|
|
// NewRootCmd creates a new root command for the 0g-chain blockchain.
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewRootCmd() *cobra.Command {
|
|
|
|
encodingConfig := app.MakeEncodingConfig()
|
|
|
|
initClientCtx := client.Context{}.
|
|
|
|
WithCodec(encodingConfig.Marshaler).
|
|
|
|
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
|
|
|
WithTxConfig(encodingConfig.TxConfig).
|
|
|
|
WithLegacyAmino(encodingConfig.Amino).
|
|
|
|
WithInput(os.Stdin).
|
|
|
|
WithAccountRetriever(types.AccountRetriever{}).
|
2024-02-06 22:54:10 +00:00
|
|
|
WithBroadcastMode(flags.FlagBroadcastMode).
|
2024-05-01 04:33:44 +00:00
|
|
|
WithHomeDir(chaincfg.DefaultNodeHome).
|
2022-04-21 20:16:28 +00:00
|
|
|
WithKeyringOptions(hd.EthSecp256k1Option()).
|
2024-05-01 04:33:44 +00:00
|
|
|
WithViper(chaincfg.EnvPrefix)
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
2024-05-01 04:33:44 +00:00
|
|
|
Use: chaincfg.AppName,
|
|
|
|
Short: "Daemon and CLI for the 0g-chain blockchain.",
|
2022-01-08 00:39:27 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-01 04:33:44 +00:00
|
|
|
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.BaseDenom)
|
2022-04-21 20:16:28 +00:00
|
|
|
|
2023-04-04 00:08:45 +00:00
|
|
|
return server.InterceptConfigsPreRunHandler(
|
|
|
|
cmd,
|
|
|
|
customAppTemplate,
|
|
|
|
customAppConfig,
|
|
|
|
tmcfg.DefaultConfig(),
|
|
|
|
)
|
2022-01-08 00:39:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-05-01 04:33:44 +00:00
|
|
|
addSubCmds(rootCmd, encodingConfig, chaincfg.DefaultNodeHome)
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
return rootCmd
|
|
|
|
}
|
|
|
|
|
2024-07-11 13:23:31 +00:00
|
|
|
// dbOpener is a function to open `application.db`, potentially with customized options.
|
|
|
|
// dbOpener sets dataDir to "data", dbName to "application" and calls generic OpenDB function.
|
|
|
|
func dbOpener(opts servertypes.AppOptions, rootDir string, backend dbm.BackendType) (dbm.DB, error) {
|
|
|
|
dataDir := filepath.Join(rootDir, "data")
|
|
|
|
return opendb.OpenDB(opts, dataDir, "application", backend)
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// addSubCmds registers all the sub commands used by kava.
|
|
|
|
func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, defaultNodeHome string) {
|
2024-02-06 22:54:10 +00:00
|
|
|
gentxModule, ok := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("expected %s module to be an instance of type %T", genutiltypes.ModuleName, genutil.AppModuleBasic{}))
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
rootCmd.AddCommand(
|
2023-04-04 00:08:45 +00:00
|
|
|
StatusCommand(),
|
2022-04-21 20:16:28 +00:00
|
|
|
ethermintclient.ValidateChainID(
|
|
|
|
genutilcli.InitCmd(app.ModuleBasics, defaultNodeHome),
|
|
|
|
),
|
2024-02-06 22:54:10 +00:00
|
|
|
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome, gentxModule.GenTxValidator),
|
2023-06-09 23:52:52 +00:00
|
|
|
AssertInvariantsCmd(encodingConfig),
|
2022-01-08 00:39:27 +00:00
|
|
|
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome),
|
|
|
|
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
|
2022-04-21 20:16:28 +00:00
|
|
|
AddGenesisAccountCmd(defaultNodeHome),
|
|
|
|
tmcli.NewCompletionCmd(rootCmd, true), // TODO add other shells, drop tmcli dependency, unhide?
|
2022-01-08 00:39:27 +00:00
|
|
|
// testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), // TODO add
|
|
|
|
debug.Cmd(),
|
|
|
|
config.Cmd(),
|
|
|
|
)
|
|
|
|
|
|
|
|
ac := appCreator{
|
|
|
|
encodingConfig: encodingConfig,
|
|
|
|
}
|
2022-04-21 20:16:28 +00:00
|
|
|
|
2023-08-22 15:24:48 +00:00
|
|
|
opts := ethermintserver.StartOptions{
|
|
|
|
AppCreator: ac.newApp,
|
2024-05-01 04:33:44 +00:00
|
|
|
DefaultNodeHome: chaincfg.DefaultNodeHome,
|
2024-07-11 13:23:31 +00:00
|
|
|
DBOpener: dbOpener,
|
2023-08-22 15:24:48 +00:00
|
|
|
}
|
2022-04-21 20:16:28 +00:00
|
|
|
// ethermintserver adds additional flags to start the JSON-RPC server for evm support
|
2023-04-04 00:08:45 +00:00
|
|
|
ethermintserver.AddCommands(
|
|
|
|
rootCmd,
|
2023-08-22 15:24:48 +00:00
|
|
|
opts,
|
2023-04-04 00:08:45 +00:00
|
|
|
ac.appExport,
|
|
|
|
ac.addStartCmdFlags,
|
|
|
|
)
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
// add keybase, auxiliary RPC, query, and tx child commands
|
|
|
|
rootCmd.AddCommand(
|
|
|
|
newQueryCmd(),
|
|
|
|
newTxCmd(),
|
2023-12-13 17:17:37 +00:00
|
|
|
keyCommands(app.DefaultNodeHome),
|
2024-01-19 18:17:13 +00:00
|
|
|
rocksdb.RocksDBCmd,
|
2024-01-05 19:25:53 +00:00
|
|
|
newShardCmd(opts),
|
2024-05-28 18:00:28 +00:00
|
|
|
iavlviewer.NewCmd(opts),
|
2022-01-08 00:39:27 +00:00
|
|
|
)
|
|
|
|
}
|