Skip to content

Commit 813a16a

Browse files
committed
wallet: Add HasCryptedKeys
1 parent 0ca1d1b commit 813a16a

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ bool LegacyScriptPubKeyMan::HavePrivateKeys() const
525525
return !mapKeys.empty() || !mapCryptedKeys.empty();
526526
}
527527

528+
bool LegacyScriptPubKeyMan::HaveCryptedKeys() const
529+
{
530+
LOCK(cs_KeyStore);
531+
return !mapCryptedKeys.empty();
532+
}
533+
528534
void LegacyScriptPubKeyMan::RewriteDB()
529535
{
530536
LOCK(cs_KeyStore);
@@ -2392,6 +2398,12 @@ bool DescriptorScriptPubKeyMan::HavePrivateKeys() const
23922398
return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0;
23932399
}
23942400

2401+
bool DescriptorScriptPubKeyMan::HaveCryptedKeys() const
2402+
{
2403+
LOCK(cs_desc_man);
2404+
return !m_map_crypted_keys.empty();
2405+
}
2406+
23952407
std::optional<int64_t> DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const
23962408
{
23972409
// This is only used for getwalletinfo output and isn't relevant to descriptor wallets.

src/wallet/scriptpubkeyman.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class ScriptPubKeyMan
221221
virtual bool Upgrade(int prev_version, int new_version, bilingual_str& error) { return true; }
222222

223223
virtual bool HavePrivateKeys() const { return false; }
224+
virtual bool HaveCryptedKeys() const { return false; }
224225

225226
//! The action to do when the DB needs rewrite
226227
virtual void RewriteDB() {}
@@ -472,6 +473,7 @@ class LegacyScriptPubKeyMan : public LegacyDataSPKM
472473
bool Upgrade(int prev_version, int new_version, bilingual_str& error) override;
473474

474475
bool HavePrivateKeys() const override;
476+
bool HaveCryptedKeys() const override;
475477

476478
void RewriteDB() override;
477479

@@ -659,6 +661,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
659661
bool HasPrivKey(const CKeyID& keyid) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
660662
//! Retrieve the particular key if it is available. Returns nullopt if the key is not in the wallet, or if the wallet is locked.
661663
std::optional<CKey> GetKey(const CKeyID& keyid) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
664+
bool HaveCryptedKeys() const override;
662665

663666
std::optional<int64_t> GetOldestKeyPoolTime() const override;
664667
unsigned int GetKeyPoolSize() const override;

src/wallet/wallet.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,6 +3695,14 @@ bool CWallet::HasEncryptionKeys() const
36953695
return !mapMasterKeys.empty();
36963696
}
36973697

3698+
bool CWallet::HaveCryptedKeys() const
3699+
{
3700+
for (const auto& spkm : GetAllScriptPubKeyMans()) {
3701+
if (spkm->HaveCryptedKeys()) return true;
3702+
}
3703+
return false;
3704+
}
3705+
36983706
void CWallet::ConnectScriptPubKeyManNotifiers()
36993707
{
37003708
for (const auto& spk_man : GetActiveScriptPubKeyMans()) {

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
969969
bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const override;
970970

971971
bool HasEncryptionKeys() const override;
972+
bool HaveCryptedKeys() const;
972973

973974
/** Get last block processed height */
974975
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)

0 commit comments

Comments
 (0)