commit 514d0ae95863f3aafdc1ffd2646ec189fb40d195
parent 8ae6ddcc00115933b45a8b691498d1f707d0b92f
Author: SomberNight <somber.night@protonmail.com>
Date: Mon, 4 Mar 2019 18:16:48 +0100
wallet: towards restoring previous performance 2
Diffstat:
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
@@ -91,7 +91,7 @@ class AddressSynchronizer(PrintError):
self.remove_local_transactions_we_dont_have()
def is_mine(self, address):
- return address in self.db.get_history()
+ return self.db.is_addr_in_history(address)
def get_addresses(self):
return sorted(self.db.get_history())
@@ -160,7 +160,7 @@ class AddressSynchronizer(PrintError):
self.storage.write()
def add_address(self, address):
- if address not in self.db.get_history():
+ if not self.db.get_addr_history(address):
self.db.history[address] = []
self.set_up_to_date(False)
if self.synchronizer:
diff --git a/electrum/json_db.py b/electrum/json_db.py
@@ -607,6 +607,10 @@ class JsonDB(PrintError):
def get_history(self):
return list(self.history.keys())
+ def is_addr_in_history(self, addr):
+ # does not mean history is non-empty!
+ return addr in self.history
+
@locked
def get_addr_history(self, addr):
return self.history.get(addr, [])
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -1575,10 +1575,10 @@ class Deterministic_Wallet(Abstract_Wallet):
def num_unused_trailing_addresses(self, addresses):
k = 0
- for a in addresses[::-1]:
- if a in self.db.get_history():
+ for addr in addresses[::-1]:
+ if self.db.get_addr_history(addr):
break
- k = k + 1
+ k += 1
return k
def min_acceptable_gap(self):
@@ -1587,12 +1587,12 @@ class Deterministic_Wallet(Abstract_Wallet):
nmax = 0
addresses = self.get_receiving_addresses()
k = self.num_unused_trailing_addresses(addresses)
- for a in addresses[0:-k]:
- if a in self.db.get_history():
+ for addr in addresses[0:-k]:
+ if self.db.get_addr_history(addr):
n = 0
else:
n += 1
- if n > nmax: nmax = n
+ nmax = max(nmax, n)
return nmax + 1
def load_addresses(self):
@@ -1647,7 +1647,7 @@ class Deterministic_Wallet(Abstract_Wallet):
return False
prev_addresses = addr_list[max(0, i - limit):max(0, i)]
for addr in prev_addresses:
- if addr in self.db.get_history():
+ if self.db.get_addr_history(addr):
return False
return True