crypto/keyring: `Keybase` interface gives way to its successor: `Keyring`. `LegacyKeybase` interface is added in order to guarantee limited backward compatibility with the old `Keybase` interface for the sole purpose of migrating keys across the new keyring backends. The package no longer depends on the `github.com/types.Config` singleton. `SupportedAlgos` and `SupportedLedgerAlgos` methods have been removed. The keyring just fails when trying to perform an action with an unsupported algorithm. crypto/ subdirs reorganization: `crypto/keys/hd` was moved to `crypto/hd`, which now groups together all HD wallets related types and utilities. client/input: * Removal of unnecessary `GetCheckPassword`, `PrintPrefixed` functions. * `GetConfirmation`'s signature changed to take in a io.Writer for better integration with `cobra.Command` types. client/context: * In-memory keyring is allocated in the context when `--gen-only` flag is passed in. `GetFromFields` does no longer silently allocate a keyring, it takes one as argument. Co-authored with @jgimeno Co-authored-by: Jonathan Gimeno <jgimeno@gmail.com>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package keys
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
const flagListNames = "list-names"
|
|
|
|
// ListKeysCmd lists all keys in the key store.
|
|
func ListKeysCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all keys",
|
|
Long: `Return a list of all public keys stored by this key manager
|
|
along with their associated name and address.`,
|
|
RunE: runListCmd,
|
|
}
|
|
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
|
|
cmd.Flags().BoolP(flagListNames, "n", false, "List names only")
|
|
return cmd
|
|
}
|
|
|
|
func runListCmd(cmd *cobra.Command, _ []string) error {
|
|
kb, err := keyring.New(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
infos, err := kb.List()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cmd.SetOut(cmd.OutOrStdout())
|
|
if !viper.GetBool(flagListNames) {
|
|
printInfos(cmd.OutOrStdout(), infos)
|
|
return nil
|
|
}
|
|
|
|
for _, info := range infos {
|
|
cmd.Println(info.GetName())
|
|
}
|
|
|
|
return nil
|
|
}
|