mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 09:21:39 +00:00
Merge pull request #4402 from kyuupichan/master
Subscribe to raw headers
This commit is contained in:
commit
d667c5d46e
3 changed files with 10 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Add table
Reference in a new issue