22std::list<const CZMQAbstractNotifier *>
24 std::list<const CZMQAbstractNotifier *> result;
26 result.push_back(n.get());
33 std::map<std::string, CZMQNotifierFactory> factories;
34 factories[
"pubhashblock"] =
35 CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
36 factories[
"pubhashtx"] =
37 CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
38 factories[
"pubrawblock"] =
39 [&get_block_by_index]() -> std::unique_ptr<CZMQAbstractNotifier> {
40 return std::make_unique<CZMQPublishRawBlockNotifier>(
43 factories[
"pubrawtx"] =
44 CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
45 factories[
"pubsequence"] =
46 CZMQAbstractNotifier::Create<CZMQPublishSequenceNotifier>;
48 std::list<std::unique_ptr<CZMQAbstractNotifier>>
notifiers;
49 for (
const auto &entry : factories) {
50 std::string arg(
"-zmq" + entry.first);
51 const auto &factory = entry.second;
53 std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
54 notifier->SetType(entry.first);
55 notifier->SetAddress(address);
56 notifier->SetOutboundMessageHighWaterMark(
64 std::unique_ptr<CZMQNotificationInterface> notificationInterface(
66 notificationInterface->notifiers = std::move(
notifiers);
68 if (notificationInterface->Initialize()) {
69 return notificationInterface;
78 int major = 0, minor = 0, patch = 0;
79 zmq_version(&major, &minor, &patch);
88 zmqError(
"Unable to initialize context");
93 if (notifier->Initialize(
pcontext)) {
95 notifier->GetType(), notifier->GetAddress());
98 notifier->GetType(), notifier->GetAddress());
112 notifier->GetType(), notifier->GetAddress());
113 notifier->Shutdown();
123template <
typename Function>
124void TryForEachAndRemoveFailed(
125 std::list<std::unique_ptr<CZMQAbstractNotifier>> ¬ifiers,
126 const Function &func) {
127 for (
auto i = notifiers.begin(); i != notifiers.end();) {
129 if (func(notifier)) {
133 i = notifiers.erase(i);
142 bool fInitialDownload) {
144 if (fInitialDownload || pindexNew == pindexFork) {
156 uint64_t mempool_sequence) {
157 const CTransaction &tx = *ptx;
159 TryForEachAndRemoveFailed(
168 uint64_t mempool_sequence) {
170 const CTransaction &tx = *ptx;
172 TryForEachAndRemoveFailed(
185 const CTransaction &tx = *ptx;
193 TryForEachAndRemoveFailed(
200 const std::shared_ptr<const CBlock> &pblock,
203 const CTransaction &tx = *ptx;
211 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 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,...)
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)