fuels_contract/
call_response.rs1use crate::logs::LogDecoder;
2use fuel_tx::Receipt;
3use fuels_core::{Parameterize, Tokenizable};
4use fuels_types::errors::Error;
5
6#[derive(Debug)]
13pub struct FuelCallResponse<D> {
15 pub value: D,
16 pub receipts: Vec<Receipt>,
17 pub gas_used: u64,
18 pub log_decoder: LogDecoder,
19}
20impl<D> FuelCallResponse<D> {
23 fn get_gas_used(receipts: &[Receipt]) -> u64 {
25 receipts
26 .iter()
27 .rfind(|r| matches!(r, Receipt::ScriptResult { .. }))
28 .expect("could not retrieve ScriptResult")
29 .gas_used()
30 .expect("could not retrieve gas used from ScriptResult")
31 }
32
33 pub fn new(value: D, receipts: Vec<Receipt>, log_decoder: LogDecoder) -> Self {
34 Self {
35 value,
36 gas_used: Self::get_gas_used(&receipts),
37 receipts,
38 log_decoder,
39 }
40 }
41
42 pub fn get_logs(&self) -> Result<Vec<String>, Error> {
43 self.log_decoder.get_logs(&self.receipts)
44 }
45
46 pub fn get_logs_with_type<T: Tokenizable + Parameterize>(&self) -> Result<Vec<T>, Error> {
47 self.log_decoder.get_logs_with_type::<T>(&self.receipts)
48 }
49}