anvil/eth/backend/
validate.rs

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