dash/contrib/zmq/zmq_sub.py
PaulieD 0e689341d2 Implement Governance ZMQ notification messages (#2160)
* fix whitespace

* added zmq stuff for governance objects and votes
it seems that zmq is currently not in a working state, need to figure that out.

Need to:
plug in the new methods added
possibly plug in the old methods, as it doesn't look like they are.

* formatting fix. Will probably need to revert for this PR

* continue linking new zmq messages in

* added comment, might need to revert

* fixes error of it not knowing about the classes

* Actually link in, all new govobjects and govvotes should be broadcast over zmq now.

* fix compile error, forgot to change params when copying

* fix compile error

* add imports to the header files in zmqconfig.h

* fixing linking(i think) error

* Revert "added comment, might need to revert"

This reverts commit 2918ea40fe.

* Revert "formatting fix. Will probably need to revert for this PR"

This reverts commit ca10558866.

* fix tabs etc

* EOL added

* optimization of hash.begin() @nmarley thoughts?

* remove formatting changes

* iterator i -> it and removal of notifier

* typo in df879f57

* use auto for the iterators

* introduce hash prefix

* implement changes in zmq_sub.py, update the doc, and change argument name to fix typo

* deref iterators before calling methods

* continued e8a4c505

* missed one... continued e8a4c505

* killing some tabs

* fix spacing for setting or comparing iterators

* change order of new variables to match current setup

* re-add elif's I didn't realize got removed

* Revert "fix spacing for setting or comparing iterators"

This reverts commit 8ce2068148.

* Revert "use auto for the iterators"

This reverts commit cb16cf0760.

* Revert "missed one... continued e8a4c505"

This reverts commit 2087cf894f.

* Revert "continued e8a4c505"

This reverts commit a78c8ad2c9.

* Revert "deref iterators before calling methods"

This reverts commit e8a4c505d1.

* Revert "iterator i -> it and removal of notifier"

This reverts commit 29574248b1.

* Revert "fix whitespace"

This reverts commit 612be48d96.

* Revert "typo in df879f5"

* Revert "Optimization of hash.begin()"

* fixes problem with revert

* Udjin complain's a lot ;)

* help text, init.cpp

* add signals in validationinterface.cpp

* Change location of vote notification call.

* remain consistent

* remove unneeded include due to change of notification location

* implement raw notifications
2018-07-12 12:06:30 +03:00

71 lines
2.7 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright (c) 2014-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
import binascii
import zmq
import struct
port = 28332
zmqContext = zmq.Context()
zmqSubSocket = zmqContext.socket(zmq.SUB)
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtxlock")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashgovernancevote")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashgovernanceobject")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawblock")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawtx")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawtxlock")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawgovernancevote")
zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawgovernanceobject")
zmqSubSocket.connect("tcp://127.0.0.1:%i" % port)
try:
while True:
msg = zmqSubSocket.recv_multipart()
topic = str(msg[0].decode("utf-8"))
body = msg[1]
sequence = "Unknown"
if len(msg[-1]) == 4:
msgSequence = struct.unpack('<I', msg[-1])[-1]
sequence = str(msgSequence)
if topic == "hashblock":
print('- HASH BLOCK ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "hashtx":
print ('- HASH TX ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "hashtxlock":
print('- HASH TX LOCK ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "rawblock":
print('- RAW BLOCK HEADER ('+sequence+') -')
print(binascii.hexlify(body[:80]).decode("utf-8"))
elif topic == "rawtx":
print('- RAW TX ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "rawtxlock":
print('- RAW TX LOCK ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "hashgovernancevote":
print('- HASH GOVERNANCE VOTE ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "hashgovernanceobject":
print('- HASH GOVERNANCE OBJECT ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "rawgovernancevote":
print('- RAW GOVERNANCE VOTE ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
elif topic == "rawgovernanceobject":
print('- RAW GOVERNANCE OBJECT ('+sequence+') -')
print(binascii.hexlify(body).decode("utf-8"))
except KeyboardInterrupt:
zmqContext.destroy()