BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
zmqrpc.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 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>
10 
11 #include <univalue.h>
12 
13 namespace {
14 
15 UniValue getzmqnotifications(const JSONRPCRequest& request)
16 {
17  if (request.fHelp || request.params.size() != 0) {
18  throw std::runtime_error(
19  "getzmqnotifications\n"
20  "\nReturns information about the active ZeroMQ notifications.\n"
21  "\nResult:\n"
22  "[\n"
23  " { (json object)\n"
24  " \"type\": \"pubhashtx\", (string) Type of notification\n"
25  " \"address\": \"...\" (string) Address of the publisher\n"
26  " },\n"
27  " ...\n"
28  "]\n"
29  "\nExamples:\n"
30  + HelpExampleCli("getzmqnotifications", "")
31  + HelpExampleRpc("getzmqnotifications", "")
32  );
33  }
34 
35  UniValue result(UniValue::VARR);
36  if (g_zmq_notification_interface != nullptr) {
37  for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
39  obj.pushKV("type", n->GetType());
40  obj.pushKV("address", n->GetAddress());
41  result.push_back(obj);
42  }
43  }
44 
45  return result;
46 }
47 
48 const CRPCCommand commands[] =
49 { // category name actor (function) argNames
50  // ----------------- ------------------------ ----------------------- ----------
51  { "zmq", "getzmqnotifications", &getzmqnotifications, {} },
52 };
53 
54 } // anonymous namespace
55 
57 {
58  for (const auto& c : commands) {
59  t.appendCommand(c.name, &c);
60  }
61 }
Bitcoin RPC command dispatcher.
Definition: server.h:143
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:516
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:285
UniValue params
Definition: server.h:44
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:511
bool fHelp
Definition: server.h:45
void RegisterZMQRPCCommands(CRPCTable &t)
Definition: zmqrpc.cpp:56
size_t size() const
Definition: univalue.h:69
std::list< const CZMQAbstractNotifier * > GetActiveNotifiers() const
CZMQNotificationInterface * g_zmq_notification_interface