zmqnotificationinterface.h raw

   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  
   8  #include <primitives/transaction.h>
   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;
  19  class CZMQAbstractNotifier;
  20  
  21  class CZMQNotificationInterface final : public CValidationInterface
  22  {
  23  public:
  24      ~CZMQNotificationInterface();
  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:
  42      CZMQNotificationInterface();
  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
  51