Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.h
Show All 11 Lines | |||||
#include <support/allocators/secure.h> | #include <support/allocators/secure.h> | ||||
#include <atomic> | #include <atomic> | ||||
#include <memory> | #include <memory> | ||||
#include <string> | #include <string> | ||||
struct bilingual_str; | struct bilingual_str; | ||||
/** | |||||
* Given a wallet directory path or legacy file path, return path to main data | |||||
* file in the wallet database. | |||||
*/ | |||||
fs::path WalletDataFilePath(const fs::path &wallet_path); | |||||
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, | void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, | ||||
std::string &database_filename); | std::string &database_filename); | ||||
/** RAII class that provides access to a WalletDatabase */ | /** RAII class that provides access to a WalletDatabase */ | ||||
class DatabaseBatch { | class DatabaseBatch { | ||||
private: | private: | ||||
virtual bool ReadKey(CDataStream &&key, CDataStream &value) = 0; | virtual bool ReadKey(CDataStream &&key, CDataStream &value) = 0; | ||||
virtual bool WriteKey(CDataStream &&key, CDataStream &&value, | virtual bool WriteKey(CDataStream &&key, CDataStream &&value, | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | public: | ||||
/* flush the wallet passively (TRY_LOCK) | /* flush the wallet passively (TRY_LOCK) | ||||
ideal to be called periodically */ | ideal to be called periodically */ | ||||
virtual bool PeriodicFlush() = 0; | virtual bool PeriodicFlush() = 0; | ||||
virtual void IncrementUpdateCounter() = 0; | virtual void IncrementUpdateCounter() = 0; | ||||
virtual void ReloadDbEnv() = 0; | virtual void ReloadDbEnv() = 0; | ||||
/** Return path to main database file for logs and error messages. */ | |||||
virtual std::string Filename() = 0; | |||||
std::atomic<unsigned int> nUpdateCounter; | std::atomic<unsigned int> nUpdateCounter; | ||||
unsigned int nLastSeen; | unsigned int nLastSeen; | ||||
unsigned int nLastFlushed; | unsigned int nLastFlushed; | ||||
int64_t nLastWalletUpdate; | int64_t nLastWalletUpdate; | ||||
std::string m_file_path; | |||||
/** Make a DatabaseBatch connected to this database */ | /** Make a DatabaseBatch connected to this database */ | ||||
virtual std::unique_ptr<DatabaseBatch> | virtual std::unique_ptr<DatabaseBatch> | ||||
MakeBatch(const char *mode = "r+", bool flush_on_close = true) = 0; | MakeBatch(const char *mode = "r+", bool flush_on_close = true) = 0; | ||||
}; | }; | ||||
/** RAII class that provides access to a DummyDatabase. Never fails. */ | /** RAII class that provides access to a DummyDatabase. Never fails. */ | ||||
class DummyBatch : public DatabaseBatch { | class DummyBatch : public DatabaseBatch { | ||||
private: | private: | ||||
Show All 33 Lines | public: | ||||
void RemoveRef() override {} | void RemoveRef() override {} | ||||
bool Rewrite(const char *pszSkip = nullptr) override { return true; } | bool Rewrite(const char *pszSkip = nullptr) override { return true; } | ||||
bool Backup(const std::string &strDest) const override { return true; } | bool Backup(const std::string &strDest) const override { return true; } | ||||
void Close() override {} | void Close() override {} | ||||
void Flush() override {} | void Flush() override {} | ||||
bool PeriodicFlush() override { return true; } | bool PeriodicFlush() override { return true; } | ||||
void IncrementUpdateCounter() override { ++nUpdateCounter; } | void IncrementUpdateCounter() override { ++nUpdateCounter; } | ||||
void ReloadDbEnv() override {} | void ReloadDbEnv() override {} | ||||
std::string Filename() override { return "dummy"; } | |||||
std::unique_ptr<DatabaseBatch> | std::unique_ptr<DatabaseBatch> | ||||
MakeBatch(const char *mode = "r+", bool flush_on_close = true) override { | MakeBatch(const char *mode = "r+", bool flush_on_close = true) override { | ||||
return std::make_unique<DummyBatch>(); | return std::make_unique<DummyBatch>(); | ||||
} | } | ||||
}; | }; | ||||
enum class DatabaseFormat { | enum class DatabaseFormat { | ||||
BERKELEY, | BERKELEY, | ||||
Show All 28 Lines |