2021-03-19 15:44:59 +00:00
|
|
|
//! Mod of types for ethereum logs
|
|
|
|
use ethers_core::abi::Error;
|
|
|
|
use ethers_core::abi::RawLog;
|
|
|
|
|
|
|
|
/// A trait for types (events) that can be decoded from a `RawLog`
|
2021-07-13 11:13:12 +00:00
|
|
|
pub trait EthLogDecode: Send + Sync {
|
2021-03-19 15:44:59 +00:00
|
|
|
/// decode from a `RawLog`
|
|
|
|
fn decode_log(log: &RawLog) -> Result<Self, Error>
|
|
|
|
where
|
|
|
|
Self: Sized;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Decodes a series of logs into a vector
|
|
|
|
pub fn decode_logs<T: EthLogDecode>(logs: &[RawLog]) -> Result<Vec<T>, Error> {
|
|
|
|
logs.iter().map(T::decode_log).collect()
|
|
|
|
}
|