fuels_contract/
call_response.rsuse 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)
}
}