Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple WalletModel from RPCExecutor #841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: describe wallet_name as a param[in] (wallet_model wasn't there either)

Suggested change
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
* @param[in] wallet_mame ...

*/

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
Loading