From 2be79ab9a075b7f084bd9edd6a5088b4a7b773c4 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 5 Jan 2023 18:27:27 +0100 Subject: [PATCH 1/4] fix: keyring flags usage --- client/flags/flags.go | 60 ++++++++++++++++++++++++------------------- client/keys/root.go | 3 +-- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index e654b9e2dd4f..c7f379334cb0 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/spf13/cobra" + "github.com/spf13/pflag" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -106,34 +107,41 @@ func AddQueryFlagsToCmd(cmd *cobra.Command) { // AddTxFlagsToCmd adds common flags to a module tx command. func AddTxFlagsToCmd(cmd *cobra.Command) { - cmd.Flags().StringP(FlagOutput, "o", "json", "Output format (text|json)") - cmd.Flags().String(FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used") - cmd.Flags().String(FlagFrom, "", "Name or address of private key with which to sign") - cmd.Flags().Uint64P(FlagAccountNumber, "a", 0, "The account number of the signing account (offline mode only)") - cmd.Flags().Uint64P(FlagSequence, "s", 0, "The sequence number of the signing account (offline mode only)") - cmd.Flags().String(FlagNote, "", "Note to add a description to the transaction (previously --memo)") - cmd.Flags().String(FlagFees, "", "Fees to pay along with transaction; eg: 10uatom") - cmd.Flags().String(FlagGasPrices, "", "Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)") - cmd.Flags().String(FlagNode, "tcp://localhost:26657", ": to tendermint rpc interface for this chain") - cmd.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device") - cmd.Flags().Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") - cmd.Flags().StringP(FlagBroadcastMode, "b", BroadcastSync, "Transaction broadcasting mode (sync|async)") - cmd.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)") - cmd.Flags().Bool(FlagGenerateOnly, false, "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)") - cmd.Flags().Bool(FlagOffline, false, "Offline mode (does not allow any online functionality)") - cmd.Flags().BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation") - cmd.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test|memory)") - cmd.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature") - cmd.Flags().Uint64(FlagTimeoutHeight, 0, "Set a block timeout height to prevent the tx from being committed past a certain height") - cmd.Flags().String(FlagFeePayer, "", "Fee payer pays fees for the transaction instead of deducting from the signer") - cmd.Flags().String(FlagFeeGranter, "", "Fee granter grants fees for the transaction") - cmd.Flags().String(FlagTip, "", "Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator") - cmd.Flags().Bool(FlagAux, false, "Generate aux signer data instead of sending a tx") - cmd.Flags().String(FlagChainID, "", "The network chain ID") - + f := cmd.Flags() + f.StringP(FlagOutput, "o", "json", "Output format (text|json)") + f.String(FlagFrom, "", "Name or address of private key with which to sign") + f.Uint64P(FlagAccountNumber, "a", 0, "The account number of the signing account (offline mode only)") + f.Uint64P(FlagSequence, "s", 0, "The sequence number of the signing account (offline mode only)") + f.String(FlagNote, "", "Note to add a description to the transaction (previously --memo)") + f.String(FlagFees, "", "Fees to pay along with transaction; eg: 10uatom") + f.String(FlagGasPrices, "", "Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)") + f.String(FlagNode, "tcp://localhost:26657", ": to tendermint rpc interface for this chain") + f.Bool(FlagUseLedger, false, "Use a connected Ledger device") + f.Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") + f.StringP(FlagBroadcastMode, "b", BroadcastSync, "Transaction broadcasting mode (sync|async)") + f.Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)") + f.Bool(FlagGenerateOnly, false, "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)") + f.Bool(FlagOffline, false, "Offline mode (does not allow any online functionality)") + f.BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation") + f.String(FlagSignMode, "", "Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature") + f.Uint64(FlagTimeoutHeight, 0, "Set a block timeout height to prevent the tx from being committed past a certain height") + f.String(FlagFeePayer, "", "Fee payer pays fees for the transaction instead of deducting from the signer") + f.String(FlagFeeGranter, "", "Fee granter grants fees for the transaction") + f.String(FlagTip, "", "Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator") + f.Bool(FlagAux, false, "Generate aux signer data instead of sending a tx") + f.String(FlagChainID, "", "The network chain ID") // --gas can accept integers and "auto" - cmd.Flags().String(FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically. Note: %q option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of %q. (default %d)", + f.String(FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically. Note: %q option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of %q. (default %d)", GasFlagAuto, GasFlagAuto, FlagFees, DefaultGasLimit)) + + AddKeyringFlags(f) +} + +// AddKeyringFlags sets common keyring flags +func AddKeyringFlags(flags *pflag.FlagSet) { + flags.String(FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used") + flags.String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test|memory)") + } // AddPaginationFlagsToCmd adds common pagination flags to cmd diff --git a/client/keys/root.go b/client/keys/root.go index e8b1ef156987..93eb20ddd0c0 100644 --- a/client/keys/root.go +++ b/client/keys/root.go @@ -51,9 +51,8 @@ The pass backend requires GnuPG: https://gnupg.org/ ) cmd.PersistentFlags().String(flags.FlagHome, defaultNodeHome, "The application home directory") - cmd.PersistentFlags().String(flags.FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used") - cmd.PersistentFlags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") cmd.PersistentFlags().String(cli.OutputFlag, "text", "Output format (text|json)") + flags.AddKeyringFlags(cmd.PersistentFlags()) return cmd } From 37e249c1ca31341b540b45e7ae52e49e8d5df91f Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 5 Jan 2023 18:33:30 +0100 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51abb84dc5ec..2675eab54aaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#13473](https://github.com/cosmos/cosmos-sdk/pull/13473) ADR-038: Go plugin system proposal * [#14356](https://github.com/cosmos/cosmos-sdk/pull/14356) Add `events.GetAttributes` and `event.GetAttribute` methods to simplify the retrieval of an attribute from event(s). * [#14472](https://github.com/cosmos/cosmos-sdk/pull/14356) The recommended metadata format for x/gov and x/group proposals now uses an array of strings (instead of a single string) for the `authors` field. +* (client) [#14509](https://github.com/cosmos/cosmos-sdk/pull/#14509) Added `AddKeyringFlags` function. ### Improvements @@ -236,6 +237,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf * (server) [#13778](https://github.com/cosmos/cosmos-sdk/pull/13778) Set Cosmos SDK default endpoints to localhost to avoid unknown exposure of endpoints. * (x/auth) [#13877](https://github.com/cosmos/cosmos-sdk/pull/13877) Handle missing account numbers during `InitGenesis`. * (ante) [#14448](https://github.com/cosmos/cosmos-sdk/pull/14448) Return anteEvents when postHandler fail. +* (cli) [#14509](https://github.com/cosmos/cosmos-sdk/pull/#14509) Added missing options to keyring-backend flag usage ### Deprecated From cb9b9381b99c7e53f8fbf7141b07b670fb0bce45 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 5 Jan 2023 19:02:42 +0100 Subject: [PATCH 3/4] improve keyring docs --- docs/docs/run-node/00-keyring.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/run-node/00-keyring.md b/docs/docs/run-node/00-keyring.md index 46e0f772f746..2cb15b115cfd 100644 --- a/docs/docs/run-node/00-keyring.md +++ b/docs/docs/run-node/00-keyring.md @@ -106,6 +106,10 @@ The `memory` backend stores keys in memory. The keys are immediately deleted aft **Provided for testing purposes only. The `memory` backend is not recommended for use in production environments**. +### Setting backend using the env variable + +You can set the keyring-backend using env variable: `BINNAME_KEYRING_BACKEND`. For example, if you binary name is `gaia-v5` then set: `export GAIA_V5_KEYRING_BACKEND=pass` + ## Adding keys to the keyring :::warning From bd7033a33e6982a889fdcfa8ad6c55902622bc39 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 5 Jan 2023 21:32:43 +0100 Subject: [PATCH 4/4] `make lint-fix` --- client/flags/flags.go | 1 - 1 file changed, 1 deletion(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index c7f379334cb0..1e209f47be4e 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -141,7 +141,6 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { func AddKeyringFlags(flags *pflag.FlagSet) { flags.String(FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used") flags.String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test|memory)") - } // AddPaginationFlagsToCmd adds common pagination flags to cmd