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
50
51
52
53
54
55
56
57
58
59
60
pub mod exec_tracer;
pub mod gasman;
mod utils;

use exec_tracer::ExecTracer;
use gasman::GasMan;

use cfx_executor::{
    executive_observer::{AsTracer, DrainTrace, TracerTrait},
    machine::Machine,
};
use cfx_vm_tracer_derive::{AsTracer, DrainTrace};
use std::sync::Arc;

use alloy_rpc_types_trace::geth::GethDebugTracingOptions;
use geth_tracer::{GethTracer, TxExecContext};

#[derive(AsTracer, DrainTrace)]
pub struct Observer {
    pub tracer: Option<ExecTracer>,
    pub gas_man: Option<GasMan>,
    pub geth_tracer: Option<GethTracer>,
}

impl Observer {
    pub fn with_tracing() -> Self {
        Observer {
            tracer: Some(ExecTracer::default()),
            gas_man: None,
            geth_tracer: None,
        }
    }

    pub fn with_no_tracing() -> Self {
        Observer {
            tracer: None,
            gas_man: None,
            geth_tracer: None,
        }
    }

    pub fn virtual_call() -> Self {
        Observer {
            tracer: Some(ExecTracer::default()),
            gas_man: Some(GasMan::default()),
            geth_tracer: None,
        }
    }

    pub fn geth_tracer(
        tx_exec_context: TxExecContext, machine: Arc<Machine>,
        opts: GethDebugTracingOptions,
    ) -> Self {
        Observer {
            tracer: None,
            gas_man: None,
            geth_tracer: Some(GethTracer::new(tx_exec_context, machine, opts)),
        }
    }
}