feat: introduce EthLogDecode trait

This commit is contained in:
Matthias Seitz 2021-03-18 12:25:14 +01:00
parent e071b32535
commit c4d87d11b8
2 changed files with 17 additions and 0 deletions

View File

@ -28,6 +28,9 @@ pub use factory::ContractFactory;
mod event; mod event;
pub use event::EthEvent; pub use event::EthEvent;
mod log;
pub use log::{decode_logs, EthLogDecode};
mod stream; mod stream;
mod multicall; mod multicall;

View File

@ -0,0 +1,14 @@
//! 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`
pub trait EthLogDecode {
/// 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.into_iter().map(T::decode_log).collect()
}