From fbfc8f9ed819b1872fffebe240a1cff5fad13f60 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Mon, 19 Sep 2022 13:27:16 +0100 Subject: [PATCH 1/2] Correct the doc comment for the `Builder::value_balance` method added in #352. Signed-off-by: Daira Hopwood --- src/builder.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index fe6b6226..964aa17a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -306,7 +306,12 @@ impl Builder { /// 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. + /// 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.) + /// + /// [added]: https://zips.z.cash/protocol/protocol.pdf#orchardbalance + /// [must not have a negative value]: https://zips.z.cash/protocol/protocol.pdf#transactions pub fn value_balance>(&self) -> Result { let value_balance = self .spends From 6458e2718557bc6c1e7871199a2217957be068dc Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Mon, 19 Sep 2022 13:41:41 +0100 Subject: [PATCH 2/2] Add minimal test that `Builder::value_balance` works. Signed-off-by: Daira Hopwood --- src/builder.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 964aa17a..6662aaa3 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -832,6 +832,9 @@ mod tests { builder .add_recipient(None, recipient, NoteValue::from_raw(5000), None) .unwrap(); + let balance: i64 = builder.value_balance().unwrap(); + assert_eq!(balance, -5000); + let bundle: Bundle = builder .build(&mut rng) .unwrap()