6 #ifndef BITCOIN_WALLET_DB_H 7 #define BITCOIN_WALLET_DB_H 22 void SplitWalletPath(
const fs::path& wallet_path, fs::path& env_directory, std::string& database_filename);
40 virtual void Flush() = 0;
41 virtual void Close() = 0;
43 template <
typename K,
typename T>
44 bool Read(
const K& key, T& value)
51 if (!
ReadKey(std::move(ssKey), ssValue))
return false;
55 }
catch (
const std::exception&) {
60 template <
typename K,
typename T>
61 bool Write(
const K& key,
const T& value,
bool fOverwrite =
true)
71 return WriteKey(std::move(ssKey), std::move(ssValue), fOverwrite);
91 return HasKey(std::move(ssKey));
108 WalletDatabase() : nUpdateCounter(0), nLastSeen(0), nLastFlushed(0), nLastWalletUpdate(0) {}
112 virtual void Open() = 0;
115 std::atomic<int> m_refcount{0};
117 virtual void AddRef() = 0;
119 virtual void RemoveRef() = 0;
123 virtual bool Rewrite(
const char* pszSkip=
nullptr) = 0;
127 virtual bool Backup(
const std::string& strDest)
const = 0;
131 virtual void Flush() = 0;
135 virtual void Close() = 0;
138 virtual bool PeriodicFlush() = 0;
140 virtual void IncrementUpdateCounter() = 0;
142 virtual void ReloadDbEnv() = 0;
145 virtual std::string Filename() = 0;
147 virtual std::string Format() = 0;
155 virtual std::unique_ptr<DatabaseBatch> MakeBatch(
bool flush_on_close =
true) = 0;
187 bool Rewrite(
const char* pszSkip=
nullptr)
override {
return true; }
188 bool Backup(
const std::string& strDest)
const override {
return true; }
194 std::string
Filename()
override {
return "dummy"; }
195 std::string
Format()
override {
return "dummy"; }
196 std::unique_ptr<DatabaseBatch>
MakeBatch(
bool flush_on_close =
true)
override {
return MakeUnique<DummyBatch>(); }
205 bool require_existing =
false;
206 bool require_create =
false;
208 uint64_t create_flags = 0;
228 #endif // BITCOIN_WALLET_DB_H
int64_t nLastWalletUpdate
WalletDatabase()
Create dummy DB handle.
virtual bool ReadKey(CDataStream &&key, CDataStream &value)=0
virtual bool HasKey(CDataStream &&key)=0
bool HasKey(CDataStream &&key) override
std::string Format() override
void RemoveRef() override
Indicate that database user has stopped using the database and that it could be flushed or closed...
virtual bool TxnAbort()=0
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
virtual bool TxnBegin()=0
Double ended buffer combining vector and stream-like interfaces.
virtual bool EraseKey(CDataStream &&key)=0
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, std::string &database_filename)
bool Write(const K &key, const T &value, bool fOverwrite=true)
bool StartCursor() override
bool error(const char *fmt, const Args &...args)
bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete) override
DatabaseBatch & operator=(const DatabaseBatch &)=delete
void CloseCursor() override
bool PeriodicFlush() override
virtual bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, bool &complete)=0
bool Read(const K &key, T &value)
RAII class that provides access to a WalletDatabase.
void Close() override
Flush to the database file and close the database.
void AddRef() override
Indicate the a new database user has began using the database.
A dummy WalletDatabase that does nothing and never fails.
bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true) override
void ReloadDbEnv() override
bool Backup(const std::string &strDest) const override
Back up the entire database to a file.
virtual void CloseCursor()=0
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a DatabaseBatch connected to this database.
void Flush() override
Make sure all changes are flushed to database file.
bool EraseKey(CDataStream &&key) override
void IncrementUpdateCounter() override
void reserve(size_type n)
std::atomic< unsigned int > nUpdateCounter
virtual bool TxnCommit()=0
unsigned int nLastFlushed
virtual bool StartCursor()=0
virtual ~WalletDatabase()
bool TxnCommit() override
SecureString create_passphrase
virtual bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true)=0
boost::optional< T > Optional
Substitute for C++17 std::optional.
std::string Filename() override
Return path to main database file for logs and error messages.
Optional< DatabaseFormat > require_format
RAII class that provides access to a DummyDatabase.
bool Exists(const K &key)
bool ReadKey(CDataStream &&key, CDataStream &value) override
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
void Open() override
Open the database if it is not already opened.
bool Rewrite(const char *pszSkip=nullptr) override
Rewrite the entire database on disk, with the exception of key pszSkip if non-zero.
An instance of this class represents one database.