Skip to content

Commit

Permalink
perf: reduce user's password prompts when calling keyring List functi…
Browse files Browse the repository at this point in the history
…on (backport cosmos#13207) (cosmos#13368)

* perf: reduce user's password prompts when calling keyring List function (cosmos#13207)

* Reduce user password prompts by taking advantage of the already existing MigrateAll function

* Print message when no records were found on the keyring

* Update changelog

* Fix migration test

* Add keys sort

(cherry picked from commit 4882f93)

# Conflicts:
#	CHANGELOG.md

* fix conflicts

* suggestions

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

Co-authored-by: Ezequiel Raynaudo <raynaudo.ee@gmail.com>
Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
  • Loading branch information
5 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent af62580 commit 2c90a0f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (cli) [#13207](https://github.com/cosmos/cosmos-sdk/pull/13207) Reduce user's password prompts when calling keyring `List()` function.
* (cli) [#13353](https://github.com/cosmos/cosmos-sdk/pull/13353) Add `tx group draft-proposal` command for generating group proposal JSONs (skeleton).
* (cli) [#13304](https://github.com/cosmos/cosmos-sdk/pull/13304) Add `tx gov draft-proposal` command for generating proposal JSONs (skeleton).
* (x/authz) [#13047](https://github.com/cosmos/cosmos-sdk/pull/13047) Add a GetAuthorization function to the keeper.
Expand Down
2 changes: 1 addition & 1 deletion client/keys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func runListCmd(cmd *cobra.Command, _ []string) error {
return err
}

if len(records) == 0 && clientCtx.OutputFormat == flags.OutputFormatText {
if len(records) == 0 {
cmd.Println("No records were found in keyring")
return nil
}
Expand Down
53 changes: 3 additions & 50 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,56 +535,8 @@ func wrapKeyNotFound(err error, msg string) error {
return err
}

func (ks keystore) List() ([]Info, error) {
res := []Info{}

keys, err := ks.db.Keys()
if err != nil {
return nil, err
}

if len(keys) == 0 {
return res, nil
}

sort.Strings(keys)
for _, key := range keys {
if strings.HasSuffix(key, infoSuffix) {
rawInfo, err := ks.db.Get(key)
if err != nil {
fmt.Printf("err for key %s: %q\n", key, err)

// add the name of the key in case the user wants to retrieve it
// afterwards
info := newOfflineInfo(key, nil, hd.PubKeyType(""))
res = append(res, info)
continue
}

if len(rawInfo.Data) == 0 {
fmt.Println(sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key))

// add the name of the key in case the user wants to retrieve it
// afterwards
info := newOfflineInfo(key, nil, hd.PubKeyType(""))
res = append(res, info)
continue
}

info, err := unmarshalInfo(rawInfo.Data)
if err != nil {
fmt.Printf("err for key %s: %q\n", key, err)

// add the name of the key in case the user wants to retrieve it
// afterwards
info = newOfflineInfo(key, nil, hd.PubKeyType(""))
}

res = append(res, info)
}
}

return res, nil
func (ks keystore) List() ([]*Record, error) {
return ks.MigrateAll()
}

func (ks keystore) NewMnemonic(uid string, language Language, hdPath, bip39Passphrase string, algo SignatureAlgo) (*Record, string, error) {
Expand Down Expand Up @@ -959,6 +911,7 @@ func (ks keystore) MigrateAll() ([]*Record, error) {
}

sort.Strings(keys)

var recs []*Record
for _, key := range keys {
// The keyring items only with `.info` consists the key info.
Expand Down

0 comments on commit 2c90a0f

Please sign in to comment.