Qt: Add wallet selector to debug console
This commit is contained in:
parent
d558f44c58
commit
d49cc70e6d
5 changed files with 55 additions and 14 deletions
|
@ -554,6 +554,7 @@ bool BitcoinGUI::addWallet(const QString& name, WalletModel *walletModel)
|
|||
m_wallet_selector->setVisible(true);
|
||||
m_wallet_selector->setVisible(true);
|
||||
}
|
||||
rpcConsole->addWallet(name, walletModel);
|
||||
return walletFrame->addWallet(name, walletModel);
|
||||
}
|
||||
|
||||
|
|
|
@ -412,6 +412,22 @@
|
|||
<property name="spacing">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="WalletSelectorLabel">
|
||||
<property name="text">
|
||||
<string>Wallet: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="WalletSelector">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>(none)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <qt/bantablemodel.h>
|
||||
#include <qt/clientmodel.h>
|
||||
#include <qt/platformstyle.h>
|
||||
#include <qt/walletmodel.h>
|
||||
#include <chainparams.h>
|
||||
#include <netbase.h>
|
||||
#include <rpc/server.h>
|
||||
|
@ -84,7 +85,7 @@ class RPCExecutor : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public Q_SLOTS:
|
||||
void request(const QString &command);
|
||||
void request(const QString &command, const QString &walletID);
|
||||
|
||||
Q_SIGNALS:
|
||||
void reply(int category, const QString &command);
|
||||
|
@ -145,7 +146,7 @@ public:
|
|||
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
|
||||
*/
|
||||
|
||||
bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut)
|
||||
bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const std::string *walletID)
|
||||
{
|
||||
std::vector< std::vector<std::string> > stack;
|
||||
stack.push_back(std::vector<std::string>());
|
||||
|
@ -303,10 +304,8 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
|
|||
req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
|
||||
req.strMethod = stack.back()[0];
|
||||
#ifdef ENABLE_WALLET
|
||||
// TODO: Move this logic to WalletModel
|
||||
if (!vpwallets.empty()) {
|
||||
// in Qt, use always the wallet with index 0 when running with multiple wallets
|
||||
QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(vpwallets[0]->GetName()));
|
||||
if (walletID && !walletID->empty()) {
|
||||
QByteArray encodedName = QUrl::toPercentEncoding(QString::fromStdString(*walletID));
|
||||
req.URI = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
|
||||
}
|
||||
#endif
|
||||
|
@ -385,7 +384,7 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
|
|||
}
|
||||
}
|
||||
|
||||
void RPCExecutor::request(const QString &command)
|
||||
void RPCExecutor::request(const QString &command, const QString &walletID)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -416,7 +415,8 @@ void RPCExecutor::request(const QString &command)
|
|||
" example: getblock(getblockhash(0),true)[tx][0]\n\n")));
|
||||
return;
|
||||
}
|
||||
if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand))
|
||||
std::string wallet_id = walletID.toStdString();
|
||||
if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand, nullptr, &wallet_id))
|
||||
{
|
||||
Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
|
||||
return;
|
||||
|
@ -687,6 +687,18 @@ void RPCConsole::setClientModel(ClientModel *model)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
void RPCConsole::addWallet(const QString name, WalletModel * const walletModel)
|
||||
{
|
||||
// use name for text and internal data object (to allow to move to a wallet id later)
|
||||
ui->WalletSelector->addItem(name, name);
|
||||
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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static QString categoryClass(int category)
|
||||
{
|
||||
switch(category)
|
||||
|
@ -874,8 +886,16 @@ void RPCConsole::on_lineEdit_returnPressed()
|
|||
|
||||
cmdBeforeBrowsing = QString();
|
||||
|
||||
QString walletID;
|
||||
#ifdef ENABLE_WALLET
|
||||
const int wallet_index = ui->WalletSelector->currentIndex();
|
||||
if (wallet_index > 0) {
|
||||
walletID = (QString)ui->WalletSelector->itemData(wallet_index).value<QString>();
|
||||
}
|
||||
#endif
|
||||
|
||||
message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
|
||||
Q_EMIT cmdRequest(cmd);
|
||||
Q_EMIT cmdRequest(cmd, walletID);
|
||||
|
||||
cmd = QString::fromStdString(strFilteredCmd);
|
||||
|
||||
|
@ -923,7 +943,7 @@ void RPCConsole::startExecutor()
|
|||
// Replies from executor object must go to this object
|
||||
connect(executor, SIGNAL(reply(int,QString)), this, SLOT(message(int,QString)));
|
||||
// Requests from this object must go to executor
|
||||
connect(this, SIGNAL(cmdRequest(QString)), executor, SLOT(request(QString)));
|
||||
connect(this, SIGNAL(cmdRequest(QString, QString)), executor, SLOT(request(QString, QString)));
|
||||
|
||||
// On stopExecutor signal
|
||||
// - quit the Qt event loop in the execution thread
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
class ClientModel;
|
||||
class PlatformStyle;
|
||||
class RPCTimerInterface;
|
||||
class WalletModel;
|
||||
|
||||
namespace Ui {
|
||||
class RPCConsole;
|
||||
|
@ -36,12 +37,13 @@ public:
|
|||
explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
|
||||
~RPCConsole();
|
||||
|
||||
static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr);
|
||||
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr) {
|
||||
return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut);
|
||||
static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const std::string *walletID = nullptr);
|
||||
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const std::string *walletID = nullptr) {
|
||||
return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut, walletID);
|
||||
}
|
||||
|
||||
void setClientModel(ClientModel *model);
|
||||
void addWallet(const QString name, WalletModel * const walletModel);
|
||||
|
||||
enum MessageClass {
|
||||
MC_ERROR,
|
||||
|
@ -120,7 +122,7 @@ public Q_SLOTS:
|
|||
Q_SIGNALS:
|
||||
// For RPC command executor
|
||||
void stopExecutor();
|
||||
void cmdRequest(const QString &command);
|
||||
void cmdRequest(const QString &command, const QString &walletID);
|
||||
|
||||
private:
|
||||
void startExecutor();
|
||||
|
|
|
@ -131,6 +131,8 @@ public:
|
|||
TransactionTableModel *getTransactionTableModel();
|
||||
RecentRequestsTableModel *getRecentRequestsTableModel();
|
||||
|
||||
CWallet *getWallet() const { return wallet; };
|
||||
|
||||
CAmount getBalance(const CCoinControl *coinControl = nullptr) const;
|
||||
CAmount getUnconfirmedBalance() const;
|
||||
CAmount getImmatureBalance() const;
|
||||
|
|
Loading…
Reference in a new issue