electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit d667c5d46e3347c05fd031169e9e4952df509d2a
parent 105101bb5c10072fffcead00ecd474bea2cb1a1e
Author: ghost43 <somber.night@protonmail.com>
Date:   Mon,  4 Jun 2018 17:15:49 +0200

Merge pull request #4402 from kyuupichan/master

Subscribe to raw headers
Diffstat:
Mlib/network.py | 9++++-----
Mscripts/block_headers | 3++-
Mscripts/watch_address | 5++++-
3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/network.py b/lib/network.py @@ -711,7 +711,7 @@ class Network(util.DaemonThread): interface.mode = 'default' interface.request = None self.interfaces[server] = interface - self.queue_request('blockchain.headers.subscribe', [], interface) + self.queue_request('blockchain.headers.subscribe', [True], interface) if server == self.default_server: self.switch_to_interface(server) #self.notify('interfaces') @@ -983,10 +983,9 @@ class Network(util.DaemonThread): self.stop_network() self.on_stop() - def on_notify_header(self, interface, header): - height = header.get('block_height') - if not height: - return + def on_notify_header(self, interface, header_dict): + header_hex, height = header_dict['hex'], header_dict['height'] + header = blockchain.deserialize_header(bfh(header_hex), height) if height < self.max_checkpoint(): self.connection_down(interface.server) return diff --git a/scripts/block_headers b/scripts/block_headers @@ -21,7 +21,8 @@ if not network.is_connected(): # 2. send the subscription callback = lambda response: print_msg(json_encode(response.get('result'))) -network.send([('blockchain.headers.subscribe',[])], callback) +network.send([('server.version',["block_headers script", "1.2"])], callback) +network.send([('blockchain.headers.subscribe',[True])], callback) # 3. wait for results while network.is_connected(): diff --git a/scripts/watch_address b/scripts/watch_address @@ -2,6 +2,7 @@ import sys import time +from electrum import bitcoin from electrum import SimpleConfig, Network from electrum.util import print_msg, json_encode @@ -11,6 +12,8 @@ except Exception: print("usage: watch_address <bitcoin_address>") sys.exit(1) +sh = bitcoin.address_to_scripthash(addr) + # start network c = SimpleConfig() network = Network(c) @@ -26,7 +29,7 @@ if not network.is_connected(): # 2. send the subscription callback = lambda response: print_msg(json_encode(response.get('result'))) -network.send([('blockchain.address.subscribe',[addr])], callback) +network.send([('blockchain.scripthash.subscribe',[sh])], callback) # 3. wait for results while network.is_connected():