Changeset View
Changeset View
Standalone View
Standalone View
contrib/zmq/zmq_sub.py
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | async def handle(self): | ||||
print(binascii.hexlify(body)) | print(binascii.hexlify(body)) | ||||
elif topic == b"rawblock": | elif topic == b"rawblock": | ||||
print(f'- RAW BLOCK HEADER ({sequence}) -') | print(f'- RAW BLOCK HEADER ({sequence}) -') | ||||
print(binascii.hexlify(body[:80])) | print(binascii.hexlify(body[:80])) | ||||
elif topic == b"rawtx": | elif topic == b"rawtx": | ||||
print(f'- RAW TX ({sequence}) -') | print(f'- RAW TX ({sequence}) -') | ||||
print(binascii.hexlify(body)) | print(binascii.hexlify(body)) | ||||
elif topic == b"sequence": | elif topic == b"sequence": | ||||
hash = binascii.hexlify(body[:32]) | item_hash = binascii.hexlify(body[:32]) | ||||
label = chr(body[32]) | label = chr(body[32]) | ||||
mempool_sequence = (None if len(body) != 32 + 1 + 8 else | mempool_sequence = (None if len(body) != 32 + 1 + 8 else | ||||
struct.unpack("<Q", body[32 + 1:])[0]) | struct.unpack("<Q", body[32 + 1:])[0]) | ||||
print('- SEQUENCE (' + sequence + ') -') | print('- SEQUENCE (' + sequence + ') -') | ||||
print(hash, label, mempool_sequence) | print(item_hash, label, mempool_sequence) | ||||
# schedule ourselves to receive the next message | # schedule ourselves to receive the next message | ||||
asyncio.ensure_future(self.handle()) | asyncio.ensure_future(self.handle()) | ||||
def start(self): | def start(self): | ||||
self.loop.add_signal_handler(signal.SIGINT, self.stop) | self.loop.add_signal_handler(signal.SIGINT, self.stop) | ||||
self.loop.create_task(self.handle()) | self.loop.create_task(self.handle()) | ||||
self.loop.run_forever() | self.loop.run_forever() | ||||
def stop(self): | def stop(self): | ||||
self.loop.stop() | self.loop.stop() | ||||
self.zmqContext.destroy() | self.zmqContext.destroy() | ||||
daemon = ZMQHandler() | daemon = ZMQHandler() | ||||
daemon.start() | daemon.start() |