aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorGregory Sanders <gsanders87@gmail.com>2020-09-01 15:14:58 -0400
committerGregory Sanders <gsanders87@gmail.com>2020-09-22 11:34:30 -0400
commit759d94e70f6844443106404882c7b105f3a4dba7 (patch)
tree21d8c98214a1e6e24c86f42fbe6d1ef8b59d634e /contrib
parent68c3c7e1bdd00bbe7d70592a8eb39520fa3f87f1 (diff)
downloadbitcoin-759d94e70f6844443106404882c7b105f3a4dba7.tar.xz
Update zmq notification documentation and sample consumer
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/zmq/zmq_sub.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/contrib/zmq/zmq_sub.py b/contrib/zmq/zmq_sub.py
index 06893407f5..8b8503331d 100755
--- a/contrib/zmq/zmq_sub.py
+++ b/contrib/zmq/zmq_sub.py
@@ -11,7 +11,8 @@
-zmqpubrawtx=tcp://127.0.0.1:28332 \
-zmqpubrawblock=tcp://127.0.0.1:28332 \
-zmqpubhashtx=tcp://127.0.0.1:28332 \
- -zmqpubhashblock=tcp://127.0.0.1:28332
+ -zmqpubhashblock=tcp://127.0.0.1:28332 \
+ -zmqpubsequence=tcp://127.0.0.1:28332
We use the asyncio library here. `self.handle()` installs itself as a
future at the end of the function. Since it never returns with the event
@@ -47,16 +48,14 @@ class ZMQHandler():
self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "hashtx")
self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "rawblock")
self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "rawtx")
+ self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "sequence")
self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % port)
async def handle(self) :
- msg = await self.zmqSubSocket.recv_multipart()
- topic = msg[0]
- body = msg[1]
+ topic, body, seq = await self.zmqSubSocket.recv_multipart()
sequence = "Unknown"
- if len(msg[-1]) == 4:
- msgSequence = struct.unpack('<I', msg[-1])[-1]
- sequence = str(msgSequence)
+ if len(seq) == 4:
+ sequence = str(struct.unpack('<I', seq)[-1])
if topic == b"hashblock":
print('- HASH BLOCK ('+sequence+') -')
print(binascii.hexlify(body))
@@ -69,6 +68,12 @@ class ZMQHandler():
elif topic == b"rawtx":
print('- RAW TX ('+sequence+') -')
print(binascii.hexlify(body))
+ elif topic == b"sequence":
+ hash = binascii.hexlify(body[:32])
+ label = chr(body[32])
+ mempool_sequence = None if len(body) != 32+1+8 else struct.unpack("<Q", body[32+1:])[0]
+ print('- SEQUENCE ('+sequence+') -')
+ print(hash, label, mempool_sequence)
# schedule ourselves to receive the next message
asyncio.ensure_future(self.handle())