Merge PR #6651: More CLI cleanup
This commit is contained in:
parent
589c1a531e
commit
b25e3fc76d
|
@ -39,6 +39,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||||
|
|
||||||
### Client Breaking
|
### Client Breaking
|
||||||
|
|
||||||
|
* (cli) [\#6651](https://github.com/cosmos/cosmos-sdk/pull/6651) The `gentx` command has been improved. No longer are `--from` and `--name` flags required. Instead, a single argument, `name`, is required which refers to the key pair in the Keyring. In addition, an optional
|
||||||
|
`--moniker` flag can be provided to override the moniker found in `config.toml`.
|
||||||
* (api) [\#6426](https://github.com/cosmos/cosmos-sdk/pull/6426) The ability to start an out-of-process API REST server has now been removed. Instead, the API server is now started in-process along with the application and Tendermint. Configuration options have been added to `app.toml` to enable/disable the API server along with additional HTTP server options.
|
* (api) [\#6426](https://github.com/cosmos/cosmos-sdk/pull/6426) The ability to start an out-of-process API REST server has now been removed. Instead, the API server is now started in-process along with the application and Tendermint. Configuration options have been added to `app.toml` to enable/disable the API server along with additional HTTP server options.
|
||||||
* (baseapp) [\#6384](https://github.com/cosmos/cosmos-sdk/pull/6384) The `Result.Data` is now a Protocol Buffer encoded binary blob of type `TxData`. The `TxData` contains `Data` which contains a list of Protocol Buffer encoded message data and the corresponding message type.
|
* (baseapp) [\#6384](https://github.com/cosmos/cosmos-sdk/pull/6384) The `Result.Data` is now a Protocol Buffer encoded binary blob of type `TxData`. The `TxData` contains `Data` which contains a list of Protocol Buffer encoded message data and the corresponding message type.
|
||||||
* (x/gov) [#6295](https://github.com/cosmos/cosmos-sdk/pull/6295) Fix typo in querying governance params.
|
* (x/gov) [#6295](https://github.com/cosmos/cosmos-sdk/pull/6295) Fix typo in querying governance params.
|
||||||
|
|
|
@ -21,14 +21,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagClientHome = "home-client"
|
|
||||||
flagVestingStart = "vesting-start-time"
|
flagVestingStart = "vesting-start-time"
|
||||||
flagVestingEnd = "vesting-end-time"
|
flagVestingEnd = "vesting-end-time"
|
||||||
flagVestingAmt = "vesting-amount"
|
flagVestingAmt = "vesting-amount"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
|
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
|
||||||
func AddGenesisAccountCmd(defaultClientHome string) *cobra.Command {
|
func AddGenesisAccountCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
|
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
|
||||||
Short: "Add a genesis account to genesis.json",
|
Short: "Add a genesis account to genesis.json",
|
||||||
|
@ -48,14 +47,13 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
|
||||||
|
|
||||||
config.SetRoot(clientCtx.HomeDir)
|
config.SetRoot(clientCtx.HomeDir)
|
||||||
|
|
||||||
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
|
|
||||||
clientHome, _ := cmd.Flags().GetString(flagClientHome)
|
|
||||||
|
|
||||||
addr, err := sdk.AccAddressFromBech32(args[0])
|
addr, err := sdk.AccAddressFromBech32(args[0])
|
||||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||||
|
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
|
||||||
|
|
||||||
// attempt to lookup address from Keybase if no address was provided
|
// attempt to lookup address from Keybase if no address was provided
|
||||||
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientHome, inBuf)
|
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -160,7 +158,6 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
|
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
|
||||||
cmd.Flags().String(flagClientHome, defaultClientHome, "client's home directory")
|
|
||||||
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
|
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
|
||||||
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
|
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
|
||||||
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
|
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
|
||||||
|
|
|
@ -74,11 +74,11 @@ func init() {
|
||||||
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome),
|
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome),
|
||||||
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
|
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}),
|
||||||
genutilcli.MigrateGenesisCmd(),
|
genutilcli.MigrateGenesisCmd(),
|
||||||
genutilcli.GenTxCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
|
genutilcli.GenTxCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
|
||||||
genutilcli.ValidateGenesisCmd(simapp.ModuleBasics),
|
genutilcli.ValidateGenesisCmd(simapp.ModuleBasics),
|
||||||
AddGenesisAccountCmd(simapp.DefaultNodeHome),
|
AddGenesisAccountCmd(),
|
||||||
cli.NewCompletionCmd(rootCmd, true),
|
cli.NewCompletionCmd(rootCmd, true),
|
||||||
testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
|
testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
|
||||||
debug.Cmd(),
|
debug.Cmd(),
|
||||||
|
@ -114,7 +114,7 @@ func queryCommand() *cobra.Command {
|
||||||
)
|
)
|
||||||
|
|
||||||
simapp.ModuleBasics.AddQueryCommands(cmd, initClientCtx)
|
simapp.ModuleBasics.AddQueryCommands(cmd, initClientCtx)
|
||||||
cmd.PersistentFlags().String(flags.FlagChainID, "", "network chain ID")
|
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func txCommand() *cobra.Command {
|
||||||
)
|
)
|
||||||
|
|
||||||
simapp.ModuleBasics.AddTxCommands(cmd, initClientCtx)
|
simapp.ModuleBasics.AddTxCommands(cmd, initClientCtx)
|
||||||
cmd.PersistentFlags().String(flags.FlagChainID, "", "network chain ID")
|
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/tendermint/tendermint/libs/cli"
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||||
|
@ -18,7 +18,7 @@ import (
|
||||||
const flagGenTxDir = "gentx-dir"
|
const flagGenTxDir = "gentx-dir"
|
||||||
|
|
||||||
// CollectGenTxsCmd - return the cobra command to collect genesis transactions
|
// CollectGenTxsCmd - return the cobra command to collect genesis transactions
|
||||||
func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command {
|
func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "collect-gentxs",
|
Use: "collect-gentxs",
|
||||||
Short: "Collect genesis txs and output a genesis.json file",
|
Short: "Collect genesis txs and output a genesis.json file",
|
||||||
|
@ -57,12 +57,11 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeH
|
||||||
|
|
||||||
toPrint.AppMessage = appMessage
|
toPrint.AppMessage = appMessage
|
||||||
|
|
||||||
// print out some key information
|
|
||||||
return displayInfo(cdc, toPrint)
|
return displayInfo(cdc, toPrint)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
|
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
|
||||||
cmd.Flags().String(flagGenTxDir, "", "override default \"gentx\" directory from which collect and execute genesis transactions; default [--home]/config/gentx/")
|
cmd.Flags().String(flagGenTxDir, "", "override default \"gentx\" directory from which collect and execute genesis transactions; default [--home]/config/gentx/")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||||
|
@ -30,46 +31,52 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenTxCmd builds the application's gentx command.
|
// GenTxCmd builds the application's gentx command.
|
||||||
// nolint: errcheck
|
func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesIterator) *cobra.Command {
|
||||||
func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command {
|
|
||||||
ipDefault, _ := server.ExternalIP()
|
ipDefault, _ := server.ExternalIP()
|
||||||
fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault)
|
fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "gentx",
|
Use: "gentx [key_name]",
|
||||||
Short: "Generate a genesis tx carrying a self delegation",
|
Short: "Generate a genesis tx carrying a self delegation",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.ExactArgs(1),
|
||||||
Long: fmt.Sprintf(`This command is an alias of the 'tx create-validator' command'.
|
Long: fmt.Sprintf(`Generate a genesis transaction that creates a validator with a self-delegation,
|
||||||
|
that is signed by the key in the Keyring referenced by a given name. A node ID and Bech32 consensus
|
||||||
It creates a genesis transaction to create a validator.
|
pubkey may optionally be provided. If they are omitted, they will be retrieved from the priv_validator.json
|
||||||
The following default parameters are included:
|
file. The following default parameters are included:
|
||||||
%s`, defaultsDesc),
|
%s
|
||||||
|
|
||||||
|
Example:
|
||||||
|
$ %s gentx my-key-name --home=/path/to/home/dir --keyring-backend=os --chain-id=test-chain-1 \
|
||||||
|
--amount=1000000stake \
|
||||||
|
--moniker="myvalidator" \
|
||||||
|
--commission-max-change-rate=0.01 \
|
||||||
|
--commission-max-rate=1.0 \
|
||||||
|
--commission-rate=0.07 \
|
||||||
|
--details="..." \
|
||||||
|
--security-contact="..." \
|
||||||
|
--website="..."
|
||||||
|
`, defaultsDesc, version.AppName,
|
||||||
|
),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
serverCtx := server.GetServerContextFromCmd(cmd)
|
serverCtx := server.GetServerContextFromCmd(cmd)
|
||||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
cdc := clientCtx.JSONMarshaler
|
cdc := clientCtx.JSONMarshaler
|
||||||
|
|
||||||
home, _ := cmd.Flags().GetString(flags.FlagHome)
|
|
||||||
|
|
||||||
config := serverCtx.Config
|
config := serverCtx.Config
|
||||||
config.SetRoot(home)
|
config.SetRoot(clientCtx.HomeDir)
|
||||||
|
|
||||||
nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(serverCtx.Config)
|
nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(serverCtx.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to initialize node validator files")
|
return errors.Wrap(err, "failed to initialize node validator files")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read --nodeID, if empty take it from priv_validator.json
|
// read --nodeID, if empty take it from priv_validator.json
|
||||||
nodeIDString, _ := cmd.Flags().GetString(cli.FlagNodeID)
|
if nodeIDString, _ := cmd.Flags().GetString(cli.FlagNodeID); nodeIDString != "" {
|
||||||
|
|
||||||
if nodeIDString != "" {
|
|
||||||
nodeID = nodeIDString
|
nodeID = nodeIDString
|
||||||
}
|
}
|
||||||
// Read --pubkey, if empty take it from priv_validator.json
|
|
||||||
valPubKeyString, _ := cmd.Flags().GetString(cli.FlagPubKey)
|
|
||||||
|
|
||||||
if valPubKeyString != "" {
|
// read --pubkey, if empty take it from priv_validator.json
|
||||||
|
if valPubKeyString, _ := cmd.Flags().GetString(cli.FlagPubKey); valPubKeyString != "" {
|
||||||
valPubKey, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, valPubKeyString)
|
valPubKey, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, valPubKeyString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to get consensus node public key")
|
return errors.Wrap(err, "failed to get consensus node public key")
|
||||||
|
@ -92,27 +99,30 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera
|
||||||
|
|
||||||
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
|
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
|
||||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||||
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
|
|
||||||
|
kr, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to initialize keybase")
|
return errors.Wrap(err, "failed to initialize keyring")
|
||||||
}
|
}
|
||||||
|
|
||||||
name, _ := cmd.Flags().GetString(flags.FlagName)
|
name := args[0]
|
||||||
|
key, err := kr.Key(name)
|
||||||
key, err := kb.Key(name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to read from keybase")
|
return errors.Wrapf(err, "failed to fetch '%s' from the keyring", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set flags for creating gentx
|
moniker := config.Moniker
|
||||||
createValCfg, err := cli.PrepareConfigForTxCreateValidator(config, cmd.Flags(), nodeID, genDoc.ChainID, valPubKey)
|
if m, _ := cmd.Flags().GetString(cli.FlagMoniker); m != "" {
|
||||||
|
moniker = m
|
||||||
|
}
|
||||||
|
|
||||||
|
// set flags for creating a gentx
|
||||||
|
createValCfg, err := cli.PrepareConfigForTxCreateValidator(cmd.Flags(), moniker, nodeID, genDoc.ChainID, valPubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error creating configuration to create validator msg")
|
return errors.Wrap(err, "error creating configuration to create validator msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the amount of coins staked
|
|
||||||
amount, _ := cmd.Flags().GetString(cli.FlagAmount)
|
amount, _ := cmd.Flags().GetString(cli.FlagAmount)
|
||||||
|
|
||||||
coins, err := sdk.ParseCoins(amount)
|
coins, err := sdk.ParseCoins(amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to parse coins")
|
return errors.Wrap(err, "failed to parse coins")
|
||||||
|
@ -129,14 +139,7 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera
|
||||||
}
|
}
|
||||||
|
|
||||||
txBldr = txBldr.WithTxEncoder(authclient.GetTxEncoder(clientCtx.Codec))
|
txBldr = txBldr.WithTxEncoder(authclient.GetTxEncoder(clientCtx.Codec))
|
||||||
|
clientCtx = clientCtx.WithInput(inBuf).WithFromAddress(key.GetAddress())
|
||||||
from, _ := cmd.Flags().GetString(flags.FlagFrom)
|
|
||||||
fromAddress, _, err := client.GetFromFields(txBldr.Keybase(), from, false)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "error getting from address")
|
|
||||||
}
|
|
||||||
|
|
||||||
clientCtx = clientCtx.WithInput(inBuf).WithFromAddress(fromAddress)
|
|
||||||
|
|
||||||
// create a 'create-validator' message
|
// create a 'create-validator' message
|
||||||
txBldr, msg, err := cli.BuildCreateValidatorMsg(clientCtx, createValCfg, txBldr, true)
|
txBldr, msg, err := cli.BuildCreateValidatorMsg(clientCtx, createValCfg, txBldr, true)
|
||||||
|
@ -169,9 +172,7 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera
|
||||||
return errors.Wrap(err, "failed to sign std tx")
|
return errors.Wrap(err, "failed to sign std tx")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch output file name
|
|
||||||
outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
|
outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
|
||||||
|
|
||||||
if outputDocument == "" {
|
if outputDocument == "" {
|
||||||
outputDocument, err = makeOutputFilepath(config.RootDir, nodeID)
|
outputDocument, err = makeOutputFilepath(config.RootDir, nodeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -185,16 +186,13 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera
|
||||||
|
|
||||||
cmd.PrintErrf("Genesis transaction written to %q\n", outputDocument)
|
cmd.PrintErrf("Genesis transaction written to %q\n", outputDocument)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
|
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
|
||||||
cmd.Flags().String(flags.FlagName, "", "name of private key with which to sign the gentx")
|
cmd.Flags().String(flags.FlagOutputDocument, "", "Write the genesis transaction JSON document to the given file instead of the default location")
|
||||||
cmd.Flags().String(flags.FlagOutputDocument, "", "write the genesis transaction JSON document to the given file instead of the default location")
|
cmd.Flags().String(flags.FlagChainID, "", "The network chain ID")
|
||||||
cmd.Flags().AddFlagSet(fsCreateValidator)
|
cmd.Flags().AddFlagSet(fsCreateValidator)
|
||||||
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
|
|
||||||
cmd.MarkFlagRequired(flags.FlagName)
|
|
||||||
|
|
||||||
flags.PostCommands(cmd)
|
flags.PostCommands(cmd)
|
||||||
|
|
||||||
|
@ -238,5 +236,3 @@ func writeSignedGenTx(cdc codec.JSONMarshaler, outputDocument string, tx authtyp
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONTCOVER
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
@ -329,6 +328,7 @@ func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc
|
||||||
fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError)
|
fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP")
|
fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP")
|
||||||
fsCreateValidator.String(FlagNodeID, "", "The node's NodeID")
|
fsCreateValidator.String(FlagNodeID, "", "The node's NodeID")
|
||||||
|
fsCreateValidator.String(FlagMoniker, "", "The validator's (optional) moniker")
|
||||||
fsCreateValidator.String(FlagWebsite, "", "The validator's (optional) website")
|
fsCreateValidator.String(FlagWebsite, "", "The validator's (optional) website")
|
||||||
fsCreateValidator.String(FlagSecurityContact, "", "The validator's (optional) security contact email")
|
fsCreateValidator.String(FlagSecurityContact, "", "The validator's (optional) security contact email")
|
||||||
fsCreateValidator.String(FlagDetails, "", "The validator's (optional) details")
|
fsCreateValidator.String(FlagDetails, "", "The validator's (optional) details")
|
||||||
|
@ -353,7 +353,6 @@ func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc
|
||||||
|
|
||||||
type TxCreateValidatorConfig struct {
|
type TxCreateValidatorConfig struct {
|
||||||
ChainID string
|
ChainID string
|
||||||
From string
|
|
||||||
NodeID string
|
NodeID string
|
||||||
Moniker string
|
Moniker string
|
||||||
|
|
||||||
|
@ -374,9 +373,7 @@ type TxCreateValidatorConfig struct {
|
||||||
Identity string
|
Identity string
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrepareConfigForTxCreateValidator(
|
func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey crypto.PubKey) (TxCreateValidatorConfig, error) {
|
||||||
config *cfg.Config, flagSet *flag.FlagSet, nodeID, chainID string, valPubKey crypto.PubKey,
|
|
||||||
) (TxCreateValidatorConfig, error) {
|
|
||||||
c := TxCreateValidatorConfig{}
|
c := TxCreateValidatorConfig{}
|
||||||
|
|
||||||
ip, err := flagSet.GetString(FlagIP)
|
ip, err := flagSet.GetString(FlagIP)
|
||||||
|
@ -413,12 +410,6 @@ func PrepareConfigForTxCreateValidator(
|
||||||
}
|
}
|
||||||
c.Identity = identity
|
c.Identity = identity
|
||||||
|
|
||||||
c.ChainID = chainID
|
|
||||||
c.From, err = flagSet.GetString(flags.FlagName)
|
|
||||||
if err != nil {
|
|
||||||
return c, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Amount, err = flagSet.GetString(FlagAmount)
|
c.Amount, err = flagSet.GetString(FlagAmount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
|
@ -447,15 +438,12 @@ func PrepareConfigForTxCreateValidator(
|
||||||
c.NodeID = nodeID
|
c.NodeID = nodeID
|
||||||
c.TrustNode = true
|
c.TrustNode = true
|
||||||
c.PubKey = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey)
|
c.PubKey = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey)
|
||||||
c.Moniker = config.Moniker
|
|
||||||
c.Website = website
|
c.Website = website
|
||||||
c.SecurityContact = securityContact
|
c.SecurityContact = securityContact
|
||||||
c.Details = details
|
c.Details = details
|
||||||
c.Identity = identity
|
c.Identity = identity
|
||||||
|
c.ChainID = chainID
|
||||||
if config.Moniker == "" {
|
c.Moniker = moniker
|
||||||
c.Moniker = c.From
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Amount == "" {
|
if c.Amount == "" {
|
||||||
c.Amount = defaultAmount
|
c.Amount = defaultAmount
|
||||||
|
|
|
@ -4,12 +4,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,21 +15,15 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||||
ip := "1.1.1.1"
|
ip := "1.1.1.1"
|
||||||
nodeID := "nodeID"
|
nodeID := "nodeID"
|
||||||
valPubKey, _ := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, "cosmosvalconspub1zcjduepq7jsrkl9fgqk0wj3ahmfr8pgxj6vakj2wzn656s8pehh0zhv2w5as5gd80a")
|
valPubKey, _ := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, "cosmosvalconspub1zcjduepq7jsrkl9fgqk0wj3ahmfr8pgxj6vakj2wzn656s8pehh0zhv2w5as5gd80a")
|
||||||
moniker := "myMoniker"
|
moniker := "DefaultMoniker"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
config func() *cfg.Config
|
|
||||||
fsModify func(fs *pflag.FlagSet)
|
fsModify func(fs *pflag.FlagSet)
|
||||||
expectedCfg TxCreateValidatorConfig
|
expectedCfg TxCreateValidatorConfig
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "all defaults",
|
name: "all defaults",
|
||||||
config: func() *cfg.Config {
|
|
||||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
|
||||||
config.Moniker = moniker
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
fsModify: func(fs *pflag.FlagSet) {
|
fsModify: func(fs *pflag.FlagSet) {
|
||||||
return
|
return
|
||||||
},
|
},
|
||||||
|
@ -50,48 +41,14 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||||
MinSelfDelegation: "1",
|
MinSelfDelegation: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "If moniker is empty it sets from Flag.",
|
|
||||||
config: func() *cfg.Config {
|
|
||||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
|
||||||
config.Moniker = ""
|
|
||||||
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
fsModify: func(fs *pflag.FlagSet) {
|
|
||||||
fs.Set(flags.FlagName, "theNameFlag")
|
|
||||||
},
|
|
||||||
expectedCfg: TxCreateValidatorConfig{
|
|
||||||
IP: ip,
|
|
||||||
From: "theNameFlag",
|
|
||||||
Moniker: "theNameFlag",
|
|
||||||
ChainID: chainID,
|
|
||||||
NodeID: nodeID,
|
|
||||||
TrustNode: true,
|
|
||||||
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
|
|
||||||
Amount: "100000000stake",
|
|
||||||
CommissionRate: "0.1",
|
|
||||||
CommissionMaxRate: "0.2",
|
|
||||||
CommissionMaxChangeRate: "0.01",
|
|
||||||
MinSelfDelegation: "1",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "Custom amount",
|
name: "Custom amount",
|
||||||
config: func() *cfg.Config {
|
|
||||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
|
||||||
config.Moniker = ""
|
|
||||||
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
fsModify: func(fs *pflag.FlagSet) {
|
fsModify: func(fs *pflag.FlagSet) {
|
||||||
fs.Set(flags.FlagName, "theNameFlag")
|
|
||||||
fs.Set(FlagAmount, "2000stake")
|
fs.Set(FlagAmount, "2000stake")
|
||||||
},
|
},
|
||||||
expectedCfg: TxCreateValidatorConfig{
|
expectedCfg: TxCreateValidatorConfig{
|
||||||
IP: ip,
|
IP: ip,
|
||||||
From: "theNameFlag",
|
Moniker: moniker,
|
||||||
Moniker: "theNameFlag",
|
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
TrustNode: true,
|
TrustNode: true,
|
||||||
|
@ -105,20 +62,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Custom commission rate",
|
name: "Custom commission rate",
|
||||||
config: func() *cfg.Config {
|
|
||||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
|
||||||
config.Moniker = ""
|
|
||||||
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
fsModify: func(fs *pflag.FlagSet) {
|
fsModify: func(fs *pflag.FlagSet) {
|
||||||
fs.Set(flags.FlagName, "theNameFlag")
|
|
||||||
fs.Set(FlagCommissionRate, "0.54")
|
fs.Set(FlagCommissionRate, "0.54")
|
||||||
},
|
},
|
||||||
expectedCfg: TxCreateValidatorConfig{
|
expectedCfg: TxCreateValidatorConfig{
|
||||||
IP: ip,
|
IP: ip,
|
||||||
From: "theNameFlag",
|
Moniker: moniker,
|
||||||
Moniker: "theNameFlag",
|
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
TrustNode: true,
|
TrustNode: true,
|
||||||
|
@ -132,20 +81,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Custom commission max rate",
|
name: "Custom commission max rate",
|
||||||
config: func() *cfg.Config {
|
|
||||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
|
||||||
config.Moniker = ""
|
|
||||||
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
fsModify: func(fs *pflag.FlagSet) {
|
fsModify: func(fs *pflag.FlagSet) {
|
||||||
fs.Set(flags.FlagName, "theNameFlag")
|
|
||||||
fs.Set(FlagCommissionMaxRate, "0.89")
|
fs.Set(FlagCommissionMaxRate, "0.89")
|
||||||
},
|
},
|
||||||
expectedCfg: TxCreateValidatorConfig{
|
expectedCfg: TxCreateValidatorConfig{
|
||||||
IP: ip,
|
IP: ip,
|
||||||
From: "theNameFlag",
|
Moniker: moniker,
|
||||||
Moniker: "theNameFlag",
|
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
TrustNode: true,
|
TrustNode: true,
|
||||||
|
@ -159,20 +100,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Custom commission max change rate",
|
name: "Custom commission max change rate",
|
||||||
config: func() *cfg.Config {
|
|
||||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
|
||||||
config.Moniker = ""
|
|
||||||
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
fsModify: func(fs *pflag.FlagSet) {
|
fsModify: func(fs *pflag.FlagSet) {
|
||||||
fs.Set(flags.FlagName, "theNameFlag")
|
|
||||||
fs.Set(FlagCommissionMaxChangeRate, "0.55")
|
fs.Set(FlagCommissionMaxChangeRate, "0.55")
|
||||||
},
|
},
|
||||||
expectedCfg: TxCreateValidatorConfig{
|
expectedCfg: TxCreateValidatorConfig{
|
||||||
IP: ip,
|
IP: ip,
|
||||||
From: "theNameFlag",
|
Moniker: moniker,
|
||||||
Moniker: "theNameFlag",
|
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
TrustNode: true,
|
TrustNode: true,
|
||||||
|
@ -186,20 +119,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Custom min self delegations",
|
name: "Custom min self delegations",
|
||||||
config: func() *cfg.Config {
|
|
||||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
|
||||||
config.Moniker = ""
|
|
||||||
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
fsModify: func(fs *pflag.FlagSet) {
|
fsModify: func(fs *pflag.FlagSet) {
|
||||||
fs.Set(flags.FlagName, "theNameFlag")
|
|
||||||
fs.Set(FlagMinSelfDelegation, "0.33")
|
fs.Set(FlagMinSelfDelegation, "0.33")
|
||||||
},
|
},
|
||||||
expectedCfg: TxCreateValidatorConfig{
|
expectedCfg: TxCreateValidatorConfig{
|
||||||
IP: ip,
|
IP: ip,
|
||||||
From: "theNameFlag",
|
Moniker: moniker,
|
||||||
Moniker: "theNameFlag",
|
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
TrustNode: true,
|
TrustNode: true,
|
||||||
|
@ -221,9 +146,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||||
|
|
||||||
tc.fsModify(fs)
|
tc.fsModify(fs)
|
||||||
|
|
||||||
config := tc.config()
|
cvCfg, err := PrepareConfigForTxCreateValidator(fs, moniker, nodeID, chainID, valPubKey)
|
||||||
|
|
||||||
cvCfg, err := PrepareConfigForTxCreateValidator(config, fs, nodeID, chainID, valPubKey)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, tc.expectedCfg, cvCfg)
|
require.Equal(t, tc.expectedCfg, cvCfg)
|
||||||
|
|
Loading…
Reference in New Issue