alloy_sol_types/types/interface/event.rs
1use crate::{Result, Word};
2use alloy_primitives::Log;
3
4/// A collection of [`SolEvent`]s.
5///
6/// [`SolEvent`]: crate::SolEvent
7///
8/// # Implementer's Guide
9///
10/// It should not be necessary to implement this trait manually. Instead, use
11/// the [`sol!`](crate::sol!) procedural macro to parse Solidity syntax into
12/// types that implement this trait.
13pub trait SolEventInterface: Sized {
14 /// The name of this type.
15 const NAME: &'static str;
16
17 /// The number of variants.
18 const COUNT: usize;
19
20 /// Decode the events from the given log info.
21 fn decode_raw_log(topics: &[Word], data: &[u8], validate: bool) -> Result<Self>;
22
23 /// Decode the events from the given log object.
24 fn decode_log(log: &Log, validate: bool) -> Result<Log<Self>> {
25 Self::decode_raw_log(log.topics(), &log.data.data, validate)
26 .map(|data| Log { address: log.address, data })
27 }
28}