Skip to content

Commit 360e92c

Browse files
fedekunzeJeancarloBarrios
authored andcommitted
imp(keyring): improve UX for keyring.List (cosmos#13369)
* imp(keyring): improve UX for keyring.List * use offline info in case of error * Delete .dccache * c++ * conflicts
1 parent a8ab40a commit 360e92c

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.swm
77
*.swn
88
*.pyc
9+
.dccache
910

1011
# private files
1112
private[.-]*

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040

4141
### Improvements
4242

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

4647
### API Breaking Changes
4748

crypto/keyring/keyring.go

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,56 @@ func wrapKeyNotFound(err error, msg string) error {
535535
return err
536536
}
537537

538-
func (ks keystore) List() ([]*Record, error) {
539-
return ks.MigrateAll()
538+
func (ks keystore) List() ([]Info, error) {
539+
res := []Info{}
540+
541+
keys, err := ks.db.Keys()
542+
if err != nil {
543+
return nil, err
544+
}
545+
546+
if len(keys) == 0 {
547+
return res, nil
548+
}
549+
550+
sort.Strings(keys)
551+
for _, key := range keys {
552+
if strings.HasSuffix(key, infoSuffix) {
553+
rawInfo, err := ks.db.Get(key)
554+
if err != nil {
555+
fmt.Printf("err for key %s: %q\n", key, err)
556+
557+
// add the name of the key in case the user wants to retrieve it
558+
// afterwards
559+
info := newOfflineInfo(key, nil, hd.PubKeyType(""))
560+
res = append(res, info)
561+
continue
562+
}
563+
564+
if len(rawInfo.Data) == 0 {
565+
fmt.Println(sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key))
566+
567+
// add the name of the key in case the user wants to retrieve it
568+
// afterwards
569+
info := newOfflineInfo(key, nil, hd.PubKeyType(""))
570+
res = append(res, info)
571+
continue
572+
}
573+
574+
info, err := unmarshalInfo(rawInfo.Data)
575+
if err != nil {
576+
fmt.Printf("err for key %s: %q\n", key, err)
577+
578+
// add the name of the key in case the user wants to retrieve it
579+
// afterwards
580+
info = newOfflineInfo(key, nil, hd.PubKeyType(""))
581+
}
582+
583+
res = append(res, info)
584+
}
585+
}
586+
587+
return res, nil
540588
}
541589

542590
func (ks keystore) NewMnemonic(uid string, language Language, hdPath, bip39Passphrase string, algo SignatureAlgo) (*Record, string, error) {

0 commit comments

Comments
 (0)