substreams_ethereum_core/
function.rs1use crate::pb::eth::v2::Call;
2
3pub trait Function: Sized {
4 const NAME: &'static str;
5
6 fn match_call(log: &Call) -> bool;
7 fn decode(log: &Call) -> Result<Self, String>;
8 fn encode(&self) -> Vec<u8>;
9
10 fn match_and_decode(call: impl AsRef<Call>) -> Option<Self> {
14 let call = call.as_ref();
15 if !Self::match_call(call) {
16 return None;
17 }
18
19 match Self::decode(&call) {
20 Ok(function) => Some(function),
21 Err(err) => {
22 substreams::log::info!(
23 "Call for function `{}` at index {} matched but failed to decode with error: {}",
24 Self::NAME,
25 call.index,
26 err
27 );
28 None
29 }
30 }
31 }
32}
33
34impl AsRef<Call> for Call {
35 fn as_ref(&self) -> &Self {
36 self
37 }
38}