21std::list<const CZMQAbstractNotifier *>
23 std::list<const CZMQAbstractNotifier *> result;
25 result.push_back(n.get());
32 std::map<std::string, CZMQNotifierFactory> factories;
33 factories[
"pubhashblock"] =
34 CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
35 factories[
"pubhashtx"] =
36 CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
37 factories[
"pubrawblock"] =
38 [&get_block_by_index]() -> std::unique_ptr<CZMQAbstractNotifier> {
39 return std::make_unique<CZMQPublishRawBlockNotifier>(
42 factories[
"pubrawtx"] =
43 CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
44 factories[
"pubsequence"] =
45 CZMQAbstractNotifier::Create<CZMQPublishSequenceNotifier>;
47 std::list<std::unique_ptr<CZMQAbstractNotifier>>
notifiers;
48 for (
const auto &entry : factories) {
49 std::string arg(
"-zmq" + entry.first);
50 const auto &factory = entry.second;
52 std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
53 notifier->SetType(entry.first);
54 notifier->SetAddress(address);
55 notifier->SetOutboundMessageHighWaterMark(
63 std::unique_ptr<CZMQNotificationInterface> notificationInterface(
65 notificationInterface->notifiers = std::move(
notifiers);
67 if (notificationInterface->Initialize()) {
68 return notificationInterface;
77 int major = 0, minor = 0, patch = 0;
78 zmq_version(&major, &minor, &patch);
87 zmqError(
"Unable to initialize context");
92 if (notifier->Initialize(
pcontext)) {
94 notifier->GetType(), notifier->GetAddress());
97 notifier->GetType(), notifier->GetAddress());
111 notifier->GetType(), notifier->GetAddress());
112 notifier->Shutdown();
122template <
typename Function>
123void TryForEachAndRemoveFailed(
124 std::list<std::unique_ptr<CZMQAbstractNotifier>> ¬ifiers,
125 const Function &func) {
126 for (
auto i = notifiers.begin(); i != notifiers.end();) {
128 if (func(notifier)) {
132 i = notifiers.erase(i);
141 bool fInitialDownload) {
143 if (fInitialDownload || pindexNew == pindexFork) {
155 uint64_t mempool_sequence) {
156 const CTransaction &tx = *ptx;
158 TryForEachAndRemoveFailed(
167 uint64_t mempool_sequence) {
169 const CTransaction &tx = *ptx;
171 TryForEachAndRemoveFailed(
178 const std::shared_ptr<const CBlock> &pblock,
181 const CTransaction &tx = *ptx;
189 TryForEachAndRemoveFailed(
196 const std::shared_ptr<const CBlock> &pblock,
199 const CTransaction &tx = *ptx;
207 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)
virtual ~CZMQNotificationInterface()
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override
Notifies listeners of a block being connected.
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.
std::unique_ptr< CZMQNotificationInterface > g_zmq_notification_interface
void zmqError(const char *str)