2016-10-17 22:09:21 +02:00
|
|
|
#!/usr/bin/env python
|
2016-09-19 16:55:00 +02:00
|
|
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2014-11-18 18:06:32 +01:00
|
|
|
|
|
|
|
import binascii
|
|
|
|
import zmq
|
2016-10-17 22:09:21 +02:00
|
|
|
import struct
|
2014-11-18 18:06:32 +01:00
|
|
|
|
|
|
|
port = 28332
|
|
|
|
|
|
|
|
zmqContext = zmq.Context()
|
|
|
|
zmqSubSocket = zmqContext.socket(zmq.SUB)
|
2016-10-17 22:09:21 +02:00
|
|
|
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock")
|
|
|
|
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx")
|
|
|
|
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtxlock")
|
|
|
|
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawblock")
|
|
|
|
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawtx")
|
|
|
|
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawtxlock")
|
2014-11-18 18:06:32 +01:00
|
|
|
zmqSubSocket.connect("tcp://127.0.0.1:%i" % port)
|
|
|
|
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
msg = zmqSubSocket.recv_multipart()
|
2016-10-17 22:09:21 +02:00
|
|
|
topic = str(msg[0].decode("utf-8"))
|
2014-11-18 18:06:32 +01:00
|
|
|
body = msg[1]
|
2017-01-23 13:22:32 +01:00
|
|
|
sequence = "Unknown"
|
2016-10-17 22:09:21 +02:00
|
|
|
|
|
|
|
if len(msg[-1]) == 4:
|
|
|
|
msgSequence = struct.unpack('<I', msg[-1])[-1]
|
|
|
|
sequence = str(msgSequence)
|
2014-11-18 18:06:32 +01:00
|
|
|
|
|
|
|
if topic == "hashblock":
|
2016-10-17 22:09:21 +02:00
|
|
|
print('- HASH BLOCK ('+sequence+') -')
|
|
|
|
print(binascii.hexlify(body).decode("utf-8"))
|
2014-11-18 18:06:32 +01:00
|
|
|
elif topic == "hashtx":
|
2016-10-17 22:09:21 +02:00
|
|
|
print ('- HASH TX ('+sequence+') -')
|
|
|
|
print(binascii.hexlify(body).decode("utf-8"))
|
2016-07-15 08:38:33 +02:00
|
|
|
elif topic == "hashtxlock":
|
2016-10-17 22:09:21 +02:00
|
|
|
print('- HASH TX LOCK ('+sequence+') -')
|
|
|
|
print(binascii.hexlify(body).decode("utf-8"))
|
2014-11-18 18:06:32 +01:00
|
|
|
elif topic == "rawblock":
|
2016-10-17 22:09:21 +02:00
|
|
|
print('- RAW BLOCK HEADER ('+sequence+') -')
|
|
|
|
print(binascii.hexlify(body[:80]).decode("utf-8"))
|
2014-11-18 18:06:32 +01:00
|
|
|
elif topic == "rawtx":
|
2016-10-17 22:09:21 +02:00
|
|
|
print('- RAW TX ('+sequence+') -')
|
|
|
|
print(binascii.hexlify(body).decode("utf-8"))
|
2016-07-15 08:38:33 +02:00
|
|
|
elif topic == "rawtxlock":
|
2016-10-17 22:09:21 +02:00
|
|
|
print('- RAW TX LOCK ('+sequence+') -')
|
|
|
|
print(binascii.hexlify(body).decode("utf-8"))
|
2014-11-18 18:06:32 +01:00
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
zmqContext.destroy()
|