revm/handler/handle_types/
validation.rs
1use crate::{
2 handler::mainnet,
3 primitives::{db::Database, EVMError, Env, Spec},
4 Context,
5};
6use std::sync::Arc;
7
8pub type ValidateEnvHandle<'a, DB> =
10 Arc<dyn Fn(&Env) -> Result<(), EVMError<<DB as Database>::Error>> + 'a>;
11
12pub type ValidateTxEnvAgainstState<'a, EXT, DB> =
15 Arc<dyn Fn(&mut Context<EXT, DB>) -> Result<(), EVMError<<DB as Database>::Error>> + 'a>;
16
17pub type ValidateInitialTxGasHandle<'a, DB> =
19 Arc<dyn Fn(&Env) -> Result<u64, EVMError<<DB as Database>::Error>> + 'a>;
20
21pub struct ValidationHandler<'a, EXT, DB: Database> {
23 pub initial_tx_gas: ValidateInitialTxGasHandle<'a, DB>,
25 pub tx_against_state: ValidateTxEnvAgainstState<'a, EXT, DB>,
27 pub env: ValidateEnvHandle<'a, DB>,
29}
30
31impl<'a, EXT: 'a, DB: Database + 'a> ValidationHandler<'a, EXT, DB> {
32 pub fn new<SPEC: Spec + 'a>() -> Self {
34 Self {
35 initial_tx_gas: Arc::new(mainnet::validate_initial_tx_gas::<SPEC, DB>),
36 env: Arc::new(mainnet::validate_env::<SPEC, DB>),
37 tx_against_state: Arc::new(mainnet::validate_tx_against_state::<SPEC, EXT, DB>),
38 }
39 }
40}
41
42impl<EXT, DB: Database> ValidationHandler<'_, EXT, DB> {
43 pub fn env(&self, env: &Env) -> Result<(), EVMError<DB::Error>> {
45 (self.env)(env)
46 }
47
48 pub fn initial_tx_gas(&self, env: &Env) -> Result<u64, EVMError<DB::Error>> {
50 (self.initial_tx_gas)(env)
51 }
52
53 pub fn tx_against_state(
55 &self,
56 context: &mut Context<EXT, DB>,
57 ) -> Result<(), EVMError<DB::Error>> {
58 (self.tx_against_state)(context)
59 }
60}