Bitcoin Core  0.19.99
P2P Digital Currency
zmqrpc.cpp
Go to the documentation of this file.
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>
11 
12 #include <univalue.h>
13 
14 namespace {
15 
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  },
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()) {
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 
61 {
62  for (const auto& c : commands) {
63  t.appendCommand(c.name, &c);
64  }
65 }
Bitcoin RPC command dispatcher.
Definition: server.h:119
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:262
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:117
void RegisterZMQRPCCommands(CRPCTable &t)
Definition: zmqrpc.cpp:60
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:112
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
static const CRPCCommand commands[]
CZMQNotificationInterface * g_zmq_notification_interface