Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ pub struct Builder {
recipients: Vec<RecipientInfo>,
flags: Flags,
anchor: Anchor,
value_balance: i64,
}

impl Builder {
Expand All @@ -231,9 +232,15 @@ impl Builder {
recipients: vec![],
flags,
anchor,
value_balance: 0,
}
}

/// Returns the net value represented by the spends and outputs added to this builder.
pub fn value_balance(&self) -> i64 {
self.value_balance
}

/// Adds a note to be spent in this transaction.
///
/// - `note` is a spendable note, obtained by trial-decrypting an [`Action`] using the
Expand Down Expand Up @@ -277,6 +284,8 @@ impl Builder {
merkle_path,
});

self.value_balance += note.value().inner() as i64;

Ok(())
}

Expand All @@ -299,6 +308,8 @@ impl Builder {
memo,
});

self.value_balance -= value.inner() as i64;

Ok(())
}

Expand Down