Add spends/outputs getter fns to builders for use in change calculation

This commit is contained in:
Hazel OHearn 2022-12-01 16:15:10 -04:00
parent 06cea3fa53
commit 13d0d5592c
No known key found for this signature in database
GPG Key ID: 6D7E97BEE54A57C0
2 changed files with 46 additions and 1 deletions

View File

@ -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`

View File

@ -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<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.
///
@ -711,6 +721,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")))]