Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More CLI cleanup #6651

Merged
merged 3 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### 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.
* (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.
Expand Down
13 changes: 5 additions & 8 deletions simapp/simd/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import (
)

const (
flagClientHome = "home-client"
flagVestingStart = "vesting-start-time"
flagVestingEnd = "vesting-end-time"
flagVestingAmt = "vesting-amount"
)

// AddGenesisAccountCmd returns add-genesis-account cobra Command.
func AddGenesisAccountCmd(defaultClientHome string) *cobra.Command {
func AddGenesisAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
Short: "Add a genesis account to genesis.json",
Expand All @@ -48,14 +47,13 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa

config.SetRoot(clientCtx.HomeDir)

keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
clientHome, _ := cmd.Flags().GetString(flagClientHome)

addr, err := sdk.AccAddressFromBech32(args[0])
inBuf := bufio.NewReader(cmd.InOrStdin())
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
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientHome, inBuf)
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
if err != nil {
return err
}
Expand Down Expand Up @@ -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(flagClientHome, defaultClientHome, "client's home directory")
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(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
Expand Down
10 changes: 5 additions & 5 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func init() {

rootCmd.AddCommand(
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}),
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
genutilcli.GenTxCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
genutilcli.ValidateGenesisCmd(simapp.ModuleBasics),
AddGenesisAccountCmd(simapp.DefaultNodeHome),
AddGenesisAccountCmd(),
cli.NewCompletionCmd(rootCmd, true),
testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
Expand Down Expand Up @@ -114,7 +114,7 @@ func queryCommand() *cobra.Command {
)

simapp.ModuleBasics.AddQueryCommands(cmd, initClientCtx)
cmd.PersistentFlags().String(flags.FlagChainID, "", "network chain ID")
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

return cmd
}
Expand All @@ -141,7 +141,7 @@ func txCommand() *cobra.Command {
)

simapp.ModuleBasics.AddTxCommands(cmd, initClientCtx)
cmd.PersistentFlags().String(flags.FlagChainID, "", "network chain ID")
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

return cmd
}
Expand Down
7 changes: 3 additions & 4 deletions x/genutil/client/cli/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
Expand All @@ -18,7 +18,7 @@ import (
const flagGenTxDir = "gentx-dir"

// 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{
Use: "collect-gentxs",
Short: "Collect genesis txs and output a genesis.json file",
Expand Down Expand Up @@ -57,12 +57,11 @@ func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, defaultNodeH

toPrint.AppMessage = appMessage

// print out some key information
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/")

return cmd
Expand Down
92 changes: 44 additions & 48 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
Expand All @@ -30,46 +31,52 @@ import (
)

// GenTxCmd builds the application's gentx command.
// nolint: errcheck
func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command {
func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesIterator) *cobra.Command {
ipDefault, _ := server.ExternalIP()
fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault)

cmd := &cobra.Command{
Use: "gentx",
Use: "gentx [key_name]",
Short: "Generate a genesis tx carrying a self delegation",
Args: cobra.NoArgs,
Long: fmt.Sprintf(`This command is an alias of the 'tx create-validator' command'.

It creates a genesis transaction to create a validator.
The following default parameters are included:
%s`, defaultsDesc),

Args: cobra.ExactArgs(1),
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
pubkey may optionally be provided. If they are omitted, they will be retrieved from the priv_validator.json
file. The following default parameters are included:
%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 {
serverCtx := server.GetServerContextFromCmd(cmd)
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.JSONMarshaler

home, _ := cmd.Flags().GetString(flags.FlagHome)

config := serverCtx.Config
config.SetRoot(home)
config.SetRoot(clientCtx.HomeDir)

nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(serverCtx.Config)
if err != nil {
return errors.Wrap(err, "failed to initialize node validator files")
}

// Read --nodeID, if empty take it from priv_validator.json
nodeIDString, _ := cmd.Flags().GetString(cli.FlagNodeID)

if nodeIDString != "" {
// read --nodeID, if empty take it from priv_validator.json
if nodeIDString, _ := cmd.Flags().GetString(cli.FlagNodeID); 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)
if err != nil {
return errors.Wrap(err, "failed to get consensus node public key")
Expand All @@ -92,27 +99,30 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera

keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
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 {
return errors.Wrap(err, "failed to initialize keybase")
return errors.Wrap(err, "failed to initialize keyring")
}

name, _ := cmd.Flags().GetString(flags.FlagName)

key, err := kb.Key(name)
name := args[0]
key, err := kr.Key(name)
if err != nil {
return errors.Wrap(err, "failed to read from keybase")
return errors.Wrapf(err, "failed to fetch '%s' from the keyring", name)
}

moniker := config.Moniker
if m, _ := cmd.Flags().GetString(cli.FlagMoniker); m != "" {
moniker = m
}

// Set flags for creating gentx
createValCfg, err := cli.PrepareConfigForTxCreateValidator(config, cmd.Flags(), nodeID, genDoc.ChainID, valPubKey)
// set flags for creating a gentx
createValCfg, err := cli.PrepareConfigForTxCreateValidator(cmd.Flags(), moniker, nodeID, genDoc.ChainID, valPubKey)
if err != nil {
return errors.Wrap(err, "error creating configuration to create validator msg")
}

// Fetch the amount of coins staked
amount, _ := cmd.Flags().GetString(cli.FlagAmount)

coins, err := sdk.ParseCoins(amount)
if err != nil {
return errors.Wrap(err, "failed to parse coins")
Expand All @@ -129,14 +139,7 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera
}

txBldr = txBldr.WithTxEncoder(authclient.GetTxEncoder(clientCtx.Codec))

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)
clientCtx = clientCtx.WithInput(inBuf).WithFromAddress(key.GetAddress())

// create a 'create-validator' message
txBldr, msg, err := cli.BuildCreateValidatorMsg(clientCtx, createValCfg, txBldr, true)
Expand Down Expand Up @@ -169,9 +172,7 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera
return errors.Wrap(err, "failed to sign std tx")
}

// Fetch output file name
outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument)

if outputDocument == "" {
outputDocument, err = makeOutputFilepath(config.RootDir, nodeID)
if err != nil {
Expand All @@ -185,16 +186,13 @@ func GenTxCmd(mbm module.BasicManager, genBalIterator types.GenesisBalancesItera

cmd.PrintErrf("Genesis transaction written to %q\n", outputDocument)
return nil

},
}

cmd.Flags().String(flags.FlagHome, defaultNodeHome, "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.FlagHome, "", "The application home directory")
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().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.MarkFlagRequired(flags.FlagName)

flags.PostCommands(cmd)

Expand Down Expand Up @@ -238,5 +236,3 @@ func writeSignedGenTx(cdc codec.JSONMarshaler, outputDocument string, tx authtyp

return err
}

// DONTCOVER
20 changes: 4 additions & 16 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -329,6 +328,7 @@ func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc
fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError)
fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP")
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(FlagSecurityContact, "", "The validator's (optional) security contact email")
fsCreateValidator.String(FlagDetails, "", "The validator's (optional) details")
Expand All @@ -353,7 +353,6 @@ func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc

type TxCreateValidatorConfig struct {
ChainID string
From string
NodeID string
Moniker string

Expand All @@ -374,9 +373,7 @@ type TxCreateValidatorConfig struct {
Identity string
}

func PrepareConfigForTxCreateValidator(
config *cfg.Config, flagSet *flag.FlagSet, nodeID, chainID string, valPubKey crypto.PubKey,
) (TxCreateValidatorConfig, error) {
func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey crypto.PubKey) (TxCreateValidatorConfig, error) {
c := TxCreateValidatorConfig{}

ip, err := flagSet.GetString(FlagIP)
Expand Down Expand Up @@ -413,12 +410,6 @@ func PrepareConfigForTxCreateValidator(
}
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)
if err != nil {
return c, err
Expand Down Expand Up @@ -447,15 +438,12 @@ func PrepareConfigForTxCreateValidator(
c.NodeID = nodeID
c.TrustNode = true
c.PubKey = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey)
c.Moniker = config.Moniker
c.Website = website
c.SecurityContact = securityContact
c.Details = details
c.Identity = identity

if config.Moniker == "" {
c.Moniker = c.From
}
c.ChainID = chainID
c.Moniker = moniker

if c.Amount == "" {
c.Amount = defaultAmount
Expand Down
Loading