11#include <validation.h>
25 std::list<const CZMQAbstractNotifier*> result;
27 result.push_back(n.get());
34 std::map<std::string, CZMQNotifierFactory> factories;
35 factories[
"pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
36 factories[
"pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
37 factories[
"pubrawblock"] = CZMQAbstractNotifier::Create<CZMQPublishRawBlockNotifier>;
38 factories[
"pubrawtx"] = CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
39 factories[
"pubsequence"] = CZMQAbstractNotifier::Create<CZMQPublishSequenceNotifier>;
41 std::list<std::unique_ptr<CZMQAbstractNotifier>>
notifiers;
42 for (
const auto& entry : factories)
44 std::string arg(
"-zmq" + entry.first);
45 const auto& factory = entry.second;
47 std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
48 notifier->SetType(entry.first);
49 notifier->SetAddress(address);
58 notificationInterface->notifiers = std::move(
notifiers);
60 if (notificationInterface->Initialize()) {
61 return notificationInterface.release();
71 int major = 0, minor = 0, patch = 0;
72 zmq_version(&major, &minor, &patch);
82 zmqError(
"Unable to initialize context");
87 if (notifier->Initialize(
pcontext)) {
88 LogPrint(
BCLog::ZMQ,
"zmq: Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
90 LogPrint(
BCLog::ZMQ,
"zmq: Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
105 LogPrint(
BCLog::ZMQ,
"zmq: Shutdown notifier %s at %s\n", notifier->GetType(), notifier->GetAddress());
106 notifier->Shutdown();
116template <
typename Function>
117void TryForEachAndRemoveFailed(std::list<std::unique_ptr<CZMQAbstractNotifier>>& notifiers,
const Function& func)
119 for (
auto i = notifiers.begin(); i != notifiers.end(); ) {
121 if (func(notifier)) {
125 i = notifiers.erase(i);
134 if (fInitialDownload || pindexNew == pindexFork)
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
The block chain is a tree shaped structure starting with the genesis block at the root,...
The basic transaction that is broadcasted on the network and contained in blocks.
virtual void Shutdown()=0
virtual bool NotifyBlockConnect(const CBlockIndex *pindex)
static const int DEFAULT_ZMQ_SNDHWM
virtual bool NotifyTransactionRemoval(const CTransaction &transaction, uint64_t mempool_sequence)
virtual bool NotifyBlock(const CBlockIndex *pindex)
virtual bool NotifyTransaction(const CTransaction &transaction)
virtual bool NotifyBlockDisconnect(const CBlockIndex *pindex)
virtual bool NotifyTransactionAcceptance(const CTransaction &transaction, uint64_t mempool_sequence)
virtual ~CZMQNotificationInterface()
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override
Notifies listeners of a block being connected.
static CZMQNotificationInterface * Create()
void TransactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Notifies listeners of a transaction having been added to mempool.
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
std::list< std::unique_ptr< CZMQAbstractNotifier > > notifiers
void BlockDisconnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexDisconnected) override
Notifies listeners of a block being disconnected.
CZMQNotificationInterface()
void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Notifies listeners of a transaction leaving mempool.
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
#define LogPrint(category,...)
std::shared_ptr< const CTransaction > CTransactionRef
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
CZMQNotificationInterface * g_zmq_notification_interface
void zmqError(const std::string &str)