23std::list<const CZMQAbstractNotifier *>
25 std::list<const CZMQAbstractNotifier *> result;
27 result.push_back(n.get());
34 std::map<std::string, CZMQNotifierFactory> factories;
35 factories[
"pubhashblock"] =
36 CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
37 factories[
"pubhashtx"] =
38 CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
39 factories[
"pubrawblock"] =
40 [&get_block_by_index]() -> std::unique_ptr<CZMQAbstractNotifier> {
41 return std::make_unique<CZMQPublishRawBlockNotifier>(
44 factories[
"pubrawtx"] =
45 CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
46 factories[
"pubsequence"] =
47 CZMQAbstractNotifier::Create<CZMQPublishSequenceNotifier>;
49 std::list<std::unique_ptr<CZMQAbstractNotifier>>
notifiers;
50 for (
const auto &entry : factories) {
51 std::string arg(
"-zmq" + entry.first);
52 const auto &factory = entry.second;
61 std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
62 notifier->SetType(entry.first);
63 notifier->SetAddress(address);
64 notifier->SetOutboundMessageHighWaterMark(
72 std::unique_ptr<CZMQNotificationInterface> notificationInterface(
74 notificationInterface->notifiers = std::move(
notifiers);
76 if (notificationInterface->Initialize()) {
77 return notificationInterface;
86 int major = 0, minor = 0, patch = 0;
87 zmq_version(&major, &minor, &patch);
96 zmqError(
"Unable to initialize context");
101 if (notifier->Initialize(
pcontext)) {
103 notifier->GetType(), notifier->GetAddress());
106 notifier->GetType(), notifier->GetAddress());
120 notifier->GetType(), notifier->GetAddress());
121 notifier->Shutdown();
131template <
typename Function>
132void TryForEachAndRemoveFailed(
133 std::list<std::unique_ptr<CZMQAbstractNotifier>> ¬ifiers,
134 const Function &func) {
135 for (
auto i = notifiers.begin(); i != notifiers.end();) {
137 if (func(notifier)) {
141 i = notifiers.erase(i);
150 bool fInitialDownload) {
152 if (fInitialDownload || pindexNew == pindexFork) {
164 uint64_t mempool_sequence) {
165 const CTransaction &tx = *ptx;
167 TryForEachAndRemoveFailed(
176 uint64_t mempool_sequence) {
178 const CTransaction &tx = *ptx;
180 TryForEachAndRemoveFailed(
193 const CTransaction &tx = *ptx;
201 TryForEachAndRemoveFailed(
208 const std::shared_ptr<const CBlock> &pblock,
211 const CTransaction &tx = *ptx;
219 TryForEachAndRemoveFailed(
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,...
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)
void TransactionAddedToMempool(const CTransactionRef &tx, std::shared_ptr< const std::vector< Coin > >, uint64_t mempool_sequence) override
Notifies listeners of a transaction having been added to mempool.
static std::unique_ptr< CZMQNotificationInterface > Create(std::function< bool(CBlock &, const CBlockIndex &)> get_block_by_index)
~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.
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,...)
const std::string ADDR_PREFIX_UNIX
Prefix for unix domain socket addresses (which are local filesystem paths)
std::shared_ptr< const CTransaction > CTransactionRef
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
std::unique_ptr< CZMQNotificationInterface > g_zmq_notification_interface
void zmqError(const char *str)
const std::string ADDR_PREFIX_IPC
Prefix for unix domain socket addresses (which are local filesystem paths) Used by libzmq,...