use super::HlEvm; use crate::evm::{ api::{ builder::HlBuilder, ctx::{DefaultHl, HlContext}, }, spec::HlSpecId, transaction::HlTxEnv, }; use reth_evm::{Database, EvmEnv, EvmFactory, precompiles::PrecompilesMap}; use reth_revm::Context; use revm::{ Inspector, context::{ TxEnv, result::{EVMError, HaltReason}, }, inspector::NoOpInspector, precompile::{PrecompileSpecId, Precompiles}, }; /// Factory producing [`HlEvm`]. #[derive(Debug, Default, Clone, Copy)] #[non_exhaustive] pub struct HlEvmFactory; impl EvmFactory for HlEvmFactory { type Evm>> = HlEvm; type Context = HlContext; type Tx = HlTxEnv; type Error = EVMError; type HaltReason = HaltReason; type Spec = HlSpecId; type Precompiles = PrecompilesMap; fn create_evm( &self, db: DB, input: EvmEnv, ) -> Self::Evm { let spec_id = *input.spec_id(); HlEvm { inner: Context::hl() .with_block(input.block_env) .with_cfg(input.cfg_env) .with_db(db) .build_hl_with_inspector(NoOpInspector {}) .with_precompiles(hl_precompiles(spec_id)), inspect: false, } } fn create_evm_with_inspector< DB: Database, I: Inspector>, >( &self, db: DB, input: EvmEnv, inspector: I, ) -> Self::Evm { let spec_id = *input.spec_id(); HlEvm { inner: Context::hl() .with_block(input.block_env) .with_cfg(input.cfg_env) .with_db(db) .build_hl_with_inspector(inspector) .with_precompiles(hl_precompiles(spec_id)), inspect: true, } } } fn hl_precompiles(spec_id: HlSpecId) -> PrecompilesMap { let spec = PrecompileSpecId::from_spec_id(spec_id.into()); PrecompilesMap::from_static(Precompiles::new(spec)) }