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
use crate::logs::LogDecoder;
use fuel_tx::Receipt;
use fuels_core::{Parameterize, Tokenizable};
use fuels_types::errors::Error;
#[derive(Debug)]
pub struct FuelCallResponse<D> {
pub value: D,
pub receipts: Vec<Receipt>,
pub gas_used: u64,
pub log_decoder: LogDecoder,
}
impl<D> FuelCallResponse<D> {
fn get_gas_used(receipts: &[Receipt]) -> u64 {
receipts
.iter()
.rfind(|r| matches!(r, Receipt::ScriptResult { .. }))
.expect("could not retrieve ScriptResult")
.gas_used()
.expect("could not retrieve gas used from ScriptResult")
}
pub fn new(value: D, receipts: Vec<Receipt>, log_decoder: LogDecoder) -> Self {
Self {
value,
gas_used: Self::get_gas_used(&receipts),
receipts,
log_decoder,
}
}
pub fn get_logs(&self) -> Result<Vec<String>, Error> {
self.log_decoder.get_logs(&self.receipts)
}
pub fn get_logs_with_type<T: Tokenizable + Parameterize>(&self) -> Result<Vec<T>, Error> {
self.log_decoder.get_logs_with_type::<T>(&self.receipts)
}
}