6eef37b0c6
* Basic transactions set up (to be separated) * Change transaction command to not include create operation (to include other command in next commit) * set up create command and made minor changes * wip implements module queries * Added tests for query address decoding * Added ambiguous encoding of to address in transaction and added tests * Fix linting issue * Move registering key types to application level to allow module usage to ignore * Move genaccounts code to be reused * Switches nonce increase to always happen in ante handler * change SetNonce from keeper to point to actual nonce operation * Remove no op nonce switch (not needed with clearing cache) * Changes to update all accounts pre state transition and clear cache at end of block * Update accounts before end of block commit (edge case where necessary) * Fix nonce of sender going into evm in case it's checked, and let evm set contract starting nonce
142 lines
3.6 KiB
Go
142 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
|
|
emintapp "github.com/cosmos/ethermint/app"
|
|
emintcrypto "github.com/cosmos/ethermint/crypto"
|
|
"github.com/cosmos/ethermint/rpc"
|
|
|
|
"github.com/tendermint/go-amino"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
sdkrpc "github.com/cosmos/cosmos-sdk/client/rpc"
|
|
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
|
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
|
"github.com/tendermint/tendermint/libs/cli"
|
|
)
|
|
|
|
func main() {
|
|
cobra.EnableCommandSorting = false
|
|
|
|
cdc := emintapp.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: "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(
|
|
sdkrpc.StatusCommand(),
|
|
client.ConfigCmd(emintapp.DefaultCLIHome),
|
|
queryCmd(cdc),
|
|
txCmd(cdc),
|
|
// TODO: Set up rest routes (if included, different from web3 api)
|
|
rpc.Web3RpcCmd(cdc),
|
|
client.LineBreak,
|
|
keyCommands(),
|
|
client.LineBreak,
|
|
)
|
|
|
|
executor := cli.PrepareMainCmd(rootCmd, "EM", emintapp.DefaultCLIHome)
|
|
err := executor.Execute()
|
|
if err != nil {
|
|
panic(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
|
|
emintapp.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),
|
|
client.LineBreak,
|
|
authcmd.GetBroadcastCommand(cdc),
|
|
authcmd.GetEncodeCommand(cdc),
|
|
client.LineBreak,
|
|
)
|
|
|
|
// add modules' tx commands
|
|
emintapp.ModuleBasics.AddTxCommands(txCmd, cdc)
|
|
|
|
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))
|
|
}
|