forked from cerc-io/laconicd-deprecated
Set up CLI framework without logic for query, tx, SDK rest, and web3 api commands (#61)
This commit is contained in:
+78
-3
@@ -1,7 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
emintapp "github.com/cosmos/ethermint/app"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// TODO: Implement CLI commands and logic
|
||||
//
|
||||
// Ref: https://github.com/cosmos/ethermint/issues/432
|
||||
cobra.EnableCommandSorting = false
|
||||
|
||||
// TODO: Set up codec
|
||||
|
||||
// Read in the configuration file for the sdk
|
||||
config := sdk.GetConfig()
|
||||
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
|
||||
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
|
||||
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
|
||||
config.Seal()
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "emintcli",
|
||||
Short: "Ethermint Client",
|
||||
}
|
||||
|
||||
// Add --chain-id to persistent flags and mark it required
|
||||
rootCmd.PersistentFlags().String(client.FlagChainID, "", "Chain ID of tendermint node")
|
||||
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
|
||||
return initConfig(rootCmd)
|
||||
}
|
||||
|
||||
// Construct Root Command
|
||||
rootCmd.AddCommand(
|
||||
rpc.StatusCommand(),
|
||||
client.ConfigCmd(emintapp.DefaultCLIHome),
|
||||
// TODO: Set up query command
|
||||
// TODO: Set up tx command
|
||||
// TODO: Set up rest routes (if included, different from web3 api)
|
||||
// TODO: Set up web3 API setup command?
|
||||
client.LineBreak,
|
||||
keys.Commands(),
|
||||
client.LineBreak,
|
||||
)
|
||||
|
||||
executor := cli.PrepareMainCmd(rootCmd, "EM", emintapp.DefaultCLIHome)
|
||||
err := executor.Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initConfig(cmd *cobra.Command) error {
|
||||
home, err := cmd.PersistentFlags().GetString(cli.HomeFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfgFile := path.Join(home, "config", "config.toml")
|
||||
if _, err := os.Stat(cfgFile); err == nil {
|
||||
viper.SetConfigFile(cfgFile)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := viper.BindPFlag(client.FlagChainID, cmd.PersistentFlags().Lookup(client.FlagChainID)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil {
|
||||
return err
|
||||
}
|
||||
return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user