#![allow(clippy::return_self_not_must_use)]
use crate::EthLogDecode;
use ethers_core::{
abi::{Detokenize, Error as AbiError, RawLog},
types::{Log, H256},
};
use std::borrow::Cow;
if_providers! {
use std::borrow::Borrow;
use std::marker::PhantomData;
use ethers_core::types::Filter;
use ethers_providers::Middleware;
use crate::event::Event;
}
pub fn parse_log<D>(log: Log) -> std::result::Result<D, AbiError>
where
D: EthLogDecode,
{
D::decode_log(&RawLog { topics: log.topics, data: log.data.to_vec() })
}
pub trait EthEvent: Detokenize + Send + Sync {
fn name() -> Cow<'static, str>;
fn signature() -> H256;
fn abi_signature() -> Cow<'static, str>;
fn decode_log(log: &RawLog) -> Result<Self, ethers_core::abi::Error>
where
Self: Sized;
fn is_anonymous() -> bool;
#[cfg(feature = "providers")]
fn new<B, M>(filter: Filter, provider: B) -> Event<B, M, Self>
where
Self: Sized,
B: Borrow<M>,
M: Middleware,
{
let filter = filter.event(&Self::abi_signature());
Event { filter, provider, datatype: PhantomData, _m: PhantomData }
}
}
impl<T: EthEvent> EthLogDecode for T {
fn decode_log(log: &RawLog) -> Result<Self, ethers_core::abi::Error>
where
Self: Sized,
{
T::decode_log(log)
}
}