38 std::list<const CZMQAbstractNotifier*> result;
40 result.push_back(n.get());
47 std::map<std::string, CZMQNotifierFactory> factories;
48 factories[
"pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
49 factories[
"pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
50 factories[
"pubrawblock"] = [&get_block_by_index]() -> std::unique_ptr<CZMQAbstractNotifier> {
51 return std::make_unique<CZMQPublishRawBlockNotifier>(get_block_by_index);
53 factories[
"pubrawtx"] = CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
54 factories[
"pubsequence"] = CZMQAbstractNotifier::Create<CZMQPublishSequenceNotifier>;
56 std::list<std::unique_ptr<CZMQAbstractNotifier>>
notifiers;
57 for (
const auto& entry : factories)
59 std::string arg(
"-zmq" + entry.first);
60 const auto& factory = entry.second;
67 std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
68 notifier->SetType(entry.first);
69 notifier->SetAddress(address);
78 notificationInterface->notifiers = std::move(
notifiers);
80 if (notificationInterface->Initialize()) {
81 return notificationInterface;
91 int major = 0, minor = 0, patch = 0;
92 zmq_version(&major, &minor, &patch);
102 zmqError(
"Unable to initialize context");
107 if (notifier->Initialize(
pcontext)) {
108 LogPrint(
BCLog::ZMQ,
"Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
110 LogPrint(
BCLog::ZMQ,
"Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
125 LogPrint(
BCLog::ZMQ,
"Shutdown notifier %s at %s\n", notifier->GetType(), notifier->GetAddress());
126 notifier->Shutdown();
136 template <
typename Function>
137 void TryForEachAndRemoveFailed(std::list<std::unique_ptr<CZMQAbstractNotifier>>& notifiers,
const Function& func)
139 for (
auto i = notifiers.begin(); i != notifiers.end(); ) {
141 if (func(notifier)) {
145 i = notifiers.erase(i);
154 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)
static std::unique_ptr< CZMQNotificationInterface > Create(std::function< bool(std::vector< uint8_t > &, const CBlockIndex &)> get_block_by_index)
void TransactionAddedToMempool(const NewMempoolTransactionInfo &tx, uint64_t mempool_sequence) override
Notifies listeners of a transaction having been added to mempool.
virtual ~CZMQNotificationInterface()
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 Provides the block that was disconnected.
CZMQNotificationInterface()
void BlockConnected(ChainstateRole role, const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override
Notifies listeners of a block being connected.
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
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
#define LogPrint(category,...)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
const std::string ADDR_PREFIX_UNIX
Prefix for unix domain socket addresses (which are local filesystem paths)
std::shared_ptr< const CTransaction > CTransactionRef
const CTransactionRef m_tx
std::unique_ptr< CZMQNotificationInterface > g_zmq_notification_interface
void zmqError(const std::string &str)
const std::string ADDR_PREFIX_IPC
Prefix for unix domain socket addresses (which are local filesystem paths)