From 388082b0225aaa9249be7c792836c337e3169938 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 5 Jan 2023 21:52:18 +0100 Subject: [PATCH 1/2] fix: keyring-backend flag usage (#14509) (cherry picked from commit 3e2dde54c53b0b2c16e90c500c8326326d393a4f) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 12 +++++++ client/flags/flags.go | 59 ++++++++++++++++++-------------- client/keys/root.go | 3 +- docs/docs/run-node/00-keyring.md | 4 +++ 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4be73f8ca15b..ad6f03a03627 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -127,6 +127,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/auth) [#13210](https://github.com/cosmos/cosmos-sdk/pull/13210) Add `Query/AccountInfo` endpoint for simplified access to basic account info. * (x/consensus) [#12905](https://github.com/cosmos/cosmos-sdk/pull/12905) Create a new `x/consensus` module that is now responsible for maintaining Tendermint consensus parameters instead of `x/param`. Legacy types remain in order to facilitate parameter migration from the deprecated `x/params`. App developers should ensure that they execute `baseapp.MigrateParams` during their chain upgrade. These legacy types will be removed in a future release. * (client/tx) [#13670](https://github.com/cosmos/cosmos-sdk/pull/13670) Add validation in `BuildUnsignedTx` to prevent simple inclusion of valid mnemonics +<<<<<<< HEAD +======= +* [#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. +>>>>>>> 3e2dde54c (fix: keyring-backend flag usage (#14509)) ### Improvements @@ -268,7 +275,12 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf * (snapshot) [#13400](https://github.com/cosmos/cosmos-sdk/pull/13400) Fix snapshot checksum issue in golang 1.19. * (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`. +<<<<<<< HEAD * (x/gov) [#13918](https://github.com/cosmos/cosmos-sdk/pull/13918) Fix propagation of message errors when executing a proposal. +======= +* (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 +>>>>>>> 3e2dde54c (fix: keyring-backend flag usage (#14509)) ### Deprecated diff --git a/client/flags/flags.go b/client/flags/flags.go index a0c408a61bd4..497ee383b983 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,40 @@ 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 } 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 5177e1449d197b9bc891aa44b34dfc90c5150edf Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 5 Jan 2023 21:56:05 +0100 Subject: [PATCH 2/2] updates --- CHANGELOG.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6f03a03627..5ca063e483c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (client) [#14509](https://github.com/cosmos/cosmos-sdk/pull/#14509) Added `AddKeyringFlags` function. * (x/slashing, x/staking) [#14363](https://github.com/cosmos/cosmos-sdk/pull/14363) Add the infraction a validator commited type as an argument to a `SlashWithInfractionReason` keeper method. * (client) [#14051](https://github.com/cosmos/cosmos-sdk/pull/14051) Add `--grpc` client option. * (x/genutil) [#14149](https://github.com/cosmos/cosmos-sdk/pull/14149) Add `genutilcli.GenesisCoreCommand` command, which contains all genesis-related sub-commands. @@ -71,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (cli) [#14509](https://github.com/cosmos/cosmos-sdk/pull/#14509) Added missing options to keyring-backend flag usage * (server) [#14441](https://github.com/cosmos/cosmos-sdk/pull/14441) Fix `--log_format` flag not working. * (ante) [#14448](https://github.com/cosmos/cosmos-sdk/pull/14448) Return anteEvents when postHandler fail. @@ -127,13 +129,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/auth) [#13210](https://github.com/cosmos/cosmos-sdk/pull/13210) Add `Query/AccountInfo` endpoint for simplified access to basic account info. * (x/consensus) [#12905](https://github.com/cosmos/cosmos-sdk/pull/12905) Create a new `x/consensus` module that is now responsible for maintaining Tendermint consensus parameters instead of `x/param`. Legacy types remain in order to facilitate parameter migration from the deprecated `x/params`. App developers should ensure that they execute `baseapp.MigrateParams` during their chain upgrade. These legacy types will be removed in a future release. * (client/tx) [#13670](https://github.com/cosmos/cosmos-sdk/pull/13670) Add validation in `BuildUnsignedTx` to prevent simple inclusion of valid mnemonics -<<<<<<< HEAD -======= -* [#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. ->>>>>>> 3e2dde54c (fix: keyring-backend flag usage (#14509)) ### Improvements @@ -275,12 +270,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf * (snapshot) [#13400](https://github.com/cosmos/cosmos-sdk/pull/13400) Fix snapshot checksum issue in golang 1.19. * (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`. -<<<<<<< HEAD * (x/gov) [#13918](https://github.com/cosmos/cosmos-sdk/pull/13918) Fix propagation of message errors when executing a proposal. -======= -* (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 ->>>>>>> 3e2dde54c (fix: keyring-backend flag usage (#14509)) ### Deprecated