LCOV - code coverage report
Current view: top level - src/zmq - zmqrpc.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 66.7 % 33 22
Test Date: 2026-02-01 04:44:48 Functions: 100.0 % 3 3
Branches: 34.7 % 98 34

             Branch data     Line data    Source code
       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>
      10                 :             : #include <zmq/zmqabstractnotifier.h>
      11                 :             : #include <zmq/zmqnotificationinterface.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                 :         294 : static RPCHelpMan getzmqnotifications()
      24                 :             : {
      25                 :         294 :     return RPCHelpMan{
      26                 :         294 :         "getzmqnotifications",
      27         [ +  - ]:         588 :         "Returns information about the active ZeroMQ notifications.\n",
      28                 :             :                 {},
      29         [ +  - ]:         588 :                 RPCResult{
      30         [ +  - ]:         588 :                     RPCResult::Type::ARR, "", "",
      31                 :             :                     {
      32   [ +  -  +  - ]:         588 :                         {RPCResult::Type::OBJ, "", "",
      33                 :             :                         {
      34   [ +  -  +  - ]:         588 :                             {RPCResult::Type::STR, "type", "Type of notification"},
      35   [ +  -  +  - ]:         588 :                             {RPCResult::Type::STR, "address", "Address of the publisher"},
      36   [ +  -  +  - ]:         588 :                             {RPCResult::Type::NUM, "hwm", "Outbound message high water mark"},
      37                 :             :                         }},
      38                 :             :                     }
      39   [ +  -  +  -  :        2646 :                 },
          +  -  +  +  +  
             +  -  -  -  
                      - ]
      40                 :         294 :                 RPCExamples{
      41   [ +  -  +  -  :         588 :                     HelpExampleCli("getzmqnotifications", "")
                   +  - ]
      42   [ +  -  +  -  :        1176 :             + HelpExampleRpc("getzmqnotifications", "")
             +  -  +  - ]
      43         [ +  - ]:         294 :                 },
      44                 :         294 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      45                 :             : {
      46                 :           0 :     UniValue result(UniValue::VARR);
      47         [ #  # ]:           0 :     if (g_zmq_notification_interface != nullptr) {
      48   [ #  #  #  # ]:           0 :         for (const auto* n : g_zmq_notification_interface->GetActiveNotifiers()) {
      49                 :           0 :             UniValue obj(UniValue::VOBJ);
      50   [ #  #  #  #  :           0 :             obj.pushKV("type", n->GetType());
             #  #  #  # ]
      51   [ #  #  #  #  :           0 :             obj.pushKV("address", n->GetAddress());
             #  #  #  # ]
      52   [ #  #  #  #  :           0 :             obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark());
                   #  # ]
      53         [ #  # ]:           0 :             result.push_back(std::move(obj));
      54                 :           0 :         }
      55                 :             :     }
      56                 :             : 
      57                 :           0 :     return result;
      58                 :           0 : },
      59   [ +  -  +  - ]:        1176 :     };
      60   [ +  -  +  -  :        1176 : }
          +  -  +  -  -  
                      - ]
      61                 :             : 
      62                 :             : const CRPCCommand commands[]{
      63                 :             :     {"zmq", &getzmqnotifications},
      64                 :             : };
      65                 :             : 
      66                 :             : } // anonymous namespace
      67                 :             : 
      68                 :           1 : void RegisterZMQRPCCommands(CRPCTable& t)
      69                 :             : {
      70         [ +  + ]:           2 :     for (const auto& c : commands) {
      71                 :           1 :         t.appendCommand(c.name, &c);
      72                 :             :     }
      73                 :           1 : }
        

Generated by: LCOV version 2.0-1