Skip to content

Commit 6d8707b

Browse files
committed
Merge #631: Disallow encryption of watchonly wallets
4c49541 Disallow encryption of watchonly wallets (Andrew Chow) Pull request description: 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. As our current behavior allows for encrypting watchonly wallets (no crash with legacy, crash, but still encrypted with descriptors), the new `NoKeys` status is only returned for unencrypted watchonly wallets. This allows any watchonly wallets that were previously encrypted to show the correct encryption status (they have encryption keys, and so should be indicated as being encrypted). ACKs for top commit: w0xlt: tACK 4c49541 hebasto: ACK 4c49541, tested on Ubuntu 22.04. Tree-SHA512: 054dba0a8c1343a0df17689508cd628a974555828955a3c8820bf020868b95a3df98c47253b0ffe2252765b020160bb76ea21647d76d59ba748b3b41c481f2ae
2 parents 1b285b7 + 4c49541 commit 6d8707b

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)