From 339be11fb21196581d0ca1bdd72aae4c92a6e9ad Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 11 Jul 2016 19:59:53 +0300 Subject: [PATCH] implement zmqpubrawtxlock --- doc/zmq.md | 1 + src/init.cpp | 1 + src/instantx.cpp | 2 +- src/validationinterface.h | 4 ++-- src/zmq/zmqabstractnotifier.cpp | 2 +- src/zmq/zmqabstractnotifier.h | 2 +- src/zmq/zmqnotificationinterface.cpp | 5 +++-- src/zmq/zmqnotificationinterface.h | 2 +- src/zmq/zmqpublishnotifier.cpp | 13 ++++++++++++- src/zmq/zmqpublishnotifier.h | 8 +++++++- 10 files changed, 30 insertions(+), 10 deletions(-) diff --git a/doc/zmq.md b/doc/zmq.md index 13a0870951..f85c338b71 100644 --- a/doc/zmq.md +++ b/doc/zmq.md @@ -61,6 +61,7 @@ Currently, the following notifications are supported: -zmqpubhashblock=address -zmqpubrawblock=address -zmqpubrawtx=address + -zmqpubrawtxlock=address The socket type is PUB and the address must be a valid ZeroMQ socket address. The same address can be used in more than one notification. diff --git a/src/init.cpp b/src/init.cpp index cca8aec8bb..2f4a2c518a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -484,6 +484,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-zmqpubhashtxlock=
", _("Enable publish hash transaction (locked via InstantSend) in
")); strUsage += HelpMessageOpt("-zmqpubrawblock=
", _("Enable publish raw block in
")); strUsage += HelpMessageOpt("-zmqpubrawtx=
", _("Enable publish raw transaction in
")); + strUsage += HelpMessageOpt("-zmqpubrawtxlock=
", _("Enable publish raw transaction (locked via InstantSend) in
")); #endif strUsage += HelpMessageGroup(_("Debugging/Testing options:")); diff --git a/src/instantx.cpp b/src/instantx.cpp index efbc0ee514..928658fbbd 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -406,7 +406,7 @@ void UpdateLockedTransaction(CTransaction& tx, bool fForceNotification) { #endif if(nSignatures == INSTANTX_SIGNATURES_REQUIRED || (fForceNotification && nSignatures > INSTANTX_SIGNATURES_REQUIRED)) { - GetMainSignals().NotifyTransactionLock(txHash); + GetMainSignals().NotifyTransactionLock(tx); } } diff --git a/src/validationinterface.h b/src/validationinterface.h index f936d3a1e5..d621fd709a 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -33,7 +33,7 @@ class CValidationInterface { protected: virtual void UpdatedBlockTip(const CBlockIndex *pindex) {} virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {} - virtual void NotifyTransactionLock(const uint256 &hash) {} + virtual void NotifyTransactionLock(const CTransaction &tx) {} virtual void SetBestChain(const CBlockLocator &locator) {} virtual bool UpdatedTransaction(const uint256 &hash) { return false;} virtual void Inventory(const uint256 &hash) {} @@ -52,7 +52,7 @@ struct CMainSignals { /** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */ boost::signals2::signal SyncTransaction; /** Notifies listeners of an updated transaction lock without new data. */ - boost::signals2::signal NotifyTransactionLock; + boost::signals2::signal NotifyTransactionLock; /** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */ boost::signals2::signal UpdatedTransaction; /** Notifies listeners of a new active block chain. */ diff --git a/src/zmq/zmqabstractnotifier.cpp b/src/zmq/zmqabstractnotifier.cpp index 0369ced683..76543a4a79 100644 --- a/src/zmq/zmqabstractnotifier.cpp +++ b/src/zmq/zmqabstractnotifier.cpp @@ -21,7 +21,7 @@ bool CZMQAbstractNotifier::NotifyTransaction(const CTransaction &/*transaction*/ return true; } -bool CZMQAbstractNotifier::NotifyTransactionLock(const uint256 &/*hash*/) +bool CZMQAbstractNotifier::NotifyTransactionLock(const CTransaction &/*transaction*/) { return true; } diff --git a/src/zmq/zmqabstractnotifier.h b/src/zmq/zmqabstractnotifier.h index 9f52ba720f..0d3f1fcd4e 100644 --- a/src/zmq/zmqabstractnotifier.h +++ b/src/zmq/zmqabstractnotifier.h @@ -34,7 +34,7 @@ public: virtual bool NotifyBlock(const CBlockIndex *pindex); virtual bool NotifyTransaction(const CTransaction &transaction); - virtual bool NotifyTransactionLock(const uint256 &hash); + virtual bool NotifyTransactionLock(const CTransaction &transaction); protected: void *psocket; diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 21265bf62d..a8d3b2b892 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -40,6 +40,7 @@ CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const factories["pubhashtxlock"] = CZMQAbstractNotifier::Create; factories["pubrawblock"] = CZMQAbstractNotifier::Create; factories["pubrawtx"] = CZMQAbstractNotifier::Create; + factories["pubrawtxlock"] = CZMQAbstractNotifier::Create; for (std::map::const_iterator i=factories.begin(); i!=factories.end(); ++i) { @@ -160,12 +161,12 @@ void CZMQNotificationInterface::SyncTransaction(const CTransaction &tx, const CB } } -void CZMQNotificationInterface::NotifyTransactionLock(const uint256 &hash) +void CZMQNotificationInterface::NotifyTransactionLock(const CTransaction &tx) { for (std::list::iterator i = notifiers.begin(); i!=notifiers.end(); ) { CZMQAbstractNotifier *notifier = *i; - if (notifier->NotifyTransactionLock(hash)) + if (notifier->NotifyTransactionLock(tx)) { i++; } diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index e37073f5f6..11d4db83dd 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -26,7 +26,7 @@ protected: // CValidationInterface void SyncTransaction(const CTransaction &tx, const CBlock *pblock); void UpdatedBlockTip(const CBlockIndex *pindex); - void NotifyTransactionLock(const uint256 &hash); + void NotifyTransactionLock(const CTransaction &tx); private: CZMQNotificationInterface(); diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index e5109ae382..07f0167be8 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -139,8 +139,9 @@ bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &t return rc == 0; } -bool CZMQPublishHashTransactionLockNotifier::NotifyTransactionLock(const uint256 &hash) +bool CZMQPublishHashTransactionLockNotifier::NotifyTransactionLock(const CTransaction &transaction) { + uint256 hash = transaction.GetHash(); LogPrint("zmq", "zmq: Publish hashtxlock %s\n", hash.GetHex()); char data[32]; for (unsigned int i = 0; i < 32; i++) @@ -180,3 +181,13 @@ bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &tr int rc = zmq_send_multipart(psocket, "rawtx", 5, &(*ss.begin()), ss.size(), 0); return rc == 0; } + +bool CZMQPublishRawTransactionLockNotifier::NotifyTransactionLock(const CTransaction &transaction) +{ + uint256 hash = transaction.GetHash(); + LogPrint("zmq", "zmq: Publish rawtxlock %s\n", hash.GetHex()); + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << transaction; + int rc = zmq_send_multipart(psocket, "rawtxlock", 9, &(*ss.begin()), ss.size(), 0); + return rc == 0; +} diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h index 4d805657ce..c921504725 100644 --- a/src/zmq/zmqpublishnotifier.h +++ b/src/zmq/zmqpublishnotifier.h @@ -31,7 +31,7 @@ public: class CZMQPublishHashTransactionLockNotifier : public CZMQAbstractPublishNotifier { public: - bool NotifyTransactionLock(const uint256 &hash); + bool NotifyTransactionLock(const CTransaction &transaction); }; class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier @@ -46,4 +46,10 @@ public: bool NotifyTransaction(const CTransaction &transaction); }; +class CZMQPublishRawTransactionLockNotifier : public CZMQAbstractPublishNotifier +{ +public: + bool NotifyTransactionLock(const CTransaction &transaction); +}; + #endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H