Changeset View
Changeset View
Standalone View
Standalone View
src/coins.cpp
Show First 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < tx.vin.size(); i++) { | ||||
if (!HaveCoin(tx.vin[i].prevout)) { | if (!HaveCoin(tx.vin[i].prevout)) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight, | |||||
Amount &inChainInputValue) const { | |||||
inChainInputValue = Amount::zero(); | |||||
if (tx.IsCoinBase()) { | |||||
return 0.0; | |||||
} | |||||
double dResult = 0.0; | |||||
for (const CTxIn &txin : tx.vin) { | |||||
const Coin &coin = AccessCoin(txin.prevout); | |||||
if (coin.IsSpent()) { | |||||
continue; | |||||
} | |||||
if (int64_t(coin.GetHeight()) <= nHeight) { | |||||
dResult += double(coin.GetTxOut().nValue / SATOSHI) * | |||||
(nHeight - coin.GetHeight()); | |||||
inChainInputValue += coin.GetTxOut().nValue; | |||||
} | |||||
} | |||||
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(), PROTOCOL_VERSION); | MAX_TX_SIZE / ::GetSerializeSize(CTxOut(), PROTOCOL_VERSION); | ||||
const Coin &AccessByTxid(const CCoinsViewCache &view, const TxId &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; | ||||
} | } |