diff --git a/lib/__init__.py b/lib/__init__.py index b81198540..fcea25d4f 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -1,6 +1,6 @@ from version import ELECTRUM_VERSION from util import format_satoshis, print_msg, print_json, print_error, set_verbosity -from wallet import WalletSynchronizer, WalletStorage +from wallet import Synchronizer, WalletStorage from wallet import Wallet, Imported_Wallet from network import Network, DEFAULT_SERVERS, DEFAULT_PORTS, pick_random_server from interface import Interface diff --git a/lib/network_proxy.py b/lib/network_proxy.py index 950f7a496..6bf3ea981 100644 --- a/lib/network_proxy.py +++ b/lib/network_proxy.py @@ -60,15 +60,13 @@ class NetworkProxy(util.DaemonThread): self.blockchain_height = 0 self.server_height = 0 self.interfaces = [] - self.jobs = [] # value returned by estimatefee self.fee = None def run(self): while self.is_running(): - for job in self.jobs: - job() + self.run_jobs() # Synchronizer, for now try: response = self.pipe.get() except util.timeout: diff --git a/lib/synchronizer.py b/lib/synchronizer.py index 9a4d9ce13..1386ea83f 100644 --- a/lib/synchronizer.py +++ b/lib/synchronizer.py @@ -21,10 +21,10 @@ from threading import Lock from bitcoin import Hash, hash_encode from transaction import Transaction -from util import print_error, print_msg +from util import print_error, print_msg, ThreadJob -class WalletSynchronizer(): +class Synchronizer(ThreadJob): '''The synchronizer keeps the wallet up-to-date with its set of addresses and their transactions. It subscribes over the network to wallet addresses, gets the wallet to generate new addresses @@ -46,12 +46,6 @@ class WalletSynchronizer(): self.lock = Lock() self.initialize() - def print_error(self, *msg): - print_error("[Synchronizer]", *msg) - - def print_msg(self, *msg): - print_msg("[Synchronizer]", *msg) - def parse_response(self, response): if response.get('error'): self.print_error("response error:", response) @@ -165,7 +159,7 @@ class WalletSynchronizer(): self.print_error("missing tx", self.requested_tx) self.subscribe_to_addresses(set(self.wallet.addresses(True))) - def main_loop(self): + def run(self): '''Called from the network proxy thread main loop.''' # 1. Create new addresses self.wallet.synchronize() diff --git a/lib/wallet.py b/lib/wallet.py index 367162e95..9e3f3c2e5 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -38,7 +38,7 @@ from version import * from transaction import Transaction from plugins import run_hook import bitcoin -from synchronizer import WalletSynchronizer +from synchronizer import Synchronizer from mnemonic import Mnemonic import paymentrequest @@ -1110,8 +1110,8 @@ class Abstract_Wallet(object): self.verifier = SPV(self.network, self) self.verifier.start() self.set_verifier(self.verifier) - self.synchronizer = WalletSynchronizer(self, network) - network.jobs.append(self.synchronizer.main_loop) + self.synchronizer = Synchronizer(self, network) + network.add_job(self.synchronizer) else: self.verifier = None self.synchronizer = None @@ -1119,7 +1119,7 @@ class Abstract_Wallet(object): def stop_threads(self): if self.network: self.verifier.stop() - self.network.jobs.remove(self.synchronizer.main_loop) + self.network.remove_job(self.synchronizer) self.synchronizer = None self.storage.put('stored_height', self.get_local_height(), True)