Bitcoin Core 22.99.0
P2P Digital Currency
zmqrpc.cpp
Go to the documentation of this file.
1// Copyright (c) 2018-2020 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
14namespace {
15
16static RPCHelpMan getzmqnotifications()
17{
18 return RPCHelpMan{"getzmqnotifications",
19 "\nReturns information about the active ZeroMQ notifications.\n",
20 {},
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 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
37{
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}
53
54const CRPCCommand commands[] =
55{ // category actor (function)
56 // ----------------- -----------------------
57 { "zmq", &getzmqnotifications, },
58};
59
60} // anonymous namespace
61
63{
64 for (const auto& c : commands) {
65 t.appendCommand(c.name, &c);
66 }
67}
RPC command dispatcher.
Definition: server.h:126
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:270
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
@ VOBJ
Definition: univalue.h:19
@ VARR
Definition: univalue.h:19
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:156
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:174
CZMQNotificationInterface * g_zmq_notification_interface
void RegisterZMQRPCCommands(CRPCTable &t)
Definition: zmqrpc.cpp:62