Add valueBalance to value balances, and enforce its consensus rules
This commit is contained in:
@@ -256,9 +256,18 @@ CAmount CTransaction::GetValueOut() const
|
||||
throw std::runtime_error("CTransaction::GetValueOut(): value out of range");
|
||||
}
|
||||
|
||||
if (valueBalance <= 0) {
|
||||
// NB: negative valueBalance "takes" money from the transparent value pool just as outputs do
|
||||
nValueOut += -valueBalance;
|
||||
|
||||
if (!MoneyRange(-valueBalance) || !MoneyRange(nValueOut)) {
|
||||
throw std::runtime_error("CTransaction::GetValueOut(): value out of range");
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<JSDescription>::const_iterator it(vjoinsplit.begin()); it != vjoinsplit.end(); ++it)
|
||||
{
|
||||
// NB: vpub_old "takes" money from the value pool just as outputs do
|
||||
// NB: vpub_old "takes" money from the transparent value pool just as outputs do
|
||||
nValueOut += it->vpub_old;
|
||||
|
||||
if (!MoneyRange(it->vpub_old) || !MoneyRange(nValueOut))
|
||||
@@ -267,16 +276,26 @@ CAmount CTransaction::GetValueOut() const
|
||||
return nValueOut;
|
||||
}
|
||||
|
||||
CAmount CTransaction::GetJoinSplitValueIn() const
|
||||
CAmount CTransaction::GetShieldedValueIn() const
|
||||
{
|
||||
CAmount nValue = 0;
|
||||
|
||||
if (valueBalance >= 0) {
|
||||
// NB: positive valueBalance "gives" money to the transparent value pool just as inputs do
|
||||
nValue += valueBalance;
|
||||
|
||||
if (!MoneyRange(valueBalance) || !MoneyRange(nValue)) {
|
||||
throw std::runtime_error("CTransaction::GetShieldedValueIn(): value out of range");
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<JSDescription>::const_iterator it(vjoinsplit.begin()); it != vjoinsplit.end(); ++it)
|
||||
{
|
||||
// NB: vpub_new "gives" money to the value pool just as inputs do
|
||||
// NB: vpub_new "gives" money to the transparent value pool just as inputs do
|
||||
nValue += it->vpub_new;
|
||||
|
||||
if (!MoneyRange(it->vpub_new) || !MoneyRange(nValue))
|
||||
throw std::runtime_error("CTransaction::GetJoinSplitValueIn(): value out of range");
|
||||
throw std::runtime_error("CTransaction::GetShieldedValueIn(): value out of range");
|
||||
}
|
||||
|
||||
return nValue;
|
||||
|
||||
@@ -651,13 +651,13 @@ public:
|
||||
return header;
|
||||
}
|
||||
|
||||
// Return sum of txouts.
|
||||
// Return sum of txouts, (negative valueBalance or zero) and JoinSplit vpub_old.
|
||||
CAmount GetValueOut() const;
|
||||
// GetValueIn() is a method on CCoinsViewCache, because
|
||||
// inputs must be known to compute value in.
|
||||
|
||||
// Return sum of JoinSplit vpub_new
|
||||
CAmount GetJoinSplitValueIn() const;
|
||||
// Return sum of (positive valueBalance or zero) and JoinSplit vpub_new
|
||||
CAmount GetShieldedValueIn() const;
|
||||
|
||||
// Compute priority, given priority of inputs and (optionally) tx size
|
||||
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const;
|
||||
|
||||
Reference in New Issue
Block a user