diff --git a/chain/wallet/wallet.go b/chain/wallet/wallet.go index 8d074a117..884557520 100644 --- a/chain/wallet/wallet.go +++ b/chain/wallet/wallet.go @@ -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 == addr { - err = w.SetDefault(address.Undef) - if err != nil { - return xerrors.Errorf("unsetting default address: %w", err) + if def, err := w.GetDefault(); err == nil { + if def == addr { + w.deleteDefault() } } - return nil }