fuels_programs/responses/
submit.rs

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use std::fmt::Debug;

use fuel_types::Bytes32;
use fuels_accounts::Account;
use fuels_core::{
    traits::{Parameterize, Tokenizable},
    types::errors::Result,
};

use crate::{
    calls::{
        traits::{ContractDependencyConfigurator, ResponseParser, TransactionTuner},
        CallHandler, ContractCall,
    },
    responses::CallResponse,
};

/// Represents the response of a submitted transaction with customizable retry behavior.
///
/// This struct holds information about the retry configuration, transaction ID (`tx_id`),
/// and the call handler that manages the type of call (contract or script).
///
/// # Type Parameters
///
/// - `T`: The account type associated with the transaction.
/// - `D`: The data type representing the response value.
/// - `C`: The call type.
///
/// # Fields
///
/// - `retry_config`: The retry configuration for the transaction.
/// - `tx_id`: The optional transaction ID of the submitted transaction.
/// - `call_handler`: The call handler that manages the type of call.
///
/// ```
#[derive(Debug)]
pub struct SubmitResponse<A, C, T> {
    tx_id: Bytes32,
    call_handler: CallHandler<A, C, T>,
}

impl<A, C, T> SubmitResponse<A, C, T>
where
    A: Account,
    C: ContractDependencyConfigurator + TransactionTuner + ResponseParser,
    T: Tokenizable + Parameterize + Debug,
{
    pub fn new(tx_id: Bytes32, call_handler: CallHandler<A, C, T>) -> Self {
        Self {
            tx_id,
            call_handler,
        }
    }

    pub async fn response(self) -> Result<CallResponse<T>> {
        let provider = self.call_handler.account.try_provider()?;
        let receipts = provider
            .tx_status(&self.tx_id)
            .await?
            .take_receipts_checked(Some(&self.call_handler.log_decoder))?;

        self.call_handler.get_response(receipts)
    }

    pub fn tx_id(&self) -> Bytes32 {
        self.tx_id
    }
}

/// Represents the response of a submitted transaction with multiple contract calls.
impl<A: Account> SubmitResponse<A, Vec<ContractCall>, ()> {
    pub fn new(tx_id: Bytes32, call_handler: CallHandler<A, Vec<ContractCall>, ()>) -> Self {
        Self {
            tx_id,
            call_handler,
        }
    }

    pub async fn response<T: Tokenizable + Debug>(self) -> Result<CallResponse<T>> {
        let provider = self.call_handler.account.try_provider()?;
        let receipts = provider
            .tx_status(&self.tx_id)
            .await?
            .take_receipts_checked(Some(&self.call_handler.log_decoder))?;

        self.call_handler.get_response(receipts)
    }

    pub fn tx_id(&self) -> Bytes32 {
        self.tx_id
    }
}