forked from cerc-io/laconicd-deprecated
upgrade changes cleanup (#236)
* 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
This commit is contained in:
@@ -14,14 +14,15 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
||||
|
||||
emintcrypto "github.com/cosmos/ethermint/crypto"
|
||||
)
|
||||
|
||||
func exportEthKeyCommand() *cobra.Command {
|
||||
func unsafeExportEthKeyCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "export-eth-key <name>",
|
||||
Short: "Export an Ethereum private key",
|
||||
Long: `Export an Ethereum private key unencrypted to use in dev tooling **UNSAFE**`,
|
||||
Use: "unsafe-export-eth-key [name]",
|
||||
Short: "**UNSAFE** Export an Ethereum private key",
|
||||
Long: `**UNSAFE** Export an Ethereum private key unencrypted to use in dev tooling`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runExportCmd,
|
||||
}
|
||||
@@ -29,12 +30,13 @@ func exportEthKeyCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
func runExportCmd(cmd *cobra.Command, args []string) error {
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
|
||||
kb, err := clientkeys.NewKeyringFromHomeFlag(cmd.InOrStdin())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf := bufio.NewReader(cmd.InOrStdin())
|
||||
decryptPassword := ""
|
||||
conf := true
|
||||
keyringBackend := viper.GetString(flags.FlagKeyringBackend)
|
||||
@@ -42,11 +44,11 @@ func runExportCmd(cmd *cobra.Command, args []string) error {
|
||||
case flags.KeyringBackendFile:
|
||||
decryptPassword, err = input.GetPassword(
|
||||
"**WARNING this is an unsafe way to export your unencrypted private key**\nEnter key password:",
|
||||
buf)
|
||||
inBuf)
|
||||
case flags.KeyringBackendOS:
|
||||
conf, err = input.GetConfirmation(
|
||||
"**WARNING** this is an unsafe way to export your unencrypted private key, are you sure?",
|
||||
buf)
|
||||
inBuf)
|
||||
}
|
||||
if err != nil || !conf {
|
||||
return err
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"bufio"
|
||||
"io"
|
||||
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
|
||||
emintCrypto "github.com/cosmos/ethermint/crypto"
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -46,7 +47,7 @@ func keyCommands() *cobra.Command {
|
||||
clientkeys.ParseKeyStringCommand(),
|
||||
clientkeys.MigrateCommand(),
|
||||
flags.LineBreak,
|
||||
exportEthKeyCommand(),
|
||||
unsafeExportEthKeyCommand(),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
+37
-16
@@ -1,34 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
emintapp "github.com/cosmos/ethermint/app"
|
||||
"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"
|
||||
sdkrpc "github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
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"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Configure cobra to sort commands
|
||||
cobra.EnableCommandSorting = false
|
||||
|
||||
cdc := emintapp.MakeCodec()
|
||||
cdc := app.MakeCodec()
|
||||
|
||||
tmamino.RegisterKeyType(emintcrypto.PubKeySecp256k1{}, emintcrypto.PubKeyAminoName)
|
||||
tmamino.RegisterKeyType(emintcrypto.PrivKeySecp256k1{}, emintcrypto.PrivKeyAminoName)
|
||||
@@ -45,7 +49,7 @@ func main() {
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "emintcli",
|
||||
Short: "Ethermint Client",
|
||||
Short: "Command line interface for interacting with emintd",
|
||||
}
|
||||
|
||||
// Add --chain-id to persistent flags and mark it required
|
||||
@@ -56,20 +60,24 @@ func main() {
|
||||
|
||||
// Construct Root Command
|
||||
rootCmd.AddCommand(
|
||||
sdkrpc.StatusCommand(),
|
||||
client.ConfigCmd(emintapp.DefaultCLIHome),
|
||||
clientrpc.StatusCommand(),
|
||||
client.ConfigCmd(app.DefaultCLIHome),
|
||||
queryCmd(cdc),
|
||||
txCmd(cdc),
|
||||
rpc.EmintServeCmd(cdc),
|
||||
client.LineBreak,
|
||||
keyCommands(),
|
||||
client.LineBreak,
|
||||
version.Cmd,
|
||||
client.NewCompletionCmd(rootCmd, true),
|
||||
)
|
||||
|
||||
executor := cli.PrepareMainCmd(rootCmd, "EM", emintapp.DefaultCLIHome)
|
||||
// Add flags and prefix all env exposed with EM
|
||||
executor := cli.PrepareMainCmd(rootCmd, "EM", app.DefaultCLIHome)
|
||||
|
||||
err := executor.Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(fmt.Errorf("failed executing CLI command: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +97,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command {
|
||||
)
|
||||
|
||||
// add modules' query commands
|
||||
emintapp.ModuleBasics.AddQueryCommands(queryCmd, cdc)
|
||||
app.ModuleBasics.AddQueryCommands(queryCmd, cdc)
|
||||
|
||||
return queryCmd
|
||||
}
|
||||
@@ -104,14 +112,27 @@ func txCmd(cdc *amino.Codec) *cobra.Command {
|
||||
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
|
||||
emintapp.ModuleBasics.AddTxCommands(txCmd, cdc)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
||||
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
ethermint "github.com/cosmos/ethermint/types"
|
||||
)
|
||||
|
||||
const (
|
||||
flagClientHome = "home-client"
|
||||
flagVestingStart = "vesting-start-time"
|
||||
flagVestingEnd = "vesting-end-time"
|
||||
flagVestingAmt = "vesting-amount"
|
||||
)
|
||||
|
||||
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
|
||||
func AddGenesisAccountCmd(
|
||||
ctx *server.Context, cdc *codec.Codec, defaultNodeHome, defaultClientHome string,
|
||||
) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
|
||||
Short: "Add a genesis account to genesis.json",
|
||||
Long: `Add a genesis account to genesis.json. The provided account must specify
|
||||
the account address or key name and a list of initial coins. If a key name is given,
|
||||
the address will be looked up in the local Keybase. The list of initial tokens must
|
||||
contain valid denominations. Accounts may optionally be supplied with vesting parameters.
|
||||
`,
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
config := ctx.Config
|
||||
config.SetRoot(viper.GetString(cli.HomeFlag))
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(args[0])
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
if err != nil {
|
||||
// attempt to lookup address from Keybase if no address was provided
|
||||
kb, err := keys.NewKeyringFromDir(viper.GetString(flagClientHome), inBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
info, err := kb.Get(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get address from Keybase: %w", err)
|
||||
}
|
||||
|
||||
addr = info.GetAddress()
|
||||
}
|
||||
|
||||
coins, err := sdk.ParseCoins(args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse coins: %w", err)
|
||||
}
|
||||
|
||||
vestingStart := viper.GetInt64(flagVestingStart)
|
||||
vestingEnd := viper.GetInt64(flagVestingEnd)
|
||||
vestingAmt, err := sdk.ParseCoins(viper.GetString(flagVestingAmt))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse vesting amount: %w", err)
|
||||
}
|
||||
|
||||
// create concrete account type based on input parameters
|
||||
var genAccount authexported.GenesisAccount
|
||||
|
||||
baseAccount := auth.NewBaseAccount(addr, coins.Sort(), nil, 0, 0)
|
||||
if !vestingAmt.IsZero() {
|
||||
baseVestingAccount, err := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create base vesting account: %w", err)
|
||||
}
|
||||
|
||||
switch {
|
||||
case vestingStart != 0 && vestingEnd != 0:
|
||||
genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart)
|
||||
|
||||
case vestingEnd != 0:
|
||||
genAccount = authvesting.NewDelayedVestingAccountRaw(baseVestingAccount)
|
||||
|
||||
default:
|
||||
return errors.New("invalid vesting parameters; must supply start and end time or end time")
|
||||
}
|
||||
} else {
|
||||
genAccount = ethermint.Account{
|
||||
BaseAccount: baseAccount,
|
||||
CodeHash: ethcrypto.Keccak256(nil),
|
||||
}
|
||||
}
|
||||
|
||||
if err := genAccount.Validate(); err != nil {
|
||||
return fmt.Errorf("failed to validate new genesis account: %w", err)
|
||||
}
|
||||
|
||||
genFile := config.GenesisFile()
|
||||
appState, genDoc, err := genutil.GenesisStateFromGenFile(cdc, genFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
|
||||
}
|
||||
|
||||
authGenState := auth.GetGenesisStateFromAppState(cdc, appState)
|
||||
|
||||
if authGenState.Accounts.Contains(addr) {
|
||||
return fmt.Errorf("cannot add account at existing address %s", addr)
|
||||
}
|
||||
|
||||
// Add the new account to the set of genesis accounts and sanitize the
|
||||
// accounts afterwards.
|
||||
authGenState.Accounts = append(authGenState.Accounts, genAccount)
|
||||
authGenState.Accounts = auth.SanitizeGenesisAccounts(authGenState.Accounts)
|
||||
|
||||
authGenStateBz, err := cdc.MarshalJSON(authGenState)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
|
||||
}
|
||||
|
||||
appState[auth.ModuleName] = authGenStateBz
|
||||
|
||||
appStateJSON, err := cdc.MarshalJSON(appState)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal application genesis state: %w", err)
|
||||
}
|
||||
|
||||
genDoc.AppState = appStateJSON
|
||||
return genutil.ExportGenesisFile(genDoc, genFile)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
|
||||
cmd.Flags().String(flagClientHome, defaultClientHome, "client's home directory")
|
||||
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
|
||||
cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
|
||||
cmd.Flags().Uint64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
|
||||
|
||||
return cmd
|
||||
}
|
||||
+17
-11
@@ -23,17 +23,20 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/ethermint/app"
|
||||
"github.com/cosmos/ethermint/client/genaccounts"
|
||||
emintcrypto "github.com/cosmos/ethermint/crypto"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
tmlog "github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
)
|
||||
|
||||
const flagInvCheckPeriod = "inv-check-period"
|
||||
|
||||
var invCheckPeriod uint
|
||||
|
||||
func main() {
|
||||
cobra.EnableCommandSorting = false
|
||||
|
||||
@@ -65,12 +68,14 @@ func main() {
|
||||
withChainIDValidation(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome)),
|
||||
genutilcli.CollectGenTxsCmd(ctx, cdc, auth.GenesisAccountIterator{}, app.DefaultNodeHome),
|
||||
genutilcli.GenTxCmd(
|
||||
ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{}, auth.GenesisAccountIterator{}, app.DefaultNodeHome, app.DefaultCLIHome,
|
||||
ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{}, auth.GenesisAccountIterator{},
|
||||
app.DefaultNodeHome, app.DefaultCLIHome,
|
||||
),
|
||||
genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics),
|
||||
|
||||
// AddGenesisAccountCmd allows users to add accounts to the genesis file
|
||||
genaccounts.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome),
|
||||
AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome),
|
||||
client.NewCompletionCmd(rootCmd, true),
|
||||
)
|
||||
|
||||
// Tendermint node base commands
|
||||
@@ -78,23 +83,25 @@ func main() {
|
||||
|
||||
// prepare and add flags
|
||||
executor := cli.PrepareBaseCmd(rootCmd, "EM", app.DefaultNodeHome)
|
||||
rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod,
|
||||
0, "Assert registered invariants every N blocks")
|
||||
err := executor.Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func newApp(logger tmlog.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
|
||||
return app.NewEthermintApp(logger, db, true, 0,
|
||||
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
|
||||
return app.NewEthermintApp(logger, db, traceStore, true, 0,
|
||||
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))))
|
||||
}
|
||||
|
||||
func exportAppStateAndTMValidators(
|
||||
logger tmlog.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
|
||||
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
|
||||
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
|
||||
|
||||
if height != -1 {
|
||||
emintApp := app.NewEthermintApp(logger, db, true, 0)
|
||||
emintApp := app.NewEthermintApp(logger, db, traceStore, true, 0)
|
||||
err := emintApp.LoadHeight(height)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -102,7 +109,7 @@ func exportAppStateAndTMValidators(
|
||||
return emintApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
||||
}
|
||||
|
||||
emintApp := app.NewEthermintApp(logger, db, true, 0)
|
||||
emintApp := app.NewEthermintApp(logger, db, traceStore, true, 0)
|
||||
|
||||
return emintApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
||||
}
|
||||
@@ -119,8 +126,7 @@ func withChainIDValidation(baseCmd *cobra.Command) *cobra.Command {
|
||||
// Verify that the chain-id entered is a base 10 integer
|
||||
_, ok := new(big.Int).SetString(chainIDFlag, 10)
|
||||
if !ok {
|
||||
return fmt.Errorf(
|
||||
fmt.Sprintf("invalid chainID: %s, must be base-10 integer format", chainIDFlag))
|
||||
return fmt.Errorf("invalid chainID: %s, must be base-10 integer format", chainIDFlag)
|
||||
}
|
||||
|
||||
return baseRunE(cmd, args)
|
||||
|
||||
Reference in New Issue
Block a user