Skip to main content

anvil/eth/backend/
validate.rs

1//! Support for validating transactions at certain stages
2
3use crate::eth::error::{BlockchainError, InvalidTransactionError};
4use alloy_evm::EvmEnv;
5use anvil_core::eth::transaction::PendingTransaction;
6use revm::state::AccountInfo;
7
8/// A trait for validating transactions
9#[async_trait::async_trait]
10pub trait TransactionValidator<T> {
11    /// Validates the transaction's validity when it comes to nonce, payment
12    ///
13    /// This is intended to be checked before the transaction makes it into the pool and whether it
14    /// should rather be outright rejected if the sender has insufficient funds.
15    async fn validate_pool_transaction(
16        &self,
17        tx: &PendingTransaction<T>,
18    ) -> Result<(), BlockchainError>;
19
20    /// Validates the transaction against a specific account before entering the pool
21    fn validate_pool_transaction_for(
22        &self,
23        tx: &PendingTransaction<T>,
24        account: &AccountInfo,
25        evm_env: &EvmEnv,
26    ) -> Result<(), InvalidTransactionError>;
27
28    /// Validates the transaction against a specific account
29    ///
30    /// This should succeed if the transaction is ready to be executed
31    fn validate_for(
32        &self,
33        tx: &PendingTransaction<T>,
34        account: &AccountInfo,
35        evm_env: &EvmEnv,
36    ) -> Result<(), InvalidTransactionError>;
37}