Merge pull request #5019 from zgfzgf/fix-wallet-default-delete

fix wallet delete address where address is default
This commit is contained in:
Łukasz Magiera 2020-11-26 16:10:39 +01:00 committed by GitHub
commit 42173e29d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -306,23 +306,26 @@ func (w *LocalWallet) walletDelete(ctx context.Context, addr address.Address) er
return nil
}
func (w *LocalWallet) deleteDefault() {
w.lk.Lock()
defer w.lk.Unlock()
if err := w.keystore.Delete(KDefault); err != nil {
if !xerrors.Is(err, types.ErrKeyInfoNotFound) {
log.Warnf("failed to unregister current default key: %s", err)
}
}
}
func (w *LocalWallet) WalletDelete(ctx context.Context, addr address.Address) error {
if err := w.walletDelete(ctx, addr); err != nil {
return xerrors.Errorf("wallet delete: %w", err)
}
def, err := w.GetDefault()
if err != nil {
return xerrors.Errorf("getting default address: %w", err)
}
if def, err := w.GetDefault(); err == nil {
if def == addr {
err = w.SetDefault(address.Undef)
if err != nil {
return xerrors.Errorf("unsetting default address: %w", err)
w.deleteDefault()
}
}
return nil
}