use crate::ContractError; use ethers_providers::{networks::Network, JsonRpcClient, Provider}; use ethers_types::{ abi::{Detokenize, Event as AbiEvent, RawLog}, BlockNumber, Filter, ValueOrArray, H256, }; use std::marker::PhantomData; pub struct Event<'a, 'b, P, N, D> { pub filter: Filter, pub(crate) provider: &'a Provider
,
pub(crate) event: &'b AbiEvent,
pub(crate) datatype: PhantomData > {
// get the logs
let logs = self
.provider
.get_logs(&self.filter)
.await
.map_err(ContractError::CallError)?;
let events = logs
.into_iter()
.map(|log| {
// ethabi parses the unindexed and indexed logs together to a
// vector of tokens
let tokens = self
.event
.parse_log(RawLog {
topics: log.topics,
data: log.data.0,
})?
.params
.into_iter()
.map(|param| param.value)
.collect:: >(D::from_tokens(tokens)?)
})
.collect::