Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/init.cpp
Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | bool VerifyWallets(const CChainParams &chainParams, interfaces::Chain &chain, | ||||
const std::vector<std::string> &wallet_files) { | const std::vector<std::string> &wallet_files) { | ||||
if (gArgs.IsArgSet("-walletdir")) { | if (gArgs.IsArgSet("-walletdir")) { | ||||
fs::path wallet_dir = gArgs.GetArg("-walletdir", ""); | fs::path wallet_dir = gArgs.GetArg("-walletdir", ""); | ||||
boost::system::error_code error; | boost::system::error_code error; | ||||
// The canonical path cleans the path, preventing >1 Berkeley | // The canonical path cleans the path, preventing >1 Berkeley | ||||
// environment instances for the same directory | // environment instances for the same directory | ||||
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error); | fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error); | ||||
if (error || !fs::exists(wallet_dir)) { | if (error || !fs::exists(wallet_dir)) { | ||||
return InitError( | chain.initError( | ||||
strprintf(_("Specified -walletdir \"%s\" does not exist"), | strprintf(_("Specified -walletdir \"%s\" does not exist"), | ||||
wallet_dir.string())); | wallet_dir.string())); | ||||
return false; | |||||
} else if (!fs::is_directory(wallet_dir)) { | } else if (!fs::is_directory(wallet_dir)) { | ||||
return InitError( | chain.initError( | ||||
strprintf(_("Specified -walletdir \"%s\" is not a directory"), | strprintf(_("Specified -walletdir \"%s\" is not a directory"), | ||||
wallet_dir.string())); | wallet_dir.string())); | ||||
return false; | |||||
// The canonical path transforms relative paths into absolute ones, | // The canonical path transforms relative paths into absolute ones, | ||||
// so we check the non-canonical version | // so we check the non-canonical version | ||||
} else if (!wallet_dir.is_absolute()) { | } else if (!wallet_dir.is_absolute()) { | ||||
return InitError( | chain.initError( | ||||
strprintf(_("Specified -walletdir \"%s\" is a relative path"), | strprintf(_("Specified -walletdir \"%s\" is a relative path"), | ||||
wallet_dir.string())); | wallet_dir.string())); | ||||
return false; | |||||
} | } | ||||
gArgs.ForceSetArg("-walletdir", canonical_wallet_dir.string()); | gArgs.ForceSetArg("-walletdir", canonical_wallet_dir.string()); | ||||
} | } | ||||
LogPrintf("Using wallet directory %s\n", GetWalletDir().string()); | LogPrintf("Using wallet directory %s\n", GetWalletDir().string()); | ||||
uiInterface.InitMessage(_("Verifying wallet(s)...")); | uiInterface.InitMessage(_("Verifying wallet(s)...")); | ||||
// Parameter interaction code should have thrown an error if -salvagewallet | // Parameter interaction code should have thrown an error if -salvagewallet | ||||
// was enabled with more than wallet file, so the wallet_files size check | // was enabled with more than wallet file, so the wallet_files size check | ||||
// here should have no effect. | // here should have no effect. | ||||
bool salvage_wallet = | bool salvage_wallet = | ||||
gArgs.GetBoolArg("-salvagewallet", false) && wallet_files.size() <= 1; | gArgs.GetBoolArg("-salvagewallet", false) && wallet_files.size() <= 1; | ||||
// Keep track of each wallet absolute path to detect duplicates. | // Keep track of each wallet absolute path to detect duplicates. | ||||
std::set<fs::path> wallet_paths; | std::set<fs::path> wallet_paths; | ||||
for (const auto &wallet_file : wallet_files) { | for (const auto &wallet_file : wallet_files) { | ||||
WalletLocation location(wallet_file); | WalletLocation location(wallet_file); | ||||
if (!wallet_paths.insert(location.GetPath()).second) { | if (!wallet_paths.insert(location.GetPath()).second) { | ||||
return InitError(strprintf(_("Error loading wallet %s. Duplicate " | chain.initError(strprintf(_("Error loading wallet %s. Duplicate " | ||||
"-wallet filename specified."), | "-wallet filename specified."), | ||||
wallet_file)); | wallet_file)); | ||||
return false; | |||||
} | } | ||||
std::string error_string; | std::string error_string; | ||||
std::string warning_string; | std::string warning_string; | ||||
bool verify_success = | bool verify_success = | ||||
CWallet::Verify(chainParams, chain, location, salvage_wallet, | CWallet::Verify(chainParams, chain, location, salvage_wallet, | ||||
error_string, warning_string); | error_string, warning_string); | ||||
if (!error_string.empty()) { | if (!error_string.empty()) { | ||||
InitError(error_string); | chain.initError(error_string); | ||||
} | } | ||||
if (!warning_string.empty()) { | if (!warning_string.empty()) { | ||||
InitWarning(warning_string); | chain.initWarning(warning_string); | ||||
} | } | ||||
if (!verify_success) { | if (!verify_success) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |