aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-03-28 18:18:30 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-04-15 16:33:05 +0200
commit509cb006d514cece5ab7680094f033c8dc8a2318 (patch)
treef14b1a13f7613a592d2489616c48f71c734ee2d3 /src/txdb.h
parent1b2460bd5824170ab85757e35f81197199cce9d6 (diff)
downloadbitcoin-509cb006d514cece5ab7680094f033c8dc8a2318.tar.xz
txdb: Add Cursor() method to CCoinsView to iterate over UTXO set
Add a method Cursor() to CCoinsView that returns a cursor which can be used to iterate over the whole UTXO set. - rpc: Change gettxoutsetinfo to use new Cursor method - txdb: Remove GetStats method - Now that GetStats is implemented in terms of Cursor, remove it.
Diffstat (limited to 'src/txdb.h')
-rw-r--r--src/txdb.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/txdb.h b/src/txdb.h
index 22e0c5704c..749802f0e5 100644
--- a/src/txdb.h
+++ b/src/txdb.h
@@ -26,6 +26,8 @@ static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
//! min. -dbcache in (MiB)
static const int64_t nMinDbCache = 4;
+class CCoinsViewDBCursor;
+
/** CCoinsView backed by the coin database (chainstate/) */
class CCoinsViewDB : public CCoinsView
{
@@ -38,7 +40,29 @@ public:
bool HaveCoins(const uint256 &txid) const;
uint256 GetBestBlock() const;
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
- bool GetStats(CCoinsStats &stats) const;
+ CCoinsViewCursor *Cursor() const;
+};
+
+/** Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB */
+class CCoinsViewDBCursor: public CCoinsViewCursor
+{
+public:
+ ~CCoinsViewDBCursor() {}
+
+ bool GetKey(uint256 &key) const;
+ bool GetValue(CCoins &coins) const;
+ unsigned int GetValueSize() const;
+
+ bool Valid() const;
+ void Next();
+
+private:
+ CCoinsViewDBCursor(CDBIterator* pcursorIn, const uint256 &hashBlockIn):
+ CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {}
+ boost::scoped_ptr<CDBIterator> pcursor;
+ std::pair<char, uint256> keyTmp;
+
+ friend class CCoinsViewDB;
};
/** Access to the block database (blocks/index/) */