Coverage Report

Created: 2026-04-29 19:21

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