Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/load.cpp
Show All 10 Lines | |||||
#include <util/string.h> | #include <util/string.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <wallet/walletdb.h> | #include <wallet/walletdb.h> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
bool VerifyWallets(interfaces::Chain &chain, | bool VerifyWallets(interfaces::Chain &chain) { | ||||
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( | chain.initError( | ||||
Show All 15 Lines | if (gArgs.IsArgSet("-walletdir")) { | ||||
} | } | ||||
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); | ||||
// For backwards compatibility if an unnamed top level wallet exists in the | |||||
// wallets directory, include it in the default list of wallets to load. | |||||
if (!gArgs.IsArgSet("wallet")) { | |||||
DatabaseOptions options; | |||||
DatabaseStatus status; | |||||
bilingual_str error_string; | |||||
options.require_existing = true; | |||||
options.verify = false; | |||||
if (MakeWalletDatabase("", options, status, error_string)) { | |||||
gArgs.LockSettings([&](util::Settings &settings) { | |||||
util::SettingsValue wallets(util::SettingsValue::VARR); | |||||
// Default wallet name is "" | |||||
wallets.push_back(""); | |||||
settings.rw_settings["wallet"] = wallets; | |||||
}); | |||||
} | |||||
} | |||||
// 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 : gArgs.GetArgs("-wallet")) { | ||||
const fs::path path = fs::absolute(wallet_file, GetWalletDir()); | const fs::path path = fs::absolute(wallet_file, GetWalletDir()); | ||||
if (!wallet_paths.insert(path).second) { | if (!wallet_paths.insert(path).second) { | ||||
chain.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; | return false; | ||||
} | } | ||||
DatabaseOptions options; | DatabaseOptions options; | ||||
DatabaseStatus status; | DatabaseStatus status; | ||||
options.verify = true; | options.verify = true; | ||||
bilingual_str error_string; | bilingual_str error_string; | ||||
if (!MakeWalletDatabase(wallet_file, options, status, error_string)) { | if (!MakeWalletDatabase(wallet_file, options, status, error_string)) { | ||||
chain.initError(error_string); | chain.initError(error_string); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool LoadWallets(interfaces::Chain &chain, | bool LoadWallets(interfaces::Chain &chain) { | ||||
const std::vector<std::string> &wallet_files) { | |||||
try { | try { | ||||
for (const std::string &name : wallet_files) { | for (const std::string &name : gArgs.GetArgs("-wallet")) { | ||||
DatabaseOptions options; | DatabaseOptions options; | ||||
DatabaseStatus status; | DatabaseStatus status; | ||||
// No need to verify, assuming verified earlier in VerifyWallets() | // No need to verify, assuming verified earlier in VerifyWallets() | ||||
options.verify = false; | options.verify = false; | ||||
bilingual_str error; | bilingual_str error; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
std::unique_ptr<WalletDatabase> database = | std::unique_ptr<WalletDatabase> database = | ||||
MakeWalletDatabase(name, options, status, error); | MakeWalletDatabase(name, options, status, error); | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |