Skip to content

Commit 7b7bbc1

Browse files
achow101hebasto
authored andcommitted
Disallow encryption of watchonly wallets
Watchonly wallets do not have any private keys to encrypt. It does not make sense to encrypt such wallets, so disable the option to encrypt them. This avoids an assertion that can be hit when encrypting watchonly descriptor wallets. Github-Pull: bitcoin-core/gui#631 Rebased-From: 4c49541
1 parent a46e178 commit 7b7bbc1

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/qt/bitcoingui.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,12 @@ void BitcoinGUI::setEncryptionStatus(int status)
13101310
{
13111311
switch(status)
13121312
{
1313+
case WalletModel::NoKeys:
1314+
labelWalletEncryptionIcon->hide();
1315+
encryptWalletAction->setChecked(false);
1316+
changePassphraseAction->setEnabled(false);
1317+
encryptWalletAction->setEnabled(false);
1318+
break;
13131319
case WalletModel::Unencrypted:
13141320
labelWalletEncryptionIcon->hide();
13151321
encryptWalletAction->setChecked(false);

src/qt/walletmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
305305
{
306306
if(!m_wallet->isCrypted())
307307
{
308+
// A previous bug allowed for watchonly wallets to be encrypted (encryption keys set, but nothing is actually encrypted).
309+
// To avoid misrepresenting the encryption status of such wallets, we only return NoKeys for watchonly wallets that are unencrypted.
310+
if (m_wallet->privateKeysDisabled()) {
311+
return NoKeys;
312+
}
308313
return Unencrypted;
309314
}
310315
else if(m_wallet->isLocked())

src/qt/walletmodel.h

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

7272
enum EncryptionStatus
7373
{
74+
NoKeys, // wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)
7475
Unencrypted, // !wallet->IsCrypted()
7576
Locked, // wallet->IsCrypted() && wallet->IsLocked()
7677
Unlocked // wallet->IsCrypted() && !wallet->IsLocked()

0 commit comments

Comments
 (0)