1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::indexer::TemplateManager;
use crate::process_logs::ExecutionMode;
use alloy::primitives::Address;
use alloy::providers::RootProvider;
use alloy::rpc::types::eth::Log;
use alloy::transports::http::{Client, Http};
use async_trait::async_trait;
use std::sync::Arc;

pub struct Context {
    pub log: Log,
    pub provider: RootProvider<Http<Client>>,
    pub templates: TemplateManager,
    pub contract_address: Address
}

pub type HandleInstance = Arc<Box<(dyn Handler + Send + Sync)>>;

#[async_trait]
pub trait Handler {
    async fn handle(&self, params: Context);
    fn get_source(&self) -> String;
    fn is_template(&self) -> bool;
    fn get_event_signature(&self) -> String;
}

#[derive(Clone)]
pub struct HandlerConfig {
    pub start_block: u64,
    pub step: u64,
    pub address: String,
    pub handler: HandleInstance,
    pub provider: RootProvider<Http<Client>>,
    pub templates: TemplateManager,
    pub execution_mode: ExecutionMode
}