Browse Source

Merge pull request #1266 from kyuupichan/fast_freezing

Speed up freezing and unfreezing of many addresses
283
ThomasV 10 years ago
parent
commit
6cb5ba4314
  1. 7
      gui/gtk.py
  2. 13
      gui/qt/main_window.py
  3. 4
      lib/commands.py
  4. 25
      lib/wallet.py

7
gui/gtk.py

@ -1079,10 +1079,7 @@ class ElectrumWindow:
path, col = treeview.get_cursor()
if path:
address = liststore.get_value( liststore.get_iter(path), 0)
if address in wallet.frozen_addresses:
wallet.unfreeze(address)
else:
wallet.freeze(address)
wallet.set_frozen_state([address], not wallet.is_frozen(address))
self.update_receiving_tab()
button.connect("clicked", freeze_address, treeview, liststore, self.wallet)
button.show()
@ -1151,7 +1148,7 @@ class ElectrumWindow:
if address in self.wallet.imported_keys.keys():
Type = "I"
c, u, x = self.wallet.get_addr_balance(address)
if address in self.wallet.frozen_addresses: Type = Type + "F"
if self.wallet.is_frozen(address): Type = Type + "F"
label = self.wallet.labels.get(address)
h = self.wallet.history.get(address,[])
n = len(h)

13
gui/qt/main_window.py

@ -1291,13 +1291,8 @@ class ElectrumWindow(QMainWindow):
run_hook('do_clear')
def set_addrs_frozen(self,addrs,freeze):
for addr in addrs:
if not addr: continue
if addr in self.wallet.frozen_addresses and not freeze:
self.wallet.unfreeze(addr)
elif addr not in self.wallet.frozen_addresses and freeze:
self.wallet.freeze(addr)
def set_frozen_state(self, addrs, freeze):
self.wallet.set_frozen_state(addrs, freeze)
self.update_address_tab()
self.update_fee(False)
@ -1416,9 +1411,9 @@ class ElectrumWindow(QMainWindow):
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL))
if any(addr not in self.wallet.frozen_addresses for addr in addrs):
menu.addAction(_("Freeze"), lambda: self.set_addrs_frozen(addrs, True))
menu.addAction(_("Freeze"), lambda: self.set_frozen_state(addrs, True))
if any(addr in self.wallet.frozen_addresses for addr in addrs):
menu.addAction(_("Unfreeze"), lambda: self.set_addrs_frozen(addrs, False))
menu.addAction(_("Unfreeze"), lambda: self.set_frozen_state(addrs, False))
def can_send(addr):
return addr not in self.wallet.frozen_addresses and self.wallet.get_addr_balance(addr) != (0, 0)

4
lib/commands.py

@ -322,10 +322,10 @@ class Commands:
return {'address':address, 'redeemScript':redeem_script}
def freeze(self,addr):
return self.wallet.freeze(addr)
return self.wallet.set_frozen_state([addr], True)
def unfreeze(self,addr):
return self.wallet.unfreeze(addr)
return self.wallet.set_frozen_state([addr], False)
def getprivatekeys(self, addr):
return self.wallet.get_private_key(addr, self.password)

25
lib/wallet.py

@ -149,7 +149,7 @@ class Abstract_Wallet(object):
self.use_encryption = storage.get('use_encryption', False)
self.seed = storage.get('seed', '') # encrypted
self.labels = storage.get('labels', {})
self.frozen_addresses = storage.get('frozen_addresses',[])
self.frozen_addresses = set(storage.get('frozen_addresses',[]))
self.stored_height = storage.get('stored_height', 0) # last known height (for offline mode)
self.history = storage.get('addr_history',{}) # address -> list(txid, height)
@ -1016,21 +1016,16 @@ class Abstract_Wallet(object):
def is_frozen(self, addr):
return addr in self.frozen_addresses
def freeze(self,addr):
if self.is_mine(addr) and self.is_frozen(addr):
self.frozen_addresses.append(addr)
self.storage.put('frozen_addresses', self.frozen_addresses, True)
return True
else:
return False
def unfreeze(self,addr):
if self.is_mine(addr) and self.is_frozen(addr):
self.frozen_addresses.remove(addr)
self.storage.put('frozen_addresses', self.frozen_addresses, True)
def set_frozen_state(self, addrs, freeze):
'''Set frozen state of the addresses to FREEZE, True or False'''
if all(self.is_mine(addr) for addr in addrs):
if freeze:
self.frozen_addresses |= set(addrs)
else:
self.frozen_addresses -= set(addrs)
self.storage.put('frozen_addresses', list(self.frozen_addresses), True)
return True
else:
return False
return False
def set_verifier(self, verifier):
self.verifier = verifier

Loading…
Cancel
Save