fuels_programs/responses/
submit.rs1use 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#[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 tx_status = provider.tx_status(&self.tx_id).await?;
58
59 self.call_handler.get_response(tx_status)
60 }
61
62 pub fn tx_id(&self) -> Bytes32 {
63 self.tx_id
64 }
65}
66
67impl<A: Account> SubmitResponse<A, Vec<ContractCall>, ()> {
69 pub fn new(tx_id: Bytes32, call_handler: CallHandler<A, Vec<ContractCall>, ()>) -> Self {
70 Self {
71 tx_id,
72 call_handler,
73 }
74 }
75
76 pub async fn response<T: Tokenizable + Debug>(self) -> Result<CallResponse<T>> {
77 let provider = self.call_handler.account.try_provider()?;
78 let tx_status = provider.tx_status(&self.tx_id).await?;
79
80 self.call_handler.get_response(tx_status)
81 }
82
83 pub fn tx_id(&self) -> Bytes32 {
84 self.tx_id
85 }
86}