![]() |
Dash Core
0.12.2.1
P2P Digital Currency
|
#include <coins.h>
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 |
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) |
bool | HaveCoinsInCache (const uint256 &txid) const |
const CCoins * | AccessCoins (const uint256 &txid) const |
CCoinsModifier | ModifyCoins (const uint256 &txid) |
CCoinsModifier | ModifyNewCoins (const uint256 &txid) |
bool | Flush () |
void | Uncache (const uint256 &txid) |
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... | |
CAmount | GetValueIn (const CTransaction &tx) const |
bool | HaveInputs (const CTransaction &tx) const |
Check whether all prevouts of the transaction are present in the UTXO set represented by this view. More... | |
double | GetPriority (const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const |
const CTxOut & | GetOutputFor (const CTxIn &input) const |
![]() | |
CCoinsViewBacked (CCoinsView *viewIn) | |
void | SetBackend (CCoinsView &viewIn) |
bool | GetStats (CCoinsStats &stats) const |
Calculate statistics about the unspent transaction output set. More... | |
![]() | |
virtual | ~CCoinsView () |
As we use CCoinsViews polymorphically, have a virtual destructor. More... | |
Protected Attributes | |
bool | hasModifier |
uint256 | hashBlock |
CCoinsMap | cacheCoins |
size_t | cachedCoinsUsage |
![]() | |
CCoinsView * | base |
Private Member Functions | |
CCoinsMap::iterator | FetchCoins (const uint256 &txid) |
CCoinsMap::const_iterator | FetchCoins (const uint256 &txid) const |
CCoinsViewCache (const CCoinsViewCache &) | |
Friends | |
class | CCoinsModifier |
CCoinsView that adds a memory cache for transactions to another CCoinsView
CCoinsViewCache::CCoinsViewCache | ( | CCoinsView * | baseIn | ) |
|
private |
By making the copy constructor private, we prevent accidentally using it when one intends to create a cache on top of a base cache.
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 129 of file coins.cpp.
Referenced by AcceptToMemoryPoolWorker(), CTxMemPool::check(), CheckInputs(), Consensus::CheckTxInputs(), ConnectBlock(), GetOutputFor(), GetPriority(), GetTransaction(), HaveInputs(), MutateTxSign(), CTxMemPool::removeForReorg(), sendrawtransaction(), and signrawtransaction().
Do a bulk modification (multiple CCoins changes + BestBlock change). The passed mapCoins can be modified.
Reimplemented from CCoinsViewBacked.
size_t CCoinsViewCache::DynamicMemoryUsage | ( | ) | const |
Calculate the size of the cache (in bytes)
Definition at line 68 of file coins.cpp.
Referenced by FlushStateToDisk(), UpdateTip(), and CVerifyDB::VerifyDB().
|
private |
Referenced by AccessCoins(), GetCoins(), and HaveCoins().
|
private |
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 207 of file coins.cpp.
Referenced by ConnectTip(), DisconnectTip(), and FlushStateToDisk().
|
virtual |
Retrieve the block hash whose state this CCoinsView currently represents.
Reimplemented from CCoinsViewBacked.
Definition at line 152 of file coins.cpp.
Referenced by AcceptToMemoryPoolWorker(), ConnectBlock(), DisconnectBlock(), GetSpendHeight(), gettxout(), and LoadBlockIndexDB().
unsigned int CCoinsViewCache::GetCacheSize | ( | ) | const |
Calculate the size of the cache (in number of transactions)
Definition at line 223 of file coins.cpp.
Referenced by FlushStateToDisk(), and UpdateTip().
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Reimplemented from CCoinsViewBacked.
Definition at line 90 of file coins.cpp.
Referenced by gettxout(), gettxoutproof(), GetUTXOCoins(), rest_getutxos(), and TransactionDesc::toHTML().
Definition at line 227 of file coins.cpp.
Referenced by CTxMemPool::addAddressIndex(), CTxMemPool::addSpentIndex(), AreInputsStandard(), ConnectBlock(), DisconnectBlock(), GetP2SHSigOpCount(), and GetValueIn().
double CCoinsViewCache::GetPriority | ( | const CTransaction & | tx, |
int | nHeight, | ||
CAmount & | inChainInputValue | ||
) | const |
Return priority of tx at height nHeight. Also calculate the sum of the values of the inputs that are already in the chain. These are the inputs that will age and increase priority as new blocks are added to the chain.
Definition at line 260 of file coins.cpp.
Referenced by AcceptToMemoryPoolWorker().
CAmount CCoinsViewCache::GetValueIn | ( | const CTransaction & | tx | ) | const |
Amount of dash coming in to a transaction Note that lightweight clients may not know anything besides the hash of previous transactions, so may not be able to calculate this.
[in] | tx | transaction for which we are checking input total |
Definition at line 234 of file coins.cpp.
Referenced by AcceptToMemoryPoolWorker(), and ConnectBlock().
|
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 138 of file coins.cpp.
Referenced by AcceptToMemoryPoolWorker(), and AlreadyHave().
bool CCoinsViewCache::HaveCoinsInCache | ( | const uint256 & | txid | ) | const |
Check if we have the given tx already loaded in this cache. The semantics are the same as HaveCoins(), but no calls to the backing CCoinsView are made.
Definition at line 147 of file coins.cpp.
Referenced by AcceptToMemoryPoolWorker().
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 246 of file coins.cpp.
Referenced by AcceptToMemoryPoolWorker(), CTxMemPool::check(), Consensus::CheckTxInputs(), and ConnectBlock().
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 99 of file coins.cpp.
Referenced by ApplyTxInUndo(), DisconnectBlock(), MutateTxSign(), signrawtransaction(), and UpdateCoins().
CCoinsModifier CCoinsViewCache::ModifyNewCoins | ( | const uint256 & | txid | ) |
Return a modifiable reference to a CCoins. Assumes that no entry with the given txid exists and creates a new one. This saves a database access in the case where the coins were to be wiped out by FromTx anyway. This should not be called with the 2 historical coinbase duplicate pairs because the new coins are marked fresh, and in the event the duplicate coinbase was spent before a flush, the now pruned coins would not properly overwrite the first coinbase of the pair. Simultaneous modifications are not allowed.
Definition at line 120 of file coins.cpp.
Referenced by UpdateCoins().
void CCoinsViewCache::SetBestBlock | ( | const uint256 & | hashBlock | ) |
Definition at line 158 of file coins.cpp.
Referenced by ConnectBlock(), and DisconnectBlock().
void CCoinsViewCache::Uncache | ( | const uint256 & | txid | ) |
Removes the transaction with the given hash from the cache, if it is not modified.
Definition at line 214 of file coins.cpp.
Referenced by AcceptToMemoryPool(), and LimitMempoolSize().
|
friend |
Definition at line 481 of file coins.h.
Referenced by ModifyCoins(), and ModifyNewCoins().
|
mutableprotected |
Definition at line 392 of file coins.h.
Referenced by AccessCoins(), BatchWrite(), DynamicMemoryUsage(), FetchCoins(), Flush(), GetCacheSize(), GetCoins(), HaveCoins(), HaveCoinsInCache(), ModifyCoins(), ModifyNewCoins(), Uncache(), and CCoinsModifier::~CCoinsModifier().
|
mutableprotected |
Definition at line 395 of file coins.h.
Referenced by BatchWrite(), DynamicMemoryUsage(), FetchCoins(), Flush(), Uncache(), and CCoinsModifier::~CCoinsModifier().
|
mutableprotected |
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
Definition at line 391 of file coins.h.
Referenced by BatchWrite(), Flush(), GetBestBlock(), and SetBestBlock().
|
protected |
Definition at line 384 of file coins.h.
Referenced by BatchWrite(), CCoinsModifier::CCoinsModifier(), ModifyCoins(), ModifyNewCoins(), CCoinsModifier::~CCoinsModifier(), and ~CCoinsViewCache().