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 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
70impl<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}