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
//! Extension trait for [`fuel_tx::TransactionBuilder`]

use super::{Checked, IntoChecked};
use crate::checked_transaction::CheckPredicates;
use crate::prelude::*;
use fuel_tx::ConsensusParameters;

/// 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: Word, params: &ConsensusParameters, 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: Word, params: &ConsensusParameters) -> Checked<Tx>;
}

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

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