Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -33,7 +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`
- `orchard::circuit::Circuit::from_action_context`
- impls of `Eq` for:
- `orchard::zip32::ChildIndex`
Expand Down
45 changes: 45 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@ impl Builder {
Ok(())
}

/// Returns the action spend components that will be produced by the
/// transaction being constructed
pub fn spends(&self) -> &Vec<impl InputView<()>> {
&self.spends
}

/// Returns the action output components that will be produced by the
/// transaction being constructed
pub fn outputs(&self) -> &Vec<impl OutputView> {
&self.recipients
}

/// The net value of the bundle to be built. The value of all spends,
/// minus the value of all outputs.
///
Expand Down Expand Up @@ -711,6 +723,39 @@ impl<V> Bundle<InProgress<Proof, PartiallyAuthorized>, V> {
}
}

/// A trait that provides a minimized view of an Orchard input suitable for use in
/// fee and change calculation.
pub trait InputView<NoteRef> {
/// An identifier for the input being spent.
fn note_id(&self) -> &NoteRef;
/// The value of the input being spent.
fn value<V: From<u64>>(&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<V: From<u64>>(&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<V: From<u64>>(&self) -> V;
}

impl OutputView for RecipientInfo {
fn value<V: From<u64>>(&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")))]
Expand Down