mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: move EvmEnvProvider (#8420)
This commit is contained in:
@ -19,6 +19,7 @@ reth-storage-errors.workspace = true
|
||||
|
||||
revm.workspace = true
|
||||
|
||||
auto_impl.workspace = true
|
||||
futures-util.workspace = true
|
||||
parking_lot = { workspace = true, optional = true }
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId,
|
||||
|
||||
pub mod either;
|
||||
pub mod execute;
|
||||
pub mod provider;
|
||||
|
||||
#[cfg(any(test, feature = "test-utils"))]
|
||||
/// test helpers for mocking executor
|
||||
|
||||
89
crates/evm/src/provider.rs
Normal file
89
crates/evm/src/provider.rs
Normal file
@ -0,0 +1,89 @@
|
||||
//! Provider trait for populating the EVM environment.
|
||||
|
||||
use crate::ConfigureEvmEnv;
|
||||
use reth_primitives::{BlockHashOrNumber, Header};
|
||||
use reth_storage_errors::provider::ProviderResult;
|
||||
use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId};
|
||||
|
||||
/// A provider type that knows chain specific information required to configure a
|
||||
/// [CfgEnvWithHandlerCfg].
|
||||
///
|
||||
/// This type is mainly used to provide required data to configure the EVM environment that is
|
||||
/// usually stored on disk.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait EvmEnvProvider: Send + Sync {
|
||||
/// Fills the [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the given
|
||||
/// [BlockHashOrNumber].
|
||||
fn fill_env_at<EvmConfig>(
|
||||
&self,
|
||||
cfg: &mut CfgEnvWithHandlerCfg,
|
||||
block_env: &mut BlockEnv,
|
||||
at: BlockHashOrNumber,
|
||||
evm_config: EvmConfig,
|
||||
) -> ProviderResult<()>
|
||||
where
|
||||
EvmConfig: ConfigureEvmEnv;
|
||||
|
||||
/// Fills the default [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the
|
||||
/// given [Header].
|
||||
fn env_with_header<EvmConfig>(
|
||||
&self,
|
||||
header: &Header,
|
||||
evm_config: EvmConfig,
|
||||
) -> ProviderResult<(CfgEnvWithHandlerCfg, BlockEnv)>
|
||||
where
|
||||
EvmConfig: ConfigureEvmEnv,
|
||||
{
|
||||
let mut cfg = CfgEnvWithHandlerCfg::new_with_spec_id(CfgEnv::default(), SpecId::LATEST);
|
||||
let mut block_env = BlockEnv::default();
|
||||
self.fill_env_with_header::<EvmConfig>(&mut cfg, &mut block_env, header, evm_config)?;
|
||||
Ok((cfg, block_env))
|
||||
}
|
||||
|
||||
/// Fills the [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the given
|
||||
/// [Header].
|
||||
fn fill_env_with_header<EvmConfig>(
|
||||
&self,
|
||||
cfg: &mut CfgEnvWithHandlerCfg,
|
||||
block_env: &mut BlockEnv,
|
||||
header: &Header,
|
||||
evm_config: EvmConfig,
|
||||
) -> ProviderResult<()>
|
||||
where
|
||||
EvmConfig: ConfigureEvmEnv;
|
||||
|
||||
/// Fills the [BlockEnv] fields with values specific to the given [BlockHashOrNumber].
|
||||
fn fill_block_env_at(
|
||||
&self,
|
||||
block_env: &mut BlockEnv,
|
||||
at: BlockHashOrNumber,
|
||||
) -> ProviderResult<()>;
|
||||
|
||||
/// Fills the [BlockEnv] fields with values specific to the given [Header].
|
||||
fn fill_block_env_with_header(
|
||||
&self,
|
||||
block_env: &mut BlockEnv,
|
||||
header: &Header,
|
||||
) -> ProviderResult<()>;
|
||||
|
||||
/// Fills the [CfgEnvWithHandlerCfg] fields with values specific to the given
|
||||
/// [BlockHashOrNumber].
|
||||
fn fill_cfg_env_at<EvmConfig>(
|
||||
&self,
|
||||
cfg: &mut CfgEnvWithHandlerCfg,
|
||||
at: BlockHashOrNumber,
|
||||
evm_config: EvmConfig,
|
||||
) -> ProviderResult<()>
|
||||
where
|
||||
EvmConfig: ConfigureEvmEnv;
|
||||
|
||||
/// Fills the [CfgEnvWithHandlerCfg] fields with values specific to the given [Header].
|
||||
fn fill_cfg_env_with_header<EvmConfig>(
|
||||
&self,
|
||||
cfg: &mut CfgEnvWithHandlerCfg,
|
||||
header: &Header,
|
||||
evm_config: EvmConfig,
|
||||
) -> ProviderResult<()>
|
||||
where
|
||||
EvmConfig: ConfigureEvmEnv;
|
||||
}
|
||||
Reference in New Issue
Block a user