6 #ifndef BITCOIN_WALLET_DB_H 7 #define BITCOIN_WALLET_DB_H 41 virtual void Flush() = 0;
42 virtual void Close() = 0;
44 template <
typename K,
typename T>
45 bool Read(
const K& key, T& value)
52 if (!
ReadKey(std::move(ssKey), ssValue))
return false;
56 }
catch (
const std::exception&) {
61 template <
typename K,
typename T>
62 bool Write(
const K& key,
const T& value,
bool fOverwrite =
true)
72 return WriteKey(std::move(ssKey), std::move(ssValue), fOverwrite);
92 return HasKey(std::move(ssKey));
113 virtual void Open() = 0;
118 virtual void AddRef() = 0;
124 virtual bool Rewrite(
const char* pszSkip=
nullptr) = 0;
128 virtual bool Backup(
const std::string& strDest)
const = 0;
132 virtual void Flush() = 0;
136 virtual void Close() = 0;
148 virtual std::string
Format() = 0;
156 virtual std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true) = 0;
188 bool Rewrite(
const char* pszSkip=
nullptr)
override {
return true; }
189 bool Backup(
const std::string& strDest)
const override {
return true; }
195 std::string
Filename()
override {
return "dummy"; }
196 std::string
Format()
override {
return "dummy"; }
197 std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true)
override {
return std::make_unique<DummyBatch>(); }
245 #endif // BITCOIN_WALLET_DB_H std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
std::optional< DatabaseFormat > require_format
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
virtual bool Backup(const std::string &strDest) const =0
Back up the entire database to a file.
virtual bool TxnAbort()=0
virtual bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true)=0
virtual void CloseCursor()=0
virtual void Flush()=0
Make sure all changes are flushed to database file.
bool use_unsafe_sync
Disable file sync for faster performance.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
virtual void Open()=0
Open the database if it is not already opened.
void Close() override
Flush to the database file and close the database.
WalletDatabase()
Create dummy DB handle.
virtual void Close()=0
Flush to the database file and close the database.
Double ended buffer combining vector and stream-like interfaces.
std::string Filename() override
Return path to main database file for logs and error messages.
bool Write(const K &key, const T &value, bool fOverwrite=true)
std::atomic< unsigned int > nUpdateCounter
virtual bool Rewrite(const char *pszSkip=nullptr)=0
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a DatabaseBatch connected to this database.
RAII class that provides access to a WalletDatabase.
bool TxnCommit() override
fs::path SQLiteDataFile(const fs::path &path)
virtual bool TxnBegin()=0
virtual void RemoveRef()=0
Indicate that database user has stopped using the database and that it could be flushed or closed...
int64_t nLastWalletUpdate
bool PeriodicFlush() override
virtual bool ReadKey(CDataStream &&key, CDataStream &value)=0
std::atomic< int > m_refcount
Counts the number of active database users to be sure that the database is not closed while someone i...
bool Read(const K &key, T &value)
SecureString create_passphrase
bool IsBDBFile(const fs::path &path)
virtual bool EraseKey(CDataStream &&key)=0
bool Exists(const K &key)
bool StartCursor() override
bool ReadKey(CDataStream &&key, CDataStream &value) override
unsigned int nLastFlushed
virtual std::string Filename()=0
Return path to main database file for logs and error messages.
virtual void ReloadDbEnv()=0
RAII class that provides access to a DummyDatabase.
virtual void IncrementUpdateCounter()=0
virtual bool StartCursor()=0
virtual void AddRef()=0
Indicate the a new database user has began using the database.
void Flush() override
Make sure all changes are flushed to database file.
virtual ~WalletDatabase()
bool EraseKey(CDataStream &&key) override
void ReloadDbEnv() override
void IncrementUpdateCounter() override
virtual bool TxnCommit()=0
virtual bool PeriodicFlush()=0
bool use_shared_memory
Let other processes access the database.
void AddRef() override
Indicate the a new database user has began using the database.
virtual bool HasKey(CDataStream &&key)=0
A dummy WalletDatabase that does nothing and never fails.
int64_t max_log_mb
Max log size to allow before consolidating.
void CloseCursor() override
void reserve(size_type n)
fs::path BDBDataFile(const fs::path &wallet_path)
bool IsSQLiteFile(const fs::path &path)
virtual bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete)=0
virtual std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true)=0
Make a DatabaseBatch connected to this database.
bool Rewrite(const char *pszSkip=nullptr) override
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
bool HasKey(CDataStream &&key) override
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, std::string &database_filename)
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
std::string Format() override
virtual std::string Format()=0
void RemoveRef() override
Indicate that database user has stopped using the database and that it could be flushed or closed...
bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true) override
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool verify
Check data integrity on load.
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
bool error(const char *fmt, const Args &... args)
DatabaseBatch & operator=(const DatabaseBatch &)=delete
An instance of this class represents one database.
bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete) override
void Open() override
Open the database if it is not already opened.