Skip to content

Commit 46f79dd

Browse files
committed
Merge #841: Decouple WalletModel from RPCExecutor
002b792 gui: decouple WalletModel from RPCExecutor (furszy) Pull request description: A more comprehensive fix for the issue described in #837. Since the `WalletModel` class is unavailable when compiling without wallet support `(-DENABLE_WALLET=0)`, the RPC executor class should not be coupled to it. This decoupling ensures GUI compatibility with builds that omit wallet support. This also drops an extra `#ifdef ENABLE_WALLET` block which is always good. ACKs for top commit: w0xlt: Code Review ACK 002b792 pablomartin4btc: tACK 002b792 BrandonOdiwuor: tACK 002b792 hebasto: ACK 002b792, I have reviewed the code and it looks OK. Tree-SHA512: a8e6b7e9d88dd8e0ff5e2d0de91be2f85fd0559265267d3bf6cae5a37606cf1ab6bc7415d5817a11006008de362f2ca3557ba772b4e1bd9fbef5f564be3b53bb
2 parents 746ab19 + 002b792 commit 46f79dd

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/qt/rpcconsole.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class RPCExecutor : public QObject
8989
explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}
9090

9191
public Q_SLOTS:
92-
void request(const QString &command, const WalletModel* wallet_model);
92+
void request(const QString &command, const QString& wallet_name);
9393

9494
Q_SIGNALS:
9595
void reply(int category, const QString &command);
@@ -166,7 +166,7 @@ class PeerIdViewDelegate : public QStyledItemDelegate
166166
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
167167
*/
168168

169-
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
169+
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const QString& wallet_name)
170170
{
171171
std::vector< std::vector<std::string> > stack;
172172
stack.emplace_back();
@@ -325,12 +325,10 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
325325
UniValue params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
326326
std::string method = stack.back()[0];
327327
std::string uri;
328-
#ifdef ENABLE_WALLET
329-
if (wallet_model) {
330-
QByteArray encodedName = QUrl::toPercentEncoding(wallet_model->getWalletName());
328+
if (!wallet_name.isEmpty()) {
329+
QByteArray encodedName = QUrl::toPercentEncoding(wallet_name);
331330
uri = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
332331
}
333-
#endif
334332
assert(node);
335333
lastResult = node->executeRpc(method, params, uri);
336334
}
@@ -408,7 +406,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
408406
}
409407
}
410408

411-
void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
409+
void RPCExecutor::request(const QString &command, const QString& wallet_name)
412410
{
413411
try
414412
{
@@ -438,7 +436,7 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode
438436
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
439437
return;
440438
}
441-
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {
439+
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_name)) {
442440
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
443441
return;
444442
}
@@ -1057,10 +1055,10 @@ void RPCConsole::on_lineEdit_returnPressed()
10571055

10581056
ui->lineEdit->clear();
10591057

1060-
WalletModel* wallet_model{nullptr};
1058+
QString in_use_wallet_name;
10611059
#ifdef ENABLE_WALLET
1062-
wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
1063-
1060+
WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
1061+
in_use_wallet_name = wallet_model ? wallet_model->getWalletName() : QString();
10641062
if (m_last_wallet_model != wallet_model) {
10651063
if (wallet_model) {
10661064
message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
@@ -1076,8 +1074,8 @@ void RPCConsole::on_lineEdit_returnPressed()
10761074
message(CMD_REPLY, tr("Executing…"));
10771075
m_is_executing = true;
10781076

1079-
QMetaObject::invokeMethod(m_executor, [this, cmd, wallet_model] {
1080-
m_executor->request(cmd, wallet_model);
1077+
QMetaObject::invokeMethod(m_executor, [this, cmd, in_use_wallet_name] {
1078+
m_executor->request(cmd, in_use_wallet_name);
10811079
});
10821080

10831081
cmd = QString::fromStdString(strFilteredCmd);

src/qt/rpcconsole.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class RPCConsole: public QWidget
4646
explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
4747
~RPCConsole();
4848

49-
static bool RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr);
50-
static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
51-
return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
49+
static bool RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {});
50+
static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {}) {
51+
return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_name);
5252
}
5353

5454
void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);

0 commit comments

Comments
 (0)