Skip to content

Commit 07b7c94

Browse files
committed
rpc: add external signer RPC files
1 parent 8ce7767 commit 07b7c94

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ BITCOIN_CORE_H = \
271271
wallet/fees.h \
272272
wallet/ismine.h \
273273
wallet/load.h \
274+
wallet/rpcsigner.h \
274275
wallet/rpcwallet.h \
275276
wallet/salvage.h \
276277
wallet/scriptpubkeyman.h \
@@ -388,6 +389,7 @@ libbitcoin_wallet_a_SOURCES = \
388389
wallet/interfaces.cpp \
389390
wallet/load.cpp \
390391
wallet/rpcdump.cpp \
392+
wallet/rpcsigner.cpp \
391393
wallet/rpcwallet.cpp \
392394
wallet/scriptpubkeyman.cpp \
393395
wallet/wallet.cpp \

src/wallet/interfaces.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <wallet/fees.h>
2424
#include <wallet/ismine.h>
2525
#include <wallet/load.h>
26+
#include <wallet/rpcsigner.h>
2627
#include <wallet/rpcwallet.h>
2728
#include <wallet/wallet.h>
2829

@@ -518,6 +519,15 @@ class WalletClientImpl : public WalletClient
518519
}, command.argNames, command.unique_id);
519520
m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
520521
}
522+
523+
#ifdef ENABLE_EXTERNAL_SIGNER
524+
for (const CRPCCommand& command : GetSignerRPCCommands()) {
525+
m_rpc_commands.emplace_back(command.category, command.name, [this, &command](const JSONRPCRequest& request, UniValue& result, bool last_handler) {
526+
return command.actor({request, m_context}, result, last_handler);
527+
}, command.argNames, command.unique_id);
528+
m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
529+
}
530+
#endif
521531
}
522532
bool verify() override { return VerifyWallets(*m_context.chain); }
523533
bool load() override { return LoadWallets(*m_context.chain); }

src/wallet/rpcsigner.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 <rpc/server.h>
6+
#include <util/strencodings.h>
7+
#include <wallet/rpcsigner.h>
8+
#include <wallet/wallet.h>
9+
10+
#ifdef ENABLE_EXTERNAL_SIGNER
11+
12+
// CRPCCommand table won't compile with an empty array
13+
static RPCHelpMan dummy()
14+
{
15+
return RPCHelpMan{"dummy",
16+
"\nDoes nothing.\n"
17+
"",
18+
{},
19+
RPCResult{RPCResult::Type::NONE, "", ""},
20+
RPCExamples{""},
21+
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
22+
{
23+
return NullUniValue;
24+
},
25+
};
26+
}
27+
28+
Span<const CRPCCommand> GetSignerRPCCommands()
29+
{
30+
// clang-format off
31+
static const CRPCCommand commands[] =
32+
{ // category actor (function)
33+
// --------------------- ------------------------
34+
{ "signer", &dummy, },
35+
};
36+
// clang-format on
37+
return MakeSpan(commands);
38+
}
39+
40+
41+
#endif // ENABLE_EXTERNAL_SIGNER

src/wallet/rpcsigner.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#ifndef BITCOIN_WALLET_RPCSIGNER_H
6+
#define BITCOIN_WALLET_RPCSIGNER_H
7+
8+
#include <span.h>
9+
#include <util/system.h>
10+
#include <vector>
11+
12+
#ifdef ENABLE_EXTERNAL_SIGNER
13+
14+
class CRPCCommand;
15+
16+
namespace interfaces {
17+
class Chain;
18+
class Handler;
19+
}
20+
21+
Span<const CRPCCommand> GetSignerRPCCommands();
22+
23+
#endif // ENABLE_EXTERNAL_SIGNER
24+
25+
#endif //BITCOIN_WALLET_RPCSIGNER_H

test/functional/rpc_help.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ def test_categories(self):
105105
if self.is_wallet_compiled():
106106
components.append('Wallet')
107107

108+
if self.is_external_signer_compiled():
109+
components.append('Signer')
110+
108111
if self.is_zmq_compiled():
109112
components.append('Zmq')
110113

111-
assert_equal(titles, components)
114+
assert_equal(titles, sorted(components))
112115

113116
def dump_help(self):
114117
dump_dir = os.path.join(self.options.tmpdir, 'rpc_help_dump')

0 commit comments

Comments
 (0)