Skip to content

Commit 3e942a7

Browse files
committed
Merge #8774: Qt refactors to better abstract wallet access
178cd88 Qt/splash: Specifically keep track of which wallet(s) we are connected to for later disconnecting (Luke Dashjr) 1880aeb Qt: Get the private key for signing messages via WalletModel (Luke Dashjr)
2 parents 5d2c8e5 + 178cd88 commit 3e942a7

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/qt/signverifymessagedialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void SignVerifyMessageDialog::on_signMessageButton_SM_clicked()
142142
}
143143

144144
CKey key;
145-
if (!pwalletMain->GetKey(keyID, key))
145+
if (!model->getPrivKey(keyID, key))
146146
{
147147
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
148148
ui->statusLabel_SM->setText(tr("Private key for the entered address is not available."));

src/qt/splashscreen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
164164
}
165165

166166
#ifdef ENABLE_WALLET
167-
static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
167+
void SplashScreen::ConnectWallet(CWallet* wallet)
168168
{
169-
wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
169+
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
170+
connectedWallets.push_back(wallet);
170171
}
171172
#endif
172173

@@ -176,7 +177,7 @@ void SplashScreen::subscribeToCoreSignals()
176177
uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
177178
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
178179
#ifdef ENABLE_WALLET
179-
uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
180+
uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1));
180181
#endif
181182
}
182183

@@ -186,8 +187,9 @@ void SplashScreen::unsubscribeFromCoreSignals()
186187
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
187188
uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
188189
#ifdef ENABLE_WALLET
189-
if(pwalletMain)
190-
pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
190+
Q_FOREACH(CWallet* const & pwallet, connectedWallets) {
191+
pwallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
192+
}
191193
#endif
192194
}
193195

src/qt/splashscreen.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <QSplashScreen>
99

10+
class CWallet;
1011
class NetworkStyle;
1112

1213
/** Class for the splashscreen with information of the running client.
@@ -39,11 +40,15 @@ public Q_SLOTS:
3940
void subscribeToCoreSignals();
4041
/** Disconnect core signals to splash screen */
4142
void unsubscribeFromCoreSignals();
43+
/** Connect wallet signals to splash screen */
44+
void ConnectWallet(CWallet*);
4245

4346
QPixmap pixmap;
4447
QString curMessage;
4548
QColor curColor;
4649
int curAlignment;
50+
51+
QList<CWallet*> connectedWallets;
4752
};
4853

4954
#endif // BITCOIN_QT_SPLASHSCREEN_H

src/qt/walletmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ bool WalletModel::havePrivKey(const CKeyID &address) const
563563
return wallet->HaveKey(address);
564564
}
565565

566+
bool WalletModel::getPrivKey(const CKeyID &address, CKey& vchPrivKeyOut) const
567+
{
568+
return wallet->GetKey(address, vchPrivKeyOut);
569+
}
570+
566571
// returns a list of COutputs from COutPoints
567572
void WalletModel::getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs)
568573
{

src/qt/walletmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class WalletModel : public QObject
187187

188188
bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
189189
bool havePrivKey(const CKeyID &address) const;
190+
bool getPrivKey(const CKeyID &address, CKey& vchPrivKeyOut) const;
190191
void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
191192
bool isSpent(const COutPoint& outpoint) const;
192193
void listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const;

0 commit comments

Comments
 (0)