Skip to content

Commit

Permalink
Exposed some detail about where assets are coming from and where they…
Browse files Browse the repository at this point in the history
… are going.
  • Loading branch information
Murisi Tarusenga committed Apr 18, 2023
1 parent 0f9ec18 commit 3fee08a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion masp_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<P, R, K, N> Builder<P, R, K, N> {

/// Returns the set of Sapling inputs currently committed to be consumed
/// by the transaction.
pub fn sapling_inputs(&self) -> &[impl sapling::fees::InputView<()>] {
pub fn sapling_inputs(&self) -> &[impl sapling::fees::InputView<(), K>] {
self.sapling_builder.inputs()
}

Expand Down
12 changes: 10 additions & 2 deletions masp_primitives/src/transaction/components/sapling/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<Key: BorshDeserialize> BorshDeserialize for SpendDescriptionInfo<Key> {
}
}

impl<K> fees::InputView<()> for SpendDescriptionInfo<K> {
impl<K> fees::InputView<(), K> for SpendDescriptionInfo<K> {
fn note_id(&self) -> &() {
// The builder does not make use of note identifiers, so we can just return the unit value.
&()
Expand All @@ -116,6 +116,10 @@ impl<K> fees::InputView<()> for SpendDescriptionInfo<K> {
fn asset_type(&self) -> AssetType {
self.note.asset_type
}

fn key(&self) -> &K {
&self.extsk
}
}

/// A struct containing the information required in order to construct a
Expand Down Expand Up @@ -207,6 +211,10 @@ impl fees::OutputView for SaplingOutputInfo {
fn asset_type(&self) -> AssetType {
self.note.asset_type
}

fn address(&self) -> PaymentAddress {
self.to
}
}

/// Metadata about a transaction created by a [`SaplingBuilder`].
Expand Down Expand Up @@ -349,7 +357,7 @@ impl<P, K> SaplingBuilder<P, K> {

/// Returns the list of Sapling inputs that will be consumed by the transaction being
/// constructed.
pub fn inputs(&self) -> &[impl fees::InputView<()>] {
pub fn inputs(&self) -> &[impl fees::InputView<(), K>] {
&self.spends
}

Expand Down
7 changes: 6 additions & 1 deletion masp_primitives/src/transaction/components/sapling/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
//! of a transaction.
use crate::asset_type::AssetType;
use crate::sapling::PaymentAddress;

/// A trait that provides a minimized view of a Sapling input suitable for use in
/// fee and change calculation.
pub trait InputView<NoteRef> {
pub trait InputView<NoteRef, Key> {
/// An identifier for the input being spent.
fn note_id(&self) -> &NoteRef;
/// The value of the input being spent.
fn value(&self) -> u64;
/// The asset type of the input being spent.
fn asset_type(&self) -> AssetType;
/// The spend/view key of the input being spent.
fn key(&self) -> &Key;
}

/// A trait that provides a minimized view of a Sapling output suitable for use in
Expand All @@ -21,4 +24,6 @@ pub trait OutputView {
fn value(&self) -> u64;
/// The asset type of the output being produced.
fn asset_type(&self) -> AssetType;
/// The destination of this output
fn address(&self) -> PaymentAddress;
}

0 comments on commit 3fee08a

Please sign in to comment.