6 #ifndef BITCOIN_WALLET_DB_H 7 #define BITCOIN_WALLET_DB_H 27 bool operator<(BytePrefix a, Span<const std::byte> b);
28 bool operator<(Span<const std::byte> a,
BytePrefix b);
65 virtual void Flush() = 0;
66 virtual void Close() = 0;
68 template <
typename K,
typename T>
69 bool Read(
const K& key, T& value)
76 if (!
ReadKey(std::move(ssKey), ssValue))
return false;
80 }
catch (
const std::exception&) {
85 template <
typename K,
typename T>
86 bool Write(
const K& key,
const T& value,
bool fOverwrite =
true)
96 return WriteKey(std::move(ssKey), std::move(ssValue), fOverwrite);
109 template <
typename K>
116 return HasKey(std::move(ssKey));
120 virtual std::unique_ptr<DatabaseCursor>
GetNewCursor() = 0;
138 virtual void Open() = 0;
143 virtual void AddRef() = 0;
149 virtual bool Rewrite(
const char* pszSkip=
nullptr) = 0;
153 virtual bool Backup(
const std::string& strDest)
const = 0;
157 virtual void Flush() = 0;
161 virtual void Close() = 0;
173 virtual std::string
Format() = 0;
181 virtual std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true) = 0;
231 #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)
virtual std::unique_ptr< DatabaseCursor > GetNewCursor()=0
void reserve(size_type n)
virtual bool HasKey(DataStream &&key)=0
virtual bool Backup(const std::string &strDest) const =0
Back up the entire database to a file.
virtual bool TxnAbort()=0
std::vector< std::pair< fs::path, std::string > > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
virtual void Flush()=0
Make sure all changes are flushed to database file.
bool use_unsafe_sync
Disable file sync for faster performance.
virtual bool ErasePrefix(Span< const std::byte > prefix)=0
virtual ~WalletDatabase()=default
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.
virtual std::unique_ptr< DatabaseCursor > GetNewPrefixCursor(Span< const std::byte > prefix)=0
WalletDatabase()
Create dummy DB handle.
virtual void Close()=0
Flush to the database file and close the database.
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.
RAII class that provides access to a WalletDatabase.
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...
virtual bool HasActiveTxn()=0
int64_t nLastWalletUpdate
std::atomic< int > m_refcount
Counts the number of active database users to be sure that the database is not closed while someone i...
DatabaseCursor & operator=(const DatabaseCursor &)=delete
bool Read(const K &key, T &value)
SecureString create_passphrase
bool IsBDBFile(const fs::path &path)
bool Exists(const K &key)
virtual bool WriteKey(DataStream &&key, DataStream &&value, bool overwrite=true)=0
Double ended buffer combining vector and stream-like interfaces.
unsigned int nLastFlushed
virtual std::string Filename()=0
Return path to main database file for logs and error messages.
virtual void ReloadDbEnv()=0
virtual void IncrementUpdateCounter()=0
virtual void AddRef()=0
Indicate the a new database user has began using the database.
virtual bool ReadKey(DataStream &&key, DataStream &value)=0
virtual bool EraseKey(DataStream &&key)=0
virtual bool TxnCommit()=0
virtual bool PeriodicFlush()=0
bool use_shared_memory
Let other processes access the database.
virtual Status Next(DataStream &key, DataStream &value)
int64_t max_log_mb
Max log size to allow before consolidating.
fs::path BDBDataFile(const fs::path &wallet_path)
bool IsSQLiteFile(const fs::path &path)
virtual ~DatabaseCursor()=default
virtual std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true)=0
Make a DatabaseBatch connected to this database.
virtual std::string Format()=0
virtual ~DatabaseBatch()=default
Span< const std::byte > prefix
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.
DatabaseBatch & operator=(const DatabaseBatch &)=delete
An instance of this class represents one database.