Bitcoin Core  31.0.0
P2P Digital Currency
zmqrpc.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-present 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 <univalue.h>
12 
13 #include <list>
14 #include <memory>
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 class JSONRPCRequest;
20 
21 namespace {
22 
23 static RPCHelpMan getzmqnotifications()
24 {
25  return RPCHelpMan{
26  "getzmqnotifications",
27  "Returns information about the active ZeroMQ notifications.\n",
28  {},
29  RPCResult{
30  RPCResult::Type::ARR, "", "",
31  {
32  {RPCResult::Type::OBJ, "", "",
33  {
34  {RPCResult::Type::STR, "type", "Type of notification"},
35  {RPCResult::Type::STR, "address", "Address of the publisher"},
36  {RPCResult::Type::NUM, "hwm", "Outbound message high water mark"},
37  }},
38  }
39  },
41  HelpExampleCli("getzmqnotifications", "")
42  + HelpExampleRpc("getzmqnotifications", "")
43  },
44  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
45 {
47  if (g_zmq_notification_interface != nullptr) {
48  for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
50  obj.pushKV("type", n->GetType());
51  obj.pushKV("address", n->GetAddress());
52  obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark());
53  result.push_back(std::move(obj));
54  }
55  }
56 
57  return result;
58 },
59  };
60 }
61 
62 const CRPCCommand commands[]{
63  {"zmq", &getzmqnotifications},
64 };
65 
66 } // anonymous namespace
67 
69 {
70  for (const auto& c : commands) {
71  t.appendCommand(c.name, &c);
72  }
73 }
RPC command dispatcher.
Definition: server.h:86
std::unique_ptr< CZMQNotificationInterface > g_zmq_notification_interface
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:201
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:183
void RegisterZMQRPCCommands(CRPCTable &t)
Definition: zmqrpc.cpp:68
auto result
Definition: common-types.h:74