Coverage Report

Created: 2026-07-14 18:13

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
54
{
22
54
    return RPCMethod{"enumeratesigners",
23
54
        "Returns a list of external signers from -signer. Signers with duplicate master key fingerprints are skipped.",
24
54
        {},
25
54
        RPCResult{
26
54
            RPCResult::Type::OBJ, "", "",
27
54
            {
28
54
                {RPCResult::Type::ARR, "signers", /*optional=*/false, "",
29
54
                {
30
54
                    {RPCResult::Type::OBJ, "", "",
31
54
                    {
32
54
                        {RPCResult::Type::STR_HEX, "fingerprint", "Master key fingerprint"},
33
54
                        {RPCResult::Type::STR, "name", "Device name, the model returned by the signer"},
34
54
                    }},
35
54
                },
36
54
                }
37
54
            }
38
54
        },
39
54
        RPCExamples{
40
54
            HelpExampleCli("enumeratesigners", "")
41
54
            + HelpExampleRpc("enumeratesigners", "")
42
54
        },
43
54
        [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
44
54
        {
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
54
    };
66
54
}
67
68
void RegisterSignerRPCCommands(CRPCTable& t)
69
27
{
70
27
    static const CRPCCommand commands[]{
71
27
        {"signer", &enumeratesigners},
72
27
    };
73
27
    for (const auto& c : commands) {
  Branch (73:24): [True: 27, False: 27]
74
27
        t.appendCommand(c.name, &c);
75
27
    }
76
27
}
77
78
#endif // ENABLE_EXTERNAL_SIGNER