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 % 44 44
Test Date: 2026-10-09 06:24:36 Functions: 100.0 % 3 3
Branches: 53.3 % 122 65

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

Generated by: LCOV version 2.0-1