Skip to content

Commit

Permalink
Calculate value balance for native asset only
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykoren committed Nov 8, 2023
1 parent a680f41 commit e37ee65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orchard"
version = "0.5.0"
version = "0.6.0"
authors = [
"Sean Bowe <[email protected]>",
"Jack Grigg <[email protected]>",
Expand Down
2 changes: 2 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,12 @@ impl Builder {
let value_balance = self
.spends
.iter()
.filter(|spend| spend.note.asset().is_native().unwrap_u8() == 1)
.map(|spend| spend.note.value() - NoteValue::zero())
.chain(
self.recipients
.iter()
.filter(|recipient| recipient.asset.is_native().unwrap_u8() == 1)
.map(|recipient| NoteValue::zero() - recipient.value),
)
.fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value)

Check warning on line 457 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> src/builder.rs:457:14 | 457 | .fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(ValueSum::zero(), |acc, note_value| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold = note: `#[warn(clippy::manual_try_fold)]` on by default

Check warning on line 457 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

usage of `Iterator::fold` on a type that implements `Try`

warning: usage of `Iterator::fold` on a type that implements `Try` --> src/builder.rs:457:14 | 457 | .fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(ValueSum::zero(), |acc, note_value| ...)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold = note: `#[warn(clippy::manual_try_fold)]` on by default
Expand Down

0 comments on commit e37ee65

Please sign in to comment.