Use the same value balance sign for transparent and shielded outputs (#2569)
* change signs * make impl of Neg generic * change implementation of Neg for Amount Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
parent
8f4c3b09ea
commit
751185d4ec
|
@ -326,12 +326,14 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Neg for Amount<NegativeAllowed> {
|
impl<C> std::ops::Neg for Amount<C>
|
||||||
type Output = Self;
|
where
|
||||||
|
C: Constraint,
|
||||||
|
{
|
||||||
|
type Output = Amount<NegativeAllowed>;
|
||||||
fn neg(self) -> Self::Output {
|
fn neg(self) -> Self::Output {
|
||||||
Amount::try_from(-self.0)
|
Amount::<NegativeAllowed>::try_from(-self.0)
|
||||||
.expect("a change in sign to any value inside Amount<NegativeAllowed> is always valid")
|
.expect("a negation of any Amount into NegativeAllowed is always valid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -743,7 +743,7 @@ impl Transaction {
|
||||||
.sum::<Result<Amount, AmountError>>()?;
|
.sum::<Result<Amount, AmountError>>()?;
|
||||||
|
|
||||||
Ok(ValueBalance::from_transparent_amount(
|
Ok(ValueBalance::from_transparent_amount(
|
||||||
(input_value_balance - output_value_balance)?,
|
(output_value_balance - input_value_balance)?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,11 @@ where
|
||||||
///
|
///
|
||||||
/// [Consensus rule]: https://zips.z.cash/protocol/protocol.pdf#transactions
|
/// [Consensus rule]: https://zips.z.cash/protocol/protocol.pdf#transactions
|
||||||
pub fn remaining_transaction_value(&self) -> Result<Amount<NonNegative>, Error> {
|
pub fn remaining_transaction_value(&self) -> Result<Amount<NonNegative>, Error> {
|
||||||
// This rule checks the transparent value balance minus the sum of the sprout,
|
// Calculated in Zebra by negating the sum of the transparent, sprout,
|
||||||
// sapling, and orchard value balances in a transaction is nonnegative.
|
// sapling, and orchard value balances as specified in
|
||||||
(self.transparent - (self.sprout + self.sapling + self.orchard)?)?
|
// https://zebra.zfnd.org/dev/rfcs/0012-value-pools.html#definitions
|
||||||
.constrain::<NonNegative>()
|
let value = (self.transparent + self.sprout + self.sapling + self.orchard)?;
|
||||||
|
(-(value)).constrain::<NonNegative>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a [`ValueBalance`] from the given transparent amount.
|
/// Creates a [`ValueBalance`] from the given transparent amount.
|
||||||
|
|
Loading…
Reference in New Issue