aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/walletdb.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-05-26 20:54:05 -0400
committerAndrew Chow <achow101-github@achow101.com>2020-10-14 11:28:18 -0400
commitac38a87225be0f1103ff9629d63980550d2f372b (patch)
treea985380a416f93c7c2f07ae101079cbb351dbbdc /src/wallet/walletdb.cpp
parent6045f77003f167bee9a85e2d53f8fc6ff2e297d8 (diff)
downloadbitcoin-ac38a87225be0f1103ff9629d63980550d2f372b.tar.xz
Determine wallet file type based on file magic
Diffstat (limited to 'src/wallet/walletdb.cpp')
-rw-r--r--src/wallet/walletdb.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 5bf21eb91f..0092a29cb4 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -15,6 +15,7 @@
#include <util/time.h>
#include <util/translation.h>
#include <wallet/bdb.h>
+#include <wallet/sqlite.h>
#include <wallet/wallet.h>
#include <atomic>
@@ -1011,6 +1012,14 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
if (ExistsBerkeleyDatabase(path)) {
format = DatabaseFormat::BERKELEY;
}
+ if (ExistsSQLiteDatabase(path)) {
+ if (format) {
+ error = Untranslated(strprintf("Failed to load database path '%s'. Data is in ambiguous format.", path.string()));
+ status = DatabaseStatus::FAILED_BAD_FORMAT;
+ return nullptr;
+ }
+ format = DatabaseFormat::SQLITE;
+ }
} else if (options.require_existing) {
error = Untranslated(strprintf("Failed to load database path '%s'. Path does not exist.", path.string()));
status = DatabaseStatus::FAILED_NOT_FOUND;
@@ -1029,6 +1038,20 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
return nullptr;
}
+ // A db already exists so format is set, but options also specifies the format, so make sure they agree
+ if (format && options.require_format && format != options.require_format) {
+ error = Untranslated(strprintf("Failed to load database path '%s'. Data is not in required format.", path.string()));
+ status = DatabaseStatus::FAILED_BAD_FORMAT;
+ return nullptr;
+ }
+
+ // Format is not set when a db doesn't already exist, so use the format specified by the options if it is set.
+ if (!format && options.require_format) format = options.require_format;
+
+ if (format && format == DatabaseFormat::SQLITE) {
+ return MakeSQLiteDatabase(path, options, status, error);
+ }
+
return MakeBerkeleyDatabase(path, options, status, error);
}