Coverage Report

Created: 2026-05-30 09:47

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