36 std::list<const CZMQAbstractNotifier*> result;
38 result.push_back(n.get());
45 std::map<std::string, CZMQNotifierFactory> factories;
46 factories[
"pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
47 factories[
"pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
48 factories[
"pubrawblock"] = [&get_block_by_index]() -> std::unique_ptr<CZMQAbstractNotifier> {
49 return std::make_unique<CZMQPublishRawBlockNotifier>(get_block_by_index);
51 factories[
"pubrawtx"] = CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
52 factories[
"pubsequence"] = CZMQAbstractNotifier::Create<CZMQPublishSequenceNotifier>;
54 std::list<std::unique_ptr<CZMQAbstractNotifier>>
notifiers;
55 for (
const auto& entry : factories)
57 std::string arg(
"-zmq" + entry.first);
58 const auto& factory = entry.second;
60 std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
61 notifier->SetType(entry.first);
62 notifier->SetAddress(address);
71 notificationInterface->notifiers = std::move(
notifiers);
73 if (notificationInterface->Initialize()) {
74 return notificationInterface;
84 int major = 0, minor = 0, patch = 0;
85 zmq_version(&major, &minor, &patch);
95 zmqError(
"Unable to initialize context");
100 if (notifier->Initialize(
pcontext)) {
101 LogPrint(
BCLog::ZMQ,
"Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
103 LogPrint(
BCLog::ZMQ,
"Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
118 LogPrint(
BCLog::ZMQ,
"Shutdown notifier %s at %s\n", notifier->GetType(), notifier->GetAddress());
119 notifier->Shutdown();
129 template <
typename Function>
130 void TryForEachAndRemoveFailed(std::list<std::unique_ptr<CZMQAbstractNotifier>>& notifiers,
const Function& func)
132 for (
auto i = notifiers.begin(); i != notifiers.end(); ) {
134 if (func(notifier)) {
138 i = notifiers.erase(i);
147 if (fInitialDownload || pindexNew == pindexFork)
std::shared_ptr< const CTransaction > CTransactionRef
void BlockDisconnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexDisconnected) override
Notifies listeners of a block being disconnected.
#define LogPrint(category,...)
std::unique_ptr< CZMQNotificationInterface > g_zmq_notification_interface
void TransactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Notifies listeners of a transaction having been added to mempool.
virtual bool NotifyBlockDisconnect(const CBlockIndex *pindex)
virtual bool NotifyBlock(const CBlockIndex *pindex)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
std::list< std::unique_ptr< CZMQAbstractNotifier > > notifiers
virtual bool NotifyTransactionRemoval(const CTransaction &transaction, uint64_t mempool_sequence)
void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Notifies listeners of a transaction leaving mempool.
virtual bool NotifyBlockConnect(const CBlockIndex *pindex)
virtual bool NotifyTransaction(const CTransaction &transaction)
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
virtual ~CZMQNotificationInterface()
static std::unique_ptr< CZMQNotificationInterface > Create(std::function< bool(CBlock &, const CBlockIndex &)> get_block_by_index)
static const int DEFAULT_ZMQ_SNDHWM
void zmqError(const std::string &str)
void BlockConnected(ChainstateRole role, const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override
Notifies listeners of a block being connected.
virtual void Shutdown()=0
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
The block chain is a tree shaped structure starting with the genesis block at the root...
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
virtual bool NotifyTransactionAcceptance(const CTransaction &transaction, uint64_t mempool_sequence)
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
CZMQNotificationInterface()
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.