diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 20311cb631c..a908d60d720 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -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); @@ -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 > stack; stack.emplace_back(); @@ -328,12 +328,10 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes UniValue params = RPCConvertValues(stack.back()[0], std::vector(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); } @@ -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 { @@ -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; } @@ -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* wallet_model = ui->WalletSelector->currentData().value(); + 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())); @@ -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); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 4747e611d00..687c6cee6a7 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -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);