zmqabstractnotifier.h raw
1 // Copyright (c) 2015-2022 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_ZMQABSTRACTNOTIFIER_H
6 #define LIMENKA_ZMQ_ZMQABSTRACTNOTIFIER_H
7
8 #include <cstdint>
9 #include <functional>
10 #include <memory>
11 #include <string>
12
13 class CBlockIndex;
14 class CTransaction;
15 class CZMQAbstractNotifier;
16 class uint256;
17
18 using CZMQNotifierFactory = std::function<std::unique_ptr<CZMQAbstractNotifier>()>;
19
20 class CZMQAbstractNotifier
21 {
22 public:
23 static const int DEFAULT_ZMQ_SNDHWM {1000};
24
25 CZMQAbstractNotifier() : outbound_message_high_water_mark(DEFAULT_ZMQ_SNDHWM) {}
26 virtual ~CZMQAbstractNotifier();
27
28 template <typename T>
29 static std::unique_ptr<CZMQAbstractNotifier> Create()
30 {
31 return std::make_unique<T>();
32 }
33
34 std::string GetType() const { return type; }
35 void SetType(const std::string &t) { type = t; }
36 std::string GetAddress() const { return address; }
37 void SetAddress(const std::string &a) { address = a; }
38 int GetOutboundMessageHighWaterMark() const { return outbound_message_high_water_mark; }
39 void SetOutboundMessageHighWaterMark(const int sndhwm) {
40 if (sndhwm >= 0) {
41 outbound_message_high_water_mark = sndhwm;
42 }
43 }
44
45 virtual bool Initialize(void *pcontext) = 0;
46 virtual void Shutdown() = 0;
47
48 // Notifies of ConnectTip result, i.e., new active tip only
49 virtual bool NotifyBlock(const CBlockIndex *pindex);
50 // Notifies of every block connection
51 virtual bool NotifyBlockConnect(const CBlockIndex *pindex);
52 // Notifies of every block disconnection
53 virtual bool NotifyBlockDisconnect(const CBlockIndex *pindex);
54 // Notifies of every mempool acceptance
55 virtual bool NotifyTransactionAcceptance(const CTransaction &transaction, uint64_t mempool_sequence);
56 // Notifies of every mempool removal, except inclusion in blocks
57 virtual bool NotifyTransactionRemoval(const CTransaction &transaction, uint64_t mempool_sequence);
58 // Notifies of transactions added to mempool or appearing in blocks
59 virtual bool NotifyTransaction(const CTransaction &transaction);
60 virtual bool NotifyWalletTransaction(const CTransaction &transaction, const uint256 &hashBlock);
61
62 protected:
63 void* psocket{nullptr};
64 std::string type;
65 std::string address;
66 int outbound_message_high_water_mark; // aka SNDHWM
67 };
68
69 #endif // LIMENKA_ZMQ_ZMQABSTRACTNOTIFIER_H
70