Skip to content

Commit

Permalink
Added functions to expose the convert descriptions inside a Builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Murisi Tarusenga committed May 19, 2023
1 parent 6b19a51 commit cfea8c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions masp_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ impl<P, R, K, N> Builder<P, R, K, N> {
pub fn sapling_outputs(&self) -> &[impl sapling::fees::OutputView] {
self.sapling_builder.outputs()
}

/// Returns the set of Sapling converts currently set to be produced by
/// the transaction.
pub fn sapling_converts(&self) -> &[impl sapling::fees::ConvertView] {
self.sapling_builder.converts()
}
}

impl<P: consensus::Parameters> Builder<P, OsRng> {
Expand Down
12 changes: 11 additions & 1 deletion masp_primitives/src/transaction/components/sapling/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl<P, K> SaplingBuilder<P, K> {
&self.spends
}

pub fn converts(&self) -> &[ConvertDescriptionInfo] {
pub fn converts(&self) -> &[impl fees::ConvertView] {
&self.converts
}
/// Returns the Sapling outputs that will be produced by the transaction being constructed
Expand Down Expand Up @@ -790,6 +790,16 @@ pub struct ConvertDescriptionInfo {
merkle_path: MerklePath<Node>,
}

impl fees::ConvertView for ConvertDescriptionInfo {
fn value(&self) -> u64 {
self.value
}

fn conversion(&self) -> &AllowedConversion {
&self.allowed
}
}

pub trait MapBuilder<P1, K1, P2, K2> {
fn map_params(&self, s: P1) -> P2;
fn map_key(&self, s: K1) -> K2;
Expand Down
10 changes: 10 additions & 0 deletions masp_primitives/src/transaction/components/sapling/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::asset_type::AssetType;
use crate::sapling::PaymentAddress;
use crate::convert::AllowedConversion;

/// A trait that provides a minimized view of a Sapling input suitable for use in
/// fee and change calculation.
Expand All @@ -17,6 +18,15 @@ pub trait InputView<NoteRef, Key> {
fn key(&self) -> &Key;
}

/// A trait that provides a minimized view of a Sapling conversion suitable for use in
/// fee and change calculation.
pub trait ConvertView {
/// The amount of the conversion being used.
fn value(&self) -> u64;
/// The allowed conversion being used.
fn conversion(&self) -> &AllowedConversion;
}

/// A trait that provides a minimized view of a Sapling output suitable for use in
/// fee and change calculation.
pub trait OutputView {
Expand Down

0 comments on commit cfea8c9

Please sign in to comment.