Skip to content

Commit

Permalink
imp(keyring): improve UX for keyring.List (cosmos#13369)
Browse files Browse the repository at this point in the history
* imp(keyring): improve UX for keyring.List

* use offline info in case of error

* Delete .dccache

* c++

* conflicts
  • Loading branch information
fedekunze authored and JeancarloBarrios committed Sep 28, 2024
1 parent a8ab40a commit 360e92c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
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 @@ -40,8 +40,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
52 changes: 50 additions & 2 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,56 @@ func wrapKeyNotFound(err error, msg string) error {
return err
}

func (ks keystore) List() ([]*Record, error) {
return ks.MigrateAll()
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) NewMnemonic(uid string, language Language, hdPath, bip39Passphrase string, algo SignatureAlgo) (*Record, string, error) {
Expand Down

0 comments on commit 360e92c

Please sign in to comment.