LCOV - code coverage report
Current view: top level - src/zmq - zmqrpc.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 34 35 97.1 %
Date: 2020-09-26 01:30:44 Functions: 5 5 100.0 %

          Line data    Source code
       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>
       9             : #include <zmq/zmqabstractnotifier.h>
      10             : #include <zmq/zmqnotificationinterface.h>
      11             : 
      12             : #include <univalue.h>
      13             : 
      14             : namespace {
      15             : 
      16        2566 : static RPCHelpMan getzmqnotifications()
      17             : {
      18       10264 :     return RPCHelpMan{"getzmqnotifications",
      19        2566 :                 "\nReturns information about the active ZeroMQ notifications.\n",
      20        2566 :                 {},
      21        2566 :                 RPCResult{
      22        2566 :                     RPCResult::Type::ARR, "", "",
      23        5132 :                     {
      24        5132 :                         {RPCResult::Type::OBJ, "", "",
      25       10264 :                         {
      26        2566 :                             {RPCResult::Type::STR, "type", "Type of notification"},
      27        2566 :                             {RPCResult::Type::STR, "address", "Address of the publisher"},
      28        2566 :                             {RPCResult::Type::NUM, "hwm", "Outbound message high water mark"},
      29             :                         }},
      30             :                     }
      31             :                 },
      32        2566 :                 RPCExamples{
      33        2566 :                     HelpExampleCli("getzmqnotifications", "")
      34        2566 :             + HelpExampleRpc("getzmqnotifications", "")
      35             :                 },
      36        2568 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      37             : {
      38           2 :     UniValue result(UniValue::VARR);
      39           2 :     if (g_zmq_notification_interface != nullptr) {
      40           5 :         for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
      41           4 :             UniValue obj(UniValue::VOBJ);
      42           4 :             obj.pushKV("type", n->GetType());
      43           4 :             obj.pushKV("address", n->GetAddress());
      44           4 :             obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark());
      45           4 :             result.push_back(obj);
      46           4 :         }
      47           1 :     }
      48             : 
      49             :     return result;
      50           2 : },
      51             :     };
      52           0 : }
      53             : 
      54        1920 : const CRPCCommand commands[] =
      55         640 : { //  category              name                                actor (function)                argNames
      56             :   //  -----------------     ------------------------            -----------------------         ----------
      57         640 :     { "zmq",                "getzmqnotifications",              &getzmqnotifications,           {} },
      58             : };
      59             : 
      60             : } // anonymous namespace
      61             : 
      62         527 : void RegisterZMQRPCCommands(CRPCTable& t)
      63             : {
      64        1054 :     for (const auto& c : commands) {
      65         527 :         t.appendCommand(c.name, &c);
      66             :     }
      67         527 : }

Generated by: LCOV version 1.15