anvil/eth/backend/
validate.rs

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