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  "[\n"
23  " { (json object)\n"
24  " \"type\" : \"pubhashtx\", (string) Type of notification\n"
25  " \"address\" : \"...\", (string) Address of the publisher\n"
26  " \"hwm\" : n (numeric) Outbound message high water mark\n"
27  " },\n"
28  " ...\n"
29  "]\n"
30  },
32  HelpExampleCli("getzmqnotifications", "")
33  + HelpExampleRpc("getzmqnotifications", "")
34  },
35  }.Check(request);
36 
37  UniValue result(UniValue::VARR);
38  if (g_zmq_notification_interface != nullptr) {
39  for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
41  obj.pushKV("type", n->GetType());
42  obj.pushKV("address", n->GetAddress());
43  obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark());
44  result.push_back(obj);
45  }
46  }
47 
48  return result;
49 }
50 
51 const CRPCCommand commands[] =
52 { // category name actor (function) argNames
53  // ----------------- ------------------------ ----------------------- ----------
54  { "zmq", "getzmqnotifications", &getzmqnotifications, {} },
55 };
56 
57 } // anonymous namespace
58 
60 {
61  for (const auto& c : commands) {
62  t.appendCommand(c.name, &c);
63  }
64 }
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:259
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:117
void RegisterZMQRPCCommands(CRPCTable &t)
Definition: zmqrpc.cpp:59
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