Branch data Line data Source code
1 : : // Copyright (c) 2018-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 : : #include <zmq/zmqrpc.h>
6 : :
7 : : #include <rpc/server.h>
8 : : #include <rpc/util.h>
9 : : #include <zmq/zmqabstractnotifier.h>
10 : : #include <zmq/zmqnotificationinterface.h>
11 : :
12 : : #include <univalue.h>
13 : :
14 : : #include <list>
15 : : #include <string>
16 : :
17 : : class JSONRPCRequest;
18 : :
19 : : namespace {
20 : :
21 : 268 : static RPCHelpMan getzmqnotifications()
22 : : {
23 : 268 : return RPCHelpMan{
24 : : "getzmqnotifications",
25 : : "Returns information about the active ZeroMQ notifications.\n",
26 : : {},
27 : 0 : RPCResult{
28 : : RPCResult::Type::ARR, "", "",
29 : : {
30 : : {RPCResult::Type::OBJ, "", "",
31 : : {
32 : : {RPCResult::Type::STR, "type", "Type of notification"},
33 : : {RPCResult::Type::STR, "address", "Address of the publisher"},
34 : : {RPCResult::Type::NUM, "hwm", "Outbound message high water mark"},
35 : : }},
36 : : }
37 [ + - + - : 1876 : },
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + +
+ + - - -
- ]
38 : 268 : RPCExamples{
39 [ + - + - : 536 : HelpExampleCli("getzmqnotifications", "")
+ - ]
40 [ + - + - : 1072 : + HelpExampleRpc("getzmqnotifications", "")
+ - + - ]
41 [ + - ]: 268 : },
42 : 0 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
43 : : {
44 : 0 : UniValue result(UniValue::VARR);
45 [ # # ]: 0 : if (g_zmq_notification_interface != nullptr) {
46 [ # # # # ]: 0 : for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
47 : 0 : UniValue obj(UniValue::VOBJ);
48 [ # # # # : 0 : obj.pushKV("type", n->GetType());
# # # # ]
49 [ # # # # : 0 : obj.pushKV("address", n->GetAddress());
# # # # ]
50 [ # # # # : 0 : obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark());
# # ]
51 [ # # ]: 0 : result.push_back(std::move(obj));
52 : 0 : }
53 : : }
54 : :
55 : 0 : return result;
56 : 0 : },
57 [ + - + - : 1608 : };
+ - + - ]
58 [ + - + - : 1340 : }
+ - + - +
- - - ]
59 : :
60 : : const CRPCCommand commands[]{
61 : : {"zmq", &getzmqnotifications},
62 : : };
63 : :
64 : : } // anonymous namespace
65 : :
66 : 0 : void RegisterZMQRPCCommands(CRPCTable& t)
67 : : {
68 [ # # ]: 0 : for (const auto& c : commands) {
69 : 0 : t.appendCommand(c.name, &c);
70 : : }
71 : 0 : }
|