aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2019-01-04 12:17:53 +0000
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2019-01-04 15:24:00 +0000
commit91b0c5b09616bb8c5ef8107efb432ce4c7c9a383 (patch)
treeb2e562ab1b7293105ef116510fa4d0876d13cd07
parentb2ce86c3ad79db49ddf06207230512300ec11156 (diff)
downloadbitcoin-91b0c5b09616bb8c5ef8107efb432ce4c7c9a383.tar.xz
qt: Use WalletModel* instead of wallet name in console window
-rw-r--r--src/qt/rpcconsole.cpp41
-rw-r--r--src/qt/rpcconsole.h12
2 files changed, 24 insertions, 29 deletions
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index dc1abcbcff..a6187685a9 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2011-2018 The Bitcoin Core developers
+// Copyright (c) 2011-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -85,7 +85,7 @@ public:
explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}
public Q_SLOTS:
- void request(const QString &command, const QString &walletID);
+ void request(const QString &command, const WalletModel* wallet_model);
Q_SIGNALS:
void reply(int category, const QString &command);
@@ -148,7 +148,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 std::string *walletID)
+bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
{
std::vector< std::vector<std::string> > stack;
stack.push_back(std::vector<std::string>());
@@ -306,8 +306,8 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
std::string method = stack.back()[0];
std::string uri;
#ifdef ENABLE_WALLET
- if (walletID) {
- QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(*walletID));
+ if (wallet_model) {
+ QByteArray encodedName = QUrl::toPercentEncoding(wallet_model->getWalletName());
uri = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
}
#endif
@@ -387,7 +387,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
}
}
-void RPCExecutor::request(const QString &command, const QString &walletID)
+void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
{
try
{
@@ -418,9 +418,7 @@ void RPCExecutor::request(const QString &command, const QString &walletID)
" example: getblock(getblockhash(0),true)[tx][0]\n\n")));
return;
}
- std::string wallet_id = walletID.toStdString();
- if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, walletID.isNull() ? nullptr : &wallet_id))
- {
+ if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
return;
}
@@ -698,10 +696,8 @@ void RPCConsole::setClientModel(ClientModel *model)
#ifdef ENABLE_WALLET
void RPCConsole::addWallet(WalletModel * const walletModel)
{
- const QString name = walletModel->getWalletName();
- // use name for text and internal data object (to allow to move to a wallet id later)
- const QString display_name = walletModel->getDisplayName();
- ui->WalletSelector->addItem(display_name, name);
+ // use name for text and wallet model for internal data object (to allow to move to a wallet id later)
+ ui->WalletSelector->addItem(walletModel->getDisplayName(), QVariant::fromValue(walletModel));
if (ui->WalletSelector->count() == 2 && !isVisible()) {
// First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
ui->WalletSelector->setCurrentIndex(1);
@@ -714,8 +710,7 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
void RPCConsole::removeWallet(WalletModel * const walletModel)
{
- const QString name = walletModel->getWalletName();
- ui->WalletSelector->removeItem(ui->WalletSelector->findData(name));
+ ui->WalletSelector->removeItem(ui->WalletSelector->findData(QVariant::fromValue(walletModel)));
if (ui->WalletSelector->count() == 2) {
ui->WalletSelector->setVisible(false);
ui->WalletSelectorLabel->setVisible(false);
@@ -910,25 +905,25 @@ void RPCConsole::on_lineEdit_returnPressed()
cmdBeforeBrowsing = QString();
- QString walletID;
+ WalletModel* wallet_model{nullptr};
#ifdef ENABLE_WALLET
const int wallet_index = ui->WalletSelector->currentIndex();
if (wallet_index > 0) {
- walletID = (QString)ui->WalletSelector->itemData(wallet_index).value<QString>();
+ wallet_model = ui->WalletSelector->itemData(wallet_index).value<WalletModel*>();
}
- if (m_last_wallet_id != walletID) {
- if (walletID.isNull()) {
- message(CMD_REQUEST, tr("Executing command without any wallet"));
+ if (m_last_wallet_model != wallet_model) {
+ if (wallet_model) {
+ message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
} else {
- message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(walletID));
+ message(CMD_REQUEST, tr("Executing command without any wallet"));
}
- m_last_wallet_id = walletID;
+ m_last_wallet_model = wallet_model;
}
#endif
message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
- Q_EMIT cmdRequest(cmd, walletID);
+ Q_EMIT cmdRequest(cmd, m_last_wallet_model);
cmd = QString::fromStdString(strFilteredCmd);
diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h
index 20dbf5ec95..6c000ba096 100644
--- a/src/qt/rpcconsole.h
+++ b/src/qt/rpcconsole.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011-2018 The Bitcoin Core developers
+// Copyright (c) 2011-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -41,9 +41,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 std::string *walletID = nullptr);
- static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const std::string *walletID = nullptr) {
- return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, walletID);
+ 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);
}
void setClientModel(ClientModel *model);
@@ -133,7 +133,7 @@ public Q_SLOTS:
Q_SIGNALS:
// For RPC command executor
void stopExecutor();
- void cmdRequest(const QString &command, const QString &walletID);
+ void cmdRequest(const QString &command, const WalletModel* wallet_model);
private:
void startExecutor();
@@ -165,7 +165,7 @@ private:
int consoleFontSize = 0;
QCompleter *autoCompleter = nullptr;
QThread thread;
- QString m_last_wallet_id;
+ WalletModel* m_last_wallet_model{nullptr};
/** Update UI with latest network info from model. */
void updateNetworkState();