Skip to content

Commit d49cc70

Browse files
committed
Qt: Add wallet selector to debug console
1 parent d558f44 commit d49cc70

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
554554
m_wallet_selector->setVisible(true);
555555
m_wallet_selector->setVisible(true);
556556
}
557+
rpcConsole->addWallet(name, walletModel);
557558
return walletFrame->addWallet(name, walletModel);
558559
}
559560

src/qt/forms/debugwindow.ui

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,22 @@
412412
<property name="spacing">
413413
<number>4</number>
414414
</property>
415+
<item>
416+
<widget class="QLabel" name="WalletSelectorLabel">
417+
<property name="text">
418+
<string>Wallet: </string>
419+
</property>
420+
</widget>
421+
</item>
422+
<item>
423+
<widget class="QComboBox" name="WalletSelector">
424+
<item>
425+
<property name="text">
426+
<string>(none)</string>
427+
</property>
428+
</item>
429+
</widget>
430+
</item>
415431
<item>
416432
<spacer name="horizontalSpacer">
417433
<property name="orientation">

src/qt/rpcconsole.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <qt/bantablemodel.h>
1313
#include <qt/clientmodel.h>
1414
#include <qt/platformstyle.h>
15+
#include <qt/walletmodel.h>
1516
#include <chainparams.h>
1617
#include <netbase.h>
1718
#include <rpc/server.h>
@@ -84,7 +85,7 @@ class RPCExecutor : public QObject
8485
Q_OBJECT
8586

8687
public Q_SLOTS:
87-
void request(const QString &command);
88+
void request(const QString &command, const QString &walletID);
8889

8990
Q_SIGNALS:
9091
void reply(int category, const QString &command);
@@ -145,7 +146,7 @@ class QtRPCTimerInterface: public RPCTimerInterface
145146
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
146147
*/
147148

148-
bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut)
149+
bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const std::string *walletID)
149150
{
150151
std::vector< std::vector<std::string> > stack;
151152
stack.push_back(std::vector<std::string>());
@@ -303,10 +304,8 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
303304
req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
304305
req.strMethod = stack.back()[0];
305306
#ifdef ENABLE_WALLET
306-
// TODO: Move this logic to WalletModel
307-
if (!vpwallets.empty()) {
308-
// in Qt, use always the wallet with index 0 when running with multiple wallets
309-
QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(vpwallets[0]->GetName()));
307+
if (walletID && !walletID->empty()) {
308+
QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(*walletID));
310309
req.URI = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
311310
}
312311
#endif
@@ -385,7 +384,7 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
385384
}
386385
}
387386

388-
void RPCExecutor::request(const QString &command)
387+
void RPCExecutor::request(const QString &command, const QString &walletID)
389388
{
390389
try
391390
{
@@ -416,7 +415,8 @@ void RPCExecutor::request(const QString &command)
416415
" example: getblock(getblockhash(0),true)[tx][0]\n\n")));
417416
return;
418417
}
419-
if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand))
418+
std::string wallet_id = walletID.toStdString();
419+
if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand, nullptr, &wallet_id))
420420
{
421421
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
422422
return;
@@ -687,6 +687,18 @@ void RPCConsole::setClientModel(ClientModel *model)
687687
}
688688
}
689689

690+
#ifdef ENABLE_WALLET
691+
void RPCConsole::addWallet(const QString name, WalletModel * const walletModel)
692+
{
693+
// use name for text and internal data object (to allow to move to a wallet id later)
694+
ui->WalletSelector->addItem(name, name);
695+
if (ui->WalletSelector->count() == 2 && !isVisible()) {
696+
// First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
697+
ui->WalletSelector->setCurrentIndex(1);
698+
}
699+
}
700+
#endif
701+
690702
static QString categoryClass(int category)
691703
{
692704
switch(category)
@@ -874,8 +886,16 @@ void RPCConsole::on_lineEdit_returnPressed()
874886

875887
cmdBeforeBrowsing = QString();
876888

889+
QString walletID;
890+
#ifdef ENABLE_WALLET
891+
const int wallet_index = ui->WalletSelector->currentIndex();
892+
if (wallet_index > 0) {
893+
walletID = (QString)ui->WalletSelector->itemData(wallet_index).value<QString>();
894+
}
895+
#endif
896+
877897
message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
878-
Q_EMIT cmdRequest(cmd);
898+
Q_EMIT cmdRequest(cmd, walletID);
879899

880900
cmd = QString::fromStdString(strFilteredCmd);
881901

@@ -923,7 +943,7 @@ void RPCConsole::startExecutor()
923943
// Replies from executor object must go to this object
924944
connect(executor, SIGNAL(reply(int,QString)), this, SLOT(message(int,QString)));
925945
// Requests from this object must go to executor
926-
connect(this, SIGNAL(cmdRequest(QString)), executor, SLOT(request(QString)));
946+
connect(this, SIGNAL(cmdRequest(QString, QString)), executor, SLOT(request(QString, QString)));
927947

928948
// On stopExecutor signal
929949
// - quit the Qt event loop in the execution thread

src/qt/rpcconsole.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
class ClientModel;
1818
class PlatformStyle;
1919
class RPCTimerInterface;
20+
class WalletModel;
2021

2122
namespace Ui {
2223
class RPCConsole;
@@ -36,12 +37,13 @@ class RPCConsole: public QWidget
3637
explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
3738
~RPCConsole();
3839

39-
static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr);
40-
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr) {
41-
return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut);
40+
static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const std::string *walletID = nullptr);
41+
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const std::string *walletID = nullptr) {
42+
return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut, walletID);
4243
}
4344

4445
void setClientModel(ClientModel *model);
46+
void addWallet(const QString name, WalletModel * const walletModel);
4547

4648
enum MessageClass {
4749
MC_ERROR,
@@ -120,7 +122,7 @@ public Q_SLOTS:
120122
Q_SIGNALS:
121123
// For RPC command executor
122124
void stopExecutor();
123-
void cmdRequest(const QString &command);
125+
void cmdRequest(const QString &command, const QString &walletID);
124126

125127
private:
126128
void startExecutor();

src/qt/walletmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class WalletModel : public QObject
131131
TransactionTableModel *getTransactionTableModel();
132132
RecentRequestsTableModel *getRecentRequestsTableModel();
133133

134+
CWallet *getWallet() const { return wallet; };
135+
134136
CAmount getBalance(const CCoinControl *coinControl = nullptr) const;
135137
CAmount getUnconfirmedBalance() const;
136138
CAmount getImmatureBalance() const;

0 commit comments

Comments
 (0)