diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -186,6 +186,8 @@ /** Upgrades the wallet to the specified version */ virtual bool Upgrade(int prev_version, std::string &error) { return false; } + virtual bool HavePrivateKeys() const { return false; } + virtual int64_t GetOldestKeyPoolTime() { return GetTime(); } virtual size_t KeypoolCountExternalKeys() { return 0; } @@ -312,6 +314,8 @@ bool Upgrade(int prev_version, std::string &error) override; + bool HavePrivateKeys() const override; + int64_t GetOldestKeyPoolTime() override; size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -350,6 +350,11 @@ return true; } +bool LegacyScriptPubKeyMan::HavePrivateKeys() const { + LOCK(cs_KeyStore); + return !mapKeys.empty() || !mapCryptedKeys.empty(); +} + static int64_t GetOldestKeyTimeInPool(const std::set &setKeyPool, WalletBatch &batch) { if (setKeyPool.empty()) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4085,14 +4085,14 @@ return nullptr; } else if (walletInstance->IsWalletFlagSet( WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { - LOCK(walletInstance->cs_KeyStore); - if (!walletInstance->mapKeys.empty() || - !walletInstance->mapCryptedKeys.empty()) { - warnings.push_back( - strprintf(_("Warning: Private keys detected in wallet {%s} " - "with disabled private keys") - .translated, - walletFile)); + if (walletInstance->m_spk_man) { + if (walletInstance->m_spk_man->HavePrivateKeys()) { + warnings.push_back( + strprintf(_("Warning: Private keys detected in wallet {%s} " + "with disabled private keys") + .translated, + walletFile)); + } } }