Skip to content

Commit

Permalink
gui: bugfix, decouple WalletModel from RPCExecutor
Browse files Browse the repository at this point in the history
The RPC executor should not rely on the WalletModel class, which is
unavailable when compiled with '-DENABLE_WALLET=0'. This decoupling
ensures compatibility with builds that omit wallet support.
  • Loading branch information
furszy committed Oct 4, 2024
1 parent 51c6981 commit 51c0606
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
24 changes: 11 additions & 13 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RPCExecutor : public QObject
explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}

public Q_SLOTS:
void request(const QString &command, const WalletModel* wallet_model);
void request(const QString &command, const QString& wallet_name);

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

bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const QString& wallet_name)
{
std::vector< std::vector<std::string> > stack;
stack.emplace_back();
Expand Down Expand Up @@ -328,12 +328,10 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
UniValue params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
std::string method = stack.back()[0];
std::string uri;
#ifdef ENABLE_WALLET
if (wallet_model) {
QByteArray encodedName = QUrl::toPercentEncoding(wallet_model->getWalletName());
if (!wallet_name.isEmpty()) {
QByteArray encodedName = QUrl::toPercentEncoding(wallet_name);
uri = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
}
#endif
assert(node);
lastResult = node->executeRpc(method, params, uri);
}
Expand Down Expand Up @@ -411,7 +409,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
}
}

void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
void RPCExecutor::request(const QString &command, const QString& wallet_name)
{
try
{
Expand Down Expand Up @@ -441,7 +439,7 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
return;
}
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_name)) {
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
return;
}
Expand Down Expand Up @@ -1060,10 +1058,10 @@ void RPCConsole::on_lineEdit_returnPressed()

ui->lineEdit->clear();

WalletModel* wallet_model{nullptr};
QString in_use_wallet_name;
#ifdef ENABLE_WALLET
wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();

WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
in_use_wallet_name = wallet_model ? wallet_model->getWalletName() : QString();
if (m_last_wallet_model != wallet_model) {
if (wallet_model) {
message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
Expand All @@ -1079,8 +1077,8 @@ void RPCConsole::on_lineEdit_returnPressed()
message(CMD_REPLY, tr("Executing…"));
m_is_executing = true;

QMetaObject::invokeMethod(m_executor, [this, cmd, wallet_model] {
m_executor->request(cmd, wallet_model);
QMetaObject::invokeMethod(m_executor, [this, cmd, &in_use_wallet_name] {
m_executor->request(cmd, in_use_wallet_name);
});

cmd = QString::fromStdString(strFilteredCmd);
Expand Down
6 changes: 3 additions & 3 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class RPCConsole: public QWidget
explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
~RPCConsole();

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);
static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
static bool RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {});
static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {}) {
return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_name);
}

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

0 comments on commit 51c0606

Please sign in to comment.