Bitcoin ABC  0.29.2
P2P Digital Currency
zmqrpc.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 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>
11 
12 #include <univalue.h>
13 
14 namespace {
15 
16 static RPCHelpMan getzmqnotifications() {
17  return RPCHelpMan{
18  "getzmqnotifications",
19  "Returns information about the active ZeroMQ notifications.\n",
20  {},
21  RPCResult{
23  "",
24  "",
25  {
27  "",
28  "",
29  {
30  {RPCResult::Type::STR, "type", "Type of notification"},
31  {RPCResult::Type::STR, "address",
32  "Address of the publisher"},
33  {RPCResult::Type::NUM, "hwm",
34  "Outbound message high water mark"},
35  }},
36  }},
37  RPCExamples{HelpExampleCli("getzmqnotifications", "") +
38  HelpExampleRpc("getzmqnotifications", "")},
39  [&](const RPCHelpMan &self, const Config &config,
40  const JSONRPCRequest &request) -> UniValue {
41  UniValue result(UniValue::VARR);
42  if (g_zmq_notification_interface != nullptr) {
43  for (const auto *n :
46  obj.pushKV("type", n->GetType());
47  obj.pushKV("address", n->GetAddress());
48  obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark());
49  result.push_back(obj);
50  }
51  }
52 
53  return result;
54  },
55  };
56 }
57 
58 // clang-format off
59 static const CRPCCommand commands[] = {
60  // category actor (function)
61  // ----------------- -----------------------
62  { "zmq", getzmqnotifications, },
63 };
64 // clang-format on
65 
66 } // anonymous namespace
67 
69  for (const auto &c : commands) {
70  t.appendCommand(c.name, &c);
71  }
72 }
RPC command dispatcher.
Definition: server.h:183
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:330
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
Definition: config.h:17
@ VOBJ
Definition: univalue.h:27
@ VARR
Definition: univalue.h:27
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:175
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:192
CZMQNotificationInterface * g_zmq_notification_interface
void RegisterZMQRPCCommands(CRPCTable &t)
Definition: zmqrpc.cpp:68