Skip to content

Commit 4c49541

Browse files
committed
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.
1 parent 85b601e commit 4c49541

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
@@ -1350,6 +1350,12 @@ void BitcoinGUI::setEncryptionStatus(int status)
13501350
{
13511351
switch(status)
13521352
{
1353+
case WalletModel::NoKeys:
1354+
labelWalletEncryptionIcon->hide();
1355+
encryptWalletAction->setChecked(false);
1356+
changePassphraseAction->setEnabled(false);
1357+
encryptWalletAction->setEnabled(false);
1358+
break;
13531359
case WalletModel::Unencrypted:
13541360
labelWalletEncryptionIcon->hide();
13551361
encryptWalletAction->setChecked(false);

src/qt/walletmodel.cpp

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