add value_balance to builder#352
add value_balance to builder#352daira merged 1 commit intozcash:mainfrom zingolabs:add_value_balance_to_builder
Conversation
|
|
| /// The net value of the bundle. The value of all spends, minus the value | ||
| /// of all outputs. | ||
| pub fn value_balance(&self) -> i64 { |
There was a problem hiding this comment.
What is the use case for this method (calculating the value balance from the in-progress builder state)? It would be useful to describe intended use cases in the documentation.
| pub fn value_balance(&self) -> i64 { | ||
| self.spends | ||
| .iter() | ||
| .map(|spend| spend.note.value().inner() as i64) |
There was a problem hiding this comment.
I would prefer that this return a ValueSum value, which wraps an i128 internally.
nuttycom
left a comment
There was a problem hiding this comment.
i64 is not sufficiently type-safe, and we already have ValueSum to represent the values of these kinds of balances.
|
|
Switching to ValueSum necessitated adding a |
|
|
|
@AloeareV the type of a value balance is intentionally abstract in this crate, to allow different downstream consumers to use their own existing types ( |
|
Actually, now that I think about it, this PR should add "(and [ |
Codecov ReportBase: 88.90% // Head: 88.66% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #352 +/- ##
==========================================
- Coverage 88.90% 88.66% -0.25%
==========================================
Files 37 38 +1
Lines 3858 3873 +15
==========================================
+ Hits 3430 3434 +4
- Misses 428 439 +11
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
Once this PR lands, and is subsequently included in a release, If @AloeareV had written the code, would it now be landed? |
nuttycom
left a comment
There was a problem hiding this comment.
utACK, modulo it would be good to have a test for value_balance
sellout
left a comment
There was a problem hiding this comment.
Just a question, not a requested change.
daira
left a comment
There was a problem hiding this comment.
Blocking on my review tomorrow.
| /// minus the value of all outputs. | ||
| /// | ||
| /// Useful for balancing a transaction, as the value balance of an individual bundle | ||
| /// can be non-zero, but a transaction may not have a positive total value balance. |
There was a problem hiding this comment.
| /// can be non-zero, but a transaction may not have a positive total value balance. | |
| /// can be non-zero. Each bundle's value balance is added to the transparent | |
| /// transaction value pool, which [must not have a negative value]. (If it were | |
| /// negative, the transaction would output more value than it receives in inputs.) | |
| /// | |
| /// [must not have a negative value]: https://zips.z.cash/protocol/protocol.pdf#transactions |
There was a problem hiding this comment.
I forgot to commit this before merging. See #359.
| ) | ||
| .fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value) | ||
| .ok_or(OverflowError)?; | ||
| i64::try_from(value_balance).and_then(|i| V::try_from(i).map_err(|_| value::OverflowError)) |
There was a problem hiding this comment.
This is correct because i64 can represent all of
daira
left a comment
There was a problem hiding this comment.
utACK; also checked src/value.rs for overflow potential.
… in zcash#352. Signed-off-by: Daira Hopwood <daira@jacaranda.org>
… in zcash#352. Signed-off-by: Daira Hopwood <daira@jacaranda.org>
No description provided.