6#ifndef BITCOIN_WALLET_DB_H
7#define BITCOIN_WALLET_DB_H
42 template <
typename K,
typename T>
bool Read(
const K &key, T &value) {
48 if (!
ReadKey(std::move(ssKey), ssValue)) {
54 }
catch (
const std::exception &) {
59 template <
typename K,
typename T>
72 template <
typename K>
bool Erase(
const K &key) {
80 template <
typename K>
bool Exists(
const K &key) {
85 return HasKey(std::move(ssKey));
162 virtual std::unique_ptr<DatabaseBatch>
185 bool &complete)
override {
210 std::string
Filename()
override {
return "dummy"; }
211 std::unique_ptr<DatabaseBatch>
213 return std::make_unique<DummyBatch>();
Double ended buffer combining vector and stream-like interfaces.
void reserve(size_type n)
RAII class that provides access to a WalletDatabase.
DatabaseBatch & operator=(const DatabaseBatch &)=delete
DatabaseBatch(const DatabaseBatch &)=delete
virtual bool TxnCommit()=0
virtual bool TxnBegin()=0
bool Write(const K &key, const T &value, bool fOverwrite=true)
virtual bool EraseKey(CDataStream &&key)=0
virtual bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete)=0
virtual void CloseCursor()=0
bool Read(const K &key, T &value)
bool Exists(const K &key)
virtual bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true)=0
virtual bool HasKey(CDataStream &&key)=0
virtual bool StartCursor()=0
virtual bool TxnAbort()=0
virtual bool ReadKey(CDataStream &&key, CDataStream &value)=0
RAII class that provides access to a DummyDatabase.
bool StartCursor() override
bool ReadKey(CDataStream &&key, CDataStream &value) override
bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete) override
bool TxnCommit() override
bool EraseKey(CDataStream &&key) override
bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true) override
void CloseCursor() override
bool HasKey(CDataStream &&key) override
A dummy WalletDatabase that does nothing and never fails.
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
void Open() override
Open the database if it is not already opened.
void RemoveRef() override
Indicate that database user has stopped using the database and that it could be flushed or closed.
std::string Filename() override
Return path to main database file for logs and error messages.
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a DatabaseBatch connected to this database.
void IncrementUpdateCounter() override
void AddRef() override
Indicate the a new database user has began using the database.
bool Rewrite(const char *pszSkip=nullptr) override
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
bool PeriodicFlush() override
void ReloadDbEnv() override
void Close() override
Flush to the database file and close the database.
void Flush() override
Make sure all changes are flushed to database file.
An instance of this class represents one database.
unsigned int nLastFlushed
virtual void Open()=0
Open the database if it is not already opened.
std::atomic< unsigned int > nUpdateCounter
virtual void RemoveRef()=0
Indicate that database user has stopped using the database and that it could be flushed or closed.
virtual void ReloadDbEnv()=0
virtual void Flush()=0
Make sure all changes are flushed to database file.
virtual bool Backup(const std::string &strDest) const =0
Back up the entire database to a file.
WalletDatabase()
Create dummy DB handle.
virtual bool Rewrite(const char *pszSkip=nullptr)=0
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
virtual ~WalletDatabase()
virtual std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true)=0
Make a DatabaseBatch connected to this database.
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 AddRef()=0
Indicate the a new database user has began using the database.
virtual std::string Filename()=0
Return path to main database file for logs and error messages.
int64_t nLastWalletUpdate
virtual void IncrementUpdateCounter()=0
virtual void Close()=0
Flush to the database file and close the database.
virtual bool PeriodicFlush()=0
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static constexpr 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)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
SecureString create_passphrase
std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, std::string &database_filename)