revm/handler/handle_types/
pre_execution.rsuse super::{GenericContextHandle, GenericContextHandleRet};
use crate::{
handler::mainnet,
primitives::{db::Database, EVMError, Spec},
Context, ContextPrecompiles,
};
use std::sync::Arc;
pub type LoadPrecompilesHandle<'a, DB> = Arc<dyn Fn() -> ContextPrecompiles<DB> + 'a>;
pub type LoadAccountsHandle<'a, EXT, DB> = GenericContextHandle<'a, EXT, DB>;
pub type DeductCallerHandle<'a, EXT, DB> = GenericContextHandle<'a, EXT, DB>;
pub type ApplyEIP7702AuthListHandle<'a, EXT, DB> = GenericContextHandleRet<'a, EXT, DB, u64>;
pub struct PreExecutionHandler<'a, EXT, DB: Database> {
pub load_precompiles: LoadPrecompilesHandle<'a, DB>,
pub load_accounts: LoadAccountsHandle<'a, EXT, DB>,
pub deduct_caller: DeductCallerHandle<'a, EXT, DB>,
pub apply_eip7702_auth_list: ApplyEIP7702AuthListHandle<'a, EXT, DB>,
}
impl<'a, EXT: 'a, DB: Database + 'a> PreExecutionHandler<'a, EXT, DB> {
pub fn new<SPEC: Spec + 'a>() -> Self {
Self {
load_precompiles: Arc::new(mainnet::load_precompiles::<SPEC, DB>),
load_accounts: Arc::new(mainnet::load_accounts::<SPEC, EXT, DB>),
deduct_caller: Arc::new(mainnet::deduct_caller::<SPEC, EXT, DB>),
apply_eip7702_auth_list: Arc::new(mainnet::apply_eip7702_auth_list::<SPEC, EXT, DB>),
}
}
}
impl<EXT, DB: Database> PreExecutionHandler<'_, EXT, DB> {
pub fn deduct_caller(&self, context: &mut Context<EXT, DB>) -> Result<(), EVMError<DB::Error>> {
(self.deduct_caller)(context)
}
pub fn load_accounts(&self, context: &mut Context<EXT, DB>) -> Result<(), EVMError<DB::Error>> {
(self.load_accounts)(context)
}
pub fn apply_eip7702_auth_list(
&self,
context: &mut Context<EXT, DB>,
) -> Result<u64, EVMError<DB::Error>> {
(self.apply_eip7702_auth_list)(context)
}
pub fn load_precompiles(&self) -> ContextPrecompiles<DB> {
(self.load_precompiles)()
}
}