commit a00439b6f8a6507a142d7b5b29a793d340a183a9
parent 6ef921cbbee61e819baf0e21ab95508c41c973ac
Author: SomberNight <somber.night@protonmail.com>
Date: Thu, 22 Mar 2018 07:27:18 +0100
fix #4158
Diffstat:
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -1771,8 +1771,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def remove_address(self, addr):
if self.question(_("Do you want to remove")+" %s "%addr +_("from your wallet?")):
self.wallet.delete_address(addr)
- self.address_list.update()
- self.history_list.update()
+ self.need_update.set() # history, addresses, coins
self.clear_receive_tab()
def get_coins(self):
diff --git a/lib/bitcoin.py b/lib/bitcoin.py
@@ -465,6 +465,7 @@ def DecodeBase58Check(psz):
# backwards compat
# extended WIF for segwit (used in 3.0.x; but still used internally)
+# the keys in this dict should be a superset of what Imported Wallets can import
SCRIPT_TYPES = {
'p2pkh':0,
'p2wpkh':1,
diff --git a/lib/keystore.py b/lib/keystore.py
@@ -143,6 +143,10 @@ class Imported_KeyStore(Software_KeyStore):
# re-serialize the key so the internal storage format is consistent
serialized_privkey = serialize_privkey(
privkey, compressed, txin_type, internal_use=True)
+ # NOTE: if the same pubkey is reused for multiple addresses (script types),
+ # there will only be one pubkey-privkey pair for it in self.keypairs,
+ # and the privkey will encode a txin_type but that txin_type can not be trusted.
+ # Removing keys complicates this further.
self.keypairs[pubkey] = pw_encode(serialized_privkey, password)
return txin_type, pubkey
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -1929,8 +1929,18 @@ class Imported_Wallet(Simple_Wallet):
pubkey = self.get_public_key(address)
self.addresses.pop(address)
if pubkey:
- self.keystore.delete_imported_key(pubkey)
- self.save_keystore()
+ # delete key iff no other address uses it (e.g. p2pkh and p2wpkh for same key)
+ for txin_type in bitcoin.SCRIPT_TYPES.keys():
+ try:
+ addr2 = bitcoin.pubkey_to_address(txin_type, pubkey)
+ except NotImplementedError:
+ pass
+ else:
+ if addr2 in self.addresses:
+ break
+ else:
+ self.keystore.delete_imported_key(pubkey)
+ self.save_keystore()
self.storage.put('addresses', self.addresses)
self.storage.write()