@@ -190,55 +190,24 @@ bool WalletInit::Verify() const
190
190
191
191
uiInterface.InitMessage (_ (" Verifying wallet(s)..." ));
192
192
193
+ std::vector<std::string> wallet_files = gArgs .GetArgs (" -wallet" );
194
+
195
+ // Parameter interaction code should have thrown an error if -salvagewallet
196
+ // was enabled with more than wallet file, so the wallet_files size check
197
+ // here should have no effect.
198
+ bool salvage_wallet = gArgs .GetBoolArg (" -salvagewallet" , false ) && wallet_files.size () <= 1 ;
199
+
193
200
// Keep track of each wallet absolute path to detect duplicates.
194
201
std::set<fs::path> wallet_paths;
195
202
196
- for (const std::string& walletFile : gArgs .GetArgs (" -wallet" )) {
197
- // Do some checking on wallet path. It should be either a:
198
- //
199
- // 1. Path where a directory can be created.
200
- // 2. Path to an existing directory.
201
- // 3. Path to a symlink to a directory.
202
- // 4. For backwards compatibility, the name of a data file in -walletdir.
203
- fs::path wallet_path = fs::absolute (walletFile, GetWalletDir ());
204
- fs::file_type path_type = fs::symlink_status (wallet_path).type ();
205
- if (!(path_type == fs::file_not_found || path_type == fs::directory_file ||
206
- (path_type == fs::symlink_file && fs::is_directory (wallet_path)) ||
207
- (path_type == fs::regular_file && fs::path (walletFile).filename () == walletFile))) {
208
- return InitError (strprintf (
209
- _ (" Invalid -wallet path '%s'. -wallet path should point to a directory where wallet.dat and "
210
- " database/log.?????????? files can be stored, a location where such a directory could be created, "
211
- " or (for backwards compatibility) the name of an existing data file in -walletdir (%s)" ),
212
- walletFile, GetWalletDir ()));
213
- }
203
+ for (const auto wallet_file : wallet_files) {
204
+ fs::path wallet_path = fs::absolute (wallet_file, GetWalletDir ());
214
205
215
206
if (!wallet_paths.insert (wallet_path).second ) {
216
- return InitError (strprintf (_ (" Error loading wallet %s. Duplicate -wallet filename specified." ), walletFile));
217
- }
218
-
219
- std::string strError;
220
- if (!WalletBatch::VerifyEnvironment (wallet_path, strError)) {
221
- return InitError (strError);
207
+ return InitError (strprintf (_ (" Error loading wallet %s. Duplicate -wallet filename specified." ), wallet_file));
222
208
}
223
209
224
- if (gArgs .GetBoolArg (" -salvagewallet" , false )) {
225
- // Recover readable keypairs:
226
- CWallet dummyWallet (" dummy" , WalletDatabase::CreateDummy ());
227
- std::string backup_filename;
228
- if (!WalletBatch::Recover (wallet_path, (void *)&dummyWallet, WalletBatch::RecoverKeysOnlyFilter, backup_filename)) {
229
- return false ;
230
- }
231
- }
232
-
233
- std::string strWarning;
234
- bool dbV = WalletBatch::VerifyDatabaseFile (wallet_path, strWarning, strError);
235
- if (!strWarning.empty ()) {
236
- InitWarning (strWarning);
237
- }
238
- if (!dbV) {
239
- InitError (strError);
240
- return false ;
241
- }
210
+ if (!CWallet::Verify (wallet_file, salvage_wallet)) return false ;
242
211
}
243
212
244
213
return true ;
0 commit comments