LCOV - code coverage report
Current view: top level - src/rpc - external_signer.cpp (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 23 43 53.5 %
Date: 2026-06-25 07:23:51 Functions: 3 4 75.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          92 : static RPCHelpMan enumeratesigners()
      17             : {
      18         184 :     return RPCHelpMan{"enumeratesigners",
      19          92 :         "Returns a list of external signers from -signer.",
      20          92 :         {},
      21          92 :         RPCResult{
      22          92 :             RPCResult::Type::OBJ, "", "",
      23         184 :             {
      24         184 :                 {RPCResult::Type::ARR, "signers", /*optional=*/false, "",
      25         184 :                 {
      26         184 :                     {RPCResult::Type::OBJ, "", "",
      27         276 :                     {
      28          92 :                         {RPCResult::Type::STR_HEX, "fingerprint", "Master key fingerprint"},
      29          92 :                         {RPCResult::Type::STR, "name", "Device name"},
      30             :                     }},
      31             :                 },
      32             :                 }
      33             :             }
      34             :         },
      35          92 :         RPCExamples{
      36          92 :             HelpExampleCli("enumeratesigners", "")
      37          92 :             + HelpExampleRpc("enumeratesigners", "")
      38             :         },
      39          92 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      40             :         {
      41           0 :             const std::string command = gArgs.GetArg("-signer", "");
      42           0 :             if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart dashd with -signer=<cmd>");
      43           0 :             const std::string chain = gArgs.GetChainName();
      44           0 :             UniValue signers_res = UniValue::VARR;
      45             :             try {
      46           0 :                 std::vector<ExternalSigner> signers;
      47           0 :                 ExternalSigner::Enumerate(command, signers, chain);
      48           0 :                 for (const ExternalSigner& signer : signers) {
      49           0 :                     UniValue signer_res = UniValue::VOBJ;
      50           0 :                     signer_res.pushKV("fingerprint", signer.m_fingerprint);
      51           0 :                     signer_res.pushKV("name", signer.m_name);
      52           0 :                     signers_res.push_back(signer_res);
      53           0 :                 }
      54           0 :             } catch (const std::exception& e) {
      55           0 :                 throw JSONRPCError(RPC_MISC_ERROR, e.what());
      56           0 :             }
      57           0 :             UniValue result(UniValue::VOBJ);
      58           0 :             result.pushKV("signers", signers_res);
      59           0 :             return result;
      60           0 :         }
      61             :     };
      62           0 : }
      63             : 
      64         178 : void RegisterSignerRPCCommands(CRPCTable& t)
      65             : {
      66         224 :     static const CRPCCommand commands[]{
      67          46 :         {"signer", &enumeratesigners},
      68             :     };
      69         356 :     for (const auto& c : commands) {
      70         178 :         t.appendCommand(c.name, &c);
      71             :     }
      72         178 : }
      73             : 
      74             : #endif // ENABLE_EXTERNAL_SIGNER

Generated by: LCOV version 1.16