Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zmq #2

Closed
wants to merge 10 commits into from
Closed
5 changes: 4 additions & 1 deletion src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i go with this, need to remove the one in ProcessVote

}
else {
LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what());
Expand Down Expand Up @@ -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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tobe reverted in cleanup PR

GetMainSignals().NotifyGovernanceObject(govobj);


Expand Down
6 changes: 6 additions & 0 deletions src/validationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already included, ignoring

}

void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
Expand All @@ -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));
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already included

}

void UnregisterAllValidationInterfaces() {
Expand All @@ -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();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already included

}
4 changes: 2 additions & 2 deletions src/zmq/zmqabstractnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/zmq/zmqnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create()
factories["pubrawtxlock"] = CZMQAbstractNotifier::Create<CZMQPublishRawTransactionLockNotifier>;
factories["pubhashgovernancevote"] = CZMQAbstractNotifier::Create<CZMQPublishHashGovernanceVoteNotifier>;
factories["pubhashgovernanceobject"] = CZMQAbstractNotifier::Create<CZMQPublishHashGovernanceObjectNotifier>;
factories["pubrawgovernanceobject"] = CZMQAbstractNotifier::Create<CZMQPublishRawGovernanceObjectNotifier>;
factories["pubrawgovernancevote"] = CZMQAbstractNotifier::Create<CZMQPublishRawGovernanceVoteNotifier>;

for (std::map<std::string, CZMQNotifierFactory>::const_iterator it = factories.begin(); it != factories.end(); ++it)
{
Expand Down
2 changes: 1 addition & 1 deletion src/zmq/zmqnotificationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo in formatting pr

void NotifyGovernanceVote(const CGovernanceVote& vote) override;
void NotifyGovernanceObject(const CGovernanceObject& object) override;

Expand Down
24 changes: 22 additions & 2 deletions src/zmq/zmqpublishnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ static std::multimap<std::string, CZMQAbstractPublishNotifier*> 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";
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorten to *MSG_RAWG****



// Internal function to send multipart message
Expand Down Expand Up @@ -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());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg_rawgobject

}

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());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg_rawgvote

}
16 changes: 15 additions & 1 deletion src/zmq/zmqpublishnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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