gui: 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.
This commit is contained in:
furszy 2024-10-04 10:48:27 -03:00
parent 51c698161b
commit 002b792b9a
No known key found for this signature in database
GPG Key ID: 5DD23CCC686AA623
2 changed files with 14 additions and 16 deletions

View File

@ -92,7 +92,7 @@ public:
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 @@ public:
* @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();
@ -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);
}
@ -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*>();
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()));
@ -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);

View File

@ -46,9 +46,9 @@ public:
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);