Skip to content

Commit a12acee

Browse files
achow101psgreco
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 (cherry picked from commit 7b7bbc1)
1 parent 47a07fa commit a12acee

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
@@ -1283,6 +1283,12 @@ void BitcoinGUI::setEncryptionStatus(int status)
12831283
{
12841284
switch(status)
12851285
{
1286+
case WalletModel::NoKeys:
1287+
labelWalletEncryptionIcon->hide();
1288+
encryptWalletAction->setChecked(false);
1289+
changePassphraseAction->setEnabled(false);
1290+
encryptWalletAction->setEnabled(false);
1291+
break;
12861292
case WalletModel::Unencrypted:
12871293
labelWalletEncryptionIcon->hide();
12881294
encryptWalletAction->setChecked(false);

src/qt/walletmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
343343
{
344344
if(!m_wallet->isCrypted())
345345
{
346+
// A previous bug allowed for watchonly wallets to be encrypted (encryption keys set, but nothing is actually encrypted).
347+
// To avoid misrepresenting the encryption status of such wallets, we only return NoKeys for watchonly wallets that are unencrypted.
348+
if (m_wallet->privateKeysDisabled()) {
349+
return NoKeys;
350+
}
346351
return Unencrypted;
347352
}
348353
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)