Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/load.cpp
Show All 15 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)) { | ||||
chain.initError(strprintf( | chain.initError( | ||||
_("Specified -walletdir \"%s\" does not exist").translated, | strprintf(_("Specified -walletdir \"%s\" does not exist"), | ||||
wallet_dir.string())); | wallet_dir.string())); | ||||
return false; | return false; | ||||
} else if (!fs::is_directory(wallet_dir)) { | } else if (!fs::is_directory(wallet_dir)) { | ||||
chain.initError(strprintf( | chain.initError( | ||||
_("Specified -walletdir \"%s\" is not a directory").translated, | strprintf(_("Specified -walletdir \"%s\" is not a directory"), | ||||
wallet_dir.string())); | wallet_dir.string())); | ||||
return false; | 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()) { | ||||
chain.initError(strprintf( | chain.initError( | ||||
_("Specified -walletdir \"%s\" is a relative path").translated, | strprintf(_("Specified -walletdir \"%s\" is a relative path"), | ||||
wallet_dir.string())); | wallet_dir.string())); | ||||
return false; | 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()); | ||||
chain.initMessage(_("Verifying wallet(s)...").translated); | chain.initMessage(_("Verifying wallet(s)...").translated); | ||||
// 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) { | ||||
chain.initError(strprintf(_("Error loading wallet %s. Duplicate " | chain.initError(strprintf(_("Error loading wallet %s. Duplicate " | ||||
"-wallet filename specified.") | "-wallet filename specified."), | ||||
.translated, | |||||
wallet_file)); | wallet_file)); | ||||
return false; | return false; | ||||
} | } | ||||
bilingual_str error_string; | bilingual_str error_string; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
bool verify_success = | bool verify_success = | ||||
CWallet::Verify(chainParams, chain, location, salvage_wallet, | CWallet::Verify(chainParams, chain, location, salvage_wallet, | ||||
error_string, warnings); | error_string, warnings); | ||||
if (!warnings.empty()) { | if (!warnings.empty()) { | ||||
chain.initWarning(Join(warnings, "\n", OpTranslated)); | chain.initWarning(Join(warnings, "\n", OpTranslated)); | ||||
} | } | ||||
if (!verify_success) { | if (!verify_success) { | ||||
chain.initError(error_string.translated); | chain.initError(error_string); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool LoadWallets(const CChainParams &chainParams, interfaces::Chain &chain, | bool LoadWallets(const CChainParams &chainParams, interfaces::Chain &chain, | ||||
const std::vector<std::string> &wallet_files) { | const std::vector<std::string> &wallet_files) { | ||||
for (const std::string &walletFile : wallet_files) { | for (const std::string &walletFile : wallet_files) { | ||||
bilingual_str error; | bilingual_str error; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile( | ||||
chainParams, chain, WalletLocation(walletFile), error, warnings); | chainParams, chain, WalletLocation(walletFile), error, warnings); | ||||
if (!warnings.empty()) { | if (!warnings.empty()) { | ||||
chain.initWarning(Join(warnings, "\n", OpTranslated)); | chain.initWarning(Join(warnings, "\n", OpTranslated)); | ||||
} | } | ||||
if (!pwallet) { | if (!pwallet) { | ||||
chain.initError(error.translated); | chain.initError(error); | ||||
return false; | return false; | ||||
} | } | ||||
AddWallet(pwallet); | AddWallet(pwallet); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |