Bitcoin Core  31.0.0
P2P Digital Currency
zmqnotificationinterface.h
Go to the documentation of this file.
1 // Copyright (c) 2015-present 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 <cstddef>
12 #include <cstdint>
13 #include <functional>
14 #include <list>
15 #include <memory>
16 #include <vector>
17 
18 class CBlockIndex;
20 
22 {
23 public:
25 
26  std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
27 
28  static std::unique_ptr<CZMQNotificationInterface> Create(std::function<bool(std::vector<std::byte>&, const CBlockIndex&)> get_block_by_index);
29 
30 protected:
31  bool Initialize();
32  void Shutdown();
33 
34  // CValidationInterface
35  void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override;
36  void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
37  void BlockConnected(const kernel::ChainstateRole& role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
38  void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
39  void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
40 
41 private:
43 
44  void* pcontext{nullptr};
45  std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
46 };
47 
48 extern std::unique_ptr<CZMQNotificationInterface> g_zmq_notification_interface;
49 
50 #endif // BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
void BlockDisconnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexDisconnected) override
Notifies listeners of a block being disconnected Provides the block that was disconnected.
void BlockConnected(const kernel::ChainstateRole &role, const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexConnected) override
Notifies listeners of a block being connected.
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Information about chainstate that notifications are sent from.
Definition: types.h:18
std::list< std::unique_ptr< CZMQAbstractNotifier > > notifiers
Implement this to subscribe to events generated in validation and mempool.
void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Notifies listeners of a transaction leaving mempool.
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
void TransactionAddedToMempool(const NewMempoolTransactionInfo &tx, uint64_t mempool_sequence) override
Notifies listeners of a transaction having been added to mempool.
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:93
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
std::unique_ptr< CZMQNotificationInterface > g_zmq_notification_interface
static std::unique_ptr< CZMQNotificationInterface > Create(std::function< bool(std::vector< std::byte > &, const CBlockIndex &)> get_block_by_index)