Changeset View
Changeset View
Standalone View
Standalone View
src/consensus/tx_verify.cpp
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | for (size_t txinIndex = 0; txinIndex < tx.vin.size(); txinIndex++) { | ||||
// the calculated time or height. | // the calculated time or height. | ||||
// Time-based relative lock-times are measured from the smallest | // Time-based relative lock-times are measured from the smallest | ||||
// allowed timestamp of the block containing the txout being spent, | // allowed timestamp of the block containing the txout being spent, | ||||
// which is the median time past of the block prior. | // which is the median time past of the block prior. | ||||
nMinTime = std::max( | nMinTime = std::max( | ||||
nMinTime, | nMinTime, | ||||
nCoinTime + | nCoinTime + | ||||
(int64_t)((txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_MASK) | int64_t((txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_MASK) | ||||
<< CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) - | << CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) - | ||||
1); | 1); | ||||
} else { | } else { | ||||
nMinHeight = std::max( | nMinHeight = std::max( | ||||
nMinHeight, | nMinHeight, | ||||
nCoinHeight + | nCoinHeight + | ||||
(int)(txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_MASK) - 1); | int(txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_MASK) - 1); | ||||
} | } | ||||
} | } | ||||
return std::make_pair(nMinHeight, nMinTime); | return std::make_pair(nMinHeight, nMinTime); | ||||
} | } | ||||
bool EvaluateSequenceLocks(const CBlockIndex &block, | bool EvaluateSequenceLocks(const CBlockIndex &block, | ||||
std::pair<int, int64_t> lockPair) { | std::pair<int, int64_t> lockPair) { | ||||
Show All 25 Lines | bool CheckTxInputs(const CTransaction &tx, CValidationState &state, | ||||
Amount nValueIn = Amount::zero(); | Amount nValueIn = Amount::zero(); | ||||
for (const auto &in : tx.vin) { | for (const auto &in : tx.vin) { | ||||
const COutPoint &prevout = in.prevout; | const COutPoint &prevout = in.prevout; | ||||
const Coin &coin = inputs.AccessCoin(prevout); | const Coin &coin = inputs.AccessCoin(prevout); | ||||
assert(!coin.IsSpent()); | assert(!coin.IsSpent()); | ||||
// If prev is coinbase, check that it's matured | // If prev is coinbase, check that it's matured | ||||
if (coin.IsCoinBase()) { | if (coin.IsCoinBase() && | ||||
if (nSpendHeight - coin.GetHeight() < COINBASE_MATURITY) { | nSpendHeight - coin.GetHeight() < COINBASE_MATURITY) { | ||||
return state.Invalid( | return state.Invalid( | ||||
false, REJECT_INVALID, | false, REJECT_INVALID, "bad-txns-premature-spend-of-coinbase", | ||||
"bad-txns-premature-spend-of-coinbase", | |||||
strprintf("tried to spend coinbase at depth %d", | strprintf("tried to spend coinbase at depth %d", | ||||
nSpendHeight - coin.GetHeight())); | nSpendHeight - coin.GetHeight())); | ||||
} | } | ||||
} | |||||
// Check for negative or overflow input values | // Check for negative or overflow input values | ||||
nValueIn += coin.GetTxOut().nValue; | nValueIn += coin.GetTxOut().nValue; | ||||
if (!MoneyRange(coin.GetTxOut().nValue) || !MoneyRange(nValueIn)) { | if (!MoneyRange(coin.GetTxOut().nValue) || !MoneyRange(nValueIn)) { | ||||
return state.DoS(100, false, REJECT_INVALID, | return state.DoS(100, false, REJECT_INVALID, | ||||
"bad-txns-inputvalues-outofrange"); | "bad-txns-inputvalues-outofrange"); | ||||
} | } | ||||
} | } | ||||
Show All 19 Lines |