da9157e406
* changes from update version * app changes * cmd changes * build and send tx * fix tests * eth_rpc fixes * lint * add WithEventManager to handler ctx * changelog * go mod verify and tidy
162 lines
4.2 KiB
Go
162 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/cosmos/ethermint/app"
|
|
emintcrypto "github.com/cosmos/ethermint/crypto"
|
|
"github.com/cosmos/ethermint/rpc"
|
|
|
|
"github.com/tendermint/go-amino"
|
|
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
|
"github.com/tendermint/tendermint/libs/cli"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
clientrpc "github.com/cosmos/cosmos-sdk/client/rpc"
|
|
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
|
)
|
|
|
|
func main() {
|
|
// Configure cobra to sort commands
|
|
cobra.EnableCommandSorting = false
|
|
|
|
cdc := app.MakeCodec()
|
|
|
|
tmamino.RegisterKeyType(emintcrypto.PubKeySecp256k1{}, emintcrypto.PubKeyAminoName)
|
|
tmamino.RegisterKeyType(emintcrypto.PrivKeySecp256k1{}, emintcrypto.PrivKeyAminoName)
|
|
|
|
cryptokeys.CryptoCdc = cdc
|
|
clientkeys.KeysCdc = cdc
|
|
|
|
// 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: "Command line interface for interacting with emintd",
|
|
}
|
|
|
|
// 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(
|
|
clientrpc.StatusCommand(),
|
|
client.ConfigCmd(app.DefaultCLIHome),
|
|
queryCmd(cdc),
|
|
txCmd(cdc),
|
|
rpc.EmintServeCmd(cdc),
|
|
client.LineBreak,
|
|
keyCommands(),
|
|
client.LineBreak,
|
|
version.Cmd,
|
|
client.NewCompletionCmd(rootCmd, true),
|
|
)
|
|
|
|
// Add flags and prefix all env exposed with EM
|
|
executor := cli.PrepareMainCmd(rootCmd, "EM", app.DefaultCLIHome)
|
|
|
|
err := executor.Execute()
|
|
if err != nil {
|
|
panic(fmt.Errorf("failed executing CLI command: %w", err))
|
|
}
|
|
}
|
|
|
|
func queryCmd(cdc *amino.Codec) *cobra.Command {
|
|
queryCmd := &cobra.Command{
|
|
Use: "query",
|
|
Aliases: []string{"q"},
|
|
Short: "Querying subcommands",
|
|
}
|
|
|
|
queryCmd.AddCommand(
|
|
authcmd.GetAccountCmd(cdc),
|
|
client.LineBreak,
|
|
authcmd.QueryTxsByEventsCmd(cdc),
|
|
authcmd.QueryTxCmd(cdc),
|
|
client.LineBreak,
|
|
)
|
|
|
|
// add modules' query commands
|
|
app.ModuleBasics.AddQueryCommands(queryCmd, cdc)
|
|
|
|
return queryCmd
|
|
}
|
|
|
|
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),
|
|
authcmd.GetMultiSignCommand(cdc),
|
|
client.LineBreak,
|
|
authcmd.GetBroadcastCommand(cdc),
|
|
authcmd.GetEncodeCommand(cdc),
|
|
authcmd.GetDecodeCommand(cdc),
|
|
client.LineBreak,
|
|
)
|
|
|
|
// add modules' tx commands
|
|
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...)
|
|
|
|
return txCmd
|
|
}
|
|
|
|
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))
|
|
}
|