Changeset View
Changeset View
Standalone View
Standalone View
src/coins.cpp
Show First 20 Lines • Show All 292 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 CCoinsViewCache::GetChainValidTxInputValue(const CTransaction &tx, | ||||
Amount &inChainInputValue) const { | int nHeight) const { | ||||
inChainInputValue = Amount(0); | |||||
if (tx.IsCoinBase()) { | if (tx.IsCoinBase()) { | ||||
return 0.0; | return Amount(0); | ||||
} | } | ||||
double dResult = 0.0; | |||||
Amount inChainInputValue(0); | |||||
for (const CTxIn &txin : tx.vin) { | for (const CTxIn &txin : tx.vin) { | ||||
const Coin &coin = AccessCoin(txin.prevout); | const Coin &coin = AccessCoin(txin.prevout); | ||||
if (coin.IsSpent()) { | if (coin.IsSpent() || int64_t(coin.GetHeight()) > nHeight) { | ||||
continue; | continue; | ||||
} | } | ||||
if (int64_t(coin.GetHeight()) <= nHeight) { | |||||
dResult += double(coin.GetTxOut().nValue.GetSatoshis()) * | |||||
(nHeight - coin.GetHeight()); | |||||
inChainInputValue += coin.GetTxOut().nValue; | inChainInputValue += coin.GetTxOut().nValue; | ||||
} | } | ||||
return inChainInputValue; | |||||
} | |||||
double CCoinsViewCache::GetCoinBlocksDestroyed(const CTransaction &tx, | |||||
schancel: Regarding the previous comment, a refactor to put this on CTransaction, where it makes sense… | |||||
jasonbcoxUnsubmitted Not Done Inline ActionsIt seems like this function should return uint64_t and the cast-to-double done in ComputePriority instead. Returning double here implies that fractional blocks can be destroyed. jasonbcox: It seems like this function should return uint64_t and the cast-to-double done in… | |||||
int nHeight) const { | |||||
if (tx.IsCoinBase()) { | |||||
return 0.0; | |||||
} | } | ||||
return tx.ComputePriority(dResult); | |||||
double coinBlocksDestroyed = 0.0; | |||||
for (const CTxIn &txin : tx.vin) { | |||||
const Coin &coin = AccessCoin(txin.prevout); | |||||
if (coin.IsSpent() || int64_t(coin.GetHeight()) > nHeight) { | |||||
continue; | |||||
} | |||||
coinBlocksDestroyed += double(coin.GetTxOut().nValue.GetSatoshis()) * | |||||
(nHeight - coin.GetHeight()); | |||||
} | |||||
return coinBlocksDestroyed; | |||||
} | } | ||||
// 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 uint256 &txid) { | ||||
COutPoint iter(txid, 0); | COutPoint iter(txid, 0); | ||||
Show All 10 Lines |
Regarding the previous comment, a refactor to put this on CTransaction, where it makes sense, is pretty large.