revm/handler/handle_types/
pre_execution.rs
1use super::{GenericContextHandle, GenericContextHandleRet};
3use crate::{
4 handler::mainnet,
5 primitives::{db::Database, EVMError, Spec},
6 Context, ContextPrecompiles,
7};
8use std::sync::Arc;
9
10pub type LoadPrecompilesHandle<'a, DB> = Arc<dyn Fn() -> ContextPrecompiles<DB> + 'a>;
12
13pub type LoadAccountsHandle<'a, EXT, DB> = GenericContextHandle<'a, EXT, DB>;
17
18pub type DeductCallerHandle<'a, EXT, DB> = GenericContextHandle<'a, EXT, DB>;
20
21pub type ApplyEIP7702AuthListHandle<'a, EXT, DB> = GenericContextHandleRet<'a, EXT, DB, u64>;
23
24pub struct PreExecutionHandler<'a, EXT, DB: Database> {
26 pub load_precompiles: LoadPrecompilesHandle<'a, DB>,
28 pub load_accounts: LoadAccountsHandle<'a, EXT, DB>,
30 pub deduct_caller: DeductCallerHandle<'a, EXT, DB>,
32 pub apply_eip7702_auth_list: ApplyEIP7702AuthListHandle<'a, EXT, DB>,
34}
35
36impl<'a, EXT: 'a, DB: Database + 'a> PreExecutionHandler<'a, EXT, DB> {
37 pub fn new<SPEC: Spec + 'a>() -> Self {
39 Self {
40 load_precompiles: Arc::new(mainnet::load_precompiles::<SPEC, DB>),
41 load_accounts: Arc::new(mainnet::load_accounts::<SPEC, EXT, DB>),
42 deduct_caller: Arc::new(mainnet::deduct_caller::<SPEC, EXT, DB>),
43 apply_eip7702_auth_list: Arc::new(mainnet::apply_eip7702_auth_list::<SPEC, EXT, DB>),
44 }
45 }
46}
47
48impl<EXT, DB: Database> PreExecutionHandler<'_, EXT, DB> {
49 pub fn deduct_caller(&self, context: &mut Context<EXT, DB>) -> Result<(), EVMError<DB::Error>> {
51 (self.deduct_caller)(context)
52 }
53
54 pub fn load_accounts(&self, context: &mut Context<EXT, DB>) -> Result<(), EVMError<DB::Error>> {
56 (self.load_accounts)(context)
57 }
58
59 pub fn apply_eip7702_auth_list(
61 &self,
62 context: &mut Context<EXT, DB>,
63 ) -> Result<u64, EVMError<DB::Error>> {
64 (self.apply_eip7702_auth_list)(context)
65 }
66
67 pub fn load_precompiles(&self) -> ContextPrecompiles<DB> {
69 (self.load_precompiles)()
70 }
71}