Bitcoin Core  26.1.0
P2P Digital Currency
zmqnotificationinterface.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
6 #define BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
7 
9 #include <validationinterface.h>
10 
11 #include <cstdint>
12 #include <functional>
13 #include <list>
14 #include <memory>
15 
16 class CBlock;
17 class CBlockIndex;
19 
21 {
22 public:
24 
25  std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
26 
27  static std::unique_ptr<CZMQNotificationInterface> Create(std::function<bool(CBlock&, const CBlockIndex&)> get_block_by_index);
28 
29 protected:
30  bool Initialize();
31  void Shutdown();
32 
33  // CValidationInterface
34  void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) override;
35  void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
36  void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
37  void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
38  void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
39 
40 private:
42 
43  void* pcontext{nullptr};
44  std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
45 };
46 
47 extern std::unique_ptr<CZMQNotificationInterface> g_zmq_notification_interface;
48 
49 #endif // BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:421
void BlockDisconnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexDisconnected) override
Notifies listeners of a block being disconnected.
Definition: block.h:68
void TransactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Notifies listeners of a transaction having been added to mempool.
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
std::list< std::unique_ptr< CZMQAbstractNotifier > > notifiers
Implement this to subscribe to events generated in validation.
void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Notifies listeners of a transaction leaving mempool.
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
Definition: chain.h:25
static std::unique_ptr< CZMQNotificationInterface > Create(std::function< bool(CBlock &, const CBlockIndex &)> get_block_by_index)
void BlockConnected(ChainstateRole role, 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.
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:144
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
std::unique_ptr< CZMQNotificationInterface > g_zmq_notification_interface