LCOV - code coverage report
Current view: top level - src/rpc - server_util.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 43 55 78.2 %
Date: 2022-04-21 14:51:19 Functions: 11 11 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 8 14 57.1 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2021 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 <rpc/server_util.h>
#       6                 :            : 
#       7                 :            : #include <net_processing.h>
#       8                 :            : #include <node/context.h>
#       9                 :            : #include <policy/fees.h>
#      10                 :            : #include <rpc/protocol.h>
#      11                 :            : #include <rpc/request.h>
#      12                 :            : #include <txmempool.h>
#      13                 :            : #include <util/system.h>
#      14                 :            : #include <validation.h>
#      15                 :            : 
#      16                 :            : #include <any>
#      17                 :            : 
#      18                 :            : using node::NodeContext;
#      19                 :            : 
#      20                 :            : NodeContext& EnsureAnyNodeContext(const std::any& context)
#      21                 :      98834 : {
#      22                 :      98834 :     auto node_context = util::AnyPtr<NodeContext>(context);
#      23         [ -  + ]:      98834 :     if (!node_context) {
#      24                 :          0 :         throw JSONRPCError(RPC_INTERNAL_ERROR, "Node context not found");
#      25                 :          0 :     }
#      26                 :      98834 :     return *node_context;
#      27                 :      98834 : }
#      28                 :            : 
#      29                 :            : CTxMemPool& EnsureMemPool(const NodeContext& node)
#      30                 :      23771 : {
#      31         [ -  + ]:      23771 :     if (!node.mempool) {
#      32                 :          0 :         throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found");
#      33                 :          0 :     }
#      34                 :      23771 :     return *node.mempool;
#      35                 :      23771 : }
#      36                 :            : 
#      37                 :            : CTxMemPool& EnsureAnyMemPool(const std::any& context)
#      38                 :      11192 : {
#      39                 :      11192 :     return EnsureMemPool(EnsureAnyNodeContext(context));
#      40                 :      11192 : }
#      41                 :            : 
#      42                 :            : ArgsManager& EnsureArgsman(const NodeContext& node)
#      43                 :        445 : {
#      44         [ -  + ]:        445 :     if (!node.args) {
#      45                 :          0 :         throw JSONRPCError(RPC_INTERNAL_ERROR, "Node args not found");
#      46                 :          0 :     }
#      47                 :        445 :     return *node.args;
#      48                 :        445 : }
#      49                 :            : 
#      50                 :            : ArgsManager& EnsureAnyArgsman(const std::any& context)
#      51                 :        445 : {
#      52                 :        445 :     return EnsureArgsman(EnsureAnyNodeContext(context));
#      53                 :        445 : }
#      54                 :            : 
#      55                 :            : ChainstateManager& EnsureChainman(const NodeContext& node)
#      56                 :      43619 : {
#      57         [ -  + ]:      43619 :     if (!node.chainman) {
#      58                 :          0 :         throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
#      59                 :          0 :     }
#      60                 :      43619 :     return *node.chainman;
#      61                 :      43619 : }
#      62                 :            : 
#      63                 :            : ChainstateManager& EnsureAnyChainman(const std::any& context)
#      64                 :      29974 : {
#      65                 :      29974 :     return EnsureChainman(EnsureAnyNodeContext(context));
#      66                 :      29974 : }
#      67                 :            : 
#      68                 :            : CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node)
#      69                 :        311 : {
#      70         [ +  + ]:        311 :     if (!node.fee_estimator) {
#      71                 :          1 :         throw JSONRPCError(RPC_INTERNAL_ERROR, "Fee estimation disabled");
#      72                 :          1 :     }
#      73                 :        310 :     return *node.fee_estimator;
#      74                 :        311 : }
#      75                 :            : 
#      76                 :            : CBlockPolicyEstimator& EnsureAnyFeeEstimator(const std::any& context)
#      77                 :        311 : {
#      78                 :        311 :     return EnsureFeeEstimator(EnsureAnyNodeContext(context));
#      79                 :        311 : }
#      80                 :            : 
#      81                 :            : CConnman& EnsureConnman(const NodeContext& node)
#      82                 :       9221 : {
#      83         [ -  + ]:       9221 :     if (!node.connman) {
#      84                 :          0 :         throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
#      85                 :          0 :     }
#      86                 :       9221 :     return *node.connman;
#      87                 :       9221 : }
#      88                 :            : 
#      89                 :            : PeerManager& EnsurePeerman(const NodeContext& node)
#      90                 :       8694 : {
#      91         [ -  + ]:       8694 :     if (!node.peerman) {
#      92                 :          0 :         throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
#      93                 :          0 :     }
#      94                 :       8694 :     return *node.peerman;
#      95                 :       8694 : }

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a