PRCYCoin  2.0.0.7rc1
P2P Digital Currency
Public Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
CCoinsViewCache Class Reference

CCoinsView that adds a memory cache for transactions to another CCoinsView. More...

#include <coins.h>

Inheritance diagram for CCoinsViewCache:
[legend]
Collaboration diagram for CCoinsViewCache:
[legend]

Public Member Functions

 CCoinsViewCache (CCoinsView *baseIn)
 
 ~CCoinsViewCache ()
 
bool GetCoins (const uint256 &txid, CCoins &coins) const
 Retrieve the CCoins (unspent transaction outputs) for a given txid. More...
 
bool HaveCoins (const uint256 &txid) const
 Just check whether we have data for a given txid. More...
 
uint256 GetBestBlock () const
 Retrieve the block hash whose state this CCoinsView currently represents. More...
 
void SetBestBlock (const uint256 &hashBlock)
 
bool BatchWrite (CCoinsMap &mapCoins, const uint256 &hashBlock)
 Do a bulk modification (multiple CCoins changes + BestBlock change). More...
 
const CCoinsAccessCoins (const uint256 &txid) const
 Return a pointer to CCoins in the cache, or NULL if not found. More...
 
CCoinsModifier ModifyCoins (const uint256 &txid)
 Return a modifiable reference to a CCoins. More...
 
bool Flush ()
 Push the modifications applied to this cache to its base. More...
 
unsigned int GetCacheSize () const
 Calculate the size of the cache (in number of transactions) More...
 
size_t DynamicMemoryUsage () const
 Calculate the size of the cache (in bytes) More...
 
bool HaveInputs (const CTransaction &tx) const
 Check whether all prevouts of the transaction are present in the UTXO set represented by this view. More...
 
const CTxOutGetOutputFor (const CTxIn &input) const
 
- Public Member Functions inherited from CCoinsViewBacked
 CCoinsViewBacked (CCoinsView *viewIn)
 
void SetBackend (CCoinsView &viewIn)
 
bool GetStats (CCoinsStats &stats) const
 Calculate statistics about the unspent transaction output set. More...
 
- Public Member Functions inherited from CCoinsView
virtual ~CCoinsView ()
 As we use CCoinsViews polymorphically, have a virtual destructor. More...
 

Protected Attributes

bool hasModifier
 
uint256 hashBlock
 Make mutable so that we can "fill the cache" even from Get-methods declared as "const". More...
 
CCoinsMap cacheCoins
 
size_t cachedCoinsUsage
 
- Protected Attributes inherited from CCoinsViewBacked
CCoinsViewbase
 

Private Member Functions

CCoinsMap::iterator FetchCoins (const uint256 &txid)
 
CCoinsMap::const_iterator FetchCoins (const uint256 &txid) const
 

Friends

class CCoinsModifier
 

Detailed Description

CCoinsView that adds a memory cache for transactions to another CCoinsView.

Definition at line 414 of file coins.h.

Constructor & Destructor Documentation

◆ CCoinsViewCache()

CCoinsViewCache::CCoinsViewCache ( CCoinsView baseIn)

Definition at line 83 of file coins.cpp.

◆ ~CCoinsViewCache()

CCoinsViewCache::~CCoinsViewCache ( )

Definition at line 85 of file coins.cpp.

Member Function Documentation

◆ AccessCoins()

const CCoins * CCoinsViewCache::AccessCoins ( const uint256 txid) const

Return a pointer to CCoins in the cache, or NULL if not found.

This is more efficient than GetCoins. Modifications to other cache entries are allowed while accessing the returned pointer.

Definition at line 145 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BatchWrite()

bool CCoinsViewCache::BatchWrite ( CCoinsMap mapCoins,
const uint256 hashBlock 
)
virtual

Do a bulk modification (multiple CCoins changes + BestBlock change).

The passed mapCoins can be modified.

Reimplemented from CCoinsViewBacked.

Definition at line 177 of file coins.cpp.

Here is the call graph for this function:

◆ DynamicMemoryUsage()

size_t CCoinsViewCache::DynamicMemoryUsage ( ) const

Calculate the size of the cache (in bytes)

Definition at line 90 of file coins.cpp.

Here is the caller graph for this function:

◆ FetchCoins() [1/2]

CCoinsMap::iterator CCoinsViewCache::FetchCoins ( const uint256 txid)
private
Here is the caller graph for this function:

◆ FetchCoins() [2/2]

CCoinsMap::const_iterator CCoinsViewCache::FetchCoins ( const uint256 txid) const
private

Definition at line 94 of file coins.cpp.

Here is the call graph for this function:

◆ Flush()

bool CCoinsViewCache::Flush ( )

Push the modifications applied to this cache to its base.

Failure to call this method before destruction will cause the changes to be forgotten. If false is returned, the state of this cache (and its backing view) will be undefined.

Definition at line 223 of file coins.cpp.

Here is the call graph for this function:

◆ GetBestBlock()

uint256 CCoinsViewCache::GetBestBlock ( ) const
virtual

Retrieve the block hash whose state this CCoinsView currently represents.

Reimplemented from CCoinsViewBacked.

Definition at line 165 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCacheSize()

unsigned int CCoinsViewCache::GetCacheSize ( ) const

Calculate the size of the cache (in number of transactions)

Definition at line 231 of file coins.cpp.

◆ GetCoins()

bool CCoinsViewCache::GetCoins ( const uint256 txid,
CCoins coins 
) const
virtual

Retrieve the CCoins (unspent transaction outputs) for a given txid.

Reimplemented from CCoinsViewBacked.

Definition at line 113 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOutputFor()

const CTxOut & CCoinsViewCache::GetOutputFor ( const CTxIn input) const

Definition at line 236 of file coins.cpp.

Here is the call graph for this function:

◆ HaveCoins()

bool CCoinsViewCache::HaveCoins ( const uint256 txid) const
virtual

Just check whether we have data for a given txid.

This may (but cannot always) return true for fully spent transactions

Reimplemented from CCoinsViewBacked.

Definition at line 155 of file coins.cpp.

Here is the call graph for this function:

◆ HaveInputs()

bool CCoinsViewCache::HaveInputs ( const CTransaction tx) const

Check whether all prevouts of the transaction are present in the UTXO set represented by this view.

Definition at line 243 of file coins.cpp.

Here is the call graph for this function:

◆ ModifyCoins()

CCoinsModifier CCoinsViewCache::ModifyCoins ( const uint256 txid)

Return a modifiable reference to a CCoins.

If no entry with the given txid exists, a new one is created. Simultaneous modifications are not allowed.

Definition at line 123 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBestBlock()

void CCoinsViewCache::SetBestBlock ( const uint256 hashBlock)

Definition at line 172 of file coins.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ CCoinsModifier

friend class CCoinsModifier
friend

Definition at line 473 of file coins.h.

Member Data Documentation

◆ cacheCoins

CCoinsMap CCoinsViewCache::cacheCoins
mutableprotected

Definition at line 425 of file coins.h.

◆ cachedCoinsUsage

size_t CCoinsViewCache::cachedCoinsUsage
mutableprotected

Definition at line 428 of file coins.h.

◆ hashBlock

uint256 CCoinsViewCache::hashBlock
mutableprotected

Make mutable so that we can "fill the cache" even from Get-methods declared as "const".


Definition at line 424 of file coins.h.

◆ hasModifier

bool CCoinsViewCache::hasModifier
protected

Definition at line 418 of file coins.h.


The documentation for this class was generated from the following files: