diff --git a/src/governance.cpp b/src/governance.cpp index 51729541cb9ca..2184370a4e41d 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -256,6 +256,9 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- %s new\n", strHash); masternodeSync.BumpAssetLastTime("MNGOVERNANCEOBJECTVOTE"); vote.Relay(connman); + + // SEND NOTIFICATION TO ZMQ + GetMainSignals().NotifyGovernanceVote(vote); } else { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what()); @@ -362,7 +365,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman CGovernanceException exception; CheckOrphanVotes(govobj, exception, connman); - //Send notifications to scripts / zmq + // SEND NOTIFICATION TO ZMQ GetMainSignals().NotifyGovernanceObject(govobj); diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 56620c929479e..436cedf1019cb 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -26,6 +26,8 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.ScriptForMining.connect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1)); g_signals.BlockFound.connect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1)); g_signals.NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); + g_signals.NotifyGovernanceObject.connect(boost::bind(&CValidationInterface::NotifyGovernanceObject, pwalletIn, _1)); + g_signals.NotifyGovernanceVote.connect(boost::bind(&CValidationInterface::NotifyGovernanceVote, pwalletIn, _1)); } void UnregisterValidationInterface(CValidationInterface* pwalletIn) { @@ -42,6 +44,8 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.NewPoWValidBlock.disconnect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); g_signals.NotifyHeaderTip.disconnect(boost::bind(&CValidationInterface::NotifyHeaderTip, pwalletIn, _1, _2)); g_signals.AcceptedBlockHeader.disconnect(boost::bind(&CValidationInterface::AcceptedBlockHeader, pwalletIn, _1)); + g_signals.NotifyGovernanceObject.disconnect(boost::bind(&CValidationInterface::NotifyGovernanceObject, pwalletIn, _1)); + g_signals.NotifyGovernanceVote.disconnect(boost::bind(&CValidationInterface::NotifyGovernanceVote, pwalletIn, _1)); } void UnregisterAllValidationInterfaces() { @@ -58,4 +62,6 @@ void UnregisterAllValidationInterfaces() { g_signals.NewPoWValidBlock.disconnect_all_slots(); g_signals.NotifyHeaderTip.disconnect_all_slots(); g_signals.AcceptedBlockHeader.disconnect_all_slots(); + g_signals.NotifyGovernanceObject.disconnect_all_slots(); + g_signals.NotifyGovernanceVote.disconnect_all_slots(); } diff --git a/src/zmq/zmqabstractnotifier.h b/src/zmq/zmqabstractnotifier.h index e1e73011d24f6..ee6aa3ad7e2c7 100644 --- a/src/zmq/zmqabstractnotifier.h +++ b/src/zmq/zmqabstractnotifier.h @@ -37,8 +37,8 @@ class CZMQAbstractNotifier virtual bool NotifyBlock(const CBlockIndex *pindex); virtual bool NotifyTransaction(const CTransaction &transaction); virtual bool NotifyTransactionLock(const CTransaction &transaction); - virtual bool NotifyGovernanceVote(const CGovernanceVote& vote); - virtual bool NotifyGovernanceObject(const CGovernanceObject& object); + virtual bool NotifyGovernanceVote(const CGovernanceVote &vote); + virtual bool NotifyGovernanceObject(const CGovernanceObject &object); protected: diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 5766f3305191d..8f1453b725e8f 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -43,6 +43,8 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create() factories["pubrawtxlock"] = CZMQAbstractNotifier::Create; factories["pubhashgovernancevote"] = CZMQAbstractNotifier::Create; factories["pubhashgovernanceobject"] = CZMQAbstractNotifier::Create; + factories["pubrawgovernanceobject"] = CZMQAbstractNotifier::Create; + factories["pubrawgovernancevote"] = CZMQAbstractNotifier::Create; for (std::map::const_iterator it = factories.begin(); it != factories.end(); ++it) { diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index aeaed254a0073..164e41de96964 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -26,7 +26,7 @@ class CZMQNotificationInterface : public CValidationInterface // CValidationInterface void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, int posInBlock) override; void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override; - void NotifyTransactionLock(const CTransaction &tx) override; + void NotifyTransactionLock(const CTransaction& tx) override; void NotifyGovernanceVote(const CGovernanceVote& vote) override; void NotifyGovernanceObject(const CGovernanceObject& object) override; diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index 221652f2e4b78..fb3e4e47b200c 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -13,11 +13,13 @@ static std::multimap mapPublishNotifi static const char *MSG_HASHBLOCK = "hashblock"; static const char *MSG_HASHTX = "hashtx"; static const char *MSG_HASHTXLOCK = "hashtxlock"; +static const char *MSG_HASHGVOTE = "hashgovernancevote"; +static const char *MSG_HASHGOBJ = "hashgovernanceobject"; static const char *MSG_RAWBLOCK = "rawblock"; static const char *MSG_RAWTX = "rawtx"; static const char *MSG_RAWTXLOCK = "rawtxlock"; -static const char *MSG_HASHGVOTE = "hashgovernancevote"; -static const char *MSG_HASHGOBJ = "hashgovernanceobject"; +static const char *MSG_RAWGOVERNANCEOBJECT = "rawgovernanceobject"; +static const char *MSG_RAWGOVERNANCEVOTE = "rawgovernancevote"; // Internal function to send multipart message @@ -239,3 +241,21 @@ bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const CGove data[31 - i] = hashData[i]; return SendMessage(MSG_HASHGOBJ, data, 32); } + +bool CZMQPublishRawGovernanceObjectNotifier::NotifyGovernanceObject(const CGovernanceObject& govobj) +{ + uint256 nHash = govobj.GetHash(); + LogPrint("gobject", "gobject: Publish rawgovernanceobject: hash = %s, type = %d\n", nHash.ToString(), govobj.GetObjectType()); + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << govobj; + return SendMessage(MSG_RAWGOVERNANCEOBJECT, &(*ss.begin()), ss.size()); +} + +bool CZMQPublishRawGovernanceVoteNotifier::NotifyGovernanceVote(const CGovernanceVote& vote) +{ + uint256 nHash = vote.GetHash(); + LogPrint("gobject", "gobject: Publish rawgovernancevote: hash = %s, vote = %s\n", nHash.ToString(), vote.ToString()); + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << vote; + return SendMessage(MSG_RAWGOVERNANCEVOTE, &(*ss.begin()), ss.size()); +} \ No newline at end of file diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h index d2f3b8bec5422..3558cf5d82830 100644 --- a/src/zmq/zmqpublishnotifier.h +++ b/src/zmq/zmqpublishnotifier.h @@ -71,9 +71,23 @@ class CZMQPublishHashGovernanceVoteNotifier : public CZMQAbstractPublishNotifier public: bool NotifyGovernanceVote(const CGovernanceVote &vote) override; }; + class CZMQPublishHashGovernanceObjectNotifier : public CZMQAbstractPublishNotifier { public: bool NotifyGovernanceObject(const CGovernanceObject &object) override; }; -#endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H + +class CZMQPublishRawGovernanceObjectNotifier : public CZMQAbstractPublishNotifier +{ +public: + bool NotifyGovernanceObject(const CGovernanceObject &govobj); +}; + +class CZMQPublishRawGovernanceVoteNotifier : public CZMQAbstractPublishNotifier +{ +public: + bool NotifyGovernanceVote(const CGovernanceVote &vote); +}; + +#endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H \ No newline at end of file