Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251};253std::unique_ptr<CCoinsViewCursor> CCoinsViewDB::Cursor() const254{255auto i = std::make_unique<CCoinsViewDBCursor>(256const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock());257/* It seems that there are no "const iterators" for LevelDB. Since we258only need read operations on it, use a const-cast to get around259that restriction. */260i->pcursor->Seek(DB_COIN);261// Cache key of first record262if (i->pcursor->Valid()) {263CoinEntry entry(&i->keyTmp.second);264i->pcursor->GetKey(entry);265i->keyTmp.first = entry.key;266} else {267i->keyTmp.first = 0; // Make sure Valid() and GetKey() return false268}269return i;270}272bool CCoinsViewDBCursor::GetKey(COutPoint &key) const273{274// Return cached key275if (keyTmp.first == DB_COIN) {276key = keyTmp.second;277return true;278}279return false;280}282bool CCoinsViewDBCursor::GetValue(Coin &coin) const283{284return pcursor->GetValue(coin);285}287bool CCoinsViewDBCursor::Valid() const288{289return keyTmp.first == DB_COIN;290}292void CCoinsViewDBCursor::Next()293{294pcursor->Next();295CoinEntry entry(&keyTmp.second);296if (!pcursor->Valid() || !pcursor->GetKey(entry)) {297keyTmp.first = 0; // Invalidate cached key after last record so that Valid() and GetKey() return false298} else {299keyTmp.first = entry.key;300}301}