commit 68873d92f9973b3d6befe9d2b69f67be71217501
parent 8c5b6bdaf3077d5855b69c71830296917d132931
Author: ThomasV <thomasv@electrum.org>
Date: Tue, 29 Aug 2017 11:53:49 +0200
implement scripthash logic
Diffstat:
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/lib/network.py b/lib/network.py
@@ -208,6 +208,7 @@ class Network(util.DaemonThread):
# subscriptions and requests
self.subscribed_addresses = set()
+ self.h2addr = {}
# Requests from client we've not seen a response to
self.unanswered_requests = {}
# retry times
@@ -316,8 +317,8 @@ class Network(util.DaemonThread):
for i in bitcoin.FEE_TARGETS:
self.queue_request('blockchain.estimatefee', [i])
self.queue_request('blockchain.relayfee', [])
- for addr in self.subscribed_addresses:
- self.queue_request('blockchain.address.subscribe', [addr])
+ for h in self.subscribed_addresses:
+ self.queue_request('blockchain.scripthash.subscribe', [h])
def get_status_value(self, key):
if key == 'status':
@@ -584,7 +585,7 @@ class Network(util.DaemonThread):
response['params'] = params
# Only once we've received a response to an addr subscription
# add it to the list; avoids double-sends on reconnection
- if method == 'blockchain.address.subscribe':
+ if method == 'blockchain.scripthash.subscribe':
self.subscribed_addresses.add(params[0])
else:
if not response: # Closed remotely / misbehaving
@@ -597,7 +598,7 @@ class Network(util.DaemonThread):
if method == 'blockchain.headers.subscribe':
response['result'] = params[0]
response['params'] = []
- elif method == 'blockchain.address.subscribe':
+ elif method == 'blockchain.scripthash.subscribe':
response['params'] = [params[0]] # addr
response['result'] = params[1]
callbacks = self.subscriptions.get(k, [])
@@ -608,12 +609,28 @@ class Network(util.DaemonThread):
# Response is now in canonical form
self.process_response(interface, response, callbacks)
+ def addr_to_scripthash(self, addr):
+ h = bitcoin.address_to_scripthash(addr)
+ if h not in self.h2addr:
+ self.h2addr[h] = addr
+ return h
+
+ def overload_cb(self, callback):
+ def cb2(x):
+ p = x.pop('params')
+ addr = self.h2addr[p[0]]
+ x['params'] = [addr]
+ callback(x)
+ return cb2
+
def subscribe_to_addresses(self, addresses, callback):
- msgs = [('blockchain.address.subscribe', [x]) for x in addresses]
- self.send(msgs, callback)
+ hashes = [self.addr_to_scripthash(addr) for addr in addresses]
+ msgs = [('blockchain.scripthash.subscribe', [x]) for x in hashes]
+ self.send(msgs, self.overload_cb(callback))
def request_address_history(self, address, callback):
- self.send([('blockchain.address.get_history', [address])], callback)
+ h = self.addr_to_scripthash(address)
+ self.send([('blockchain.scripthash.get_history', [h])], self.overload_cb(callback))
def send(self, messages, callback):
'''Messages is a list of (method, params) tuples'''
diff --git a/lib/version.py b/lib/version.py
@@ -1,5 +1,5 @@
ELECTRUM_VERSION = '2.10.0' # version of the client package
-PROTOCOL_VERSION = '0.10' # protocol version requested
+PROTOCOL_VERSION = '0.11' # protocol version requested
# The hash of the mnemonic seed must begin with this
SEED_PREFIX = '01' # Standard wallet