1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Extension trait for [`fuel_tx::TransactionBuilder`]

use super::{
    Checked,
    IntoChecked,
};
use crate::{
    checked_transaction::CheckPredicates,
    prelude::*,
};
use fuel_types::BlockHeight;

/// Extension trait for [`fuel_tx::TransactionBuilder`] adding finalization methods
pub trait TransactionBuilderExt<Tx>
where
    Tx: IntoChecked,
{
    /// Finalize the builder into a [`Checked<Tx>`] of the correct type
    fn finalize_checked(
        &mut self,
        height: BlockHeight,
        gas_costs: &GasCosts,
    ) -> Checked<Tx>;

    /// Finalize the builder into a [`Checked<Tx>`] of the correct type, with basic checks
    /// only
    fn finalize_checked_basic(&mut self, height: BlockHeight) -> Checked<Tx>;
}

impl<Tx: ExecutableTransaction> TransactionBuilderExt<Tx> for TransactionBuilder<Tx>
where
    Self: Finalizable<Tx>,
    Checked<Tx>: CheckPredicates,
{
    fn finalize_checked(
        &mut self,
        height: BlockHeight,
        gas_costs: &GasCosts,
    ) -> Checked<Tx> {
        self.finalize()
            .into_checked(height, self.get_params(), gas_costs)
            .expect("failed to check tx")
    }

    fn finalize_checked_basic(&mut self, height: BlockHeight) -> Checked<Tx> {
        self.finalize()
            .into_checked_basic(height, self.get_params())
            .expect("failed to check tx")
    }
}