Skip to content

Commit 4455145

Browse files
committed
refactor: reduce #ifdef ENABLE_EXTERNAL_SIGNER usage
In particular this make the node interface independent on whether external signer support is compiled.
1 parent 5be90c9 commit 4455145

12 files changed

+15
-45
lines changed

src/external_signer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <string>
1414
#include <vector>
1515

16-
#ifdef ENABLE_EXTERNAL_SIGNER
17-
1816
ExternalSigner::ExternalSigner(const std::string& command, const std::string& fingerprint, const std::string chain, const std::string name): m_command(command), m_fingerprint(fingerprint), m_chain(chain), m_name(name) {}
1917

2018
const std::string ExternalSigner::NetworkArg() const
@@ -116,5 +114,3 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
116114

117115
return true;
118116
}
119-
120-
#endif // ENABLE_EXTERNAL_SIGNER

src/external_signer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <string>
1212
#include <vector>
1313

14-
#ifdef ENABLE_EXTERNAL_SIGNER
15-
1614
struct PartiallySignedTransaction;
1715

1816
//! Enables interaction with an external signing device or service, such as
@@ -65,6 +63,4 @@ class ExternalSigner
6563
bool SignTransaction(PartiallySignedTransaction& psbt, std::string& error);
6664
};
6765

68-
#endif // ENABLE_EXTERNAL_SIGNER
69-
7066
#endif // BITCOIN_EXTERNAL_SIGNER_H

src/interfaces/node.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ class Node
111111
//! Disconnect node by id.
112112
virtual bool disconnectById(NodeId id) = 0;
113113

114-
#ifdef ENABLE_EXTERNAL_SIGNER
115114
//! List external signers
116115
virtual std::vector<ExternalSigner> externalSigners() = 0;
117-
#endif
118116

119117
//! Get total bytes recv.
120118
virtual int64_t getTotalBytesRecv() = 0;

src/node/interfaces.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,24 @@ class NodeImpl : public Node
171171
}
172172
return false;
173173
}
174-
#ifdef ENABLE_EXTERNAL_SIGNER
175174
std::vector<ExternalSigner> externalSigners() override
176175
{
176+
#ifdef ENABLE_EXTERNAL_SIGNER
177177
std::vector<ExternalSigner> signers = {};
178178
const std::string command = gArgs.GetArg("-signer", "");
179179
if (command == "") return signers;
180180
ExternalSigner::Enumerate(command, signers, Params().NetworkIDString());
181181
return signers;
182+
#else
183+
// This result is undistinguisable from a succesful call that returns
184+
// no signers. For the current GUI this doesn't matter, because the wallet
185+
// creation dialog disables the external signer checkbox in both
186+
// cases. The return type could be changed to std::optional<std::vector>
187+
// (or something that also includes error messages) if this distinction
188+
// becomes important.
189+
return {};
190+
#endif // ENABLE_EXTERNAL_SIGNER
182191
}
183-
#endif
184192
int64_t getTotalBytesRecv() override { return m_context->connman ? m_context->connman->GetTotalBytesRecv() : 0; }
185193
int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
186194
size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }

src/qt/createwalletdialog.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ CreateWalletDialog::~CreateWalletDialog()
112112
delete ui;
113113
}
114114

115-
#ifdef ENABLE_EXTERNAL_SIGNER
116115
void CreateWalletDialog::setSigners(std::vector<ExternalSigner>& signers)
117116
{
118117
if (!signers.empty()) {
@@ -132,7 +131,6 @@ void CreateWalletDialog::setSigners(std::vector<ExternalSigner>& signers)
132131
ui->external_signer_checkbox->setEnabled(false);
133132
}
134133
}
135-
#endif
136134

137135
QString CreateWalletDialog::walletName() const
138136
{

src/qt/createwalletdialog.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77

88
#include <QDialog>
99

10-
class WalletModel;
11-
12-
#ifdef ENABLE_EXTERNAL_SIGNER
1310
class ExternalSigner;
14-
#endif
11+
class WalletModel;
1512

1613
namespace Ui {
1714
class CreateWalletDialog;
@@ -27,9 +24,7 @@ class CreateWalletDialog : public QDialog
2724
explicit CreateWalletDialog(QWidget* parent);
2825
virtual ~CreateWalletDialog();
2926

30-
#ifdef ENABLE_EXTERNAL_SIGNER
3127
void setSigners(std::vector<ExternalSigner>& signers);
32-
#endif
3328

3429
QString walletName() const;
3530
bool isEncryptWalletChecked() const;

src/qt/walletcontroller.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,13 @@ void CreateWalletActivity::create()
296296
{
297297
m_create_wallet_dialog = new CreateWalletDialog(m_parent_widget);
298298

299-
#ifdef ENABLE_EXTERNAL_SIGNER
300299
std::vector<ExternalSigner> signers;
301300
try {
302301
signers = node().externalSigners();
303302
} catch (const std::runtime_error& e) {
304303
QMessageBox::critical(nullptr, tr("Can't list signers"), e.what());
305304
}
306305
m_create_wallet_dialog->setSigners(signers);
307-
#endif
308306

309307
m_create_wallet_dialog->setWindowModality(Qt::ApplicationModal);
310308
m_create_wallet_dialog->show();

src/util/system.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,9 @@ void runCommand(const std::string& strCommand)
12431243
}
12441244
#endif
12451245

1246-
#ifdef ENABLE_EXTERNAL_SIGNER
12471246
UniValue RunCommandParseJSON(const std::string& str_command, const std::string& str_std_in)
12481247
{
1248+
#ifdef ENABLE_EXTERNAL_SIGNER
12491249
namespace bp = boost::process;
12501250

12511251
UniValue result_json;
@@ -1277,8 +1277,10 @@ UniValue RunCommandParseJSON(const std::string& str_command, const std::string&
12771277
if (!result_json.read(result)) throw std::runtime_error("Unable to parse JSON: " + result);
12781278

12791279
return result_json;
1280-
}
1280+
#else
1281+
throw std::runtime_error("Compiled without external signing support (required for external signing).");
12811282
#endif // ENABLE_EXTERNAL_SIGNER
1283+
}
12821284

12831285
void SetupEnvironment()
12841286
{

src/util/system.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ std::string ShellEscape(const std::string& arg);
102102
#if HAVE_SYSTEM
103103
void runCommand(const std::string& strCommand);
104104
#endif
105-
#ifdef ENABLE_EXTERNAL_SIGNER
106105
/**
107106
* Execute a command which returns JSON, and parse the result.
108107
*
@@ -111,7 +110,6 @@ void runCommand(const std::string& strCommand);
111110
* @return parsed JSON
112111
*/
113112
UniValue RunCommandParseJSON(const std::string& str_command, const std::string& str_std_in="");
114-
#endif // ENABLE_EXTERNAL_SIGNER
115113

116114
/**
117115
* Most paths passed as configuration arguments are treated as relative to

src/wallet/external_signer_scriptpubkeyman.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <utility>
1414
#include <vector>
1515

16-
#ifdef ENABLE_EXTERNAL_SIGNER
17-
1816
bool ExternalSignerScriptPubKeyMan::SetupDescriptor(std::unique_ptr<Descriptor> desc)
1917
{
2018
LOCK(cs_desc_man);
@@ -84,5 +82,3 @@ TransactionError ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySignedTransact
8482
FinalizePSBT(psbt); // This won't work in a multisig setup
8583
return TransactionError::OK;
8684
}
87-
88-
#endif

0 commit comments

Comments
 (0)