use alloy_dyn_abi::DynSolValue;
use eyre::Result;
pub trait VariableHandler {
fn get_variable_value(&self, name: &str, snapshot_id: usize) -> Result<DynSolValue>;
}
pub trait MappingArrayHandler {
fn get_mapping_or_array_value(
&self,
root: DynSolValue,
indices: Vec<DynSolValue>,
snapshot_id: usize,
) -> Result<DynSolValue>;
}
pub trait FunctionCallHandler {
fn call_function(
&self,
name: &str,
args: &[DynSolValue],
callee: Option<&DynSolValue>,
snapshot_id: usize,
) -> Result<DynSolValue>;
}
pub trait MemberAccessHandler {
fn access_member(
&self,
value: DynSolValue,
member: &str,
snapshot_id: usize,
) -> Result<DynSolValue>;
}
pub trait MsgHandler {
fn get_msg_sender(&self, snapshot_id: usize) -> Result<DynSolValue>;
fn get_msg_value(&self, snapshot_id: usize) -> Result<DynSolValue>;
}
pub trait TxHandler {
fn get_tx_origin(&self, snapshot_id: usize) -> Result<DynSolValue>;
}
pub trait ValidationHandler {
fn validate_value(&self, value: DynSolValue) -> Result<DynSolValue>;
}
pub trait BlockHandler {
fn get_block_number(&self, snapshot_id: usize) -> Result<DynSolValue>;
fn get_block_timestamp(&self, snapshot_id: usize) -> Result<DynSolValue>;
}
#[derive(Default)]
pub struct EvaluatorHandlers {
pub variable_handler: Option<Box<dyn VariableHandler>>,
pub mapping_array_handler: Option<Box<dyn MappingArrayHandler>>,
pub function_call_handler: Option<Box<dyn FunctionCallHandler>>,
pub member_access_handler: Option<Box<dyn MemberAccessHandler>>,
pub msg_handler: Option<Box<dyn MsgHandler>>,
pub tx_handler: Option<Box<dyn TxHandler>>,
pub block_handler: Option<Box<dyn BlockHandler>>,
pub validation_handler: Option<Box<dyn ValidationHandler>>,
}
impl Clone for EvaluatorHandlers {
fn clone(&self) -> Self {
Self::default()
}
}
impl EvaluatorHandlers {
pub fn new() -> Self {
Self::default()
}
pub fn with_variable_handler(mut self, handler: Box<dyn VariableHandler>) -> Self {
self.variable_handler = Some(handler);
self
}
pub fn with_mapping_array_handler(mut self, handler: Box<dyn MappingArrayHandler>) -> Self {
self.mapping_array_handler = Some(handler);
self
}
pub fn with_function_call_handler(mut self, handler: Box<dyn FunctionCallHandler>) -> Self {
self.function_call_handler = Some(handler);
self
}
pub fn with_member_access_handler(mut self, handler: Box<dyn MemberAccessHandler>) -> Self {
self.member_access_handler = Some(handler);
self
}
pub fn with_msg_handler(mut self, handler: Box<dyn MsgHandler>) -> Self {
self.msg_handler = Some(handler);
self
}
pub fn with_tx_handler(mut self, handler: Box<dyn TxHandler>) -> Self {
self.tx_handler = Some(handler);
self
}
pub fn with_block_handler(mut self, handler: Box<dyn BlockHandler>) -> Self {
self.block_handler = Some(handler);
self
}
pub fn with_validation_handler(mut self, handler: Box<dyn ValidationHandler>) -> Self {
self.validation_handler = Some(handler);
self
}
}
pub mod debug;
pub mod edb;