Skip to content

Commit 3f34c04

Browse files
committed
gui: bugfix, decouple WalletModel from RPCExecutor
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.
1 parent 51c6981 commit 3f34c04

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/qt/rpcconsole.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class RPCExecutor : public QObject
9292
explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}
9393

9494
public Q_SLOTS:
95-
void request(const QString &command, const WalletModel* wallet_model);
95+
void request(const QString &command, const QString& wallet_name);
9696

9797
Q_SIGNALS:
9898
void reply(int category, const QString &command);
@@ -169,7 +169,7 @@ class PeerIdViewDelegate : public QStyledItemDelegate
169169
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
170170
*/
171171

172-
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
172+
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const QString& wallet_name)
173173
{
174174
std::vector< std::vector<std::string> > stack;
175175
stack.emplace_back();
@@ -328,12 +328,10 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
328328
UniValue params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
329329
std::string method = stack.back()[0];
330330
std::string uri;
331-
#ifdef ENABLE_WALLET
332-
if (wallet_model) {
333-
QByteArray encodedName = QUrl::toPercentEncoding(wallet_model->getWalletName());
331+
if (!wallet_name.isEmpty()) {
332+
QByteArray encodedName = QUrl::toPercentEncoding(wallet_name);
334333
uri = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
335334
}
336-
#endif
337335
assert(node);
338336
lastResult = node->executeRpc(method, params, uri);
339337
}
@@ -411,7 +409,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
411409
}
412410
}
413411

414-
void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
412+
void RPCExecutor::request(const QString &command, const QString& wallet_name)
415413
{
416414
try
417415
{
@@ -441,7 +439,7 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode
441439
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
442440
return;
443441
}
444-
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {
442+
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_name)) {
445443
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
446444
return;
447445
}
@@ -1060,10 +1058,10 @@ void RPCConsole::on_lineEdit_returnPressed()
10601058

10611059
ui->lineEdit->clear();
10621060

1063-
WalletModel* wallet_model{nullptr};
1061+
QString in_use_wallet_name;
10641062
#ifdef ENABLE_WALLET
1065-
wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
1066-
1063+
WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
1064+
in_use_wallet_name = wallet_model ? wallet_model->getWalletName() : QString();
10671065
if (m_last_wallet_model != wallet_model) {
10681066
if (wallet_model) {
10691067
message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
@@ -1079,8 +1077,8 @@ void RPCConsole::on_lineEdit_returnPressed()
10791077
message(CMD_REPLY, tr("Executing…"));
10801078
m_is_executing = true;
10811079

1082-
QMetaObject::invokeMethod(m_executor, [this, cmd, wallet_model] {
1083-
m_executor->request(cmd, wallet_model);
1080+
QMetaObject::invokeMethod(m_executor, [this, cmd, &in_use_wallet_name] {
1081+
m_executor->request(cmd, in_use_wallet_name);
10841082
});
10851083

10861084
cmd = QString::fromStdString(strFilteredCmd);

src/qt/rpcconsole.h

+3-3
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)