Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 4,139 Lines • ▼ Show 20 Lines | if (nLoadWalletRet != DBErrors::LOAD_OK) { | ||||
PACKAGE_NAME); | PACKAGE_NAME); | ||||
return nullptr; | return nullptr; | ||||
} else { | } else { | ||||
error = strprintf(_("Error loading %s"), walletFile); | error = strprintf(_("Error loading %s"), walletFile); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
if (!UpgradeWallet(walletInstance, fFirstRun, error, warnings)) { | if (gArgs.GetBoolArg("-upgradewallet", false)) { | ||||
if (!UpgradeWallet(walletInstance, error, warnings)) { | |||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | |||||
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); | ||||
▲ Show 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | CWallet::FindAddressBookEntry(const CTxDestination &dest, | ||||
} | } | ||||
if ((!allow_change) && address_book_it->second.IsChange()) { | if ((!allow_change) && address_book_it->second.IsChange()) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
return &address_book_it->second; | return &address_book_it->second; | ||||
} | } | ||||
bool CWallet::UpgradeWallet(std::shared_ptr<CWallet> walletInstance, | bool CWallet::UpgradeWallet(std::shared_ptr<CWallet> walletInstance, | ||||
bool fFirstRun, bilingual_str &error, | bilingual_str &error, | ||||
std::vector<bilingual_str> &warnings) { | std::vector<bilingual_str> &warnings) { | ||||
int prev_version = walletInstance->GetVersion(); | int prev_version = walletInstance->GetVersion(); | ||||
if (gArgs.GetBoolArg("-upgradewallet", fFirstRun)) { | |||||
int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); | int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); | ||||
// The -upgradewallet without argument case | // The -upgradewallet without argument case | ||||
if (nMaxVersion == 0) { | if (nMaxVersion == 0) { | ||||
walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", | walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", | ||||
FEATURE_LATEST); | FEATURE_LATEST); | ||||
nMaxVersion = FEATURE_LATEST; | nMaxVersion = FEATURE_LATEST; | ||||
// permanently upgrade the wallet immediately | // permanently upgrade the wallet immediately | ||||
walletInstance->SetMinVersion(FEATURE_LATEST); | walletInstance->SetMinVersion(FEATURE_LATEST); | ||||
} else { | } else { | ||||
walletInstance->WalletLogPrintf( | walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", | ||||
"Allowing wallet upgrade up to %i\n", nMaxVersion); | nMaxVersion); | ||||
} | } | ||||
if (nMaxVersion < walletInstance->GetVersion()) { | if (nMaxVersion < walletInstance->GetVersion()) { | ||||
error = _("Cannot downgrade wallet"); | error = _("Cannot downgrade wallet"); | ||||
return false; | return false; | ||||
} | } | ||||
walletInstance->SetMaxVersion(nMaxVersion); | walletInstance->SetMaxVersion(nMaxVersion); | ||||
} | |||||
// Upgrade to HD if explicit upgrade | |||||
if (gArgs.GetBoolArg("-upgradewallet", false)) { | |||||
LOCK(walletInstance->cs_wallet); | LOCK(walletInstance->cs_wallet); | ||||
// Do not upgrade versions to any version between HD_SPLIT and | // Do not upgrade versions to any version between HD_SPLIT and | ||||
// FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT | // FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT | ||||
int max_version = walletInstance->GetVersion(); | int max_version = walletInstance->GetVersion(); | ||||
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && | if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && | ||||
max_version >= FEATURE_HD_SPLIT && | max_version >= FEATURE_HD_SPLIT && | ||||
max_version < FEATURE_PRE_SPLIT_KEYPOOL) { | max_version < FEATURE_PRE_SPLIT_KEYPOOL) { | ||||
error = | error = _("Cannot upgrade a non HD split wallet without upgrading to " | ||||
_("Cannot upgrade a non HD split wallet without upgrading to " | |||||
"support pre split keypool. Please use -upgradewallet=200300 " | "support pre split keypool. Please use -upgradewallet=200300 " | ||||
"or -upgradewallet with no version specified."); | "or -upgradewallet with no version specified."); | ||||
return false; | return false; | ||||
} | } | ||||
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { | for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { | ||||
if (!spk_man->Upgrade(prev_version, error)) { | if (!spk_man->Upgrade(prev_version, error)) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
} | |||||
return true; | return true; | ||||
} | } | ||||
void CWallet::postInitProcess() { | void CWallet::postInitProcess() { | ||||
auto locked_chain = chain().lock(); | auto locked_chain = chain().lock(); | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
▲ Show 20 Lines • Show All 270 Lines • Show Last 20 Lines |