Coverage Report

Created: 2026-06-01 18:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/rpc/external_signer.cpp
Line
Count
Source
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 <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
static RPCMethod enumeratesigners()
21
0
{
22
0
    return RPCMethod{"enumeratesigners",
23
0
        "Returns a list of external signers from -signer.",
24
0
        {},
25
0
        RPCResult{
26
0
            RPCResult::Type::OBJ, "", "",
27
0
            {
28
0
                {RPCResult::Type::ARR, "signers", /*optional=*/false, "",
29
0
                {
30
0
                    {RPCResult::Type::OBJ, "", "",
31
0
                    {
32
0
                        {RPCResult::Type::STR_HEX, "fingerprint", "Master key fingerprint"},
33
0
                        {RPCResult::Type::STR, "name", "Device name"},
34
0
                    }},
35
0
                },
36
0
                }
37
0
            }
38
0
        },
39
0
        RPCExamples{
40
0
            HelpExampleCli("enumeratesigners", "")
41
0
            + HelpExampleRpc("enumeratesigners", "")
42
0
        },
43
0
        [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
44
0
        {
45
0
            const std::string command = gArgs.GetArg("-signer", "");
46
0
            if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart bitcoind with -signer=<cmd>");
  Branch (46:17): [True: 0, False: 0]
47
0
            const std::string chain = gArgs.GetChainTypeString();
48
0
            UniValue signers_res = UniValue::VARR;
49
0
            try {
50
0
                std::vector<ExternalSigner> signers;
51
0
                ExternalSigner::Enumerate(command, signers, chain);
52
0
                for (const ExternalSigner& signer : signers) {
  Branch (52:51): [True: 0, False: 0]
53
0
                    UniValue signer_res = UniValue::VOBJ;
54
0
                    signer_res.pushKV("fingerprint", signer.m_fingerprint);
55
0
                    signer_res.pushKV("name", signer.m_name);
56
0
                    signers_res.push_back(std::move(signer_res));
57
0
                }
58
0
            } catch (const std::exception& e) {
59
0
                throw JSONRPCError(RPC_MISC_ERROR, e.what());
60
0
            }
61
0
            UniValue result(UniValue::VOBJ);
62
0
            result.pushKV("signers", std::move(signers_res));
63
0
            return result;
64
0
        }
65
0
    };
66
0
}
67
68
void RegisterSignerRPCCommands(CRPCTable& t)
69
0
{
70
0
    static const CRPCCommand commands[]{
71
0
        {"signer", &enumeratesigners},
72
0
    };
73
0
    for (const auto& c : commands) {
  Branch (73:24): [True: 0, False: 0]
74
0
        t.appendCommand(c.name, &c);
75
0
    }
76
0
}
77
78
#endif // ENABLE_EXTERNAL_SIGNER