mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Move wallet upgrading to its own function
This commit is contained in:
parent
6ef45bc968
commit
9c16b1735f
2 changed files with 47 additions and 36 deletions
|
@ -3830,43 +3830,9 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int prev_version = walletInstance->GetVersion();
|
if (!UpgradeWallet(walletInstance, fFirstRun, error, warnings)) {
|
||||||
if (gArgs.GetBoolArg("-upgradewallet", fFirstRun))
|
|
||||||
{
|
|
||||||
int nMaxVersion = gArgs.GetArg("-upgradewallet", 0);
|
|
||||||
if (nMaxVersion == 0) // the -upgradewallet without argument case
|
|
||||||
{
|
|
||||||
walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
|
|
||||||
nMaxVersion = FEATURE_LATEST;
|
|
||||||
walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
|
|
||||||
}
|
|
||||||
else
|
|
||||||
walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
|
|
||||||
if (nMaxVersion < walletInstance->GetVersion())
|
|
||||||
{
|
|
||||||
error = _("Cannot downgrade wallet").translated;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
walletInstance->SetMaxVersion(nMaxVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upgrade to HD if explicit upgrade
|
|
||||||
if (gArgs.GetBoolArg("-upgradewallet", false)) {
|
|
||||||
LOCK(walletInstance->cs_wallet);
|
|
||||||
|
|
||||||
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
|
|
||||||
int max_version = walletInstance->GetVersion();
|
|
||||||
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
|
|
||||||
error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
|
|
||||||
if (!spk_man->Upgrade(prev_version, error)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fFirstRun)
|
if (fFirstRun)
|
||||||
{
|
{
|
||||||
|
@ -4129,6 +4095,48 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest
|
||||||
return &address_book_it->second;
|
return &address_book_it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CWallet::UpgradeWallet(std::shared_ptr<CWallet> walletInstance, bool fFirstRun, std::string& error, std::vector<std::string>& warnings)
|
||||||
|
{
|
||||||
|
int prev_version = walletInstance->GetVersion();
|
||||||
|
if (gArgs.GetBoolArg("-upgradewallet", fFirstRun))
|
||||||
|
{
|
||||||
|
int nMaxVersion = gArgs.GetArg("-upgradewallet", 0);
|
||||||
|
if (nMaxVersion == 0) // the -upgradewallet without argument case
|
||||||
|
{
|
||||||
|
walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
|
||||||
|
nMaxVersion = FEATURE_LATEST;
|
||||||
|
walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
|
||||||
|
}
|
||||||
|
else
|
||||||
|
walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
|
||||||
|
if (nMaxVersion < walletInstance->GetVersion())
|
||||||
|
{
|
||||||
|
error = _("Cannot downgrade wallet").translated;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
walletInstance->SetMaxVersion(nMaxVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upgrade to HD if explicit upgrade
|
||||||
|
if (gArgs.GetBoolArg("-upgradewallet", false)) {
|
||||||
|
LOCK(walletInstance->cs_wallet);
|
||||||
|
|
||||||
|
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
|
||||||
|
int max_version = walletInstance->GetVersion();
|
||||||
|
if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
|
||||||
|
error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
|
||||||
|
if (!spk_man->Upgrade(prev_version, error)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CWallet::postInitProcess()
|
void CWallet::postInitProcess()
|
||||||
{
|
{
|
||||||
auto locked_chain = chain().lock();
|
auto locked_chain = chain().lock();
|
||||||
|
|
|
@ -1175,6 +1175,9 @@ public:
|
||||||
LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
|
LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Upgrade the wallet */
|
||||||
|
static bool UpgradeWallet(std::shared_ptr<CWallet> wallet, bool first_run, std::string& error, std::vector<std::string>& warnings);
|
||||||
|
|
||||||
//! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
|
//! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
|
||||||
std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
|
std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue