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
|
|
|
|
2020-04-01 18:49:21 +00:00
|
|
|
"github.com/spf13/cobra"
|
2019-11-13 17:00:21 +00:00
|
|
|
|
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
|
|
|
|
2020-08-04 18:52:32 +00:00
|
|
|
sdkclient "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-07-02 15:19:48 +00:00
|
|
|
sdkcodec "github.com/cosmos/cosmos-sdk/codec"
|
2020-08-23 21:41:54 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
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"
|
2020-08-04 18:52:32 +00:00
|
|
|
|
|
|
|
"github.com/cosmos/ethermint/app"
|
|
|
|
"github.com/cosmos/ethermint/client"
|
|
|
|
"github.com/cosmos/ethermint/codec"
|
|
|
|
"github.com/cosmos/ethermint/crypto"
|
|
|
|
"github.com/cosmos/ethermint/rpc"
|
2020-08-05 13:27:48 +00:00
|
|
|
ethermint "github.com/cosmos/ethermint/types"
|
2019-07-05 16:46:13 +00:00
|
|
|
)
|
|
|
|
|
2020-04-22 19:26:01 +00:00
|
|
|
var (
|
2020-04-29 20:38:57 +00:00
|
|
|
cdc = codec.MakeCodec(app.ModuleBasics)
|
2020-04-22 19:26:01 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
2020-08-04 18:52:32 +00:00
|
|
|
tmamino.RegisterKeyType(crypto.PubKeySecp256k1{}, crypto.PubKeyAminoName)
|
|
|
|
tmamino.RegisterKeyType(crypto.PrivKeySecp256k1{}, crypto.PrivKeyAminoName)
|
2019-11-15 17:02:13 +00:00
|
|
|
|
2020-08-23 21:41:54 +00:00
|
|
|
keys.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()
|
2020-08-05 13:27:48 +00:00
|
|
|
ethermint.SetBech32Prefixes(config)
|
2020-08-28 15:35:10 +00:00
|
|
|
ethermint.SetBip44CoinType(config)
|
2019-07-05 16:46:13 +00:00
|
|
|
config.Seal()
|
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
2020-08-05 15:17:50 +00:00
|
|
|
Use: "ethermintcli",
|
|
|
|
Short: "Command line interface for interacting with ethermintd",
|
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 {
|
2020-08-04 18:52:32 +00:00
|
|
|
return client.InitConfig(rootCmd)
|
2019-07-05 16:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construct Root Command
|
|
|
|
rootCmd.AddCommand(
|
2020-04-01 18:49:21 +00:00
|
|
|
clientrpc.StatusCommand(),
|
2020-08-04 18:52:32 +00:00
|
|
|
sdkclient.ConfigCmd(app.DefaultCLIHome),
|
2019-07-25 20:38:55 +00:00
|
|
|
queryCmd(cdc),
|
2019-09-15 16:12:59 +00:00
|
|
|
txCmd(cdc),
|
2020-09-24 17:50:47 +00:00
|
|
|
client.ValidateChainID(
|
|
|
|
rpc.EmintServeCmd(cdc),
|
|
|
|
),
|
2020-04-22 19:26:01 +00:00
|
|
|
flags.LineBreak,
|
2020-08-04 18:52:32 +00:00
|
|
|
client.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 15:19:48 +00:00
|
|
|
func queryCmd(cdc *sdkcodec.Codec) *cobra.Command {
|
2019-07-25 20:38:55 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-02 15:19:48 +00:00
|
|
|
func txCmd(cdc *sdkcodec.Codec) *cobra.Command {
|
2019-09-15 16:12:59 +00:00
|
|
|
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
|
|
|
|
}
|