diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-07-15 11:34:21 -0400 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2022-08-12 10:27:56 +0100 |
commit | 31ca698f2017c57aad8f9839a582c6864ede92bd (patch) | |
tree | 2dbb35a0f0adcf159bd22f1bbaaafe4ab33212e6 /src/qt | |
parent | da9578da800ba98c5763f28d5777cb4067df448e (diff) |
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: 4c495413e138ec1dd6874e41b44e689f0c15e0e3
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/bitcoingui.cpp | 6 | ||||
-rw-r--r-- | src/qt/walletmodel.cpp | 5 | ||||
-rw-r--r-- | src/qt/walletmodel.h | 1 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 7c22880dd1..548f77c74d 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -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); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 5ee32e79d5..13579e644e 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -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()) diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index ad1239ccdc..7f941142ea 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -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() |