1
- // Copyright (c) 2011-2018 The Bitcoin Core developers
1
+ // Copyright (c) 2011-2019 The Bitcoin Core developers
2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
@@ -85,7 +85,7 @@ class RPCExecutor : public QObject
85
85
explicit RPCExecutor (interfaces::Node& node) : m_node(node) {}
86
86
87
87
public Q_SLOTS:
88
- void request (const QString &command, const QString &walletID );
88
+ void request (const QString &command, const WalletModel* wallet_model );
89
89
90
90
Q_SIGNALS:
91
91
void reply (int category, const QString &command);
@@ -148,7 +148,7 @@ class QtRPCTimerInterface: public RPCTimerInterface
148
148
* @param[out] pstrFilteredOut Command line, filtered to remove any sensitive data
149
149
*/
150
150
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 )
152
152
{
153
153
std::vector< std::vector<std::string> > stack;
154
154
stack.push_back (std::vector<std::string>());
@@ -306,8 +306,8 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
306
306
std::string method = stack.back ()[0 ];
307
307
std::string uri;
308
308
#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 ( ));
311
311
uri = " /wallet/" +std::string (encodedName.constData (), encodedName.length ());
312
312
}
313
313
#endif
@@ -387,7 +387,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
387
387
}
388
388
}
389
389
390
- void RPCExecutor::request (const QString &command, const QString &walletID )
390
+ void RPCExecutor::request (const QString &command, const WalletModel* wallet_model )
391
391
{
392
392
try
393
393
{
@@ -418,9 +418,7 @@ void RPCExecutor::request(const QString &command, const QString &walletID)
418
418
" example: getblock(getblockhash(0),true)[tx][0]\n\n " )));
419
419
return ;
420
420
}
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)) {
424
422
Q_EMIT reply (RPCConsole::CMD_ERROR, QString (" Parse error: unbalanced ' or \" " ));
425
423
return ;
426
424
}
@@ -698,10 +696,8 @@ void RPCConsole::setClientModel(ClientModel *model)
698
696
#ifdef ENABLE_WALLET
699
697
void RPCConsole::addWallet (WalletModel * const walletModel)
700
698
{
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));
705
701
if (ui->WalletSelector ->count () == 2 && !isVisible ()) {
706
702
// First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
707
703
ui->WalletSelector ->setCurrentIndex (1 );
@@ -714,8 +710,7 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
714
710
715
711
void RPCConsole::removeWallet (WalletModel * const walletModel)
716
712
{
717
- const QString name = walletModel->getWalletName ();
718
- ui->WalletSelector ->removeItem (ui->WalletSelector ->findData (name));
713
+ ui->WalletSelector ->removeItem (ui->WalletSelector ->findData (QVariant::fromValue (walletModel)));
719
714
if (ui->WalletSelector ->count () == 2 ) {
720
715
ui->WalletSelector ->setVisible (false );
721
716
ui->WalletSelectorLabel ->setVisible (false );
@@ -910,25 +905,25 @@ void RPCConsole::on_lineEdit_returnPressed()
910
905
911
906
cmdBeforeBrowsing = QString ();
912
907
913
- QString walletID ;
908
+ WalletModel* wallet_model{ nullptr } ;
914
909
#ifdef ENABLE_WALLET
915
910
const int wallet_index = ui->WalletSelector ->currentIndex ();
916
911
if (wallet_index > 0 ) {
917
- walletID = (QString) ui->WalletSelector ->itemData (wallet_index).value <QString >();
912
+ wallet_model = ui->WalletSelector ->itemData (wallet_index).value <WalletModel* >();
918
913
}
919
914
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 () ));
923
918
} else {
924
- message (CMD_REQUEST, tr (" Executing command using \" %1 \" wallet" ). arg (walletID ));
919
+ message (CMD_REQUEST, tr (" Executing command without any wallet" ));
925
920
}
926
- m_last_wallet_id = walletID ;
921
+ m_last_wallet_model = wallet_model ;
927
922
}
928
923
#endif
929
924
930
925
message (CMD_REQUEST, QString::fromStdString (strFilteredCmd));
931
- Q_EMIT cmdRequest (cmd, walletID );
926
+ Q_EMIT cmdRequest (cmd, m_last_wallet_model );
932
927
933
928
cmd = QString::fromStdString (strFilteredCmd);
934
929
0 commit comments