From c88fdf1c59b99cf8b4e33072a8e693fec6223b3b Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Fri, 2 Sep 2022 10:05:38 -0500 Subject: [PATCH] Add value_balance to orchard builder --- src/builder.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index fd1e9fd5..7e5f6be2 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -221,6 +221,7 @@ pub struct Builder { recipients: Vec, flags: Flags, anchor: Anchor, + value_balance: i64, } impl Builder { @@ -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 @@ -277,6 +284,8 @@ impl Builder { merkle_path, }); + self.value_balance += note.value().inner() as i64; + Ok(()) } @@ -299,6 +308,8 @@ impl Builder { memo, }); + self.value_balance -= value.inner() as i64; + Ok(()) }