use crate::{Code, DispatchError, Key, Weight, evm::Bytes, primitives::ExecReturnValue};
use alloc::vec::Vec;
use environmental::environmental;
use sp_core::{H160, H256, U256};
environmental!(tracer: dyn Tracing + 'static);
pub const PVM_FUEL_NAME: &str = "pvm_fuel";
pub fn trace<R, F: FnOnce() -> R>(tracer: &mut (dyn Tracing + 'static), f: F) -> R {
tracer::using_once(tracer, f)
}
pub(crate) fn if_tracing<R, F: FnOnce(&mut (dyn Tracing + 'static)) -> R>(f: F) -> Option<R> {
tracer::with(f)
}
pub trait FrameTraceInfo {
fn gas_left(&self) -> u64;
fn weight_consumed(&self) -> Weight;
fn last_frame_output(&self) -> Bytes;
}
pub trait EVMFrameTraceInfo: FrameTraceInfo {
fn memory_snapshot(&self, limit: usize) -> Vec<Bytes>;
fn stack_snapshot(&self) -> Vec<Bytes>;
}
pub trait Tracing {
fn watch_address(&mut self, _addr: &H160) {}
fn enter_child_span(
&mut self,
_from: H160,
_to: H160,
_delegate_call: Option<H160>,
_is_read_only: bool,
_value: U256,
_input: &[u8],
_gas_limit: u64,
) {
}
fn terminate(
&mut self,
_contract_address: H160,
_beneficiary_address: H160,
_gas_left: u64,
_value: U256,
) {
}
fn instantiate_code(&mut self, _code: &Code, _salt: Option<&[u8; 32]>) {}
fn balance_read(&mut self, _addr: &H160, _value: U256) {}
fn storage_read(&mut self, _key: &Key, _value: Option<&[u8]>) {}
fn storage_write(
&mut self,
_key: &Key,
_old_value: Option<Vec<u8>>,
_new_value: Option<&[u8]>,
) {
}
fn log_event(&mut self, _event: H160, _topics: &[H256], _data: &[u8]) {}
fn exit_child_span(
&mut self,
_output: &ExecReturnValue,
_gas_used: u64,
_weight_consumed: Weight,
) {
}
fn exit_child_span_with_error(
&mut self,
_error: DispatchError,
_gas_used: u64,
_weight_consumed: Weight,
) {
}
fn is_execution_tracer(&self) -> bool {
false
}
fn enter_opcode(&mut self, _pc: u64, _opcode: u8, _trace_info: &dyn EVMFrameTraceInfo) {}
fn enter_ecall(
&mut self,
_ecall: &'static str,
_args: &[u64],
_trace_info: &dyn FrameTraceInfo,
) {
}
fn exit_step(&mut self, _trace_info: &dyn FrameTraceInfo, _returned: Option<u64>) {}
fn dispatch_result(&mut self, _base_call_weight: Weight, _weight_consumed: Weight) {}
}