* fix client config don't take effect (#9211)
* fix client keyring config
* fix output flag of keys commads
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
(cherry picked from commit b4d1a5e5d6
)
# Conflicts:
# client/keys/add.go
* Fix conflicts
Co-authored-by: yihuang <huang@crypto.com>
Co-authored-by: Amaury M <1293565+amaurym@users.noreply.github.com>
This commit is contained in:
parent
1327224c34
commit
9fe61a7ed4
|
@ -73,7 +73,8 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
|
|||
}
|
||||
// we need to update KeyringDir field on Client Context first cause it is used in NewKeyringFromBackend
|
||||
ctx = ctx.WithOutputFormat(conf.Output).
|
||||
WithChainID(conf.ChainID)
|
||||
WithChainID(conf.ChainID).
|
||||
WithKeyringDir(ctx.HomeDir)
|
||||
|
||||
keyring, err := client.NewKeyringFromBackend(ctx, conf.KeyringBackend)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
bip39 "github.com/cosmos/go-bip39"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
|
@ -59,7 +58,7 @@ required through --multisig-threshold. The keys are sorted by address, unless
|
|||
the flag --nosort is set.
|
||||
`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runAddCmd,
|
||||
RunE: runAddCmdPrepare,
|
||||
}
|
||||
|
||||
cmd.Flags().StringSlice(flagMultisig, nil, "Construct and store a multisig public key (implies --pubkey)")
|
||||
|
@ -83,28 +82,14 @@ the flag --nosort is set.
|
|||
return cmd
|
||||
}
|
||||
|
||||
func runAddCmd(cmd *cobra.Command, args []string) error {
|
||||
func runAddCmdPrepare(cmd *cobra.Command, args []string) error {
|
||||
buf := bufio.NewReader(cmd.InOrStdin())
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var kr keyring.Keyring
|
||||
|
||||
dryRun, _ := cmd.Flags().GetBool(flags.FlagDryRun)
|
||||
if dryRun {
|
||||
kr, err = keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, clientCtx.KeyringDir, buf)
|
||||
} else {
|
||||
backend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
|
||||
kr, err = keyring.New(sdk.KeyringServiceName(), backend, clientCtx.KeyringDir, buf)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return RunAddCmd(cmd, args, kr, buf)
|
||||
return RunAddCmd(clientCtx, cmd, args, buf)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -116,13 +101,15 @@ input
|
|||
output
|
||||
- armor encrypted private key (saved to file)
|
||||
*/
|
||||
func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *bufio.Reader) error {
|
||||
func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *bufio.Reader) error {
|
||||
var err error
|
||||
|
||||
name := args[0]
|
||||
interactive, _ := cmd.Flags().GetBool(flagInteractive)
|
||||
noBackup, _ := cmd.Flags().GetBool(flagNoBackup)
|
||||
showMnemonic := !noBackup
|
||||
kb := ctx.Keyring
|
||||
outputFormat := ctx.OutputFormat
|
||||
|
||||
keyringAlgos, _ := kb.SupportedAlgorithms()
|
||||
algoStr, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm)
|
||||
|
@ -219,7 +206,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
|
|||
return err
|
||||
}
|
||||
|
||||
return printCreate(cmd, info, false, "")
|
||||
return printCreate(cmd, info, false, "", outputFormat)
|
||||
}
|
||||
|
||||
// Get bip39 mnemonic
|
||||
|
@ -293,16 +280,14 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
|
|||
mnemonic = ""
|
||||
}
|
||||
|
||||
return printCreate(cmd, info, showMnemonic, mnemonic)
|
||||
return printCreate(cmd, info, showMnemonic, mnemonic, outputFormat)
|
||||
}
|
||||
|
||||
func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string) error {
|
||||
output, _ := cmd.Flags().GetString(cli.OutputFlag)
|
||||
|
||||
switch output {
|
||||
func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string, outputFormat string) error {
|
||||
switch outputFormat {
|
||||
case OutputFormatText:
|
||||
cmd.PrintErrln()
|
||||
printKeyInfo(cmd.OutOrStdout(), info, keyring.Bech32KeyOutput, output)
|
||||
printKeyInfo(cmd.OutOrStdout(), info, keyring.Bech32KeyOutput, outputFormat)
|
||||
|
||||
// print mnemonic unless requested not to.
|
||||
if showMnemonic {
|
||||
|
@ -329,7 +314,7 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
|
|||
cmd.Println(string(jsonString))
|
||||
|
||||
default:
|
||||
return fmt.Errorf("invalid output format %s", output)
|
||||
return fmt.Errorf("invalid output format %s", outputFormat)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -111,7 +111,9 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
output, _ := cmd.Flags().GetString(cli.OutputFlag)
|
||||
if isOutputSet {
|
||||
clientCtx.OutputFormat, _ = cmd.Flags().GetString(cli.OutputFlag)
|
||||
}
|
||||
|
||||
switch {
|
||||
case isShowAddr:
|
||||
|
@ -119,7 +121,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
|||
case isShowPubKey:
|
||||
printPubKey(cmd.OutOrStdout(), info, bechKeyOut)
|
||||
default:
|
||||
printKeyInfo(cmd.OutOrStdout(), info, bechKeyOut, output)
|
||||
printKeyInfo(cmd.OutOrStdout(), info, bechKeyOut, clientCtx.OutputFormat)
|
||||
}
|
||||
|
||||
if isShowDevice {
|
||||
|
|
Loading…
Reference in New Issue