Coverage Report

Created: 2026-07-23 20:35

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