Skip to content

Commit f45d12b

Browse files
committed
Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile
This commit does not change behavior.
1 parent 8b0d82b commit f45d12b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, std::string& error)
396396
return true;
397397
}
398398

399+
bool LegacyScriptPubKeyMan::HavePrivateKeys() const
400+
{
401+
LOCK(cs_KeyStore);
402+
return !mapKeys.empty() || !mapCryptedKeys.empty();
403+
}
404+
399405
static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) {
400406
if (setKeyPool.empty()) {
401407
return GetTime();

src/wallet/scriptpubkeyman.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ class ScriptPubKeyMan
168168
/** Upgrades the wallet to the specified version */
169169
virtual bool Upgrade(int prev_version, std::string& error) { return false; }
170170

171+
virtual bool HavePrivateKeys() const { return false; }
172+
171173
virtual int64_t GetOldestKeyPoolTime() { return GetTime(); }
172174

173175
virtual size_t KeypoolCountExternalKeys() { return 0; }
@@ -276,6 +278,8 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
276278

277279
bool Upgrade(int prev_version, std::string& error) override;
278280

281+
bool HavePrivateKeys() const override;
282+
279283
int64_t GetOldestKeyPoolTime() override;
280284
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
281285

src/wallet/wallet.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3648,9 +3648,10 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
36483648
error = strprintf(_("Error loading %s: Private keys can only be disabled during creation").translated, walletFile);
36493649
return NULL;
36503650
} else if (walletInstance->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
3651-
LOCK(walletInstance->cs_KeyStore);
3652-
if (!walletInstance->mapKeys.empty() || !walletInstance->mapCryptedKeys.empty()) {
3653-
warnings.push_back(strprintf(_("Warning: Private keys detected in wallet {%s} with disabled private keys").translated, walletFile));
3651+
if (walletInstance->m_spk_man) {
3652+
if (walletInstance->m_spk_man->HavePrivateKeys()) {
3653+
warnings.push_back(strprintf(_("Warning: Private keys detected in wallet {%s} with disabled private keys").translated, walletFile));
3654+
}
36543655
}
36553656
}
36563657

0 commit comments

Comments
 (0)