LCOV - code coverage report
Current view: top level - src/rpc - external_signer.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 36 36
Test Date: 2024-07-04 05:05:02 Functions: 100.0 % 3 3
Branches: 53.0 % 132 70

             Branch data     Line data    Source code
       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 <config/bitcoin-config.h> // IWYU pragma: keep
       6                 :             : 
       7                 :             : #include <common/args.h>
       8                 :             : #include <common/system.h>
       9                 :             : #include <external_signer.h>
      10                 :             : #include <rpc/protocol.h>
      11                 :             : #include <rpc/server.h>
      12                 :             : #include <rpc/util.h>
      13                 :             : #include <util/strencodings.h>
      14                 :             : 
      15                 :             : #include <string>
      16                 :             : #include <vector>
      17                 :             : 
      18                 :             : #ifdef ENABLE_EXTERNAL_SIGNER
      19                 :             : 
      20                 :        2420 : static RPCHelpMan enumeratesigners()
      21                 :             : {
      22                 :        2420 :     return RPCHelpMan{"enumeratesigners",
      23                 :             :         "Returns a list of external signers from -signer.",
      24                 :             :         {},
      25   [ +  -  +  -  :        9680 :         RPCResult{
             +  +  -  - ]
      26                 :             :             RPCResult::Type::OBJ, "", "",
      27                 :             :             {
      28                 :             :                 {RPCResult::Type::ARR, "signers", /*optional=*/false, "",
      29                 :             :                 {
      30                 :             :                     {RPCResult::Type::OBJ, "", "",
      31                 :             :                     {
      32                 :             :                         {RPCResult::Type::STR_HEX, "fingerprint", "Master key fingerprint"},
      33                 :             :                         {RPCResult::Type::STR, "name", "Device name"},
      34                 :             :                     }},
      35                 :             :                 },
      36                 :             :                 }
      37                 :             :             }
      38   [ +  -  +  -  :       12100 :         },
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      39         [ +  - ]:        4840 :         RPCExamples{
      40   [ +  -  +  -  :        4840 :             HelpExampleCli("enumeratesigners", "")
                   +  - ]
      41   [ +  -  +  -  :        9680 :             + HelpExampleRpc("enumeratesigners", "")
             +  -  +  - ]
      42                 :             :         },
      43                 :           5 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      44                 :             :         {
      45   [ +  -  +  - ]:          10 :             const std::string command = gArgs.GetArg("-signer", "");
      46   [ +  +  +  -  :           6 :             if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart bitcoind with -signer=<cmd>");
                   +  - ]
      47         [ +  - ]:           4 :             const std::string chain = gArgs.GetChainTypeString();
      48                 :           4 :             UniValue signers_res = UniValue::VARR;
      49                 :           4 :             try {
      50                 :           4 :                 std::vector<ExternalSigner> signers;
      51   [ +  -  +  + ]:           7 :                 ExternalSigner::Enumerate(command, signers, chain);
      52         [ +  + ]:           2 :                 for (const ExternalSigner& signer : signers) {
      53                 :           1 :                     UniValue signer_res = UniValue::VOBJ;
      54   [ +  -  +  -  :           2 :                     signer_res.pushKV("fingerprint", signer.m_fingerprint);
                   +  - ]
      55   [ +  -  +  -  :           2 :                     signer_res.pushKV("name", signer.m_name);
                   +  - ]
      56         [ +  - ]:           1 :                     signers_res.push_back(std::move(signer_res));
      57                 :           1 :                 }
      58         [ -  + ]:           7 :             } catch (const std::exception& e) {
      59   [ +  -  +  - ]:           6 :                 throw JSONRPCError(RPC_MISC_ERROR, e.what());
      60                 :           3 :             }
      61                 :           1 :             UniValue result(UniValue::VOBJ);
      62   [ +  -  +  - ]:           2 :             result.pushKV("signers", std::move(signers_res));
      63                 :           2 :             return result;
      64                 :           7 :         }
      65   [ +  -  +  -  :       14520 :     };
             +  -  +  - ]
      66   [ +  -  +  -  :       16940 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  +  +  +  -  
             -  -  -  -  
                      - ]
      67                 :             : 
      68                 :        1325 : void RegisterSignerRPCCommands(CRPCTable& t)
      69                 :             : {
      70                 :        1325 :     static const CRPCCommand commands[]{
      71                 :             :         {"signer", &enumeratesigners},
      72   [ +  +  +  -  :        1325 :     };
             +  -  +  - ]
      73         [ +  + ]:        2650 :     for (const auto& c : commands) {
      74                 :        1325 :         t.appendCommand(c.name, &c);
      75                 :             :     }
      76                 :        1325 : }
      77                 :             : 
      78                 :             : #endif // ENABLE_EXTERNAL_SIGNER
        

Generated by: LCOV version 2.0-1