Merge pull request #1062 from nuttycom/primitives/remove_sapling_fee_traits

zcash_primitives: Remove and relocate `InputView` traits.
This commit is contained in:
str4d 2023-12-07 11:47:00 +00:00 committed by GitHub
commit f1fdce499a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 221 additions and 147 deletions

View File

@ -28,7 +28,7 @@ and this library adheres to Rust's notion of
- `wallet::input_selection::ShieldingSelector` has been
factored out from the `InputSelector` trait to separate out transparent
functionality and move it behind the `transparent-inputs` feature flag.
- `zcash_client_backend::fees::standard`
- `zcash_client_backend::fees::{standard, sapling}`
- `zcash_client_backend::wallet`:
- `WalletNote`
- `ReceivedNote`

View File

@ -10,7 +10,6 @@ use zcash_primitives::{
transaction::{
components::{
amount::{BalanceError, NonNegativeAmount},
sapling::fees as sapling,
TxOut,
},
fees::FeeRule,
@ -21,7 +20,7 @@ use zcash_primitives::{
use crate::{
address::{RecipientAddress, UnifiedAddress},
data_api::SaplingInputSource,
fees::{ChangeError, ChangeStrategy, DustOutputPolicy, TransactionBalance},
fees::{sapling, ChangeError, ChangeStrategy, DustOutputPolicy, TransactionBalance},
wallet::{ReceivedNote, WalletTransparentOutput},
zip321::TransactionRequest,
};

View File

@ -6,15 +6,14 @@ use zcash_primitives::{
transaction::{
components::{
amount::{BalanceError, NonNegativeAmount},
sapling::fees as sapling,
transparent::fees as transparent,
OutPoint,
},
fees::FeeRule,
fees::{transparent, FeeRule},
},
};
pub mod fixed;
pub mod sapling;
pub mod standard;
pub mod zip317;
@ -260,12 +259,16 @@ pub trait ChangeStrategy {
#[cfg(test)]
pub(crate) mod tests {
use zcash_primitives::transaction::components::{
amount::NonNegativeAmount,
sapling::fees as sapling,
transparent::{fees as transparent, OutPoint, TxOut},
use zcash_primitives::transaction::{
components::{
amount::NonNegativeAmount,
transparent::{OutPoint, TxOut},
},
fees::transparent,
};
use super::sapling;
#[derive(Debug)]
pub(crate) struct TestTransparentInput {
pub outpoint: OutPoint,

View File

@ -4,17 +4,14 @@ use zcash_primitives::{
consensus::{self, BlockHeight},
memo::MemoBytes,
transaction::{
components::{
amount::{BalanceError, NonNegativeAmount},
sapling::fees as sapling,
transparent::fees as transparent,
},
fees::{fixed::FeeRule as FixedFeeRule, FeeRule},
components::amount::{BalanceError, NonNegativeAmount},
fees::{fixed::FeeRule as FixedFeeRule, transparent, FeeRule},
},
};
use super::{
ChangeError, ChangeStrategy, ChangeValue, DustAction, DustOutputPolicy, TransactionBalance,
sapling, ChangeError, ChangeStrategy, ChangeValue, DustAction, DustOutputPolicy,
TransactionBalance,
};
/// A change strategy that and proposes change as a single output to the most current supported

View File

@ -0,0 +1,60 @@
//! Types related to computation of fees and change related to the Sapling components
//! of a transaction.
use std::convert::Infallible;
use zcash_primitives::{
sapling::builder::{SaplingOutputInfo, SpendDescriptionInfo},
transaction::components::amount::NonNegativeAmount,
};
/// A trait that provides a minimized view of a Sapling 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(&self) -> NonNegativeAmount;
}
impl<N> InputView<N> for Infallible {
fn note_id(&self) -> &N {
unreachable!()
}
fn value(&self) -> NonNegativeAmount {
unreachable!()
}
}
// `SpendDescriptionInfo` does not contain a note identifier, so we can only implement
// `InputView<()>`
impl InputView<()> for SpendDescriptionInfo {
fn note_id(&self) -> &() {
&()
}
fn value(&self) -> NonNegativeAmount {
NonNegativeAmount::try_from(self.value())
.expect("An existing note to be spent must have a valid amount value.")
}
}
/// A trait that provides a minimized view of a Sapling output suitable for use in
/// fee and change calculation.
pub trait OutputView {
/// The value of the output being produced.
fn value(&self) -> NonNegativeAmount;
}
impl OutputView for SaplingOutputInfo {
fn value(&self) -> NonNegativeAmount {
NonNegativeAmount::try_from(self.value())
.expect("Output values should be checked at construction.")
}
}
impl OutputView for Infallible {
fn value(&self) -> NonNegativeAmount {
unreachable!()
}
}

View File

@ -4,18 +4,19 @@ use zcash_primitives::{
consensus::{self, BlockHeight},
memo::MemoBytes,
transaction::{
components::{
amount::NonNegativeAmount, sapling::fees as sapling, transparent::fees as transparent,
},
components::amount::NonNegativeAmount,
fees::{
fixed::FeeRule as FixedFeeRule,
transparent,
zip317::{FeeError as Zip317FeeError, FeeRule as Zip317FeeRule},
StandardFeeRule,
},
},
};
use super::{fixed, zip317, ChangeError, ChangeStrategy, DustOutputPolicy, TransactionBalance};
use super::{
fixed, sapling, zip317, ChangeError, ChangeStrategy, DustOutputPolicy, TransactionBalance,
};
/// A change strategy that proposes change as a single output to the most current supported
/// shielded pool and delegates fee calculation to the provided fee rule.

View File

@ -8,12 +8,9 @@ use zcash_primitives::{
consensus::{self, BlockHeight},
memo::MemoBytes,
transaction::{
components::{
amount::{BalanceError, NonNegativeAmount},
sapling::fees as sapling,
transparent::fees as transparent,
},
components::amount::{BalanceError, NonNegativeAmount},
fees::{
transparent,
zip317::{FeeError as Zip317FeeError, FeeRule as Zip317FeeRule},
FeeRule,
},
@ -21,7 +18,8 @@ use zcash_primitives::{
};
use super::{
ChangeError, ChangeStrategy, ChangeValue, DustAction, DustOutputPolicy, TransactionBalance,
sapling, ChangeError, ChangeStrategy, ChangeValue, DustAction, DustOutputPolicy,
TransactionBalance,
};
/// A change strategy that and proposes change as a single output to the most current supported

View File

@ -10,15 +10,15 @@ use zcash_primitives::{
transaction::{
components::{
amount::NonNegativeAmount,
sapling::fees as sapling_fees,
transparent::{self, OutPoint, TxOut},
transparent::{OutPoint, TxOut},
},
fees::transparent as transparent_fees,
TxId,
},
zip32::{AccountId, Scope},
};
use crate::{address::UnifiedAddress, PoolType, ShieldedProtocol};
use crate::{address::UnifiedAddress, fees::sapling as sapling_fees, PoolType, ShieldedProtocol};
/// A unique identifier for a shielded transaction output
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
@ -122,7 +122,7 @@ impl WalletTransparentOutput {
}
}
impl transparent::fees::InputView for WalletTransparentOutput {
impl transparent_fees::InputView for WalletTransparentOutput {
fn outpoint(&self) -> &OutPoint {
&self.outpoint
}

View File

@ -19,6 +19,8 @@ and this library adheres to Rust's notion of
- `builder::{InProgressProofs, Unproven, Proven}`
- `builder::{InProgressSignatures, Unsigned, PartiallyAuthorized}`
- `builder::{MaybeSigned, SigningParts}`
- `builder::{SpendDescriptionInfo::value}`
- `builder::{SaplingOutputInfo}`
- `bundle` module, containing the following types moved from
`zcash_primitives::transaction::components::sapling`:
- `Bundle`
@ -69,6 +71,8 @@ and this library adheres to Rust's notion of
- `temporary_zcashd_write_output_v4`
- `temporary_zcashd_read_v4_components`
- `temporary_zcashd_write_v4_components`
- `components::transparent`:
- `builder::TransparentInputInfo`
- `fees::StandardFeeRule`
- Constants in `fees::zip317`:
- `MARGINAL_FEE`
@ -182,7 +186,14 @@ and this library adheres to Rust's notion of
argument as the diversifier may be obtained from the note.
- `components::transparent::TxOut.value` now has type `NonNegativeAmount`
instead of `Amount`.
- `components::transparent::fees` has been moved to
`zcash_primitives::transaction::fees::transparent`
- `components::transparent::builder::TransparentBuilder::{inputs, outputs}`
have changed to return `&[TransparentInputInfo]` and `&[TxOut]` respectively,
in order to avoid coupling to the fee traits.
- `Unauthorized::SaplingAuth` now has type `InProgress<Proven, Unsigned>`.
- `fees::FeeRule::fee_required` now takes an additional `orchard_action_count`
argument.
- The following methods now take `NonNegativeAmount` instead of `Amount`:
- `builder::Builder::{add_sapling_output, add_transparent_output}`
- `components::transparent::builder::TransparentBuilder::add_output`
@ -190,12 +201,9 @@ and this library adheres to Rust's notion of
- `fees::zip317::FeeRule::non_standard`
- The following methods now return `NonNegativeAmount` instead of `Amount`:
- `components::amount::testing::arb_nonnegative_amount`
- `components::sapling`:
- `fees::InputView::value`
- `fees::OutputView::value`
- `components::transparent`:
- `fees::InputView::value`
- `fees::OutputView::value`
- `fees::transparent`:
- `InputView::value`
- `OutputView::value`
- `fees::FeeRule::{fee_required, fee_required_zfuture}`
- `fees::fixed::FeeRule::fixed_fee`
- `fees::zip317::FeeRule::marginal_fee`
@ -237,6 +245,8 @@ and this library adheres to Rust's notion of
- `SpendDescription::<Unauthorized>::apply_signature`
- `Bundle::<Unauthorized>::apply_signatures` (use
`Bundle::<InProgress<Proven, Unsigned>>::apply_signatures` instead).
- The `fees` module was removed. Its contents were unused in this crate,
are now instead made available by `zcash_client_backend::fees::sapling`.
- `impl From<zcash_primitive::components::transaction::Amount> for u64`
- `zcash_primitives::zip32`:
- `sapling` module (moved from `zcash_primitives::sapling::zip32`).

View File

@ -25,10 +25,7 @@ use crate::{
zip32::ExtendedSpendingKey,
Diversifier, MerklePath, Node, Note, PaymentAddress, ProofGenerationKey, SaplingIvk,
},
transaction::{
builder::Progress,
components::{amount::NonNegativeAmount, sapling::fees},
},
transaction::builder::Progress,
};
/// If there are any shielded inputs, always have at least two shielded outputs, padding
@ -77,18 +74,6 @@ pub struct SpendDescriptionInfo {
rcv: ValueCommitTrapdoor,
}
impl fees::InputView<()> for SpendDescriptionInfo {
fn note_id(&self) -> &() {
// The builder does not make use of note identifiers, so we can just return the unit value.
&()
}
fn value(&self) -> NonNegativeAmount {
// An existing note to be spent must have a valid amount value.
NonNegativeAmount::from_u64(self.note.value().inner()).unwrap()
}
}
impl SpendDescriptionInfo {
fn new_internal<R: RngCore>(
mut rng: &mut R,
@ -105,6 +90,10 @@ impl SpendDescriptionInfo {
}
}
pub fn value(&self) -> NoteValue {
self.note.value()
}
fn build<Pr: SpendProver>(
self,
anchor: Option<bls12_381::Scalar>,
@ -154,7 +143,7 @@ impl SpendDescriptionInfo {
/// A struct containing the information required in order to construct a
/// Sapling output to a transaction.
#[derive(Clone)]
struct SaplingOutputInfo {
pub struct SaplingOutputInfo {
/// `None` represents the `ovk = ⊥` case.
ovk: Option<OutgoingViewingKey>,
note: Note,
@ -249,12 +238,13 @@ impl SaplingOutputInfo {
zkproof,
)
}
}
impl fees::OutputView for SaplingOutputInfo {
fn value(&self) -> NonNegativeAmount {
NonNegativeAmount::from_u64(self.note.value().inner())
.expect("Note values should be checked at construction.")
pub fn recipient(&self) -> PaymentAddress {
self.note.recipient()
}
pub fn value(&self) -> NoteValue {
self.note.value()
}
}
@ -317,12 +307,12 @@ impl SaplingBuilder {
/// 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) -> &[SpendDescriptionInfo] {
&self.spends
}
/// Returns the Sapling outputs that will be produced by the transaction being constructed
pub fn outputs(&self) -> &[impl fees::OutputView] {
pub fn outputs(&self) -> &[SaplingOutputInfo] {
&self.outputs
}

View File

@ -20,8 +20,7 @@ use crate::{
transaction::{
components::{
amount::{Amount, BalanceError},
sapling::fees as sapling_fees,
transparent::{self, builder::TransparentBuilder},
transparent::{self, builder::TransparentBuilder, TxOut},
},
fees::FeeRule,
sighash::{signature_hash, SignableInput},
@ -31,7 +30,10 @@ use crate::{
};
#[cfg(feature = "transparent-inputs")]
use crate::transaction::components::transparent::TxOut;
use crate::transaction::components::transparent::builder::TransparentInputInfo;
#[cfg(not(feature = "transparent-inputs"))]
use std::convert::Infallible;
#[cfg(feature = "zfuture")]
use crate::{
@ -184,25 +186,26 @@ impl<'a, P, R> Builder<'a, P, R> {
/// Returns the set of transparent inputs currently committed to be consumed
/// by the transaction.
pub fn transparent_inputs(&self) -> &[impl transparent::fees::InputView] {
#[cfg(feature = "transparent-inputs")]
pub fn transparent_inputs(&self) -> &[TransparentInputInfo] {
self.transparent_builder.inputs()
}
/// Returns the set of transparent outputs currently set to be produced by
/// the transaction.
pub fn transparent_outputs(&self) -> &[impl transparent::fees::OutputView] {
pub fn transparent_outputs(&self) -> &[TxOut] {
self.transparent_builder.outputs()
}
/// 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) -> &[sapling::builder::SpendDescriptionInfo] {
self.sapling_builder.inputs()
}
/// Returns the set of Sapling outputs currently set to be produced by
/// the transaction.
pub fn sapling_outputs(&self) -> &[impl sapling_fees::OutputView] {
pub fn sapling_outputs(&self) -> &[sapling::builder::SaplingOutputInfo] {
self.sapling_builder.outputs()
}
}
@ -414,10 +417,16 @@ impl<'a, P: consensus::Parameters, R: RngCore + CryptoRng> Builder<'a, P, R> {
/// This fee is a function of the spends and outputs that have been added to the builder,
/// pursuant to the specified [`FeeRule`].
pub fn get_fee<FR: FeeRule>(&self, fee_rule: &FR) -> Result<NonNegativeAmount, FR::Error> {
#[cfg(feature = "transparent-inputs")]
let transparent_inputs = self.transparent_builder.inputs();
#[cfg(not(feature = "transparent-inputs"))]
let transparent_inputs: &[Infallible] = &[];
fee_rule.fee_required(
&self.params,
self.target_height,
self.transparent_builder.inputs(),
transparent_inputs,
self.transparent_builder.outputs(),
self.sapling_builder.inputs().len(),
self.sapling_builder.bundle_output_count(),
@ -460,14 +469,28 @@ impl<'a, P: consensus::Parameters, R: RngCore + CryptoRng> Builder<'a, P, R> {
output_prover: &OP,
fee_rule: &FR,
) -> Result<(Transaction, SaplingMetadata), Error<FR::Error>> {
#[cfg(feature = "transparent-inputs")]
let transparent_inputs = self.transparent_builder.inputs();
#[cfg(not(feature = "transparent-inputs"))]
let transparent_inputs: &[Infallible] = &[];
let fee = fee_rule
.fee_required_zfuture(
&self.params,
self.target_height,
self.transparent_builder.inputs(),
transparent_inputs,
self.transparent_builder.outputs(),
self.sapling_builder.inputs().len(),
self.sapling_builder.bundle_output_count(),
std::cmp::max(
self.orchard_builder
.as_ref()
.map_or(0, |builder| builder.outputs().len()),
self.orchard_builder
.as_ref()
.map_or(0, |builder| builder.spends().len()),
),
self.tze_builder.inputs(),
self.tze_builder.outputs(),
)

View File

@ -21,8 +21,6 @@ use crate::{
use super::{Amount, GROTH_PROOF_SIZE};
pub mod fees;
/// Consensus rules (§4.4) & (§4.5):
/// - Canonical encoding is enforced here.
/// - "Not small order" is enforced here.

View File

@ -1,20 +0,0 @@
//! Types related to computation of fees and change related to the Sapling components
//! of a transaction.
use crate::transaction::components::amount::NonNegativeAmount;
/// A trait that provides a minimized view of a Sapling 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(&self) -> NonNegativeAmount;
}
/// A trait that provides a minimized view of a Sapling output suitable for use in
/// fee and change calculation.
pub trait OutputView {
/// The value of the output being produced.
fn value(&self) -> NonNegativeAmount;
}

View File

@ -10,7 +10,6 @@ use crate::legacy::{Script, TransparentAddress};
use super::amount::{Amount, BalanceError, NonNegativeAmount};
pub mod builder;
pub mod fees;
pub trait Authorization: Debug {
type ScriptSig: Debug + Clone + PartialEq;

View File

@ -7,10 +7,9 @@ use crate::{
transaction::{
components::{
amount::{Amount, BalanceError, NonNegativeAmount},
transparent::{self, fees, Authorization, Authorized, Bundle, TxIn, TxOut},
transparent::{self, Authorization, Authorized, Bundle, TxIn, TxOut},
},
sighash::TransparentAuthorizingContext,
OutPoint,
},
};
@ -18,6 +17,7 @@ use crate::{
use {
crate::transaction::{
self as tx,
components::transparent::OutPoint,
sighash::{signature_hash, SignableInput, SIGHASH_ALL},
TransactionData, TxDigests,
},
@ -40,25 +40,9 @@ impl fmt::Display for Error {
}
}
/// An uninhabited type that allows the type of [`TransparentBuilder::inputs`]
/// to resolve when the transparent-inputs feature is not turned on.
#[cfg(not(feature = "transparent-inputs"))]
#[derive(Debug)]
enum InvalidTransparentInput {}
#[cfg(not(feature = "transparent-inputs"))]
impl fees::InputView for InvalidTransparentInput {
fn outpoint(&self) -> &OutPoint {
panic!("transparent-inputs feature flag is not enabled.");
}
fn coin(&self) -> &TxOut {
panic!("transparent-inputs feature flag is not enabled.");
}
}
#[cfg(feature = "transparent-inputs")]
#[derive(Debug, Clone)]
struct TransparentInputInfo {
pub struct TransparentInputInfo {
sk: secp256k1::SecretKey,
pubkey: [u8; secp256k1::constants::PUBLIC_KEY_SIZE],
utxo: OutPoint,
@ -66,12 +50,12 @@ struct TransparentInputInfo {
}
#[cfg(feature = "transparent-inputs")]
impl fees::InputView for TransparentInputInfo {
fn outpoint(&self) -> &OutPoint {
impl TransparentInputInfo {
pub fn outpoint(&self) -> &OutPoint {
&self.utxo
}
fn coin(&self) -> &TxOut {
pub fn coin(&self) -> &TxOut {
&self.coin
}
}
@ -110,19 +94,13 @@ impl TransparentBuilder {
/// Returns the list of transparent inputs that will be consumed by the transaction being
/// constructed.
pub fn inputs(&self) -> &[impl fees::InputView] {
#[cfg(feature = "transparent-inputs")]
return &self.inputs;
#[cfg(not(feature = "transparent-inputs"))]
{
let invalid: &[InvalidTransparentInput] = &[];
invalid
}
#[cfg(feature = "transparent-inputs")]
pub fn inputs(&self) -> &[TransparentInputInfo] {
&self.inputs
}
/// Returns the transparent outputs that will be produced by the transaction being constructed.
pub fn outputs(&self) -> &[impl fees::OutputView] {
pub fn outputs(&self) -> &[TxOut] {
&self.vout
}

View File

@ -12,7 +12,6 @@ use super::amount::Amount;
use crate::{extensions::transparent as tze, transaction::TxId};
pub mod builder;
pub mod fees;
fn to_io_error(_: std::num::TryFromIntError) -> io::Error {
io::Error::new(io::ErrorKind::InvalidData, "value out of range")

View File

@ -9,7 +9,7 @@ use crate::{
self as tx,
components::{
amount::{Amount, BalanceError},
tze::{fees, Authorization, Authorized, Bundle, OutPoint, TzeIn, TzeOut},
tze::{Authorization, Authorized, Bundle, OutPoint, TzeIn, TzeOut},
},
},
};
@ -36,16 +36,16 @@ pub struct TzeSigner<'a, BuildCtx> {
}
#[derive(Clone)]
struct TzeBuildInput {
pub struct TzeBuildInput {
tzein: TzeIn<()>,
coin: TzeOut,
}
impl fees::InputView for TzeBuildInput {
fn outpoint(&self) -> &OutPoint {
impl TzeBuildInput {
pub fn outpoint(&self) -> &OutPoint {
&self.tzein.prevout
}
fn coin(&self) -> &TzeOut {
pub fn coin(&self) -> &TzeOut {
&self.coin
}
}
@ -72,11 +72,11 @@ impl<'a, BuildCtx> TzeBuilder<'a, BuildCtx> {
}
}
pub fn inputs(&self) -> &[impl fees::InputView] {
pub fn inputs(&self) -> &[TzeBuildInput] {
&self.vin
}
pub fn outputs(&self) -> &[impl fees::OutputView] {
pub fn outputs(&self) -> &[TzeOut] {
&self.vout
}

View File

@ -2,15 +2,16 @@
use crate::{
consensus::{self, BlockHeight},
transaction::components::{amount::NonNegativeAmount, transparent::fees as transparent},
transaction::components::amount::NonNegativeAmount,
};
#[cfg(feature = "zfuture")]
use crate::transaction::components::tze::fees as tze;
pub mod fixed;
pub mod transparent;
pub mod zip317;
#[cfg(feature = "zfuture")]
pub mod tze;
/// A trait that represents the ability to compute the fees that must be paid
/// by a transaction having a specified set of inputs and outputs.
pub trait FeeRule {
@ -52,6 +53,7 @@ pub trait FutureFeeRule: FeeRule {
transparent_outputs: &[impl transparent::OutputView],
sapling_input_count: usize,
sapling_output_count: usize,
orchard_action_count: usize,
tze_inputs: &[impl tze::InputView],
tze_outputs: &[impl tze::OutputView],
) -> Result<NonNegativeAmount, Self::Error>;

View File

@ -1,11 +1,11 @@
use crate::{
consensus::{self, BlockHeight},
transaction::components::{amount::NonNegativeAmount, transparent::fees as transparent},
transaction::fees::zip317,
transaction::components::amount::NonNegativeAmount,
transaction::fees::{transparent, zip317},
};
#[cfg(feature = "zfuture")]
use crate::transaction::components::tze::fees as tze;
use crate::transaction::fees::tze;
/// A fee rule that always returns a fixed fee, irrespective of the structure of
/// the transaction being constructed.
@ -72,6 +72,7 @@ impl super::FutureFeeRule for FeeRule {
_transparent_outputs: &[impl transparent::OutputView],
_sapling_input_count: usize,
_sapling_output_count: usize,
_orchard_action_count: usize,
_tze_inputs: &[impl tze::InputView],
_tze_outputs: &[impl tze::OutputView],
) -> Result<NonNegativeAmount, Self::Error> {

View File

@ -1,12 +1,16 @@
//! Types related to computation of fees and change related to the transparent components
//! of a transaction.
use super::TxOut;
use std::convert::Infallible;
use crate::{
legacy::Script,
transaction::{components::amount::NonNegativeAmount, OutPoint},
transaction::components::{amount::NonNegativeAmount, transparent::TxOut, OutPoint},
};
#[cfg(feature = "transparent-inputs")]
use crate::transaction::components::transparent::builder::TransparentInputInfo;
/// This trait provides a minimized view of a transparent input suitable for use in
/// fee and change computation.
pub trait InputView: std::fmt::Debug {
@ -16,6 +20,26 @@ pub trait InputView: std::fmt::Debug {
fn coin(&self) -> &TxOut;
}
#[cfg(feature = "transparent-inputs")]
impl InputView for TransparentInputInfo {
fn outpoint(&self) -> &OutPoint {
self.outpoint()
}
fn coin(&self) -> &TxOut {
self.coin()
}
}
impl InputView for Infallible {
fn outpoint(&self) -> &OutPoint {
unreachable!()
}
fn coin(&self) -> &TxOut {
unreachable!()
}
}
/// This trait provides a minimized view of a transparent output suitable for use in
/// fee and change computation.
pub trait OutputView: std::fmt::Debug {

View File

@ -1,10 +1,10 @@
//! Abstractions and types related to fee calculations for TZE components of a transaction.
use crate::{
extensions::transparent::{self as tze},
extensions::transparent as tze,
transaction::components::{
amount::Amount,
tze::{OutPoint, TzeOut},
tze::{builder::TzeBuildInput, OutPoint, TzeOut},
},
};
@ -17,6 +17,15 @@ pub trait InputView {
fn coin(&self) -> &TzeOut;
}
impl InputView for TzeBuildInput {
fn outpoint(&self) -> &OutPoint {
self.outpoint()
}
fn coin(&self) -> &TzeOut {
self.coin()
}
}
/// This trait provides a minimized view of a TZE output suitable for use in
/// fee computation.
pub trait OutputView {

View File

@ -7,9 +7,12 @@ use core::cmp::max;
use crate::{
consensus::{self, BlockHeight},
legacy::TransparentAddress,
transaction::components::{
amount::{BalanceError, NonNegativeAmount},
transparent::{fees as transparent, OutPoint},
transaction::{
components::{
amount::{BalanceError, NonNegativeAmount},
transparent::OutPoint,
},
fees::transparent,
},
};