Branch data Line data Source code
# 1 : : // Copyright (c) 2018-2021 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 <chainparamsbase.h>
# 6 : : #include <external_signer.h>
# 7 : : #include <rpc/server.h>
# 8 : : #include <rpc/util.h>
# 9 : : #include <util/strencodings.h>
# 10 : : #include <rpc/protocol.h>
# 11 : :
# 12 : : #include <string>
# 13 : : #include <vector>
# 14 : :
# 15 : : #ifdef ENABLE_EXTERNAL_SIGNER
# 16 : :
# 17 : : static RPCHelpMan enumeratesigners()
# 18 : 1599 : {
# 19 : 1599 : return RPCHelpMan{"enumeratesigners",
# 20 : 1599 : "Returns a list of external signers from -signer.",
# 21 : 1599 : {},
# 22 : 1599 : RPCResult{
# 23 : 1599 : RPCResult::Type::OBJ, "", "",
# 24 : 1599 : {
# 25 : 1599 : {RPCResult::Type::ARR, "signers", /*optional=*/false, "",
# 26 : 1599 : {
# 27 : 1599 : {RPCResult::Type::OBJ, "", "",
# 28 : 1599 : {
# 29 : 1599 : {RPCResult::Type::STR_HEX, "fingerprint", "Master key fingerprint"},
# 30 : 1599 : {RPCResult::Type::STR, "name", "Device name"},
# 31 : 1599 : }},
# 32 : 1599 : },
# 33 : 1599 : }
# 34 : 1599 : }
# 35 : 1599 : },
# 36 : 1599 : RPCExamples{
# 37 : 1599 : HelpExampleCli("enumeratesigners", "")
# 38 : 1599 : + HelpExampleRpc("enumeratesigners", "")
# 39 : 1599 : },
# 40 : 1599 : [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
# 41 : 1599 : {
# 42 : 5 : const std::string command = gArgs.GetArg("-signer", "");
# 43 [ + + ]: 5 : if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart bitcoind with -signer=<cmd>");
# 44 : 4 : const std::string chain = gArgs.GetChainName();
# 45 : 4 : UniValue signers_res = UniValue::VARR;
# 46 : 4 : try {
# 47 : 4 : std::vector<ExternalSigner> signers;
# 48 : 4 : ExternalSigner::Enumerate(command, signers, chain);
# 49 [ + + ]: 4 : for (const ExternalSigner& signer : signers) {
# 50 : 2 : UniValue signer_res = UniValue::VOBJ;
# 51 : 2 : signer_res.pushKV("fingerprint", signer.m_fingerprint);
# 52 : 2 : signer_res.pushKV("name", signer.m_name);
# 53 : 2 : signers_res.push_back(signer_res);
# 54 : 2 : }
# 55 : 4 : } catch (const std::exception& e) {
# 56 : 3 : throw JSONRPCError(RPC_MISC_ERROR, e.what());
# 57 : 3 : }
# 58 : 1 : UniValue result(UniValue::VOBJ);
# 59 : 1 : result.pushKV("signers", signers_res);
# 60 : 1 : return result;
# 61 : 4 : }
# 62 : 1599 : };
# 63 : 1599 : }
# 64 : :
# 65 : : void RegisterSignerRPCCommands(CRPCTable &t)
# 66 : 993 : {
# 67 : : // clang-format off
# 68 : 993 : static const CRPCCommand commands[] =
# 69 : 993 : { // category actor (function)
# 70 : : // --------------------- ------------------------
# 71 : 993 : { "signer", &enumeratesigners, },
# 72 : 993 : };
# 73 : : // clang-format on
# 74 [ + + ]: 993 : for (const auto& c : commands) {
# 75 : 993 : t.appendCommand(c.name, &c);
# 76 : 993 : }
# 77 : 993 : }
# 78 : :
# 79 : : #endif // ENABLE_EXTERNAL_SIGNER
|