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
37
38
39
40
41
42
43
44
45
46
47
48
49
use alloy_primitives::Address;
use colored::Colorize;
use tracing::info;

use crate::ParserMetricEvents;

/// metric event for traces
#[derive(Clone, Debug)]
pub enum DynamicContractMetricEvent {
    /// recorded a new contract metric
    ContractMetricRecieved(ContractMetric),
}

impl DynamicContractMetricEvent {
    pub(crate) fn get_addr(&self) -> String {
        match self {
            DynamicContractMetricEvent::ContractMetricRecieved(val) => {
                format!("{:#x}", val.address)
            }
        }
    }
}

impl From<DynamicContractMetricEvent> for ParserMetricEvents {
    fn from(val: DynamicContractMetricEvent) -> Self {
        ParserMetricEvents::DynamicContractMetricRecieved(val)
    }
}

#[derive(Clone, Debug)]
pub struct ContractMetric {
    pub address:         Address,
    pub function_called: String,
}

impl ContractMetric {
    pub fn new(address: Address, function_called: String) -> Self {
        Self { address, function_called }
    }

    pub fn trace(&self) {
        let message = format!(
            "Successfuly Parsed Contract: {} --- Function Called: {}",
            format!("{:#x}", self.address).bright_blue().bold(),
            self.function_called.to_string().bright_blue().bold(),
        );
        info!(message = message);
    }
}