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

Function RestoreWallet

src/wallet/wallet.cpp:383–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381}
382
383std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings)
384{
385 DatabaseOptions options;
386 options.require_existing = true;
387
388 if (!fs::exists(backup_file)) {
389 error = Untranslated("Backup file does not exist");
390 status = DatabaseStatus::FAILED_INVALID_BACKUP_FILE;
391 return nullptr;
392 }
393
394 const fs::path wallet_path = fsbridge::AbsPathJoin(GetWalletDir(), fs::u8path(wallet_name));
395
396 if (fs::exists(wallet_path) || !TryCreateDirectories(wallet_path)) {
397 error = Untranslated(strprintf("Failed to create database path '%s'. Database already exists.", fs::PathToString(wallet_path)));
398 status = DatabaseStatus::FAILED_ALREADY_EXISTS;
399 return nullptr;
400 }
401
402 auto wallet_file = wallet_path / "wallet.dat";
403 fs::copy_file(backup_file, wallet_file, fs::copy_options::none);
404
405 auto wallet = LoadWallet(context, wallet_name, load_on_start, options, status, error, warnings);
406
407 if (!wallet) {
408 fs::remove(wallet_file);
409 fs::remove(wallet_path);
410 }
411
412 return wallet;
413}
414
415/** @defgroup mapWallet
416 *

Callers 2

restoreWalletMethod · 0.85
restorewalletFunction · 0.85

Calls 8

existsFunction · 0.85
UntranslatedFunction · 0.85
AbsPathJoinFunction · 0.85
GetWalletDirFunction · 0.85
TryCreateDirectoriesFunction · 0.85
PathToStringFunction · 0.85
copy_fileFunction · 0.85
LoadWalletFunction · 0.85

Tested by

no test coverage detected