use crate::{
consensus::{self, BlockHeight},
transaction::components::amount::NonNegativeAmount,
transaction::fees::{transparent, zip317},
};
#[cfg(zcash_unstable = "zfuture")]
use crate::transaction::fees::tze;
#[derive(Clone, Copy, Debug)]
pub struct FeeRule {
fixed_fee: NonNegativeAmount,
}
impl FeeRule {
pub fn non_standard(fixed_fee: NonNegativeAmount) -> Self {
Self { fixed_fee }
}
#[deprecated(
since = "0.12.0",
note = "To calculate the ZIP 317 fee, use `transaction::fees::zip317::FeeRule::standard()`. For a fixed fee, use the `non_standard` constructor."
)]
pub fn standard() -> Self {
Self {
fixed_fee: zip317::MINIMUM_FEE,
}
}
pub fn fixed_fee(&self) -> NonNegativeAmount {
self.fixed_fee
}
}
impl super::FeeRule for FeeRule {
type Error = std::convert::Infallible;
fn fee_required<P: consensus::Parameters>(
&self,
_params: &P,
_target_height: BlockHeight,
_transparent_input_sizes: impl IntoIterator<Item = transparent::InputSize>,
_transparent_output_sizes: impl IntoIterator<Item = usize>,
_sapling_input_count: usize,
_sapling_output_count: usize,
_orchard_action_count: usize,
) -> Result<NonNegativeAmount, Self::Error> {
Ok(self.fixed_fee)
}
}
#[cfg(zcash_unstable = "zfuture")]
impl super::FutureFeeRule for FeeRule {
fn fee_required_zfuture<P: consensus::Parameters>(
&self,
_params: &P,
_target_height: BlockHeight,
_transparent_input_sizes: impl IntoIterator<Item = transparent::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> {
Ok(self.fixed_fee)
}
}