Skip to content

Commit

Permalink
Renamed Magnitude type parameter to Value. Added is_zero function Val…
Browse files Browse the repository at this point in the history
…ueSum. Corrected comments.
  • Loading branch information
murisi committed Aug 7, 2023
1 parent 4862ae7 commit 2f18560
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 123 deletions.
14 changes: 8 additions & 6 deletions masp_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
sapling::{prover::TxProver, Diversifier, Node, Note, PaymentAddress},
transaction::{
components::{
amount::{BalanceError, FromNt, I128Sum, U64Sum, ValueSum, MAX_MONEY},
amount::{BalanceError, I128Sum, U64Sum, ValueSum, MAX_MONEY},
sapling::{
self,
builder::{SaplingBuilder, SaplingMetadata},
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<P: consensus::Parameters, R: RngCore> Builder<P, R> {
//

// After fees are accounted for, the value balance of the transaction must be zero.
let balance_after_fees = self.value_balance()? - I128Sum::from(FromNt(fee));
let balance_after_fees = self.value_balance()? - I128Sum::from_sum(fee);

if balance_after_fees != ValueSum::zero() {
return Err(Error::InsufficientFunds(-balance_after_fees));
Expand Down Expand Up @@ -479,7 +479,7 @@ mod tests {
merkle_tree::{CommitmentTree, IncrementalWitness},
sapling::Rseed,
transaction::{
components::amount::{FromNt, I128Sum, ValueSum, DEFAULT_FEE},
components::amount::{I128Sum, ValueSum, DEFAULT_FEE},
sapling::builder as build_s,
TransparentAddress,
},
Expand Down Expand Up @@ -580,7 +580,9 @@ mod tests {
let builder = Builder::new(TEST_NETWORK, tx_height);
assert_eq!(
builder.mock_build(),
Err(Error::InsufficientFunds(FromNt(DEFAULT_FEE.clone()).into()))
Err(Error::InsufficientFunds(I128Sum::from_sum(
DEFAULT_FEE.clone()
)))
);
}

Expand All @@ -599,7 +601,7 @@ mod tests {
builder.mock_build(),
Err(Error::InsufficientFunds(
I128Sum::from_pair(zec(), 50000).unwrap()
+ &I128Sum::from(FromNt(DEFAULT_FEE.clone()))
+ &I128Sum::from_sum(DEFAULT_FEE.clone())
))
);
}
Expand All @@ -615,7 +617,7 @@ mod tests {
builder.mock_build(),
Err(Error::InsufficientFunds(
I128Sum::from_pair(zec(), 50000).unwrap()
+ &I128Sum::from(FromNt(DEFAULT_FEE.clone()))
+ &I128Sum::from_sum(DEFAULT_FEE.clone())
))
);
}
Expand Down
3 changes: 1 addition & 2 deletions masp_primitives/src/transaction/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ pub mod sapling;
pub mod transparent;
pub use self::{
amount::{
FromNt, I128Sum, I16Sum, I32Sum, I64Sum, I8Sum, TryFromNt, U128Sum, U16Sum, U32Sum, U64Sum,
U8Sum, ValueSum,
I128Sum, I16Sum, I32Sum, I64Sum, I8Sum, U128Sum, U16Sum, U32Sum, U64Sum, U8Sum, ValueSum,
},
sapling::{ConvertDescription, OutputDescription, SpendDescription},
transparent::{TxIn, TxOut},
Expand Down
Loading

0 comments on commit 2f18560

Please sign in to comment.