Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 3,354 Lines • ▼ Show 20 Lines | DBErrors CWallet::LoadWallet(bool &fFirstRunRet) { | ||||
if (nLoadWalletRet == DBErrors::NEED_REWRITE) { | if (nLoadWalletRet == DBErrors::NEED_REWRITE) { | ||||
if (database->Rewrite("\x04pool")) { | if (database->Rewrite("\x04pool")) { | ||||
if (auto spk_man = m_spk_man.get()) { | if (auto spk_man = m_spk_man.get()) { | ||||
spk_man->RewriteDB(); | spk_man->RewriteDB(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// This wallet is in its first run if there are no ScriptPubKeyMans and it | |||||
// isn't blank or no privkeys | |||||
{ | { | ||||
LOCK(cs_KeyStore); | fFirstRunRet = !m_spk_man && | ||||
// This wallet is in its first run if all of these are empty | |||||
fFirstRunRet = mapKeys.empty() && mapCryptedKeys.empty() && | |||||
mapWatchKeys.empty() && setWatchOnly.empty() && | |||||
mapScripts.empty() && | |||||
!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && | !IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && | ||||
!IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET); | !IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET); | ||||
} | } | ||||
if (nLoadWalletRet != DBErrors::LOAD_OK) { | if (nLoadWalletRet != DBErrors::LOAD_OK) { | ||||
return nLoadWalletRet; | return nLoadWalletRet; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 808 Lines • ▼ Show 20 Lines | std::shared_ptr<CWallet> CWallet::CreateWalletFromFile( | ||||
} | } | ||||
if (fFirstRun) { | if (fFirstRun) { | ||||
// Ensure this wallet.dat can only be opened by clients supporting | // Ensure this wallet.dat can only be opened by clients supporting | ||||
// HD with chain split and expects no default key. | // HD with chain split and expects no default key. | ||||
walletInstance->SetMinVersion(FEATURE_LATEST); | walletInstance->SetMinVersion(FEATURE_LATEST); | ||||
walletInstance->SetWalletFlags(wallet_creation_flags, false); | walletInstance->SetWalletFlags(wallet_creation_flags, false); | ||||
// Always create LegacyScriptPubKeyMan for now | |||||
walletInstance->SetupLegacyScriptPubKeyMan(); | |||||
if (!(wallet_creation_flags & | if (!(wallet_creation_flags & | ||||
(WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) { | (WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) { | ||||
LOCK(walletInstance->cs_wallet); | LOCK(walletInstance->cs_wallet); | ||||
if (auto spk_man = walletInstance->m_spk_man.get()) { | if (auto spk_man = walletInstance->m_spk_man.get()) { | ||||
if (!spk_man->SetupGeneration()) { | if (!spk_man->SetupGeneration()) { | ||||
error = _("Unable to generate initial keys"); | error = _("Unable to generate initial keys"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 453 Lines • ▼ Show 20 Lines | CWallet::GetSigningProvider(const CScript &script, | ||||
SignatureData &sigdata) const { | SignatureData &sigdata) const { | ||||
return m_spk_man.get(); | return m_spk_man.get(); | ||||
} | } | ||||
LegacyScriptPubKeyMan *CWallet::GetLegacyScriptPubKeyMan() const { | LegacyScriptPubKeyMan *CWallet::GetLegacyScriptPubKeyMan() const { | ||||
return m_spk_man.get(); | return m_spk_man.get(); | ||||
} | } | ||||
LegacyScriptPubKeyMan *CWallet::GetOrCreateLegacyScriptPubKeyMan() { | |||||
SetupLegacyScriptPubKeyMan(); | |||||
return GetLegacyScriptPubKeyMan(); | |||||
} | |||||
void CWallet::SetupLegacyScriptPubKeyMan() { | |||||
if (!m_spk_man) { | |||||
m_spk_man = std::make_unique<LegacyScriptPubKeyMan>(*this); | |||||
} | |||||
} | |||||
const CKeyingMaterial &CWallet::GetEncryptionKey() const { | const CKeyingMaterial &CWallet::GetEncryptionKey() const { | ||||
return vMasterKey; | return vMasterKey; | ||||
} | } | ||||
bool CWallet::HasEncryptionKeys() const { | bool CWallet::HasEncryptionKeys() const { | ||||
return !mapMasterKeys.empty(); | return !mapMasterKeys.empty(); | ||||
} | } |