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