6#ifndef BITCOIN_WALLET_DB_H
7#define BITCOIN_WALLET_DB_H
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));
149 virtual bool Rewrite(
const char* pszSkip=
nullptr) = 0;
153 virtual bool Backup(
const std::string& strDest)
const = 0;
181 virtual std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true) = 0;
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
virtual ~DatabaseBatch()=default
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
DatabaseBatch & operator=(const DatabaseBatch &)=delete
virtual bool ReadKey(DataStream &&key, DataStream &value)=0
virtual std::unique_ptr< DatabaseCursor > GetNewPrefixCursor(Span< const std::byte > prefix)=0
bool Exists(const K &key)
virtual bool ErasePrefix(Span< const std::byte > prefix)=0
virtual std::unique_ptr< DatabaseCursor > GetNewCursor()=0
virtual bool HasKey(DataStream &&key)=0
virtual bool HasActiveTxn()=0
virtual bool TxnCommit()=0
DatabaseCursor & operator=(const DatabaseCursor &)=delete
virtual ~DatabaseCursor()=default
DatabaseCursor(const DatabaseCursor &)=delete
virtual Status Next(DataStream &key, DataStream &value)
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 ~WalletDatabase()=default
virtual std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true)=0
Make a DatabaseBatch connected to this database.
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 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.
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.
@ FAIL
Just act as if the signature was invalid.
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)
bool IsBDBFile(const fs::path &path)
fs::path BDBDataFile(const fs::path &wallet_path)
bool operator<(BytePrefix a, Span< const std::byte > b)
bool IsSQLiteFile(const fs::path &path)
std::vector< std::pair< fs::path, std::string > > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
@ FAILED_INVALID_BACKUP_FILE
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Span< const std::byte > prefix
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.