use crate::{
consensus::{self, BlockHeight},
transaction::{components::amount::NonNegativeAmount, fees::transparent::InputSize},
};
pub mod fixed;
pub mod transparent;
pub mod zip317;
#[cfg(zcash_unstable = "zfuture")]
pub mod tze;
pub trait FeeRule {
type Error;
#[allow(clippy::too_many_arguments)]
fn fee_required<P: consensus::Parameters>(
&self,
params: &P,
target_height: BlockHeight,
transparent_input_sizes: impl IntoIterator<Item = InputSize>,
transparent_output_sizes: impl IntoIterator<Item = usize>,
sapling_input_count: usize,
sapling_output_count: usize,
orchard_action_count: usize,
) -> Result<NonNegativeAmount, Self::Error>;
}
#[cfg(zcash_unstable = "zfuture")]
pub trait FutureFeeRule: FeeRule {
#[allow(clippy::too_many_arguments)]
fn fee_required_zfuture<P: consensus::Parameters>(
&self,
params: &P,
target_height: BlockHeight,
transparent_input_sizes: impl IntoIterator<Item = InputSize>,
transparent_output_sizes: impl IntoIterator<Item = usize>,
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>;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum StandardFeeRule {
#[deprecated(
note = "Using this fee rule violates ZIP 317, and might cause transactions built with it to fail. Use `StandardFeeRule::Zip317` instead."
)]
PreZip313,
#[deprecated(
note = "Using this fee rule violates ZIP 317, and might cause transactions built with it to fail. Use `StandardFeeRule::Zip317` instead."
)]
Zip313,
Zip317,
}
impl FeeRule for StandardFeeRule {
type Error = zip317::FeeError;
fn fee_required<P: consensus::Parameters>(
&self,
params: &P,
target_height: BlockHeight,
transparent_input_sizes: impl IntoIterator<Item = InputSize>,
transparent_output_sizes: impl IntoIterator<Item = usize>,
sapling_input_count: usize,
sapling_output_count: usize,
orchard_action_count: usize,
) -> Result<NonNegativeAmount, Self::Error> {
#[allow(deprecated)]
match self {
Self::PreZip313 => Ok(zip317::MINIMUM_FEE),
Self::Zip313 => Ok(NonNegativeAmount::const_from_u64(1000)),
Self::Zip317 => zip317::FeeRule::standard().fee_required(
params,
target_height,
transparent_input_sizes,
transparent_output_sizes,
sapling_input_count,
sapling_output_count,
orchard_action_count,
),
}
}
}