mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-21 14:22:38 +02:00
Merge bitcoin-core/gui#841: Decouple WalletModel from RPCExecutor
002b792b9a85100d89e47706c29cf1fd355d9727 gui: decouple WalletModel from RPCExecutor (furszy)
Pull request description:
A more comprehensive fix for the issue described in #837.
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 also drops an extra `#ifdef ENABLE_WALLET` block which is always good.
ACKs for top commit:
w0xlt:
Code Review ACK 002b792b9a
pablomartin4btc:
tACK 002b792b9a85100d89e47706c29cf1fd355d9727
BrandonOdiwuor:
tACK 002b792b9a85100d89e47706c29cf1fd355d9727
hebasto:
ACK 002b792b9a85100d89e47706c29cf1fd355d9727, I have reviewed the code and it looks OK.
Tree-SHA512: a8e6b7e9d88dd8e0ff5e2d0de91be2f85fd0559265267d3bf6cae5a37606cf1ab6bc7415d5817a11006008de362f2ca3557ba772b4e1bd9fbef5f564be3b53bb
This commit is contained in:
commit
46f79dde67
@ -89,7 +89,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);
|
||||
@ -166,7 +166,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();
|
||||
@ -325,12 +325,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);
|
||||
}
|
||||
@ -408,7 +406,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
|
||||
{
|
||||
@ -438,7 +436,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;
|
||||
}
|
||||
@ -1057,10 +1055,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()));
|
||||
@ -1076,8 +1074,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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user