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; | ||||
} | } | ||||
} | } | ||||
int prev_version = walletInstance->GetVersion(); | if (!UpgradeWallet(walletInstance, fFirstRun, error, warnings)) { | ||||
if (gArgs.GetBoolArg("-upgradewallet", fFirstRun)) { | |||||
int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); | |||||
// The -upgradewallet without argument case | |||||
if (nMaxVersion == 0) { | |||||
walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", | |||||
FEATURE_LATEST); | |||||
nMaxVersion = FEATURE_LATEST; | |||||
// permanently upgrade the wallet immediately | |||||
walletInstance->SetMinVersion(FEATURE_LATEST); | |||||
} else { | |||||
walletInstance->WalletLogPrintf( | |||||
"Allowing wallet upgrade up to %i\n", nMaxVersion); | |||||
} | |||||
if (nMaxVersion < walletInstance->GetVersion()) { | |||||
error = _("Cannot downgrade wallet"); | |||||
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=200300 " | |||||
"or -upgradewallet with no version specified."); | |||||
return nullptr; | |||||
} | |||||
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { | |||||
if (!spk_man->Upgrade(prev_version, error)) { | |||||
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 291 Lines • ▼ Show 20 Lines | if (address_book_it == m_address_book.end()) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
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 fFirstRun, bilingual_str &error, | |||||
std::vector<bilingual_str> &warnings) { | |||||
int prev_version = walletInstance->GetVersion(); | |||||
if (gArgs.GetBoolArg("-upgradewallet", fFirstRun)) { | |||||
int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); | |||||
// The -upgradewallet without argument case | |||||
if (nMaxVersion == 0) { | |||||
walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", | |||||
FEATURE_LATEST); | |||||
nMaxVersion = FEATURE_LATEST; | |||||
// permanently upgrade the wallet immediately | |||||
walletInstance->SetMinVersion(FEATURE_LATEST); | |||||
} else { | |||||
walletInstance->WalletLogPrintf( | |||||
"Allowing wallet upgrade up to %i\n", nMaxVersion); | |||||
} | |||||
if (nMaxVersion < walletInstance->GetVersion()) { | |||||
error = _("Cannot downgrade wallet"); | |||||
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=200300 " | |||||
"or -upgradewallet with no version specified."); | |||||
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(); | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
// Add wallet transactions that aren't already in a block to mempool. | // Add wallet transactions that aren't already in a block to mempool. | ||||
// Do this here as mempool requires genesis block to be loaded. | // Do this here as mempool requires genesis block to be loaded. | ||||
ReacceptWalletTransactions(); | ReacceptWalletTransactions(); | ||||
▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines |