Skip to content

Commit

Permalink
imp(keyring): improve UX for keyring.List (#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 dudong2 committed Nov 1, 2022
1 parent c37d9c8 commit 49cb9f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 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
29 changes: 24 additions & 5 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,29 +470,48 @@ func wrapKeyNotFound(err error, msg string) error {
}

func (ks keystore) List() ([]Info, error) {
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))

// 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

0 comments on commit 49cb9f4

Please sign in to comment.