Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/init.cpp
Show First 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | if (gArgs.IsArgSet("-walletdir")) { | ||||
wallet_dir.string())); | 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)...")); | ||||
std::vector<std::string> wallet_files = gArgs.GetArgs("-wallet"); | |||||
// Parameter interaction code should have thrown an error if -salvagewallet | |||||
// was enabled with more than wallet file, so the wallet_files size check | |||||
// here should have no effect. | |||||
bool salvage_wallet = | |||||
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 std::string &walletFile : gArgs.GetArgs("-wallet")) { | for (const auto wallet_file : wallet_files) { | ||||
// Do some checking on wallet path. It should be either a: | fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir()); | ||||
// | |||||
// 1. Path where a directory can be created. | |||||
// 2. Path to an existing directory. | |||||
// 3. Path to a symlink to a directory. | |||||
// 4. For backwards compatibility, the name of a data file in | |||||
// -walletdir. | |||||
fs::path wallet_path = fs::absolute(walletFile, GetWalletDir()); | |||||
fs::file_type path_type = fs::symlink_status(wallet_path).type(); | |||||
if (!(path_type == fs::file_not_found || | |||||
path_type == fs::directory_file || | |||||
(path_type == fs::symlink_file && | |||||
fs::is_directory(wallet_path)) || | |||||
(path_type == fs::regular_file && | |||||
fs::path(walletFile).filename() == walletFile))) { | |||||
return InitError(strprintf( | |||||
_("Invalid -wallet path '%s'. -wallet path should point to a " | |||||
"directory where wallet.dat and database/log.?????????? " | |||||
"files can be stored, a location where such a directory " | |||||
"could be created, or (for backwards compatibility) the name " | |||||
"of an existing data file in -walletdir (%s)"), | |||||
walletFile, GetWalletDir())); | |||||
} | |||||
if (!wallet_paths.insert(wallet_path).second) { | if (!wallet_paths.insert(wallet_path).second) { | ||||
return InitError(strprintf(_("Error loading wallet %s. Duplicate " | return InitError(strprintf(_("Error loading wallet %s. Duplicate " | ||||
"-wallet filename specified."), | "-wallet filename specified."), | ||||
walletFile)); | wallet_file)); | ||||
} | } | ||||
std::string strError; | if (!CWallet::Verify(chainParams, wallet_file, salvage_wallet)) { | ||||
if (!WalletBatch::VerifyEnvironment(wallet_path, strError)) { | |||||
return InitError(strError); | |||||
} | |||||
if (gArgs.GetBoolArg("-salvagewallet", false)) { | |||||
// Recover readable keypairs: | |||||
CWallet dummyWallet(chainParams, "dummy", | |||||
WalletDatabase::CreateDummy()); | |||||
std::string backup_filename; | |||||
if (!WalletBatch::Recover(wallet_path, (void *)&dummyWallet, | |||||
WalletBatch::RecoverKeysOnlyFilter, | |||||
backup_filename)) { | |||||
return false; | |||||
} | |||||
} | |||||
std::string strWarning; | |||||
bool dbV = | |||||
WalletBatch::VerifyDatabaseFile(wallet_path, strWarning, strError); | |||||
if (!strWarning.empty()) { | |||||
InitWarning(strWarning); | |||||
} | |||||
if (!dbV) { | |||||
InitError(strError); | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool WalletInit::Open(const CChainParams &chainParams) const { | bool WalletInit::Open(const CChainParams &chainParams) const { | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |