summaryrefslogtreecommitdiffstats
path: root/waitblock.py
blob: 937c89d7f7f00438d5c0db70fc6f2e0b61d54518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import zmq
import hashlib
import struct

context = zmq.Context(1)
socket = context.socket(zmq.SUB)
socket.connect("tcp://localhost:9093")
socket.setsockopt(zmq.SUBSCRIBE, "")
height = struct.unpack("<I", socket.recv())[0]
blk_hash = socket.recv().encode("hex")
blk_data = socket.recv()
print "Block (%s bytes): #%s %s" % (len(blk_data), height, blk_hash)
def hash_block(data):
    return hashlib.sha256(hashlib.sha256(data[:80]).digest()).digest()[::-1].encode("hex")
assert hash_block(blk_data) == blk_hash