Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
This commit is contained in:
parent
167bcd86ce
commit
a93c9d334e
|
@ -25,9 +25,7 @@ impl Bundle {
|
||||||
pub fn value_balance(&self) -> Option<Amount> {
|
pub fn value_balance(&self) -> Option<Amount> {
|
||||||
self.joinsplits
|
self.joinsplits
|
||||||
.iter()
|
.iter()
|
||||||
.try_fold(Amount::zero(), |total, js| {
|
.try_fold(Amount::zero(), |total, js| total + js.net_value())
|
||||||
js.value_balance().and_then(|b| total + b)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,11 +185,11 @@ impl JsDescription {
|
||||||
writer.write_all(&self.ciphertexts[1])
|
writer.write_all(&self.ciphertexts[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The value balance for the JoinSplit. When this is positive,
|
/// The net value for the JoinSplit. When this is positive,
|
||||||
/// its value is added to the transparent value pool; when it
|
/// its value is added to the transparent value pool; when it
|
||||||
/// is negative, its value is subtracted from the transparent
|
/// is negative, its value is subtracted from the transparent
|
||||||
/// value pool.
|
/// value pool.
|
||||||
pub fn value_balance(&self) -> Option<Amount> {
|
pub fn net_value(&self) -> Amount {
|
||||||
self.vpub_new - self.vpub_old
|
(self.vpub_new - self.vpub_old).expect("difference is in range [-MAX_MONEY..=MAX_MONEY]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,12 +68,10 @@ impl<A: Authorization> Bundle<A> {
|
||||||
/// transferred out of the transparent pool into shielded pools or to fees; a negative value
|
/// transferred out of the transparent pool into shielded pools or to fees; a negative value
|
||||||
/// means that the containing transaction has funds being transferred into the transparent pool
|
/// means that the containing transaction has funds being transferred into the transparent pool
|
||||||
/// from the shielded pools.
|
/// from the shielded pools.
|
||||||
pub fn value_balance<E, F: FnMut(&OutPoint) -> Result<Amount, E>>(
|
pub fn value_balance<E, F>(&self, mut get_prevout_value: F) -> Result<Amount, E>
|
||||||
&self,
|
|
||||||
mut get_prevout_value: F,
|
|
||||||
) -> Result<Amount, E>
|
|
||||||
where
|
where
|
||||||
E: From<BalanceError>,
|
E: From<BalanceError>,
|
||||||
|
F: FnMut(&OutPoint) -> Result<Amount, E>,
|
||||||
{
|
{
|
||||||
let input_sum = self.vin.iter().try_fold(Amount::zero(), |total, txin| {
|
let input_sum = self.vin.iter().try_fold(Amount::zero(), |total, txin| {
|
||||||
get_prevout_value(&txin.prevout)
|
get_prevout_value(&txin.prevout)
|
||||||
|
|
|
@ -420,7 +420,8 @@ impl<A: Authorization> TransactionData<A> {
|
||||||
.map_or_else(Amount::zero, |b| *b.value_balance()),
|
.map_or_else(Amount::zero, |b| *b.value_balance()),
|
||||||
];
|
];
|
||||||
|
|
||||||
IntoIterator::into_iter(&value_balances)
|
value_balances
|
||||||
|
.iter()
|
||||||
.sum::<Option<_>>()
|
.sum::<Option<_>>()
|
||||||
.ok_or_else(|| BalanceError::Overflow.into())
|
.ok_or_else(|| BalanceError::Overflow.into())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue