Page MenuHomePhabricator

D10048.id29799.diff
No OneTemporary

D10048.id29799.diff

diff --git a/src/wallet/db.h b/src/wallet/db.h
--- a/src/wallet/db.h
+++ b/src/wallet/db.h
@@ -18,7 +18,8 @@
/**
* 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);
void SplitWalletPath(const fs::path &wallet_path, fs::path &env_directory,
std::string &database_filename);
@@ -168,4 +169,55 @@
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
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -1135,7 +1135,7 @@
* Return object for accessing dummy database with no read/write capabilities.
*/
std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase() {
- return std::make_unique<BerkeleyDatabase>();
+ return std::make_unique<DummyDatabase>();
}
/** Return object for accessing temporary in-memory database. */

File Metadata

Mime Type
text/plain
Expires
Tue, May 20, 20:17 (9 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5865857
Default Alt Text
D10048.id29799.diff (2 KB)

Event Timeline