From 5ec3d2888f9ce8097e0bbbf8b26b01f67c0766fd Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 16 Jan 2018 16:02:58 +0100 Subject: [PATCH] websocket: migrate to scripthashes --- lib/network.py | 3 +++ lib/websockets.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/network.py b/lib/network.py index 16e321fa..06b6db33 100644 --- a/lib/network.py +++ b/lib/network.py @@ -604,6 +604,9 @@ class Network(util.DaemonThread): elif method == 'blockchain.scripthash.subscribe': response['params'] = [params[0]] # addr response['result'] = params[1] + elif method == 'blockchain.address.subscribe': + response['params'] = [params[0]] + response['result'] = params[1] callbacks = self.subscriptions.get(k, []) # update cache if it's a subscription diff --git a/lib/websockets.py b/lib/websockets.py index f2bd9149..415556b3 100644 --- a/lib/websockets.py +++ b/lib/websockets.py @@ -84,7 +84,8 @@ class WsClientThread(util.DaemonThread): l = self.subscriptions.get(addr, []) l.append((ws, amount)) self.subscriptions[addr] = l - self.network.send([('blockchain.address.subscribe', [addr])], self.response_queue.put) + h = self.network.addr_to_scripthash(addr) + self.network.send([('blockchain.scripthash.subscribe', [h])], self.response_queue.put) def run(self): @@ -100,10 +101,13 @@ class WsClientThread(util.DaemonThread): result = r.get('result') if result is None: continue - if method == 'blockchain.address.subscribe': - self.network.send([('blockchain.address.get_balance', params)], self.response_queue.put) - elif method == 'blockchain.address.get_balance': - addr = params[0] + if method == 'blockchain.scripthash.subscribe': + self.network.send([('blockchain.scripthash.get_balance', params)], self.response_queue.put) + elif method == 'blockchain.scripthash.get_balance': + h = params[0] + addr = self.network.h2addr.get(h, None) + if addr is None: + util.print_error("can't find address for scripthash: %s" % h) l = self.subscriptions.get(addr, []) for ws, amount in l: if not ws.closed: