Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 4,380 Lines • ▼ Show 20 Lines | if (gArgs.GetBoolArg("-upgradewallet", fFirstRun)) { | ||||
if (nMaxVersion < walletInstance->GetVersion()) { | if (nMaxVersion < walletInstance->GetVersion()) { | ||||
InitError(_("Cannot downgrade wallet")); | InitError(_("Cannot downgrade wallet")); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
walletInstance->SetMaxVersion(nMaxVersion); | walletInstance->SetMaxVersion(nMaxVersion); | ||||
} | } | ||||
// Upgrade to HD if explicit upgrade | |||||
if (gArgs.GetBoolArg("-upgradewallet", false)) { | |||||
LOCK(walletInstance->cs_wallet); | |||||
bool hd_upgrade = false; | |||||
if (walletInstance->CanSupportFeature(FEATURE_HD) && | |||||
!walletInstance->IsHDEnabled()) { | |||||
LogPrintf("Upgrading wallet to HD\n"); | |||||
walletInstance->SetMinVersion(FEATURE_HD); | |||||
// generate a new master key | |||||
CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); | |||||
if (!walletInstance->SetHDMasterKey(masterPubKey)) { | |||||
throw std::runtime_error(std::string(__func__) + | |||||
": Storing master key failed"); | |||||
} | |||||
hd_upgrade = true; | |||||
} | |||||
// Upgrade to HD chain split if necessary | |||||
if (walletInstance->CanSupportFeature(FEATURE_HD_SPLIT)) { | |||||
LogPrintf("Upgrading wallet to use HD chain split\n"); | |||||
walletInstance->SetMinVersion(FEATURE_HD_SPLIT); | |||||
} | |||||
// Regenerate the keypool if upgraded to HD | |||||
if (hd_upgrade) { | |||||
if (!walletInstance->NewKeyPool()) { | |||||
InitError(_("Unable to generate keys") += "\n"); | |||||
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. | ||||
if (!gArgs.GetBoolArg("-usehd", true)) { | if (!gArgs.GetBoolArg("-usehd", true)) { | ||||
InitError(strprintf(_("Error creating %s: You can't create non-HD " | InitError(strprintf(_("Error creating %s: You can't create non-HD " | ||||
"wallets with this version."), | "wallets with this version."), | ||||
walletFile)); | walletFile)); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY); | walletInstance->SetMinVersion(FEATURE_LATEST); | ||||
// Generate a new master key. | // Generate a new master key. | ||||
CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); | CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); | ||||
if (!walletInstance->SetHDMasterKey(masterPubKey)) { | if (!walletInstance->SetHDMasterKey(masterPubKey)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": Storing master key failed"); | ": Storing master key failed"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 368 Lines • Show Last 20 Lines |