Line data Source code
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_ZMQPUBLISHNOTIFIER_H
6 : #define BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H
7 :
8 : #include <zmq/zmqabstractnotifier.h>
9 :
10 : #include <cstddef>
11 : #include <cstdint>
12 : #include <functional>
13 : #include <vector>
14 :
15 : class CBlockIndex;
16 : class CTransaction;
17 :
18 18 : class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
19 : {
20 : private:
21 : uint32_t nSequence {0U}; //!< upcounting per message sequence number
22 :
23 : public:
24 :
25 : /* send zmq multipart message
26 : parts:
27 : * command
28 : * data
29 : * message sequence number
30 : */
31 : bool SendZmqMessage(const char *command, const void* data, size_t size);
32 :
33 : bool Initialize(void *pcontext) override;
34 : void Shutdown() override;
35 : };
36 :
37 5 : class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier
38 : {
39 : public:
40 : bool NotifyBlock(const CBlockIndex *pindex) override;
41 : };
42 :
43 5 : class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
44 : {
45 : public:
46 : bool NotifyTransaction(const CTransaction &transaction) override;
47 : };
48 :
49 : class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
50 : {
51 : private:
52 : const std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> m_get_block_by_index;
53 :
54 : public:
55 2 : CZMQPublishRawBlockNotifier(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index)
56 2 : : m_get_block_by_index{std::move(get_block_by_index)} {}
57 : bool NotifyBlock(const CBlockIndex *pindex) override;
58 : };
59 :
60 4 : class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier
61 : {
62 : public:
63 : bool NotifyTransaction(const CTransaction &transaction) override;
64 : };
65 :
66 2 : class CZMQPublishSequenceNotifier : public CZMQAbstractPublishNotifier
67 : {
68 : public:
69 : bool NotifyBlockConnect(const CBlockIndex *pindex) override;
70 : bool NotifyBlockDisconnect(const CBlockIndex *pindex) override;
71 : bool NotifyTransactionAcceptance(const CTransaction &transaction, uint64_t mempool_sequence) override;
72 : bool NotifyTransactionRemoval(const CTransaction &transaction, uint64_t mempool_sequence) override;
73 : };
74 :
75 : #endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H
|