Proper indentation for CheckTxInputs and other minor fixes
This commit is contained in:
parent
234ffc677e
commit
3f0ee3e501
1 changed files with 37 additions and 35 deletions
|
@ -207,44 +207,46 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
|
||||||
|
|
||||||
bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
|
bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
|
||||||
{
|
{
|
||||||
// This doesn't trigger the DoS code on purpose; if it did, it would make it easier
|
// This doesn't trigger the DoS code on purpose; if it did, it would make it easier
|
||||||
// for an attacker to attempt to split the network.
|
// for an attacker to attempt to split the network.
|
||||||
if (!inputs.HaveInputs(tx))
|
if (!inputs.HaveInputs(tx)) {
|
||||||
return state.Invalid(false, 0, "", "Inputs unavailable");
|
return state.Invalid(false, 0, "", "Inputs unavailable");
|
||||||
|
}
|
||||||
|
|
||||||
CAmount nValueIn = 0;
|
CAmount nValueIn = 0;
|
||||||
CAmount nFees = 0;
|
CAmount nFees = 0;
|
||||||
for (unsigned int i = 0; i < tx.vin.size(); i++)
|
for (unsigned int i = 0; i < tx.vin.size(); ++i) {
|
||||||
{
|
const COutPoint &prevout = tx.vin[i].prevout;
|
||||||
const COutPoint &prevout = tx.vin[i].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 (coin.IsCoinBase()) {
|
|
||||||
if (nSpendHeight - coin.nHeight < COINBASE_MATURITY)
|
|
||||||
return state.Invalid(false,
|
|
||||||
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
|
|
||||||
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for negative or overflow input values
|
|
||||||
nValueIn += coin.out.nValue;
|
|
||||||
if (!MoneyRange(coin.out.nValue) || !MoneyRange(nValueIn))
|
|
||||||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputvalues-outofrange");
|
|
||||||
|
|
||||||
|
// If prev is coinbase, check that it's matured
|
||||||
|
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < COINBASE_MATURITY) {
|
||||||
|
return state.Invalid(false,
|
||||||
|
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
|
||||||
|
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nValueIn < tx.GetValueOut())
|
// Check for negative or overflow input values
|
||||||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-belowout", false,
|
nValueIn += coin.out.nValue;
|
||||||
strprintf("value in (%s) < value out (%s)", FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())));
|
if (!MoneyRange(coin.out.nValue) || !MoneyRange(nValueIn)) {
|
||||||
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputvalues-outofrange");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tally transaction fees
|
if (nValueIn < tx.GetValueOut()) {
|
||||||
CAmount nTxFee = nValueIn - tx.GetValueOut();
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-belowout", false,
|
||||||
if (nTxFee < 0)
|
strprintf("value in (%s) < value out (%s)", FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())));
|
||||||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-negative");
|
}
|
||||||
nFees += nTxFee;
|
|
||||||
if (!MoneyRange(nFees))
|
// Tally transaction fees
|
||||||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-outofrange");
|
CAmount nTxFee = nValueIn - tx.GetValueOut();
|
||||||
|
if (nTxFee < 0) {
|
||||||
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-negative");
|
||||||
|
}
|
||||||
|
nFees += nTxFee;
|
||||||
|
if (!MoneyRange(nFees)) {
|
||||||
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-outofrange");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue