Changeset View
Changeset View
Standalone View
Standalone View
src/coins.cpp
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin coin, | ||||
it->second.flags |= | it->second.flags |= | ||||
CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0); | CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0); | ||||
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage(); | cachedCoinsUsage += it->second.coin.DynamicMemoryUsage(); | ||||
} | } | ||||
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, | void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, | ||||
bool check) { | bool check) { | ||||
bool fCoinbase = tx.IsCoinBase(); | bool fCoinbase = tx.IsCoinBase(); | ||||
const uint256 &txid = tx.GetHash(); | const TxId txid = tx.GetId(); | ||||
for (size_t i = 0; i < tx.vout.size(); ++i) { | for (size_t i = 0; i < tx.vout.size(); ++i) { | ||||
bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase; | const COutPoint outpoint(txid, i); | ||||
bool overwrite = check ? cache.HaveCoin(outpoint) : fCoinbase; | |||||
// Always set the possible_overwrite flag to AddCoin for coinbase txn, | // Always set the possible_overwrite flag to AddCoin for coinbase txn, | ||||
// in order to correctly deal with the pre-BIP30 occurrences of | // in order to correctly deal with the pre-BIP30 occurrences of | ||||
// duplicate coinbase transactions. | // duplicate coinbase transactions. | ||||
cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), | cache.AddCoin(outpoint, Coin(tx.vout[i], nHeight, fCoinbase), | ||||
overwrite); | overwrite); | ||||
} | } | ||||
} | } | ||||
bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin *moveout) { | bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin *moveout) { | ||||
CCoinsMap::iterator it = FetchCoin(outpoint); | CCoinsMap::iterator it = FetchCoin(outpoint); | ||||
if (it == cacheCoins.end()) { | if (it == cacheCoins.end()) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight, | ||||
} | } | ||||
return tx.ComputePriority(dResult); | return tx.ComputePriority(dResult); | ||||
} | } | ||||
// TODO: merge with similar definition in undo.h. | // TODO: merge with similar definition in undo.h. | ||||
static const size_t MAX_OUTPUTS_PER_TX = | static const size_t MAX_OUTPUTS_PER_TX = | ||||
MAX_TX_SIZE / ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION); | MAX_TX_SIZE / ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION); | ||||
const Coin &AccessByTxid(const CCoinsViewCache &view, const uint256 &txid) { | const Coin &AccessByTxid(const CCoinsViewCache &view, const TxId &txid) { | ||||
for (uint32_t n = 0; n < MAX_OUTPUTS_PER_TX; n++) { | for (uint32_t n = 0; n < MAX_OUTPUTS_PER_TX; n++) { | ||||
const Coin &alternate = view.AccessCoin(COutPoint(txid, n)); | const Coin &alternate = view.AccessCoin(COutPoint(txid, n)); | ||||
if (!alternate.IsSpent()) { | if (!alternate.IsSpent()) { | ||||
return alternate; | return alternate; | ||||
} | } | ||||
} | } | ||||
return coinEmpty; | return coinEmpty; | ||||
} | } |