|
9 | 9 | #include <clientversion.h>
|
10 | 10 | #include <fs.h>
|
11 | 11 | #include <streams.h>
|
| 12 | +#include <util/memory.h> |
12 | 13 |
|
13 | 14 | #include <atomic>
|
14 | 15 | #include <memory>
|
@@ -154,4 +155,44 @@ class WalletDatabase
|
154 | 155 | virtual std::unique_ptr<DatabaseBatch> MakeBatch(const char* mode = "r+", bool flush_on_close = true) = 0;
|
155 | 156 | };
|
156 | 157 |
|
| 158 | +/** RAII class that provides access to a DummyDatabase. Never fails. */ |
| 159 | +class DummyBatch : public DatabaseBatch |
| 160 | +{ |
| 161 | +private: |
| 162 | + bool ReadKey(CDataStream&& key, CDataStream& value) override { return true; } |
| 163 | + bool WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite=true) override { return true; } |
| 164 | + bool EraseKey(CDataStream&& key) override { return true; } |
| 165 | + bool HasKey(CDataStream&& key) override { return true; } |
| 166 | + |
| 167 | +public: |
| 168 | + void Flush() override {} |
| 169 | + void Close() override {} |
| 170 | + |
| 171 | + bool StartCursor() override { return true; } |
| 172 | + bool ReadAtCursor(CDataStream& ssKey, CDataStream& ssValue, bool& complete) override { return true; } |
| 173 | + void CloseCursor() override {} |
| 174 | + bool TxnBegin() override { return true; } |
| 175 | + bool TxnCommit() override { return true; } |
| 176 | + bool TxnAbort() override { return true; } |
| 177 | +}; |
| 178 | + |
| 179 | +/** A dummy WalletDatabase that does nothing and never fails. Only used by unit tests. |
| 180 | + **/ |
| 181 | +class DummyDatabase : public WalletDatabase |
| 182 | +{ |
| 183 | +public: |
| 184 | + void Open(const char* mode) override {}; |
| 185 | + void AddRef() override {} |
| 186 | + void RemoveRef() override {} |
| 187 | + bool Rewrite(const char* pszSkip=nullptr) override { return true; } |
| 188 | + bool Backup(const std::string& strDest) const override { return true; } |
| 189 | + void Close() override {} |
| 190 | + void Flush() override {} |
| 191 | + bool PeriodicFlush() override { return true; } |
| 192 | + void IncrementUpdateCounter() override { ++nUpdateCounter; } |
| 193 | + void ReloadDbEnv() override {} |
| 194 | + bool Verify(bilingual_str& errorStr) override { return true; } |
| 195 | + std::unique_ptr<DatabaseBatch> MakeBatch(const char* mode = "r+", bool flush_on_close = true) override { return MakeUnique<DummyBatch>(); } |
| 196 | +}; |
| 197 | + |
157 | 198 | #endif // BITCOIN_WALLET_DB_H
|
0 commit comments