MCPcopy Create free account
hub / github.com/ElementsProject/elements / handle

Method handle

contrib/zmq/zmq_sub.py:53–77  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

51 self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % port)
52
53 async def handle(self) :
54 topic, body, seq = await self.zmqSubSocket.recv_multipart()
55 sequence = "Unknown"
56 if len(seq) == 4:
57 sequence = str(struct.unpack('<I', seq)[-1])
58 if topic == b"hashblock":
59 print('- HASH BLOCK ('+sequence+') -')
60 print(body.hex())
61 elif topic == b"hashtx":
62 print('- HASH TX ('+sequence+') -')
63 print(body.hex())
64 elif topic == b"rawblock":
65 print('- RAW BLOCK HEADER ('+sequence+') -')
66 print(body[:80].hex())
67 elif topic == b"rawtx":
68 print('- RAW TX ('+sequence+') -')
69 print(body.hex())
70 elif topic == b"sequence":
71 hash = body[:32].hex()
72 label = chr(body[32])
73 mempool_sequence = None if len(body) != 32+1+8 else struct.unpack("<Q", body[32+1:])[0]
74 print('- SEQUENCE ('+sequence+') -')
75 print(hash, label, mempool_sequence)
76 # schedule ourselves to receive the next message
77 asyncio.ensure_future(self.handle())
78
79 def start(self):
80 self.loop.add_signal_handler(signal.SIGINT, self.stop)

Callers 2

startMethod · 0.95
UnlockFileMethod · 0.45

Calls 2

chrFunction · 0.85
hexMethod · 0.80

Tested by

no test coverage detected