From 13d0d5592cbc11e9f43299c4317fc18fd6cd9d85 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Thu, 1 Dec 2022 16:15:10 -0400 Subject: [PATCH 1/4] Add spends/outputs getter fns to builders for use in change calculation --- CHANGELOG.md | 4 +++- src/builder.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b66e0f428..ab9f7f447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,9 @@ and this project adheres to Rust's notion of - `impl memuse::DynamicUsage for Nullifier` - `orchard::note_encryption`: - `impl memuse::DynamicUsage for OrchardDomain` -- `orchard::builder::SpendInfo::new` +- `orchard::builder`: + - `{SpendInfo::new, InputView, OutputView}` + - `Builder::{spends, outputs}` - `orchard::circuit::Circuit::from_action_context` - impls of `Eq` for: - `orchard::zip32::ChildIndex` diff --git a/src/builder.rs b/src/builder.rs index ee5203e6a..96ef4cb0e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -345,6 +345,16 @@ impl Builder { Ok(()) } + /// Returns the action spend components that will be produced by the transaction being constructed + pub fn spends(&self) -> &Vec> { + &self.spends + } + + /// Returns the action output components that will be produced by the transaction being constructed + pub fn outputs(&self) -> &Vec { + &self.recipients + } + /// The net value of the bundle to be built. The value of all spends, /// minus the value of all outputs. /// @@ -711,6 +721,39 @@ impl Bundle, V> { } } +/// A trait that provides a minimized view of an Orchard input suitable for use in +/// fee and change calculation. +pub trait InputView { + /// An identifier for the input being spent. + fn note_id(&self) -> &NoteRef; + /// The value of the input being spent. + fn value>(&self) -> V; +} + +impl InputView<()> for SpendInfo { + fn note_id(&self) -> &() { + // The builder does not make use of note identifiers, so we can just return the unit value. + &() + } + + fn value>(&self) -> V { + V::from(self.note.value().inner()) + } +} + +/// A trait that provides a minimized view of an Orchard output suitable for use in +/// fee and change calculation. +pub trait OutputView { + /// The value of the output being produced. + fn value>(&self) -> V; +} + +impl OutputView for RecipientInfo { + fn value>(&self) -> V { + V::from(self.value.inner()) + } +} + /// Generators for property testing. #[cfg(any(test, feature = "test-dependencies"))] #[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))] From c34632746ff0bb759969360b31b1e9eca4b945c9 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Thu, 8 Dec 2022 10:59:36 -0400 Subject: [PATCH 2/4] fix changelog additions --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab9f7f447..a553528a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to Rust's notion of ## [Unreleased] ### Added - `orchard::builder`: + - `{SpendInfo::new, InputView, OutputView}` + - `Builder::{spends, outputs}` - `SpendError` - `OutputError` @@ -33,9 +35,6 @@ and this project adheres to Rust's notion of - `impl memuse::DynamicUsage for Nullifier` - `orchard::note_encryption`: - `impl memuse::DynamicUsage for OrchardDomain` -- `orchard::builder`: - - `{SpendInfo::new, InputView, OutputView}` - - `Builder::{spends, outputs}` - `orchard::circuit::Circuit::from_action_context` - impls of `Eq` for: - `orchard::zip32::ChildIndex` From cd8a39bd0c79561c6be235dccfe308a7ba05e861 Mon Sep 17 00:00:00 2001 From: Gygaxis Vainhardt Date: Thu, 8 Dec 2022 17:23:35 -0400 Subject: [PATCH 3/4] Format comments Co-authored-by: Kris Nuttycombe --- src/builder.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 96ef4cb0e..ab4f56c13 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -345,12 +345,14 @@ impl Builder { Ok(()) } - /// Returns the action spend components that will be produced by the transaction being constructed + /// Returns the action spend components that will be produced by the + /// transaction being constructed pub fn spends(&self) -> &Vec> { &self.spends } - /// Returns the action output components that will be produced by the transaction being constructed + /// Returns the action output components that will be produced by the + /// transaction being constructed pub fn outputs(&self) -> &Vec { &self.recipients } From b64d6ba01e6754d9af8ec28d85852df1a5e4fd6b Mon Sep 17 00:00:00 2001 From: Gygaxis Vainhardt Date: Tue, 3 Jan 2023 17:34:28 -0400 Subject: [PATCH 4/4] Update src/builder.rs Co-authored-by: Kris Nuttycombe --- src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index ab4f56c13..5586f54d4 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -345,7 +345,7 @@ impl Builder { Ok(()) } - /// Returns the action spend components that will be produced by the + /// Returns the action spend components that will be produced by the /// transaction being constructed pub fn spends(&self) -> &Vec> { &self.spends