fuels_programs/responses/
submit.rs

1use std::fmt::Debug;
2
3use fuel_types::Bytes32;
4use fuels_accounts::Account;
5use fuels_core::{
6    traits::{Parameterize, Tokenizable},
7    types::errors::Result,
8};
9
10use crate::{
11    calls::{
12        traits::{ContractDependencyConfigurator, ResponseParser, TransactionTuner},
13        CallHandler, ContractCall,
14    },
15    responses::CallResponse,
16};
17
18/// Represents the response of a submitted transaction with customizable retry behavior.
19///
20/// This struct holds information about the retry configuration, transaction ID (`tx_id`),
21/// and the call handler that manages the type of call (contract or script).
22///
23/// # Type Parameters
24///
25/// - `T`: The account type associated with the transaction.
26/// - `D`: The data type representing the response value.
27/// - `C`: The call type.
28///
29/// # Fields
30///
31/// - `retry_config`: The retry configuration for the transaction.
32/// - `tx_id`: The optional transaction ID of the submitted transaction.
33/// - `call_handler`: The call handler that manages the type of call.
34///
35/// ```
36#[derive(Debug)]
37pub struct SubmitResponse<A, C, T> {
38    tx_id: Bytes32,
39    call_handler: CallHandler<A, C, T>,
40}
41
42impl<A, C, T> SubmitResponse<A, C, T>
43where
44    A: Account,
45    C: ContractDependencyConfigurator + TransactionTuner + ResponseParser,
46    T: Tokenizable + Parameterize + Debug,
47{
48    pub fn new(tx_id: Bytes32, call_handler: CallHandler<A, C, T>) -> Self {
49        Self {
50            tx_id,
51            call_handler,
52        }
53    }
54
55    pub async fn response(self) -> Result<CallResponse<T>> {
56        let provider = self.call_handler.account.try_provider()?;
57        let receipts = provider
58            .tx_status(&self.tx_id)
59            .await?
60            .take_receipts_checked(Some(&self.call_handler.log_decoder))?;
61
62        self.call_handler.get_response(receipts)
63    }
64
65    pub fn tx_id(&self) -> Bytes32 {
66        self.tx_id
67    }
68}
69
70/// Represents the response of a submitted transaction with multiple contract calls.
71impl<A: Account> SubmitResponse<A, Vec<ContractCall>, ()> {
72    pub fn new(tx_id: Bytes32, call_handler: CallHandler<A, Vec<ContractCall>, ()>) -> Self {
73        Self {
74            tx_id,
75            call_handler,
76        }
77    }
78
79    pub async fn response<T: Tokenizable + Debug>(self) -> Result<CallResponse<T>> {
80        let provider = self.call_handler.account.try_provider()?;
81        let receipts = provider
82            .tx_status(&self.tx_id)
83            .await?
84            .take_receipts_checked(Some(&self.call_handler.log_decoder))?;
85
86        self.call_handler.get_response(receipts)
87    }
88
89    pub fn tx_id(&self) -> Bytes32 {
90        self.tx_id
91    }
92}