| 172 | } |
| 173 | |
| 174 | bool WalletInit::Verify() const |
| 175 | { |
| 176 | if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { |
| 177 | return true; |
| 178 | } |
| 179 | |
| 180 | if (gArgs.IsArgSet("-walletdir")) { |
| 181 | fs::path wallet_dir = gArgs.GetArg("-walletdir", ""); |
| 182 | if (!fs::exists(wallet_dir)) { |
| 183 | return InitError(strprintf(_("Specified -walletdir \"%s\" does not exist"), wallet_dir.string())); |
| 184 | } else if (!fs::is_directory(wallet_dir)) { |
| 185 | return InitError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), wallet_dir.string())); |
| 186 | } else if (!wallet_dir.is_absolute()) { |
| 187 | return InitError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), wallet_dir.string())); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | LogPrintf("Using wallet directory %s\n", GetWalletDir().string()); |
| 192 | |
| 193 | uiInterface.InitMessage(_("Verifying wallet(s)...")); |
| 194 | |
| 195 | std::vector<std::string> wallet_files = gArgs.GetArgs("-wallet"); |
| 196 | |
| 197 | // Parameter interaction code should have thrown an error if -salvagewallet |
| 198 | // was enabled with more than wallet file, so the wallet_files size check |
| 199 | // here should have no effect. |
| 200 | bool salvage_wallet = gArgs.GetBoolArg("-salvagewallet", false) && wallet_files.size() <= 1; |
| 201 | |
| 202 | // Keep track of each wallet absolute path to detect duplicates. |
| 203 | std::set<fs::path> wallet_paths; |
| 204 | |
| 205 | for (const auto& wallet_file : wallet_files) { |
| 206 | fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir()); |
| 207 | |
| 208 | if (!wallet_paths.insert(wallet_path).second) { |
| 209 | return InitError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file)); |
| 210 | } |
| 211 | |
| 212 | std::string error_string; |
| 213 | std::string warning_string; |
| 214 | bool verify_success = CWallet::Verify(wallet_file, salvage_wallet, error_string, warning_string); |
| 215 | if (!error_string.empty()) InitError(error_string); |
| 216 | if (!warning_string.empty()) InitWarning(warning_string); |
| 217 | if (!verify_success) return false; |
| 218 | } |
| 219 | |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | bool WalletInit::Open() const |
| 224 | { |
nothing calls this directly
no test coverage detected