2013-10-06 12:28:45 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
# A simple script that connects to a server and displays block headers
|
|
|
|
|
|
2014-07-29 10:43:04 +02:00
|
|
|
import time
|
2015-10-29 11:06:09 +01:00
|
|
|
from electrum import SimpleConfig, Network
|
|
|
|
|
from electrum.util import print_msg, json_encode
|
2013-10-06 12:28:45 +02:00
|
|
|
|
2014-07-27 11:33:02 +02:00
|
|
|
# start network
|
2015-10-29 11:06:09 +01:00
|
|
|
c = SimpleConfig()
|
|
|
|
|
network = Network(c)
|
2014-07-27 11:33:02 +02:00
|
|
|
network.start()
|
|
|
|
|
|
|
|
|
|
# wait until connected
|
|
|
|
|
while network.is_connecting():
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
if not network.is_connected():
|
|
|
|
|
print_msg("daemon is not connected")
|
|
|
|
|
sys.exit(1)
|
2013-10-06 12:28:45 +02:00
|
|
|
|
|
|
|
|
# 2. send the subscription
|
2015-10-29 11:06:09 +01:00
|
|
|
callback = lambda response: print_msg(json_encode(response.get('result')))
|
2018-05-30 13:53:19 +08:00
|
|
|
network.send([('server.version',["block_headers script", "1.2"])], callback)
|
2018-06-06 15:06:04 +02:00
|
|
|
network.subscribe_to_headers(callback)
|
2013-10-06 12:28:45 +02:00
|
|
|
|
|
|
|
|
# 3. wait for results
|
2014-07-27 11:33:02 +02:00
|
|
|
while network.is_connected():
|
2014-07-29 10:43:04 +02:00
|
|
|
time.sleep(1)
|