|
12 | 12 | #include <qt/bantablemodel.h>
|
13 | 13 | #include <qt/clientmodel.h>
|
14 | 14 | #include <qt/platformstyle.h>
|
| 15 | +#include <qt/walletmodel.h> |
15 | 16 | #include <chainparams.h>
|
16 | 17 | #include <netbase.h>
|
17 | 18 | #include <rpc/server.h>
|
@@ -84,7 +85,7 @@ class RPCExecutor : public QObject
|
84 | 85 | Q_OBJECT
|
85 | 86 |
|
86 | 87 | public Q_SLOTS:
|
87 |
| - void request(const QString &command); |
| 88 | + void request(const QString &command, const QString &walletID); |
88 | 89 |
|
89 | 90 | Q_SIGNALS:
|
90 | 91 | void reply(int category, const QString &command);
|
@@ -145,7 +146,7 @@ class QtRPCTimerInterface: public RPCTimerInterface
|
145 | 146 | * @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
|
146 | 147 | */
|
147 | 148 |
|
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) |
149 | 150 | {
|
150 | 151 | std::vector< std::vector<std::string> > stack;
|
151 | 152 | stack.push_back(std::vector<std::string>());
|
@@ -303,10 +304,8 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
|
303 | 304 | req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
|
304 | 305 | req.strMethod = stack.back()[0];
|
305 | 306 | #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)); |
310 | 309 | req.URI = "/wallet/"+std::string(encodedName.constData(), encodedName.length());
|
311 | 310 | }
|
312 | 311 | #endif
|
@@ -385,7 +384,7 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
|
385 | 384 | }
|
386 | 385 | }
|
387 | 386 |
|
388 |
| -void RPCExecutor::request(const QString &command) |
| 387 | +void RPCExecutor::request(const QString &command, const QString &walletID) |
389 | 388 | {
|
390 | 389 | try
|
391 | 390 | {
|
@@ -416,7 +415,8 @@ void RPCExecutor::request(const QString &command)
|
416 | 415 | " example: getblock(getblockhash(0),true)[tx][0]\n\n")));
|
417 | 416 | return;
|
418 | 417 | }
|
419 |
| - if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand)) |
| 418 | + std::string wallet_id = walletID.toStdString(); |
| 419 | + if(!RPCConsole::RPCExecuteCommandLine(result, executableCommand, nullptr, &wallet_id)) |
420 | 420 | {
|
421 | 421 | Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \""));
|
422 | 422 | return;
|
@@ -687,6 +687,18 @@ void RPCConsole::setClientModel(ClientModel *model)
|
687 | 687 | }
|
688 | 688 | }
|
689 | 689 |
|
| 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 | + |
690 | 702 | static QString categoryClass(int category)
|
691 | 703 | {
|
692 | 704 | switch(category)
|
@@ -874,8 +886,16 @@ void RPCConsole::on_lineEdit_returnPressed()
|
874 | 886 |
|
875 | 887 | cmdBeforeBrowsing = QString();
|
876 | 888 |
|
| 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 | + |
877 | 897 | message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
|
878 |
| - Q_EMIT cmdRequest(cmd); |
| 898 | + Q_EMIT cmdRequest(cmd, walletID); |
879 | 899 |
|
880 | 900 | cmd = QString::fromStdString(strFilteredCmd);
|
881 | 901 |
|
@@ -923,7 +943,7 @@ void RPCConsole::startExecutor()
|
923 | 943 | // Replies from executor object must go to this object
|
924 | 944 | connect(executor, SIGNAL(reply(int,QString)), this, SLOT(message(int,QString)));
|
925 | 945 | // 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))); |
927 | 947 |
|
928 | 948 | // On stopExecutor signal
|
929 | 949 | // - quit the Qt event loop in the execution thread
|
|
0 commit comments