2016-10-17 22:09:21 +02:00
|
|
|
#!/usr/bin/env python
|
2014-11-18 18:06:32 +01:00
|
|
|
|
|
|
|
import array
|
|
|
|
import binascii
|
|
|
|
import zmq
|
2016-10-17 22:09:21 +02:00
|
|
|
import struct
|
2014-11-18 18:06:32 +01:00
|
|
|
|
2024-12-16 19:40:22 +01:00
|
|
|
port = 21427
|
2014-11-18 18:06:32 +01:00
|
|
|
|
|
|
|
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]
|
2016-10-17 22:09:21 +02:00
|
|
|
sequence = "Unknown";
|
|
|
|
|
|
|
|
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()
|