MCPcopy Create free account
hub / github.com/ElementsProject/elements / VerifyWallets

Function VerifyWallets

src/wallet/load.cpp:25–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24namespace wallet {
25bool VerifyWallets(WalletContext& context)
26{
27 interfaces::Chain& chain = *context.chain;
28 ArgsManager& args = *Assert(context.args);
29
30 if (args.IsArgSet("-walletdir")) {
31 const fs::path wallet_dir{args.GetPathArg("-walletdir")};
32 std::error_code error;
33 // The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
34 // It also lets the fs::exists and fs::is_directory checks below pass on windows, since they return false
35 // if a path has trailing slashes, and it strips trailing slashes.
36 fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
37 if (error || !fs::exists(canonical_wallet_dir)) {
38 chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist"), fs::PathToString(wallet_dir)));
39 return false;
40 } else if (!fs::is_directory(canonical_wallet_dir)) {
41 chain.initError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), fs::PathToString(wallet_dir)));
42 return false;
43 // The canonical path transforms relative paths into absolute ones, so we check the non-canonical version
44 } else if (!wallet_dir.is_absolute()) {
45 chain.initError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), fs::PathToString(wallet_dir)));
46 return false;
47 }
48 args.ForceSetArg("-walletdir", fs::PathToString(canonical_wallet_dir));
49 }
50
51 LogPrintf("Using wallet directory %s\n", fs::PathToString(GetWalletDir()));
52
53 chain.initMessage(_("Verifying wallet(s)…").translated);
54
55 // For backwards compatibility if an unnamed top level wallet exists in the
56 // wallets directory, include it in the default list of wallets to load.
57 if (!args.IsArgSet("wallet")) {
58 DatabaseOptions options;
59 DatabaseStatus status;
60 bilingual_str error_string;
61 options.require_existing = true;
62 options.verify = false;
63 if (MakeWalletDatabase("", options, status, error_string)) {
64 util::SettingsValue wallets(util::SettingsValue::VARR);
65 wallets.push_back(""); // Default wallet name is ""
66 // Pass write=false because no need to write file and probably
67 // better not to. If unnamed wallet needs to be added next startup
68 // and the setting is empty, this code will just run again.
69 chain.updateRwSetting("wallet", wallets, /* write= */ false);
70 }
71 }
72
73 // Keep track of each wallet absolute path to detect duplicates.
74 std::set<fs::path> wallet_paths;
75
76 for (const auto& wallet : chain.getSettingsList("wallet")) {
77 const auto& wallet_file = wallet.get_str();
78 const fs::path path = fsbridge::AbsPathJoin(GetWalletDir(), fs::PathFromString(wallet_file));
79
80 if (!wallet_paths.insert(path).second) {
81 chain.initWarning(strprintf(_("Ignoring duplicate -wallet %s."), wallet_file));
82 continue;

Callers 1

verifyMethod · 0.85

Calls 15

existsFunction · 0.85
_Function · 0.85
PathToStringFunction · 0.85
GetWalletDirFunction · 0.85
MakeWalletDatabaseFunction · 0.85
AbsPathJoinFunction · 0.85
PathFromStringFunction · 0.85
UntranslatedFunction · 0.85
IsArgSetMethod · 0.80
GetPathArgMethod · 0.80
initErrorMethod · 0.80
ForceSetArgMethod · 0.80

Tested by

no test coverage detected