anvil/eth/backend/
validate.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Support for validating transactions at certain stages

use crate::eth::error::{BlockchainError, InvalidTransactionError};
use anvil_core::eth::transaction::PendingTransaction;
use foundry_evm::revm::primitives::{AccountInfo, EnvWithHandlerCfg};

/// A trait for validating transactions
#[async_trait::async_trait]
pub trait TransactionValidator {
    /// Validates the transaction's validity when it comes to nonce, payment
    ///
    /// This is intended to be checked before the transaction makes it into the pool and whether it
    /// should rather be outright rejected if the sender has insufficient funds.
    async fn validate_pool_transaction(
        &self,
        tx: &PendingTransaction,
    ) -> Result<(), BlockchainError>;

    /// Validates the transaction against a specific account before entering the pool
    fn validate_pool_transaction_for(
        &self,
        tx: &PendingTransaction,
        account: &AccountInfo,
        env: &EnvWithHandlerCfg,
    ) -> Result<(), InvalidTransactionError>;

    /// Validates the transaction against a specific account
    ///
    /// This should succeed if the transaction is ready to be executed
    fn validate_for(
        &self,
        tx: &PendingTransaction,
        account: &AccountInfo,
        env: &EnvWithHandlerCfg,
    ) -> Result<(), InvalidTransactionError>;
}