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: 4c495413e1
This commit is contained in:
Andrew Chow 2022-07-15 11:34:21 -04:00 committed by Hennadii Stepanov
parent da9578da80
commit 31ca698f20
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
3 changed files with 12 additions and 0 deletions

View file

@ -1316,6 +1316,12 @@ void BitcoinGUI::setEncryptionStatus(int status)
{
switch(status)
{
case WalletModel::NoKeys:
labelWalletEncryptionIcon->hide();
encryptWalletAction->setChecked(false);
changePassphraseAction->setEnabled(false);
encryptWalletAction->setEnabled(false);
break;
case WalletModel::Unencrypted:
labelWalletEncryptionIcon->hide();
encryptWalletAction->setChecked(false);

View file

@ -308,6 +308,11 @@ WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
{
if(!m_wallet->isCrypted())
{
// A previous bug allowed for watchonly wallets to be encrypted (encryption keys set, but nothing is actually encrypted).
// To avoid misrepresenting the encryption status of such wallets, we only return NoKeys for watchonly wallets that are unencrypted.
if (m_wallet->privateKeysDisabled()) {
return NoKeys;
}
return Unencrypted;
}
else if(m_wallet->isLocked())

View file

@ -72,6 +72,7 @@ public:
enum EncryptionStatus
{
NoKeys, // wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)
Unencrypted, // !wallet->IsCrypted()
Locked, // wallet->IsCrypted() && wallet->IsLocked()
Unlocked // wallet->IsCrypted() && !wallet->IsLocked()