Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.h
Show All 12 Lines | |||||
#include <atomic> | #include <atomic> | ||||
#include <memory> | #include <memory> | ||||
#include <string> | #include <string> | ||||
struct bilingual_str; | struct bilingual_str; | ||||
/** | /** | ||||
* Given a wallet directory path or legacy file path, return path to main data | * Given a wallet directory path or legacy file path, return path to main data | ||||
* file in the wallet database. */ | * file in the wallet database. | ||||
*/ | |||||
fs::path WalletDataFilePath(const fs::path &wallet_path); | fs::path WalletDataFilePath(const fs::path &wallet_path); | ||||
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, | void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory, | ||||
std::string &database_filename); | std::string &database_filename); | ||||
/** RAII class that provides access to a WalletDatabase */ | /** RAII class that provides access to a WalletDatabase */ | ||||
class DatabaseBatch { | class DatabaseBatch { | ||||
private: | private: | ||||
virtual bool ReadKey(CDataStream &&key, CDataStream &value) = 0; | virtual bool ReadKey(CDataStream &&key, CDataStream &value) = 0; | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | public: | ||||
std::string m_file_path; | std::string m_file_path; | ||||
/** Make a DatabaseBatch connected to this database */ | /** Make a DatabaseBatch connected to this database */ | ||||
virtual std::unique_ptr<DatabaseBatch> | virtual std::unique_ptr<DatabaseBatch> | ||||
MakeBatch(const char *mode = "r+", bool flush_on_close = true) = 0; | MakeBatch(const char *mode = "r+", bool flush_on_close = true) = 0; | ||||
}; | }; | ||||
/** RAII class that provides access to a DummyDatabase. Never fails. */ | |||||
class DummyBatch : public DatabaseBatch { | |||||
private: | |||||
bool ReadKey(CDataStream &&key, CDataStream &value) override { | |||||
return true; | |||||
} | |||||
bool WriteKey(CDataStream &&key, CDataStream &&value, | |||||
bool overwrite = true) override { | |||||
return true; | |||||
} | |||||
bool EraseKey(CDataStream &&key) override { return true; } | |||||
bool HasKey(CDataStream &&key) override { return true; } | |||||
public: | |||||
void Flush() override {} | |||||
void Close() override {} | |||||
bool StartCursor() override { return true; } | |||||
bool ReadAtCursor(CDataStream &ssKey, CDataStream &ssValue, | |||||
bool &complete) override { | |||||
return true; | |||||
} | |||||
void CloseCursor() override {} | |||||
bool TxnBegin() override { return true; } | |||||
bool TxnCommit() override { return true; } | |||||
bool TxnAbort() override { return true; } | |||||
}; | |||||
/** | |||||
* A dummy WalletDatabase that does nothing and never fails. Only used by unit | |||||
* tests. | |||||
*/ | |||||
class DummyDatabase : public WalletDatabase { | |||||
public: | |||||
void Open(const char *mode) override{}; | |||||
void AddRef() override {} | |||||
void RemoveRef() override {} | |||||
bool Rewrite(const char *pszSkip = nullptr) override { return true; } | |||||
bool Backup(const std::string &strDest) const override { return true; } | |||||
void Close() override {} | |||||
void Flush() override {} | |||||
bool PeriodicFlush() override { return true; } | |||||
void IncrementUpdateCounter() override { ++nUpdateCounter; } | |||||
void ReloadDbEnv() override {} | |||||
bool Verify(bilingual_str &errorStr) override { return true; } | |||||
std::unique_ptr<DatabaseBatch> | |||||
MakeBatch(const char *mode = "r+", bool flush_on_close = true) override { | |||||
return std::make_unique<DummyBatch>(); | |||||
} | |||||
}; | |||||
#endif // BITCOIN_WALLET_DB_H | #endif // BITCOIN_WALLET_DB_H |