2018-07-19 21:16:48 +00:00
|
|
|
package main
|
|
|
|
|
2019-07-05 16:46:13 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
2019-11-13 17:00:21 +00:00
|
|
|
emintapp "github.com/cosmos/ethermint/app"
|
2019-11-15 17:02:13 +00:00
|
|
|
emintcrypto "github.com/cosmos/ethermint/crypto"
|
2019-08-11 14:42:46 +00:00
|
|
|
"github.com/cosmos/ethermint/rpc"
|
2019-11-13 17:00:21 +00:00
|
|
|
|
2019-08-11 14:42:46 +00:00
|
|
|
"github.com/tendermint/go-amino"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-11-13 17:00:21 +00:00
|
|
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
2019-07-15 14:13:59 +00:00
|
|
|
sdkrpc "github.com/cosmos/cosmos-sdk/client/rpc"
|
2019-11-13 17:00:21 +00:00
|
|
|
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
2019-07-05 16:46:13 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
2019-09-15 16:12:59 +00:00
|
|
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
|
|
|
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
|
|
|
|
2019-07-05 16:46:13 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2019-11-15 17:02:13 +00:00
|
|
|
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
2019-07-05 16:46:13 +00:00
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
|
|
|
)
|
|
|
|
|
2018-07-19 21:16:48 +00:00
|
|
|
func main() {
|
2019-07-05 16:46:13 +00:00
|
|
|
cobra.EnableCommandSorting = false
|
|
|
|
|
2019-07-15 14:13:59 +00:00
|
|
|
cdc := emintapp.MakeCodec()
|
2019-07-05 16:46:13 +00:00
|
|
|
|
2019-11-15 17:02:13 +00:00
|
|
|
tmamino.RegisterKeyType(emintcrypto.PubKeySecp256k1{}, emintcrypto.PubKeyAminoName)
|
|
|
|
tmamino.RegisterKeyType(emintcrypto.PrivKeySecp256k1{}, emintcrypto.PrivKeyAminoName)
|
|
|
|
|
2019-11-13 17:00:21 +00:00
|
|
|
cryptokeys.CryptoCdc = cdc
|
|
|
|
clientkeys.KeysCdc = cdc
|
2019-09-18 18:50:06 +00:00
|
|
|
|
2019-07-05 16:46:13 +00:00
|
|
|
// 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(
|
2019-07-15 14:13:59 +00:00
|
|
|
sdkrpc.StatusCommand(),
|
2019-07-05 16:46:13 +00:00
|
|
|
client.ConfigCmd(emintapp.DefaultCLIHome),
|
2019-07-25 20:38:55 +00:00
|
|
|
queryCmd(cdc),
|
2019-09-15 16:12:59 +00:00
|
|
|
txCmd(cdc),
|
2019-12-20 09:47:02 +00:00
|
|
|
rpc.EmintServeCmd(cdc),
|
2019-07-05 16:46:13 +00:00
|
|
|
client.LineBreak,
|
2019-11-13 17:00:21 +00:00
|
|
|
keyCommands(),
|
2019-07-05 16:46:13 +00:00
|
|
|
client.LineBreak,
|
|
|
|
)
|
|
|
|
|
|
|
|
executor := cli.PrepareMainCmd(rootCmd, "EM", emintapp.DefaultCLIHome)
|
|
|
|
err := executor.Execute()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 20:38:55 +00:00
|
|
|
func queryCmd(cdc *amino.Codec) *cobra.Command {
|
|
|
|
queryCmd := &cobra.Command{
|
|
|
|
Use: "query",
|
|
|
|
Aliases: []string{"q"},
|
|
|
|
Short: "Querying subcommands",
|
|
|
|
}
|
|
|
|
|
2019-09-18 18:50:06 +00:00
|
|
|
queryCmd.AddCommand(
|
|
|
|
authcmd.GetAccountCmd(cdc),
|
|
|
|
client.LineBreak,
|
|
|
|
authcmd.QueryTxsByEventsCmd(cdc),
|
|
|
|
authcmd.QueryTxCmd(cdc),
|
|
|
|
client.LineBreak,
|
|
|
|
)
|
2019-07-25 20:38:55 +00:00
|
|
|
|
|
|
|
// add modules' query commands
|
|
|
|
emintapp.ModuleBasics.AddQueryCommands(queryCmd, cdc)
|
|
|
|
|
|
|
|
return queryCmd
|
|
|
|
}
|
|
|
|
|
2019-09-15 16:12:59 +00:00
|
|
|
func txCmd(cdc *amino.Codec) *cobra.Command {
|
|
|
|
txCmd := &cobra.Command{
|
|
|
|
Use: "tx",
|
|
|
|
Short: "Transactions subcommands",
|
|
|
|
}
|
|
|
|
|
|
|
|
txCmd.AddCommand(
|
|
|
|
bankcmd.SendTxCmd(cdc),
|
|
|
|
client.LineBreak,
|
|
|
|
authcmd.GetSignCommand(cdc),
|
|
|
|
client.LineBreak,
|
|
|
|
authcmd.GetBroadcastCommand(cdc),
|
|
|
|
authcmd.GetEncodeCommand(cdc),
|
|
|
|
client.LineBreak,
|
|
|
|
)
|
|
|
|
|
|
|
|
// add modules' tx commands
|
|
|
|
emintapp.ModuleBasics.AddTxCommands(txCmd, cdc)
|
|
|
|
|
|
|
|
return txCmd
|
|
|
|
}
|
|
|
|
|
2019-07-05 16:46:13 +00:00
|
|
|
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))
|
2018-07-19 21:16:48 +00:00
|
|
|
}
|