Skip to content

Commit 14aa4cb

Browse files
committed
wallet: Move DummyDatabase to salvage
It's only used by salvage, so make it local to that only.
1 parent f67a385 commit 14aa4cb

File tree

4 files changed

+46
-55
lines changed

4 files changed

+46
-55
lines changed

src/wallet/db.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -174,51 +174,6 @@ class WalletDatabase
174174
virtual std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) = 0;
175175
};
176176

177-
class DummyCursor : public DatabaseCursor
178-
{
179-
Status Next(DataStream& key, DataStream& value) override { return Status::FAIL; }
180-
};
181-
182-
/** RAII class that provides access to a DummyDatabase. Never fails. */
183-
class DummyBatch : public DatabaseBatch
184-
{
185-
private:
186-
bool ReadKey(DataStream&& key, DataStream& value) override { return true; }
187-
bool WriteKey(DataStream&& key, DataStream&& value, bool overwrite = true) override { return true; }
188-
bool EraseKey(DataStream&& key) override { return true; }
189-
bool HasKey(DataStream&& key) override { return true; }
190-
bool ErasePrefix(Span<const std::byte> prefix) override { return true; }
191-
192-
public:
193-
void Flush() override {}
194-
void Close() override {}
195-
196-
std::unique_ptr<DatabaseCursor> GetNewCursor() override { return std::make_unique<DummyCursor>(); }
197-
bool TxnBegin() override { return true; }
198-
bool TxnCommit() override { return true; }
199-
bool TxnAbort() override { return true; }
200-
};
201-
202-
/** A dummy WalletDatabase that does nothing and never fails. Only used by unit tests.
203-
**/
204-
class DummyDatabase : public WalletDatabase
205-
{
206-
public:
207-
void Open() override {};
208-
void AddRef() override {}
209-
void RemoveRef() override {}
210-
bool Rewrite(const char* pszSkip=nullptr) override { return true; }
211-
bool Backup(const std::string& strDest) const override { return true; }
212-
void Close() override {}
213-
void Flush() override {}
214-
bool PeriodicFlush() override { return true; }
215-
void IncrementUpdateCounter() override { ++nUpdateCounter; }
216-
void ReloadDbEnv() override {}
217-
std::string Filename() override { return "dummy"; }
218-
std::string Format() override { return "dummy"; }
219-
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override { return std::make_unique<DummyBatch>(); }
220-
};
221-
222177
enum class DatabaseFormat {
223178
BERKELEY,
224179
SQLITE,

src/wallet/salvage.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,51 @@ static bool KeyFilter(const std::string& type)
2323
return WalletBatch::IsKeyType(type) || type == DBKeys::HDCHAIN;
2424
}
2525

26+
class DummyCursor : public DatabaseCursor
27+
{
28+
Status Next(DataStream& key, DataStream& value) override { return Status::FAIL; }
29+
};
30+
31+
/** RAII class that provides access to a DummyDatabase. Never fails. */
32+
class DummyBatch : public DatabaseBatch
33+
{
34+
private:
35+
bool ReadKey(DataStream&& key, DataStream& value) override { return true; }
36+
bool WriteKey(DataStream&& key, DataStream&& value, bool overwrite=true) override { return true; }
37+
bool EraseKey(DataStream&& key) override { return true; }
38+
bool HasKey(DataStream&& key) override { return true; }
39+
bool ErasePrefix(Span<const std::byte> prefix) override { return true; }
40+
41+
public:
42+
void Flush() override {}
43+
void Close() override {}
44+
45+
std::unique_ptr<DatabaseCursor> GetNewCursor() override { return std::make_unique<DummyCursor>(); }
46+
bool TxnBegin() override { return true; }
47+
bool TxnCommit() override { return true; }
48+
bool TxnAbort() override { return true; }
49+
};
50+
51+
/** A dummy WalletDatabase that does nothing and never fails. Only used by salvage.
52+
**/
53+
class DummyDatabase : public WalletDatabase
54+
{
55+
public:
56+
void Open() override {};
57+
void AddRef() override {}
58+
void RemoveRef() override {}
59+
bool Rewrite(const char* pszSkip=nullptr) override { return true; }
60+
bool Backup(const std::string& strDest) const override { return true; }
61+
void Close() override {}
62+
void Flush() override {}
63+
bool PeriodicFlush() override { return true; }
64+
void IncrementUpdateCounter() override { ++nUpdateCounter; }
65+
void ReloadDbEnv() override {}
66+
std::string Filename() override { return "dummy"; }
67+
std::string Format() override { return "dummy"; }
68+
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override { return std::make_unique<DummyBatch>(); }
69+
};
70+
2671
bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bilingual_str& error, std::vector<bilingual_str>& warnings)
2772
{
2873
DatabaseOptions options;
@@ -135,7 +180,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil
135180
}
136181

137182
DbTxn* ptxn = env->TxnBegin();
138-
CWallet dummyWallet(nullptr, "", CreateDummyWalletDatabase());
183+
CWallet dummyWallet(nullptr, "", std::make_unique<DummyDatabase>());
139184
for (KeyValPair& row : salvagedData)
140185
{
141186
/* Filter for only private key type KV pairs to be added to the salvaged wallet */

src/wallet/walletdb.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,12 +1263,6 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
12631263
return nullptr;
12641264
}
12651265

1266-
/** Return object for accessing dummy database with no read/write capabilities. */
1267-
std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
1268-
{
1269-
return std::make_unique<DummyDatabase>();
1270-
}
1271-
12721266
/** Return object for accessing temporary in-memory database. */
12731267
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(DatabaseOptions& options)
12741268
{

src/wallet/walletdb.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ using KeyFilterFn = std::function<bool(const std::string&)>;
306306
//! Unserialize a given Key-Value pair and load it into the wallet
307307
bool ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr);
308308

309-
/** Return object for accessing dummy database with no read/write capabilities. */
310-
std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase();
311-
312309
/** Return object for accessing temporary in-memory database. */
313310
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(DatabaseOptions& options);
314311
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase();

0 commit comments

Comments
 (0)