Fix panic in wallet export when key is not found

This commit is contained in:
Łukasz Magiera 2020-10-10 15:44:22 +02:00
parent 651522cbaa
commit 4fa6afad13

View File

@ -141,6 +141,9 @@ func (w *LocalWallet) WalletExport(ctx context.Context, addr address.Address) (*
if err != nil {
return nil, xerrors.Errorf("failed to find key to export: %w", err)
}
if k == nil {
return nil, xerrors.Errorf("key not found")
}
return &k.KeyInfo, nil
}
@ -274,6 +277,9 @@ func (w *LocalWallet) WalletDelete(ctx context.Context, addr address.Address) er
if err != nil {
return xerrors.Errorf("failed to delete key %s : %w", addr, err)
}
if k == nil {
return nil // already not there
}
if err := w.keystore.Put(KTrashPrefix+k.Address.String(), k.KeyInfo); err != nil {
return xerrors.Errorf("failed to mark key %s as trashed: %w", addr, err)