6 #ifndef BITCOIN_WALLET_DB_H
7 #define BITCOIN_WALLET_DB_H
63 template <
typename K,
typename T>
64 bool Read(
const K& key, T& value)
71 if (!
ReadKey(std::move(ssKey), ssValue))
return false;
75 }
catch (
const std::exception&) {
80 template <
typename K,
typename T>
81 bool Write(
const K& key,
const T& value,
bool fOverwrite =
true)
91 return WriteKey(std::move(ssKey), std::move(ssValue), fOverwrite);
104 template <
typename K>
111 return HasKey(std::move(ssKey));
141 virtual bool Rewrite(
const char* pszSkip=
nullptr) = 0;
145 virtual bool Backup(
const std::string& strDest)
const = 0;
173 virtual std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true) = 0;
194 std::unique_ptr<DatabaseCursor>
GetNewCursor()
override {
return std::make_unique<DummyCursor>(); }
208 bool Rewrite(
const char* pszSkip=
nullptr)
override {
return true; }
209 bool Backup(
const std::string& strDest)
const override {
return true; }
215 std::string
Filename()
override {
return "dummy"; }
216 std::string
Format()
override {
return "dummy"; }
217 std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true)
override {
return std::make_unique<DummyBatch>(); }
Double ended buffer combining vector and stream-like interfaces.
void reserve(size_type n)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
RAII class that provides access to a WalletDatabase.
bool Write(const K &key, const T &value, bool fOverwrite=true)
virtual bool TxnAbort()=0
DatabaseBatch(const DatabaseBatch &)=delete
bool Read(const K &key, T &value)
virtual bool EraseKey(DataStream &&key)=0
virtual bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true)=0
virtual bool TxnBegin()=0
virtual std::unique_ptr< DatabaseCursor > GetNewCursor()=0
DatabaseBatch & operator=(const DatabaseBatch &)=delete
virtual bool ReadKey(DataStream &&key, DataStream &value)=0
bool Exists(const K &key)
virtual bool HasKey(DataStream &&key)=0
virtual bool TxnCommit()=0
DatabaseCursor & operator=(const DatabaseCursor &)=delete
virtual ~DatabaseCursor()
DatabaseCursor(const DatabaseCursor &)=delete
virtual Status Next(DataStream &key, DataStream &value)
RAII class that provides access to a DummyDatabase.
bool EraseKey(DataStream &&key) override
bool HasKey(DataStream &&key) override
std::unique_ptr< DatabaseCursor > GetNewCursor() override
bool ReadKey(DataStream &&key, DataStream &value) override
bool TxnCommit() override
bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true) override
Status Next(DataStream &key, DataStream &value) override
A dummy WalletDatabase that does nothing and never fails.
bool Rewrite(const char *pszSkip=nullptr) override
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
void AddRef() override
Indicate the a new database user has began using the database.
void ReloadDbEnv() override
bool PeriodicFlush() override
void IncrementUpdateCounter() override
void Flush() override
Make sure all changes are flushed to database file.
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a DatabaseBatch connected to this database.
std::string Filename() override
Return path to main database file for logs and error messages.
void Open() override
Open the database if it is not already opened.
std::string Format() override
void RemoveRef() override
Indicate that database user has stopped using the database and that it could be flushed or closed.
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
void Close() override
Flush to the database file and close the database.
An instance of this class represents one database.
virtual bool PeriodicFlush()=0
virtual void AddRef()=0
Indicate the a new database user has began using the database.
virtual std::string Format()=0
virtual void IncrementUpdateCounter()=0
virtual void Open()=0
Open the database if it is not already opened.
int64_t nLastWalletUpdate
virtual bool Rewrite(const char *pszSkip=nullptr)=0
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
virtual void ReloadDbEnv()=0
virtual std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true)=0
Make a DatabaseBatch connected to this database.
virtual void Close()=0
Flush to the database file and close the database.
virtual bool Backup(const std::string &strDest) const =0
Back up the entire database to a file.
std::atomic< unsigned int > nUpdateCounter
std::atomic< int > m_refcount
Counts the number of active database users to be sure that the database is not closed while someone i...
virtual void RemoveRef()=0
Indicate that database user has stopped using the database and that it could be flushed or closed.
virtual ~WalletDatabase()
unsigned int nLastFlushed
WalletDatabase()
Create dummy DB handle.
virtual std::string Filename()=0
Return path to main database file for logs and error messages.
virtual void Flush()=0
Make sure all changes are flushed to database file.
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)
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, std::string &database_filename)
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
fs::path SQLiteDataFile(const fs::path &path)
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
bool IsBDBFile(const fs::path &path)
fs::path BDBDataFile(const fs::path &wallet_path)
bool IsSQLiteFile(const fs::path &path)
@ FAILED_INVALID_BACKUP_FILE
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool verify
Check data integrity on load.
bool use_shared_memory
Let other processes access the database.
SecureString create_passphrase
std::optional< DatabaseFormat > require_format
bool use_unsafe_sync
Disable file sync for faster performance.
int64_t max_log_mb
Max log size to allow before consolidating.