LCOV - code coverage report
Current view: top level - src/rpc - external_signer.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 42 43 97.7 %
Date: 2026-06-25 07:23:43 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.16