Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show All 9 Lines | |||||
#include <fs.h> | #include <fs.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <protocol.h> | #include <protocol.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <util/bip32.h> | #include <util/bip32.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <util/translation.h> | |||||
#include <wallet/bdb.h> | |||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <atomic> | #include <atomic> | ||||
namespace DBKeys { | namespace DBKeys { | ||||
const std::string ACENTRY{"acentry"}; | const std::string ACENTRY{"acentry"}; | ||||
const std::string ACTIVEEXTERNALSPK{"activeexternalspk"}; | const std::string ACTIVEEXTERNALSPK{"activeexternalspk"}; | ||||
const std::string ACTIVEINTERNALSPK{"activeinternalspk"}; | const std::string ACTIVEINTERNALSPK{"activeinternalspk"}; | ||||
▲ Show 20 Lines • Show All 1,078 Lines • ▼ Show 20 Lines | |||||
bool WalletBatch::TxnCommit() { | bool WalletBatch::TxnCommit() { | ||||
return m_batch->TxnCommit(); | return m_batch->TxnCommit(); | ||||
} | } | ||||
bool WalletBatch::TxnAbort() { | bool WalletBatch::TxnAbort() { | ||||
return m_batch->TxnAbort(); | return m_batch->TxnAbort(); | ||||
} | } | ||||
std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path &path, | |||||
const DatabaseOptions &options, | |||||
DatabaseStatus &status, | |||||
bilingual_str &error) { | |||||
bool exists; | |||||
try { | |||||
exists = fs::symlink_status(path).type() != fs::file_not_found; | |||||
} catch (const fs::filesystem_error &e) { | |||||
error = Untranslated( | |||||
strprintf("Failed to access database path '%s': %s", path.string(), | |||||
fsbridge::get_filesystem_error_message(e))); | |||||
status = DatabaseStatus::FAILED_BAD_PATH; | |||||
return nullptr; | |||||
} | |||||
std::optional<DatabaseFormat> format; | |||||
if (exists) { | |||||
if (ExistsBerkeleyDatabase(path)) { | |||||
format = DatabaseFormat::BERKELEY; | |||||
} | |||||
} 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; | |||||
return nullptr; | |||||
} | |||||
if (!format && options.require_existing) { | |||||
error = Untranslated(strprintf("Failed to load database path '%s'. " | |||||
"Data is not in recognized format.", | |||||
path.string())); | |||||
status = DatabaseStatus::FAILED_BAD_FORMAT; | |||||
return nullptr; | |||||
} | |||||
if (format && options.require_create) { | |||||
error = Untranslated(strprintf( | |||||
"Failed to create database path '%s'. Database already exists.", | |||||
path.string())); | |||||
status = DatabaseStatus::FAILED_ALREADY_EXISTS; | |||||
return nullptr; | |||||
} | |||||
return MakeBerkeleyDatabase(path, options, status, error); | |||||
} | |||||
bool IsWalletLoaded(const fs::path &wallet_path) { | bool IsWalletLoaded(const fs::path &wallet_path) { | ||||
return IsBDBWalletLoaded(wallet_path); | return IsBDBWalletLoaded(wallet_path); | ||||
} | } | ||||
/** Return object for accessing database at specified path. */ | /** Return object for accessing database at specified path. */ | ||||
std::unique_ptr<WalletDatabase> CreateWalletDatabase(const fs::path &path) { | std::unique_ptr<WalletDatabase> CreateWalletDatabase(const fs::path &path) { | ||||
std::string filename; | std::string filename; | ||||
return std::make_unique<BerkeleyDatabase>(GetWalletEnv(path, filename), | return std::make_unique<BerkeleyDatabase>(GetWalletEnv(path, filename), | ||||
Show All 15 Lines |