Skip to content

Commit 1ba7412

Browse files
committed
Merge bitcoin/bitcoin#23004: multiprocess: add interfaces::ExternalSigner class
a032fa3 multiprocess: add interfaces::ExternalSigner class (Russell Yanofsky) Pull request description: Add `interfaces::ExternalSigner` class to let signer objects be passed between processes and let signer code run in the original process where the object was created. --- This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10). ACKs for top commit: laanwj: Concept and code review ACK a032fa3 hebasto: re-ACK a032fa3 Tree-SHA512: 99a729fb3a64d010e142cc778a9f1f358e58345b77faaf2664de7d2277715d59df3352326e8f0f2a6628038670eaa4556310a549079fb28af6d2eeb05aea1460
2 parents 36d184d + a032fa3 commit 1ba7412

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

src/interfaces/node.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define BITCOIN_INTERFACES_NODE_H
77

88
#include <consensus/amount.h>
9-
#include <external_signer.h>
109
#include <net.h> // For NodeId
1110
#include <net_types.h> // For banmap_t
1211
#include <netaddress.h> // For Network
@@ -50,6 +49,16 @@ struct BlockAndHeaderTipInfo
5049
double verification_progress;
5150
};
5251

52+
//! External signer interface used by the GUI.
53+
class ExternalSigner
54+
{
55+
public:
56+
virtual ~ExternalSigner() {};
57+
58+
//! Get signer display name
59+
virtual std::string getName() = 0;
60+
};
61+
5362
//! Top-level interface for a bitcoin node (bitcoind process).
5463
class Node
5564
{
@@ -111,8 +120,8 @@ class Node
111120
//! Disconnect node by id.
112121
virtual bool disconnectById(NodeId id) = 0;
113122

114-
//! List external signers
115-
virtual std::vector<ExternalSigner> externalSigners() = 0;
123+
//! Return list of external signers (attached devices which can sign transactions).
124+
virtual std::vector<std::unique_ptr<ExternalSigner>> listExternalSigners() = 0;
116125

117126
//! Get total bytes recv.
118127
virtual int64_t getTotalBytesRecv() = 0;

src/node/interfaces.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ using interfaces::WalletClient;
6767

6868
namespace node {
6969
namespace {
70+
#ifdef ENABLE_EXTERNAL_SIGNER
71+
class ExternalSignerImpl : public interfaces::ExternalSigner
72+
{
73+
public:
74+
ExternalSignerImpl(::ExternalSigner signer) : m_signer(std::move(signer)) {}
75+
std::string getName() override { return m_signer.m_name; }
76+
private:
77+
::ExternalSigner m_signer;
78+
};
79+
#endif
80+
7081
class NodeImpl : public Node
7182
{
7283
private:
@@ -172,14 +183,18 @@ class NodeImpl : public Node
172183
}
173184
return false;
174185
}
175-
std::vector<ExternalSigner> externalSigners() override
186+
std::vector<std::unique_ptr<interfaces::ExternalSigner>> listExternalSigners() override
176187
{
177188
#ifdef ENABLE_EXTERNAL_SIGNER
178189
std::vector<ExternalSigner> signers = {};
179190
const std::string command = gArgs.GetArg("-signer", "");
180-
if (command == "") return signers;
191+
if (command == "") return {};
181192
ExternalSigner::Enumerate(command, signers, Params().NetworkIDString());
182-
return signers;
193+
std::vector<std::unique_ptr<interfaces::ExternalSigner>> result;
194+
for (auto& signer : signers) {
195+
result.emplace_back(std::make_unique<ExternalSignerImpl>(std::move(signer)));
196+
}
197+
return result;
183198
#else
184199
// This result is indistinguishable from a successful call that returns
185200
// no signers. For the current GUI this doesn't matter, because the wallet

src/qt/createwalletdialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <config/bitcoin-config.h>
77
#endif
88

9-
#include <external_signer.h>
9+
#include <interfaces/node.h>
1010
#include <qt/createwalletdialog.h>
1111
#include <qt/forms/ui_createwalletdialog.h>
1212

@@ -113,7 +113,7 @@ CreateWalletDialog::~CreateWalletDialog()
113113
delete ui;
114114
}
115115

116-
void CreateWalletDialog::setSigners(const std::vector<ExternalSigner>& signers)
116+
void CreateWalletDialog::setSigners(const std::vector<std::unique_ptr<interfaces::ExternalSigner>>& signers)
117117
{
118118
m_has_signers = !signers.empty();
119119
if (m_has_signers) {
@@ -126,7 +126,7 @@ void CreateWalletDialog::setSigners(const std::vector<ExternalSigner>& signers)
126126
ui->blank_wallet_checkbox->setChecked(false);
127127
ui->disable_privkeys_checkbox->setEnabled(false);
128128
ui->disable_privkeys_checkbox->setChecked(true);
129-
const std::string label = signers[0].m_name;
129+
const std::string label = signers[0]->getName();
130130
ui->wallet_name_line_edit->setText(QString::fromStdString(label));
131131
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
132132
} else {

src/qt/createwalletdialog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
#include <QDialog>
99

10+
#include <memory>
11+
12+
namespace interfaces {
1013
class ExternalSigner;
14+
} // namespace interfaces
15+
1116
class WalletModel;
1217

1318
namespace Ui {
@@ -24,7 +29,7 @@ class CreateWalletDialog : public QDialog
2429
explicit CreateWalletDialog(QWidget* parent);
2530
virtual ~CreateWalletDialog();
2631

27-
void setSigners(const std::vector<ExternalSigner>& signers);
32+
void setSigners(const std::vector<std::unique_ptr<interfaces::ExternalSigner>>& signers);
2833

2934
QString walletName() const;
3035
bool isEncryptWalletChecked() const;

src/qt/walletcontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ void CreateWalletActivity::create()
280280
{
281281
m_create_wallet_dialog = new CreateWalletDialog(m_parent_widget);
282282

283-
std::vector<ExternalSigner> signers;
283+
std::vector<std::unique_ptr<interfaces::ExternalSigner>> signers;
284284
try {
285-
signers = node().externalSigners();
285+
signers = node().listExternalSigners();
286286
} catch (const std::runtime_error& e) {
287287
QMessageBox::critical(nullptr, tr("Can't list signers"), e.what());
288288
}

0 commit comments

Comments
 (0)