Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(keyring): improve UX for keyring.List #13369

Merged
merged 6 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.swm
*.swn
*.pyc
.dccache

# private files
private[.-]*
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* [#13369](https://github.com/cosmos/cosmos-sdk/pull/13369) Improve UX for `keyring.List` by returning all retrieved keys.
* [#13323](https://github.com/cosmos/cosmos-sdk/pull/13323) Ensure `withdraw_rewards` rewards are emitted from all actions that result in rewards being withdrawn.
* [#13321](https://github.com/cosmos/cosmos-sdk/pull/13321) Add flag to disable fast node migration and usage.
* [#13321](https://github.com/cosmos/cosmos-sdk/pull/13321) Add flag to disable fast node migration and usage.

### API Breaking Changes

Expand Down
29 changes: 24 additions & 5 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,29 +467,48 @@ func wrapKeyNotFound(err error, msg string) error {
}

func (ks keystore) List() ([]Info, error) {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
var res []Info
res := []Info{}

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

sort.Strings(keys)
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 {
return nil, err
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 {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key)
fmt.Println(sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key))
fedekunze marked this conversation as resolved.
Show resolved Hide resolved

// 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 {
return nil, err
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)
Expand Down