diff --git a/src/txdb.h b/src/txdb.h --- a/src/txdb.h +++ b/src/txdb.h @@ -128,6 +128,19 @@ std::function insertBlockIndex); }; +class BaseIndexDB : public CDBWrapper { +public: + BaseIndexDB(const fs::path &path, size_t n_cache_size, + bool f_memory = false, bool f_wipe = false, + bool f_obfuscate = false); + + /// Read block locator of the chain that the index is in sync with. + bool ReadBestBlock(CBlockLocator &locator) const; + + /// Write block locator of the chain that the index is in sync with. + bool WriteBestBlock(const CBlockLocator &locator); +}; + /** * Access to the txindex database (indexes/txindex/) * @@ -137,7 +150,7 @@ * and block index entries may not be flushed to disk until after this database * is updated. */ -class TxIndexDB : public CDBWrapper { +class TxIndexDB : public BaseIndexDB { public: explicit TxIndexDB(size_t n_cache_size, bool f_memory = false, bool f_wipe = false); @@ -149,12 +162,6 @@ /// Write a batch of transaction positions to the DB. bool WriteTxs(const std::vector> &v_pos); - /// Read block locator of the chain that the txindex is in sync with. - bool ReadBestBlock(CBlockLocator &locator) const; - - /// Write block locator of the chain that the txindex is in sync with. - bool WriteBestBlock(const CBlockLocator &locator); - /// Migrate txindex data from the block tree DB, where it may be for older /// nodes that have not been upgraded yet to the new database. bool MigrateData(CBlockTreeDB &block_tree_db, diff --git a/src/txdb.cpp b/src/txdb.cpp --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -444,9 +444,13 @@ return !ShutdownRequested(); } +BaseIndexDB::BaseIndexDB(const fs::path &path, size_t n_cache_size, + bool f_memory, bool f_wipe, bool f_obfuscate) + : CDBWrapper(path, n_cache_size, f_memory, f_wipe, f_obfuscate) {} + TxIndexDB::TxIndexDB(size_t n_cache_size, bool f_memory, bool f_wipe) - : CDBWrapper(GetDataDir() / "indexes" / "txindex", n_cache_size, f_memory, - f_wipe) {} + : BaseIndexDB(GetDataDir() / "indexes" / "txindex", n_cache_size, f_memory, + f_wipe) {} bool TxIndexDB::ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const { return Read(std::make_pair(DB_TXINDEX, txid), pos); @@ -461,7 +465,7 @@ return WriteBatch(batch); } -bool TxIndexDB::ReadBestBlock(CBlockLocator &locator) const { +bool BaseIndexDB::ReadBestBlock(CBlockLocator &locator) const { bool success = Read(DB_BEST_BLOCK, locator); if (!success) { locator.SetNull(); @@ -469,7 +473,7 @@ return success; } -bool TxIndexDB::WriteBestBlock(const CBlockLocator &locator) { +bool BaseIndexDB::WriteBestBlock(const CBlockLocator &locator) { return Write(DB_BEST_BLOCK, locator); }