aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/db.cpp
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2024-08-14 13:56:49 +0100
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2024-08-14 14:09:35 +0100
commite682e7db7e399ce888e492eab8f99c389aae05b5 (patch)
tree2067d7546e468a9c896fd0753b86399a428da276 /src/wallet/db.cpp
parent1a41e63575986887ae34993b4433ec711ae0ffbc (diff)
parent8f2522d242961ceb9e79672aa43e856863a1a6dd (diff)
downloadbitcoin-e682e7db7e399ce888e492eab8f99c389aae05b5.tar.xz
Merge bitcoin-core/gui#824: Migrate legacy wallets that are not loaded
8f2522d242961ceb9e79672aa43e856863a1a6dd gui: Use menu for wallet migration (Ava Chow) d56a450bf5172e2c3f4b9a2786e71268019e1277 gui: Use wallet name for wallet migration rather than WalletModel (Ava Chow) c3918583dd5fcd9001136da2192e02e092128901 gui: don't remove wallet manually before migration (furszy) bfba63880fbb1108b73540faeb0620ba24b8cdd0 gui: Consolidate wallet display name to GUIUtil function (Ava Chow) 28fc562f2692af4f37f918d4ae31c4d115e03aee wallet, interfaces: Include database format in listWalletDir (Ava Chow) Pull request description: Currently the Migrate Wallet menu item can only be used to migrate the currently loaded wallet. This is not suitable for the future when legacy wallets can no longer be loaded at all, but should still be able to be migrated. This PR changes that menu item into a menu list like Open Wallet and lets users migrate any legacy wallet in their wallet directory regardless of the wallets loaded. One issue I ran into was dealing with encrypted wallets. Ideally, we would detect whether a wallet is encrypted, and prompt the user for their passphrase at that time. However, that's actually difficult to do in the GUI since migration will unload the wallet if it was already loaded, and reload it without connecting it to any signals or interfaces. Only then can it detect whether a wallet is encrypted, but then there is no `WalletModel` or even an `interfaces::Wallet` that the GUI could use to unlock it via a callback. To deal with this, I've opted to just add a button to the migration dialog box that has the user enter their passphrase first, along with instructional text to use that button if their wallet was encrypted. If the user enters the wrong passphrase or clicked the other button that does not prompt for the passphrase, migration will fail with a message indicating that the passphrase was incorrect. ACKs for top commit: hebasto: ACK 8f2522d242961ceb9e79672aa43e856863a1a6dd. furszy: ACK 8f2522d Tree-SHA512: a0e3b70dbfcacb89617956510ebcea94cad8617a987c68fe39fa16ac1721190b7cf7afc156c39b9032920cfb67b5d4ca28791681f5021d92d16acc691387afa1
Diffstat (limited to 'src/wallet/db.cpp')
-rw-r--r--src/wallet/db.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index 1523b7d613..400b9dc44f 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -19,9 +19,9 @@ namespace wallet {
bool operator<(BytePrefix a, Span<const std::byte> b) { return a.prefix < b.subspan(0, std::min(a.prefix.size(), b.size())); }
bool operator<(Span<const std::byte> a, BytePrefix b) { return a.subspan(0, std::min(a.size(), b.prefix.size())) < b.prefix; }
-std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
+std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wallet_dir)
{
- std::vector<fs::path> paths;
+ std::vector<std::pair<fs::path, std::string>> paths;
std::error_code ec;
for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
@@ -38,21 +38,29 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
try {
const fs::path path{it->path().lexically_relative(wallet_dir)};
- if (it->status().type() == fs::file_type::directory &&
- (IsBDBFile(BDBDataFile(it->path())) || IsSQLiteFile(SQLiteDataFile(it->path())))) {
- // Found a directory which contains wallet.dat btree file, add it as a wallet.
- paths.emplace_back(path);
+ if (it->status().type() == fs::file_type::directory) {
+ if (IsBDBFile(BDBDataFile(it->path()))) {
+ // Found a directory which contains wallet.dat btree file, add it as a wallet with BERKELEY format.
+ paths.emplace_back(path, "bdb");
+ } else if (IsSQLiteFile(SQLiteDataFile(it->path()))) {
+ // Found a directory which contains wallet.dat sqlite file, add it as a wallet with SQLITE format.
+ paths.emplace_back(path, "sqlite");
+ }
} else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && it->path().extension() != ".bak") {
if (it->path().filename() == "wallet.dat") {
- // Found top-level wallet.dat btree file, add top level directory ""
+ // Found top-level wallet.dat file, add top level directory ""
// as a wallet.
- paths.emplace_back();
+ if (IsBDBFile(it->path())) {
+ paths.emplace_back(fs::path(), "bdb");
+ } else if (IsSQLiteFile(it->path())) {
+ paths.emplace_back(fs::path(), "sqlite");
+ }
} else if (IsBDBFile(it->path())) {
// Found top-level btree file not called wallet.dat. Current bitcoin
// software will never create these files but will allow them to be
// opened in a shared database environment for backwards compatibility.
// Add it to the list of available wallets.
- paths.emplace_back(path);
+ paths.emplace_back(path, "bdb");
}
}
} catch (const std::exception& e) {