aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r--src/txdb.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 762f71feb1..4b76bee5ab 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -168,9 +168,34 @@ bool CBlockTreeDB::ReadLastBlockFile(int &nFile) {
return Read(DB_LAST_BLOCK, nFile);
}
-CCoinsViewCursor *CCoinsViewDB::Cursor() const
+/** Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB */
+class CCoinsViewDBCursor: public CCoinsViewCursor
{
- CCoinsViewDBCursor *i = new CCoinsViewDBCursor(const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock());
+public:
+ // Prefer using CCoinsViewDB::Cursor() since we want to perform some
+ // cache warmup on instantiation.
+ CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256&hashBlockIn):
+ CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {}
+ ~CCoinsViewDBCursor() {}
+
+ bool GetKey(COutPoint &key) const override;
+ bool GetValue(Coin &coin) const override;
+ unsigned int GetValueSize() const override;
+
+ bool Valid() const override;
+ void Next() override;
+
+private:
+ std::unique_ptr<CDBIterator> pcursor;
+ std::pair<char, COutPoint> keyTmp;
+
+ friend class CCoinsViewDB;
+};
+
+std::unique_ptr<CCoinsViewCursor> CCoinsViewDB::Cursor() const
+{
+ auto i = std::make_unique<CCoinsViewDBCursor>(
+ const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock());
/* It seems that there are no "const iterators" for LevelDB. Since we
only need read operations on it, use a const-cast to get around
that restriction. */