feat: introduce EthLogDecode trait
This commit is contained in:
parent
e071b32535
commit
c4d87d11b8
|
@ -28,6 +28,9 @@ pub use factory::ContractFactory;
|
|||
mod event;
|
||||
pub use event::EthEvent;
|
||||
|
||||
mod log;
|
||||
pub use log::{decode_logs, EthLogDecode};
|
||||
|
||||
mod stream;
|
||||
|
||||
mod multicall;
|
||||
|
|
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue