aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/walletdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/walletdb.cpp')
-rw-r--r--src/wallet/walletdb.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 5bf21eb91f..aa3b3c10b0 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -15,6 +15,9 @@
#include <util/time.h>
#include <util/translation.h>
#include <wallet/bdb.h>
+#ifdef USE_SQLITE
+#include <wallet/sqlite.h>
+#endif
#include <wallet/wallet.h>
#include <atomic>
@@ -1011,6 +1014,16 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
if (ExistsBerkeleyDatabase(path)) {
format = DatabaseFormat::BERKELEY;
}
+#ifdef USE_SQLITE
+ 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;
+ }
+#endif
} 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 +1042,24 @@ 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;
+
+#ifdef USE_SQLITE
+ if (format && format == DatabaseFormat::SQLITE) {
+ return MakeSQLiteDatabase(path, options, status, error);
+ }
+#else
+ assert(format != DatabaseFormat::SQLITE);
+#endif
+
return MakeBerkeleyDatabase(path, options, status, error);
}