mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Refactor: Allow LegacyScriptPubKeyMan to be null
In CWallet::LoadWallet, use this to detect and empty wallet with no keys This commit does not change behavior.
This commit is contained in:
@@ -2993,10 +2993,9 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
}
|
||||
}
|
||||
|
||||
// This wallet is in its first run if there are no ScriptPubKeyMans and it isn't blank or no privkeys
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
// This wallet is in its first run if all of these are empty
|
||||
fFirstRunRet = mapKeys.empty() && mapCryptedKeys.empty() && mapWatchKeys.empty() && setWatchOnly.empty() && mapScripts.empty()
|
||||
fFirstRunRet = !m_spk_man
|
||||
&& !IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
|
||||
}
|
||||
|
||||
@@ -3727,6 +3726,10 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||
walletInstance->SetMinVersion(FEATURE_LATEST);
|
||||
|
||||
walletInstance->SetWalletFlags(wallet_creation_flags, false);
|
||||
|
||||
// Always create LegacyScriptPubKeyMan for now
|
||||
walletInstance->SetupLegacyScriptPubKeyMan();
|
||||
|
||||
if (!(wallet_creation_flags & (WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) {
|
||||
LOCK(walletInstance->cs_wallet);
|
||||
if (auto spk_man = walletInstance->m_spk_man.get()) {
|
||||
@@ -4121,6 +4124,17 @@ LegacyScriptPubKeyMan* CWallet::GetLegacyScriptPubKeyMan() const
|
||||
return m_spk_man.get();
|
||||
}
|
||||
|
||||
LegacyScriptPubKeyMan* CWallet::GetOrCreateLegacyScriptPubKeyMan()
|
||||
{
|
||||
SetupLegacyScriptPubKeyMan();
|
||||
return GetLegacyScriptPubKeyMan();
|
||||
}
|
||||
|
||||
void CWallet::SetupLegacyScriptPubKeyMan()
|
||||
{
|
||||
if (!m_spk_man) m_spk_man = MakeUnique<LegacyScriptPubKeyMan>(*this);
|
||||
}
|
||||
|
||||
const CKeyingMaterial& CWallet::GetEncryptionKey() const
|
||||
{
|
||||
return vMasterKey;
|
||||
|
||||
Reference in New Issue
Block a user