Coverage Report

Created: 2025-06-10 13:21

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