Skip to content

Commit 91b0c5b

Browse files
committed
qt: Use WalletModel* instead of wallet name in console window
1 parent b2ce86c commit 91b0c5b

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

src/qt/rpcconsole.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -85,7 +85,7 @@ class RPCExecutor : public QObject
8585
explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}
8686

8787
public Q_SLOTS:
88-
void request(const QString &command, const QString &walletID);
88+
void request(const QString &command, const WalletModel* wallet_model);
8989

9090
Q_SIGNALS:
9191
void reply(int category, const QString &command);
@@ -148,7 +148,7 @@ class QtRPCTimerInterface: public RPCTimerInterface
148148
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
149149
*/
150150

151-
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const std::string *walletID)
151+
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
152152
{
153153
std::vector< std::vector<std::string> > stack;
154154
stack.push_back(std::vector<std::string>());
@@ -306,8 +306,8 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
306306
std::string method = stack.back()[0];
307307
std::string uri;
308308
#ifdef ENABLE_WALLET
309-
if (walletID) {
310-
QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(*walletID));
309+
if (wallet_model) {
310+
QByteArray encodedName = QUrl::toPercentEncoding(wallet_model->getWalletName());
311311
uri = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
312312
}
313313
#endif
@@ -387,7 +387,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
387387
}
388388
}
389389

390-
void RPCExecutor::request(const QString &command, const QString &walletID)
390+
void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
391391
{
392392
try
393393
{
@@ -418,9 +418,7 @@ void RPCExecutor::request(const QString &command, const QString &walletID)
418418
" example: getblock(getblockhash(0),true)[tx][0]\n\n")));
419419
return;
420420
}
421-
std::string wallet_id = walletID.toStdString();
422-
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, walletID.isNull() ? nullptr : &wallet_id))
423-
{
421+
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {
424422
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
425423
return;
426424
}
@@ -698,10 +696,8 @@ void RPCConsole::setClientModel(ClientModel *model)
698696
#ifdef ENABLE_WALLET
699697
void RPCConsole::addWallet(WalletModel * const walletModel)
700698
{
701-
const QString name = walletModel->getWalletName();
702-
// use name for text and internal data object (to allow to move to a wallet id later)
703-
const QString display_name = walletModel->getDisplayName();
704-
ui->WalletSelector->addItem(display_name, name);
699+
// use name for text and wallet model for internal data object (to allow to move to a wallet id later)
700+
ui->WalletSelector->addItem(walletModel->getDisplayName(), QVariant::fromValue(walletModel));
705701
if (ui->WalletSelector->count() == 2 && !isVisible()) {
706702
// First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
707703
ui->WalletSelector->setCurrentIndex(1);
@@ -714,8 +710,7 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
714710

715711
void RPCConsole::removeWallet(WalletModel * const walletModel)
716712
{
717-
const QString name = walletModel->getWalletName();
718-
ui->WalletSelector->removeItem(ui->WalletSelector->findData(name));
713+
ui->WalletSelector->removeItem(ui->WalletSelector->findData(QVariant::fromValue(walletModel)));
719714
if (ui->WalletSelector->count() == 2) {
720715
ui->WalletSelector->setVisible(false);
721716
ui->WalletSelectorLabel->setVisible(false);
@@ -910,25 +905,25 @@ void RPCConsole::on_lineEdit_returnPressed()
910905

911906
cmdBeforeBrowsing = QString();
912907

913-
QString walletID;
908+
WalletModel* wallet_model{nullptr};
914909
#ifdef ENABLE_WALLET
915910
const int wallet_index = ui->WalletSelector->currentIndex();
916911
if (wallet_index > 0) {
917-
walletID = (QString)ui->WalletSelector->itemData(wallet_index).value<QString>();
912+
wallet_model = ui->WalletSelector->itemData(wallet_index).value<WalletModel*>();
918913
}
919914

920-
if (m_last_wallet_id != walletID) {
921-
if (walletID.isNull()) {
922-
message(CMD_REQUEST, tr("Executing command without any wallet"));
915+
if (m_last_wallet_model != wallet_model) {
916+
if (wallet_model) {
917+
message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
923918
} else {
924-
message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(walletID));
919+
message(CMD_REQUEST, tr("Executing command without any wallet"));
925920
}
926-
m_last_wallet_id = walletID;
921+
m_last_wallet_model = wallet_model;
927922
}
928923
#endif
929924

930925
message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
931-
Q_EMIT cmdRequest(cmd, walletID);
926+
Q_EMIT cmdRequest(cmd, m_last_wallet_model);
932927

933928
cmd = QString::fromStdString(strFilteredCmd);
934929

src/qt/rpcconsole.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2018 The Bitcoin Core developers
1+
// Copyright (c) 2011-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -41,9 +41,9 @@ class RPCConsole: public QWidget
4141
explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
4242
~RPCConsole();
4343

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

4949
void setClientModel(ClientModel *model);
@@ -133,7 +133,7 @@ public Q_SLOTS:
133133
Q_SIGNALS:
134134
// For RPC command executor
135135
void stopExecutor();
136-
void cmdRequest(const QString &command, const QString &walletID);
136+
void cmdRequest(const QString &command, const WalletModel* wallet_model);
137137

138138
private:
139139
void startExecutor();
@@ -165,7 +165,7 @@ public Q_SLOTS:
165165
int consoleFontSize = 0;
166166
QCompleter *autoCompleter = nullptr;
167167
QThread thread;
168-
QString m_last_wallet_id;
168+
WalletModel* m_last_wallet_model{nullptr};
169169

170170
/** Update UI with latest network info from model. */
171171
void updateNetworkState();

0 commit comments

Comments
 (0)