zmqnotificationinterface.h raw

   1  // Copyright (c) 2015-present The Limenka 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 LIMENKA_ZMQ_ZMQNOTIFICATIONINTERFACE_H
   6  #define LIMENKA_ZMQ_ZMQNOTIFICATIONINTERFACE_H
   7  
   8  #include <primitives/transaction.h>
   9  #include <validationinterface.h>
  10  
  11  #include <cstdint>
  12  #include <functional>
  13  #include <list>
  14  #include <memory>
  15  #include <vector>
  16  
  17  #include <boost/signals2/connection.hpp>
  18  
  19  class CBlock;
  20  class CBlockIndex;
  21  class CZMQAbstractNotifier;
  22  struct NewMempoolTransactionInfo;
  23  
  24  class CZMQNotificationInterface final : public CValidationInterface
  25  {
  26  public:
  27      ~CZMQNotificationInterface();
  28  
  29      std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
  30  
  31      static std::unique_ptr<CZMQNotificationInterface> Create(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index);
  32  
  33  protected:
  34      bool Initialize();
  35      void Shutdown();
  36  
  37      void TransactionAddedToWallet(const CTransactionRef& tx, const uint256 &hashBlock);
  38  
  39      // CValidationInterface
  40      void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override;
  41      void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
  42      void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
  43      void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
  44      void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
  45  
  46  private:
  47      CZMQNotificationInterface();
  48  
  49      void* pcontext{nullptr};
  50      std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
  51      boost::signals2::connection m_wtx_added_connection;
  52  };
  53  
  54  extern std::unique_ptr<CZMQNotificationInterface> g_zmq_notification_interface;
  55  
  56  #endif // LIMENKA_ZMQ_ZMQNOTIFICATIONINTERFACE_H
  57