2 # Copyright (c) 2014-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
13 zmqContext
= zmq
.Context()
14 zmqSubSocket
= zmqContext
.socket(zmq
.SUB
)
15 zmqSubSocket
.setsockopt(zmq
.SUBSCRIBE
, "hashblock")
16 zmqSubSocket
.setsockopt(zmq
.SUBSCRIBE
, "hashtx")
17 zmqSubSocket
.setsockopt(zmq
.SUBSCRIBE
, "rawblock")
18 zmqSubSocket
.setsockopt(zmq
.SUBSCRIBE
, "rawtx")
19 zmqSubSocket
.connect("tcp://127.0.0.1:%i" % port
)
23 msg
= zmqSubSocket
.recv_multipart()
28 msgSequence
= struct
.unpack('<I', msg
[-1])[-1]
29 sequence
= str(msgSequence
)
30 if topic
== "hashblock":
31 print '- HASH BLOCK ('+sequence
+') -'
32 print binascii
.hexlify(body
)
33 elif topic
== "hashtx":
34 print '- HASH TX ('+sequence
+') -'
35 print binascii
.hexlify(body
)
36 elif topic
== "rawblock":
37 print '- RAW BLOCK HEADER ('+sequence
+') -'
38 print binascii
.hexlify(body
[:80])
39 elif topic
== "rawtx":
40 print '- RAW TX ('+sequence
+') -'
41 print binascii
.hexlify(body
)
43 except KeyboardInterrupt: