tseparate network layer from synchronizer - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 5f1d9cbcf5b79de720529f0a1771650dd8c6add9 DIR parent e4659327a136f18fde59e4a1f60f45f3e16f22d6 HTML Author: ThomasV <thomasv@electrum.org> Date: Tue, 29 Aug 2017 09:51:23 +0200 separate network layer from synchronizer Diffstat: M lib/network.py | 7 +++++++ M lib/synchronizer.py | 13 +++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) --- DIR diff --git a/lib/network.py b/lib/network.py t@@ -654,6 +654,13 @@ class Network(util.DaemonThread): # Response is now in canonical form self.process_response(interface, response, callbacks) + def subscribe_to_addresses(self, addresses, callback): + msgs = [('blockchain.address.subscribe', [x]) for x in addresses] + self.send(msgs, callback) + + def request_address_history(self, address, callback): + self.send([('blockchain.address.get_history', [address])], callback) + def send(self, messages, callback): '''Messages is a list of (method, params) tuples''' messages = list(messages) DIR diff --git a/lib/synchronizer.py b/lib/synchronizer.py t@@ -69,7 +69,7 @@ class Synchronizer(ThreadJob): and not self.requested_addrs) def release(self): - self.network.unsubscribe(self.addr_subscription_response) + self.network.unsubscribe(self.on_address_status) def add(self, address): '''This can be called from the proxy or GUI threads.''' t@@ -79,9 +79,7 @@ class Synchronizer(ThreadJob): def subscribe_to_addresses(self, addresses): if addresses: self.requested_addrs |= addresses - msgs = map(lambda addr: ('blockchain.address.subscribe', [addr]), - addresses) - self.network.send(msgs, self.addr_subscription_response) + self.network.subscribe_to_addresses(addresses, self.on_address_status) def get_status(self, h): if not h: t@@ -91,7 +89,7 @@ class Synchronizer(ThreadJob): status += tx_hash + ':%d:' % height return bh2u(hashlib.sha256(status.encode('ascii')).digest()) - def addr_subscription_response(self, response): + def on_address_status(self, response): params, result = self.parse_response(response) if not params: return t@@ -100,13 +98,12 @@ class Synchronizer(ThreadJob): if self.get_status(history) != result: if self.requested_histories.get(addr) is None: self.requested_histories[addr] = result - self.network.send([('blockchain.address.get_history', [addr])], - self.addr_history_response) + self.network.request_address_history(addr, self.on_address_history) # remove addr from list only after it is added to requested_histories if addr in self.requested_addrs: # Notifications won't be in self.requested_addrs.remove(addr) - def addr_history_response(self, response): + def on_address_history(self, response): params, result = self.parse_response(response) if not params: return