Added value balance consensus enforcement for pours.
This commit is contained in:
parent
45d6bee945
commit
f512cf7c7b
|
@ -382,6 +382,8 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
|
|||
for (unsigned int i = 0; i < tx.vin.size(); i++)
|
||||
nResult += GetOutputFor(tx.vin[i]).nValue;
|
||||
|
||||
nResult += tx.GetPourValueIn();
|
||||
|
||||
return nResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -1533,6 +1533,11 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
|
|||
|
||||
}
|
||||
|
||||
nValueIn += tx.GetPourValueIn();
|
||||
if (!MoneyRange(nValueIn))
|
||||
return state.DoS(100, error("CheckInputs(): vpub_old values out of range"),
|
||||
REJECT_INVALID, "bad-txns-inputvalues-outofrange");
|
||||
|
||||
if (nValueIn < tx.GetValueOut())
|
||||
return state.DoS(100, error("CheckInputs(): %s value in (%s) < value out (%s)",
|
||||
tx.GetHash().ToString(), FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())),
|
||||
|
|
|
@ -178,9 +178,33 @@ CAmount CTransaction::GetValueOut() const
|
|||
if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
|
||||
throw std::runtime_error("CTransaction::GetValueOut(): value out of range");
|
||||
}
|
||||
|
||||
for (std::vector<CPourTx>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
|
||||
{
|
||||
// NB: vpub_old "takes" money from the value pool just as outputs do
|
||||
nValueOut += it->vpub_old;
|
||||
|
||||
if (!MoneyRange(it->vpub_old) || !MoneyRange(nValueOut))
|
||||
throw std::runtime_error("CTransaction::GetValueOut(): value out of range");
|
||||
}
|
||||
return nValueOut;
|
||||
}
|
||||
|
||||
CAmount CTransaction::GetPourValueIn() const
|
||||
{
|
||||
CAmount nValue = 0;
|
||||
for (std::vector<CPourTx>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
|
||||
{
|
||||
// NB: vpub_old "gives" money to the value pool just as inputs do
|
||||
nValue += it->vpub_new;
|
||||
|
||||
if (!MoneyRange(it->vpub_new) || !MoneyRange(nValue))
|
||||
throw std::runtime_error("CTransaction::GetPourValueIn(): value out of range");
|
||||
}
|
||||
|
||||
return nValue;
|
||||
}
|
||||
|
||||
double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const
|
||||
{
|
||||
nTxSize = CalculateModifiedSize(nTxSize);
|
||||
|
|
|
@ -346,6 +346,9 @@ public:
|
|||
// GetValueIn() is a method on CCoinsViewCache, because
|
||||
// inputs must be known to compute value in.
|
||||
|
||||
// Return sum of pour vpub_new
|
||||
CAmount GetPourValueIn() const;
|
||||
|
||||
// Compute priority, given priority of inputs and (optionally) tx size
|
||||
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue