diff --git a/CHANGELOG.md b/CHANGELOG.md index b66e0f42..ab9f7f44 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 ee5203e6..96ef4cb0 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")))]