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:
Andrew Chow
2019-10-07 14:11:34 -04:00
parent fadc08ad94
commit eb81fc3ee5
15 changed files with 86 additions and 37 deletions

View File

@@ -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;