18 unsigned int nLastUsedByte = 0;
19 for (
unsigned int b = 0; 2+b*8 <
vout.size(); b++) {
21 for (
unsigned int i = 0; i < 8 && 2+b*8+i <
vout.size(); i++) {
22 if (!
vout[2+b*8+i].IsNull()) {
28 nLastUsedByte = b + 1;
32 nBytes += nLastUsedByte;
37 if (nPos >=
vout.size() ||
vout[nPos].IsNull())
73 CCoinsMap::iterator it =
cacheCoins.find(txid);
80 tmp.
swap(ret->second.coins);
81 if (ret->second.coins.IsPruned()) {
91 CCoinsMap::const_iterator it =
FetchCoins(txid);
93 coins = it->second.coins;
102 size_t cachedCoinUsage = 0;
106 ret.first->second.coins.Clear();
108 }
else if (ret.first->second.coins.IsPruned()) {
113 cachedCoinUsage = ret.first->second.coins.DynamicMemoryUsage();
139 if (!ret.first->second.coins.IsPruned())
140 throw std::logic_error(
"ModifyNewCoins should not find pre-existing coins on a non-coinbase unless they are pruned!");
150 ret.first->second.coins.Clear();
156 CCoinsMap::const_iterator it =
FetchCoins(txid);
160 return &it->second.coins;
165 CCoinsMap::const_iterator it =
FetchCoins(txid);
170 return (it !=
cacheCoins.end() && !it->second.coins.vout.empty());
174 CCoinsMap::const_iterator it =
cacheCoins.find(txid);
190 for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
192 CCoinsMap::iterator itUs =
cacheCoins.find(it->first);
215 throw std::logic_error(
"FRESH flag misapplied to cache entry for base transaction with spendable outputs");
227 itUs->second.coins.swap(it->second.coins);
238 CCoinsMap::iterator itOld = it++;
239 mapCoins.erase(itOld);
254 CCoinsMap::iterator it =
cacheCoins.find(hash);
255 if (it !=
cacheCoins.end() && it->second.flags == 0) {
278 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
287 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
300 inChainInputValue = 0;
303 double dResult = 0.0;
304 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
309 if (coins->
nHeight <= nHeight) {
311 inChainInputValue += coins->
vout[txin.
prevout.
n].nValue;
326 it->second.coins.Cleanup();
int64_t CAmount
Amount in satoshis (Can be negative)
Pruned version of CTransaction: only retains metadata and unspent transaction outputs.
bool Spend(uint32_t nPos)
mark a vout spent
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
void Cleanup()
remove spent outputs at the end of vout
void CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const
calculate number of bytes for the bitmask, and its number of non-zero bytes each bit in the bitmask r...
size_t DynamicMemoryUsage() const
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
int nHeight
at which height this transaction was included in the active block chain
A reference to a mutable cache entry.
CCoinsModifier(CCoinsViewCache &cache_, CCoinsMap::iterator it_, size_t usage)
CCoinsView backed by another CCoinsView.
CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
void SetBackend(CCoinsView &viewIn)
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple CCoins changes + BestBlock change).
bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
CCoinsViewBacked(CCoinsView *viewIn)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
CAmount GetValueIn(const CTransaction &tx) const
Amount of bitcoins coming in to a transaction Note that lightweight clients may not know anything bes...
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
CCoinsViewCache(CCoinsView *baseIn)
const CTxOut & GetOutputFor(const CTxIn &input) const
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple CCoins changes + BestBlock change).
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
bool HaveCoinsInCache(const uint256 &txid) const
Check if we have the given tx already loaded in this cache.
const CCoins * AccessCoins(const uint256 &txid) const
Return a pointer to CCoins in the cache, or NULL if not found.
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transactions)
CCoinsMap::const_iterator FetchCoins(const uint256 &txid) const
double GetPriority(const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const
Return priority of tx at height nHeight.
void SetBestBlock(const uint256 &hashBlock)
bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
void Uncache(const uint256 &txid)
Removes the transaction with the given hash from the cache, if it is not modified.
CCoinsModifier ModifyCoins(const uint256 &txid)
Return a modifiable reference to a CCoins.
bool Flush()
Push the modifications applied to this cache to its base.
CCoinsModifier ModifyNewCoins(const uint256 &txid, bool coinbase)
Return a modifiable reference to a CCoins.
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
friend class CCoinsModifier
Cursor for iterating over CoinsView state.
virtual ~CCoinsViewCursor()
Abstract view on the open txout dataset.
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
virtual bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple CCoins changes + BestBlock change).
virtual bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
An outpoint - a combination of a transaction hash and an index n into its vout.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxIn > vin
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const
An input of a transaction.
An output of a transaction.
boost::unordered_map< uint256, CCoinsCacheEntry, SaltedTxidHasher > CCoinsMap
uint64_t GetRand(uint64_t nMax)