2018-07-19 21:16:48 +00:00
|
|
|
package main
|
|
|
|
|
2019-07-05 16:46:13 +00:00
|
|
|
import (
|
2020-04-01 18:49:21 +00:00
|
|
|
"fmt"
|
2019-07-05 16:46:13 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
|
|
|
"github.com/cosmos/ethermint/app"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/ethermint/codec"
|
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"
|
2020-04-01 18:49:21 +00:00
|
|
|
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
2019-08-11 14:42:46 +00:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2019-11-13 17:00:21 +00:00
|
|
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
2020-04-01 18:49:21 +00:00
|
|
|
clientrpc "github.com/cosmos/cosmos-sdk/client/rpc"
|
2020-04-22 19:26:01 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
2019-07-05 16:46:13 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-01 18:49:21 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
2019-09-15 16:12:59 +00:00
|
|
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
2020-04-01 18:49:21 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
2019-09-15 16:12:59 +00:00
|
|
|
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
2019-07-05 16:46:13 +00:00
|
|
|
)
|
|
|
|
|
2020-04-22 19:26:01 +00:00
|
|
|
var (
|
|
|
|
cdc = codec.MakeCodec(app.ModuleBasics)
|
|
|
|
appCodec = codec.NewAppCodec(cdc)
|
|
|
|
)
|
|
|
|
|
2018-07-19 21:16:48 +00:00
|
|
|
func main() {
|
2020-04-01 18:49:21 +00:00
|
|
|
// Configure cobra to sort commands
|
2019-07-05 16:46:13 +00:00
|
|
|
cobra.EnableCommandSorting = false
|
|
|
|
|
2019-11-15 17:02:13 +00:00
|
|
|
tmamino.RegisterKeyType(emintcrypto.PubKeySecp256k1{}, emintcrypto.PubKeyAminoName)
|
|
|
|
tmamino.RegisterKeyType(emintcrypto.PrivKeySecp256k1{}, emintcrypto.PrivKeyAminoName)
|
|
|
|
|
2020-04-22 19:26:01 +00:00
|
|
|
keyring.CryptoCdc = cdc
|
2019-11-13 17:00:21 +00:00
|
|
|
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",
|
2020-04-01 18:49:21 +00:00
|
|
|
Short: "Command line interface for interacting with emintd",
|
2019-07-05 16:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add --chain-id to persistent flags and mark it required
|
2020-04-22 19:26:01 +00:00
|
|
|
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "Chain ID of tendermint node")
|
2019-07-05 16:46:13 +00:00
|
|
|
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
|
|
|
|
return initConfig(rootCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct Root Command
|
|
|
|
rootCmd.AddCommand(
|
2020-04-01 18:49:21 +00:00
|
|
|
clientrpc.StatusCommand(),
|
|
|
|
client.ConfigCmd(app.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),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2019-11-13 17:00:21 +00:00
|
|
|
keyCommands(),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2020-04-01 18:49:21 +00:00
|
|
|
version.Cmd,
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.NewCompletionCmd(rootCmd, true),
|
2019-07-05 16:46:13 +00:00
|
|
|
)
|
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
// Add flags and prefix all env exposed with EM
|
|
|
|
executor := cli.PrepareMainCmd(rootCmd, "EM", app.DefaultCLIHome)
|
|
|
|
|
2019-07-05 16:46:13 +00:00
|
|
|
err := executor.Execute()
|
|
|
|
if err != nil {
|
2020-04-01 18:49:21 +00:00
|
|
|
panic(fmt.Errorf("failed executing CLI command: %w", err))
|
2019-07-05 16:46:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2019-09-18 18:50:06 +00:00
|
|
|
authcmd.QueryTxsByEventsCmd(cdc),
|
|
|
|
authcmd.QueryTxCmd(cdc),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2019-09-18 18:50:06 +00:00
|
|
|
)
|
2019-07-25 20:38:55 +00:00
|
|
|
|
|
|
|
// add modules' query commands
|
2020-04-01 18:49:21 +00:00
|
|
|
app.ModuleBasics.AddQueryCommands(queryCmd, cdc)
|
2019-07-25 20:38:55 +00:00
|
|
|
|
|
|
|
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),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2019-09-15 16:12:59 +00:00
|
|
|
authcmd.GetSignCommand(cdc),
|
2020-04-01 18:49:21 +00:00
|
|
|
authcmd.GetMultiSignCommand(cdc),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2019-09-15 16:12:59 +00:00
|
|
|
authcmd.GetBroadcastCommand(cdc),
|
|
|
|
authcmd.GetEncodeCommand(cdc),
|
2020-04-01 18:49:21 +00:00
|
|
|
authcmd.GetDecodeCommand(cdc),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2019-09-15 16:12:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// add modules' tx commands
|
2020-04-01 18:49:21 +00:00
|
|
|
app.ModuleBasics.AddTxCommands(txCmd, cdc)
|
|
|
|
|
|
|
|
// remove auth and bank commands as they're mounted under the root tx command
|
|
|
|
var cmdsToRemove []*cobra.Command
|
|
|
|
|
|
|
|
for _, cmd := range txCmd.Commands() {
|
|
|
|
if cmd.Use == auth.ModuleName || cmd.Use == bank.ModuleName {
|
|
|
|
cmdsToRemove = append(cmdsToRemove, cmd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
txCmd.RemoveCommand(cmdsToRemove...)
|
2019-09-15 16:12:59 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2020-04-22 19:26:01 +00:00
|
|
|
if err := viper.BindPFlag(flags.FlagChainID, cmd.PersistentFlags().Lookup(flags.FlagChainID)); err != nil {
|
2019-07-05 16:46:13 +00:00
|
|
|
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
|
|
|
}
|