Skip to main content

zcash_primitives/transaction/fees/
fixed.rs

1use crate::transaction::fees::transparent;
2
3use zcash_protocol::{
4    consensus::{self, BlockHeight},
5    value::Zatoshis,
6};
7
8/// A fee rule that always returns a fixed fee, irrespective of the structure of
9/// the transaction being constructed.
10#[derive(Clone, Copy, Debug)]
11pub struct FeeRule {
12    fixed_fee: Zatoshis,
13}
14
15impl FeeRule {
16    /// Creates a new nonstandard fixed fee rule with the specified fixed fee.
17    pub fn non_standard(fixed_fee: Zatoshis) -> Self {
18        Self { fixed_fee }
19    }
20
21    /// Returns the fixed fee amount which this rule was configured.
22    pub fn fixed_fee(&self) -> Zatoshis {
23        self.fixed_fee
24    }
25}
26
27impl super::FeeRule for FeeRule {
28    type Error = core::convert::Infallible;
29
30    fn fee_required<P: consensus::Parameters>(
31        &self,
32        _params: &P,
33        _target_height: BlockHeight,
34        _transparent_input_sizes: impl IntoIterator<Item = transparent::InputSize>,
35        _transparent_output_sizes: impl IntoIterator<Item = usize>,
36        _sapling_input_count: usize,
37        _sapling_output_count: usize,
38        _orchard_action_count: usize,
39        _ironwood_action_count: usize,
40    ) -> Result<Zatoshis, Self::Error> {
41        Ok(self.fixed_fee)
42    }
43}