Skip to content

Commit

Permalink
wallet: Generated migrated wallet's path from walletdir and name
Browse files Browse the repository at this point in the history
Co-Authored-By: Ryan Ofsky <ryan@ofsky.org>
  • Loading branch information
achow101 and ryanofsky committed Jun 12, 2023
1 parent cb40639 commit bdbe3fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3843,16 +3843,19 @@ bool CWallet::MigrateToSQLite(bilingual_str& error)

// Close this database and delete the file
fs::path db_path = fs::PathFromString(m_database->Filename());
fs::path db_dir = db_path.parent_path();
m_database->Close();
fs::remove(db_path);

// Generate the path for the location of the migrated wallet
// Wallets that are plain files rather than wallet directories will be migrated to be wallet directories.
const fs::path wallet_path = fsbridge::AbsPathJoin(GetWalletDir(), fs::PathFromString(m_name));

// Make new DB
DatabaseOptions opts;
opts.require_create = true;
opts.require_format = DatabaseFormat::SQLITE;
DatabaseStatus db_status;
std::unique_ptr<WalletDatabase> new_db = MakeDatabase(db_dir, opts, db_status, error);
std::unique_ptr<WalletDatabase> new_db = MakeDatabase(wallet_path, opts, db_status, error);
assert(new_db); // This is to prevent doing anything further with this wallet. The original file was deleted, but a backup exists.
m_database.reset();
m_database = std::move(new_db);
Expand Down

0 comments on commit bdbe3fd

Please sign in to comment.