@@ -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+
2671bool 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 */
0 commit comments