Changeset View
Changeset View
Standalone View
Standalone View
src/coins.cpp
Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin coin, | ||||
it->second.coin = std::move(coin); | it->second.coin = std::move(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 fCoinbase = tx.IsCoinBase(); | bool fCoinbase = tx.IsCoinBase(); | ||||
const uint256 &txid = tx.GetHash(); | const unspentid_t &unspentid = tx.GetUnspentid(); | ||||
for (size_t i = 0; i < tx.vout.size(); ++i) { | for (size_t i = 0; i < tx.vout.size(); ++i) { | ||||
// Pass fCoinbase as the possible_overwrite flag to AddCoin, in order to | // Pass fCoinbase as the possible_overwrite flag to AddCoin, in order to | ||||
// correctly deal with the pre-BIP30 occurrances of duplicate coinbase | // correctly deal with the pre-BIP30 occurrances of duplicate coinbase | ||||
// transactions. | // transactions. | ||||
cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), | cache.AddCoin(COutPoint(unspentid, i), | ||||
fCoinbase); | Coin(tx.vout[i], nHeight, fCoinbase), fCoinbase); | ||||
} | } | ||||
} | } | ||||
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 171 Lines • ▼ Show 20 Lines | for (const CTxIn &txin : tx.vin) { | ||||
if (int64_t(coin.GetHeight()) <= nHeight) { | if (int64_t(coin.GetHeight()) <= nHeight) { | ||||
dResult += double(coin.GetTxOut().nValue.GetSatoshis()) * | dResult += double(coin.GetTxOut().nValue.GetSatoshis()) * | ||||
(nHeight - coin.GetHeight()); | (nHeight - coin.GetHeight()); | ||||
inChainInputValue += coin.GetTxOut().nValue; | inChainInputValue += coin.GetTxOut().nValue; | ||||
} | } | ||||
} | } | ||||
return tx.ComputePriority(dResult); | return tx.ComputePriority(dResult); | ||||
} | } | ||||
// TODO: merge with similar definition in undo.h. | |||||
static const size_t MAX_OUTPUTS_PER_TX = | |||||
MAX_TX_SIZE / ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION); | |||||
const Coin &AccessByTxid(const CCoinsViewCache &view, const uint256 &txid) { | |||||
COutPoint iter(txid, 0); | |||||
while (iter.n < MAX_OUTPUTS_PER_TX) { | |||||
const Coin &alternate = view.AccessCoin(iter); | |||||
if (!alternate.IsSpent()) { | |||||
return alternate; | |||||
} | |||||
++iter.n; | |||||
} | |||||
return coinEmpty; | |||||
} |