diff --git a/src/wallet/db.h b/src/wallet/db.h index 6834ba69632..b4ccd13a9ac 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -174,51 +174,6 @@ public: virtual std::unique_ptr MakeBatch(bool flush_on_close = true) = 0; }; -class DummyCursor : public DatabaseCursor -{ - Status Next(DataStream& key, DataStream& value) override { return Status::FAIL; } -}; - -/** RAII class that provides access to a DummyDatabase. Never fails. */ -class DummyBatch : public DatabaseBatch -{ -private: - bool ReadKey(DataStream&& key, DataStream& value) override { return true; } - bool WriteKey(DataStream&& key, DataStream&& value, bool overwrite = true) override { return true; } - bool EraseKey(DataStream&& key) override { return true; } - bool HasKey(DataStream&& key) override { return true; } - bool ErasePrefix(Span prefix) override { return true; } - -public: - void Flush() override {} - void Close() override {} - - std::unique_ptr GetNewCursor() override { return std::make_unique(); } - 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() 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 {} - std::string Filename() override { return "dummy"; } - std::string Format() override { return "dummy"; } - std::unique_ptr MakeBatch(bool flush_on_close = true) override { return std::make_unique(); } -}; - enum class DatabaseFormat { BERKELEY, SQLITE, diff --git a/src/wallet/salvage.cpp b/src/wallet/salvage.cpp index 06c8c8bb377..ab73e67285c 100644 --- a/src/wallet/salvage.cpp +++ b/src/wallet/salvage.cpp @@ -23,6 +23,51 @@ static bool KeyFilter(const std::string& type) return WalletBatch::IsKeyType(type) || type == DBKeys::HDCHAIN; } +class DummyCursor : public DatabaseCursor +{ + Status Next(DataStream& key, DataStream& value) override { return Status::FAIL; } +}; + +/** RAII class that provides access to a DummyDatabase. Never fails. */ +class DummyBatch : public DatabaseBatch +{ +private: + bool ReadKey(DataStream&& key, DataStream& value) override { return true; } + bool WriteKey(DataStream&& key, DataStream&& value, bool overwrite=true) override { return true; } + bool EraseKey(DataStream&& key) override { return true; } + bool HasKey(DataStream&& key) override { return true; } + bool ErasePrefix(Span prefix) override { return true; } + +public: + void Flush() override {} + void Close() override {} + + std::unique_ptr GetNewCursor() override { return std::make_unique(); } + 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 salvage. + **/ +class DummyDatabase : public WalletDatabase +{ +public: + void Open() 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 {} + std::string Filename() override { return "dummy"; } + std::string Format() override { return "dummy"; } + std::unique_ptr MakeBatch(bool flush_on_close = true) override { return std::make_unique(); } +}; + bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bilingual_str& error, std::vector& warnings) { DatabaseOptions options; @@ -135,7 +180,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil } DbTxn* ptxn = env->TxnBegin(); - CWallet dummyWallet(nullptr, "", CreateDummyWalletDatabase()); + CWallet dummyWallet(nullptr, "", std::make_unique()); for (KeyValPair& row : salvagedData) { /* Filter for only private key type KV pairs to be added to the salvaged wallet */ diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 005592d7203..072357022e5 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1263,12 +1263,6 @@ std::unique_ptr MakeDatabase(const fs::path& path, const Databas return nullptr; } -/** Return object for accessing dummy database with no read/write capabilities. */ -std::unique_ptr CreateDummyWalletDatabase() -{ - return std::make_unique(); -} - /** Return object for accessing temporary in-memory database. */ std::unique_ptr CreateMockWalletDatabase(DatabaseOptions& options) { diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 72086e950a6..b2045403781 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -306,9 +306,6 @@ using KeyFilterFn = std::function; //! Unserialize a given Key-Value pair and load it into the wallet bool ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr); -/** Return object for accessing dummy database with no read/write capabilities. */ -std::unique_ptr CreateDummyWalletDatabase(); - /** Return object for accessing temporary in-memory database. */ std::unique_ptr CreateMockWalletDatabase(DatabaseOptions& options); std::unique_ptr CreateMockWalletDatabase();