1 // Copyright (c) 2018-2019 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 namespace {
15 
getzmqnotifications(const JSONRPCRequest & request)16 UniValue getzmqnotifications(const JSONRPCRequest& request)
17 {
18             RPCHelpMan{"getzmqnotifications",
19                 "\nReturns information about the active ZeroMQ notifications.\n",
20                 {},
21                 RPCResult{
22                     RPCResult::Type::ARR, "", "",
23                     {
24                         {RPCResult::Type::OBJ, "", "",
25                         {
26                             {RPCResult::Type::STR, "type", "Type of notification"},
27                             {RPCResult::Type::STR, "address", "Address of the publisher"},
28                             {RPCResult::Type::NUM, "hwm", "Outbound message high water mark"},
29                         }},
30                     }
31                 },
32                 RPCExamples{
33                     HelpExampleCli("getzmqnotifications", "")
34             + HelpExampleRpc("getzmqnotifications", "")
35                 },
36             }.Check(request);
37 
38     UniValue result(UniValue::VARR);
39     if (g_zmq_notification_interface != nullptr) {
40         for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
41             UniValue obj(UniValue::VOBJ);
42             obj.pushKV("type", n->GetType());
43             obj.pushKV("address", n->GetAddress());
44             obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark());
45             result.push_back(obj);
46         }
47     }
48 
49     return result;
50 }
51 
52 const CRPCCommand commands[] =
53 { //  category              name                                actor (function)                argNames
54   //  -----------------     ------------------------            -----------------------         ----------
55     { "zmq",                "getzmqnotifications",              &getzmqnotifications,           {} },
56 };
57 
58 } // anonymous namespace
59 
RegisterZMQRPCCommands(CRPCTable & t)60 void RegisterZMQRPCCommands(CRPCTable& t)
61 {
62     for (const auto& c : commands) {
63         t.appendCommand(c.name, &c);
64     }
65 }
66