use revm::{
inspectors::GasInspector,
interpreter::{CreateInputs, CreateOutcome, Interpreter},
};
use super::*;
use crate::console::ConsoleLogs;
#[derive(Debug, Clone)]
pub struct ArbiterInspector {
pub console_log: Option<ConsoleLogs>,
pub gas: Option<GasInspector>,
}
impl ArbiterInspector {
pub fn new(console_log: bool, gas: bool) -> Self {
let console_log = if console_log {
Some(ConsoleLogs::default())
} else {
None
};
let gas = if gas {
Some(GasInspector::default())
} else {
None
};
Self { console_log, gas }
}
}
impl Inspector<ArbiterDB> for ArbiterInspector {
#[inline]
fn initialize_interp(&mut self, interp: &mut Interpreter, context: &mut EvmContext<ArbiterDB>) {
if let Some(gas) = &mut self.gas {
gas.initialize_interp(interp, context);
}
}
#[inline]
fn step_end(&mut self, interp: &mut Interpreter, context: &mut EvmContext<ArbiterDB>) {
if let Some(gas) = &mut self.gas {
gas.step_end(interp, context);
}
}
#[inline]
fn call(
&mut self,
context: &mut EvmContext<ArbiterDB>,
inputs: &mut CallInputs,
) -> Option<CallOutcome> {
if let Some(console_log) = &mut self.console_log {
console_log.call(context, inputs)
} else {
None
}
}
#[inline]
fn call_end(
&mut self,
context: &mut EvmContext<ArbiterDB>,
inputs: &CallInputs,
outcome: CallOutcome,
) -> CallOutcome {
if let Some(gas) = &mut self.gas {
gas.call_end(context, inputs, outcome)
} else {
outcome
}
}
#[inline]
fn create_end(
&mut self,
_context: &mut EvmContext<ArbiterDB>,
_inputs: &CreateInputs,
outcome: CreateOutcome,
) -> CreateOutcome {
outcome
}
}