feat: implement tx validator for either (#10328)

This commit is contained in:
Matthias Seitz
2024-08-15 12:43:51 -07:00
committed by GitHub
parent 668945f97c
commit b6f02a8e9a

View File

@ -5,6 +5,7 @@ use crate::{
identifier::{SenderId, TransactionId},
traits::{PoolTransaction, TransactionOrigin},
};
use futures_util::future::Either;
use reth_primitives::{
Address, BlobTransactionSidecar, IntoRecoveredTransaction,
PooledTransactionsElementEcRecovered, SealedBlock, TransactionSignedEcRecovered, TxHash, B256,
@ -209,6 +210,42 @@ pub trait TransactionValidator: Send + Sync {
fn on_new_head_block(&self, _new_tip_block: &SealedBlock) {}
}
impl<A, B> TransactionValidator for Either<A, B>
where
A: TransactionValidator,
B: TransactionValidator<Transaction = A::Transaction>,
{
type Transaction = A::Transaction;
async fn validate_transaction(
&self,
origin: TransactionOrigin,
transaction: Self::Transaction,
) -> TransactionValidationOutcome<Self::Transaction> {
match self {
Self::Left(v) => v.validate_transaction(origin, transaction).await,
Self::Right(v) => v.validate_transaction(origin, transaction).await,
}
}
async fn validate_transactions(
&self,
transactions: Vec<(TransactionOrigin, Self::Transaction)>,
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
match self {
Self::Left(v) => v.validate_transactions(transactions).await,
Self::Right(v) => v.validate_transactions(transactions).await,
}
}
fn on_new_head_block(&self, new_tip_block: &SealedBlock) {
match self {
Self::Left(v) => v.on_new_head_block(new_tip_block),
Self::Right(v) => v.on_new_head_block(new_tip_block),
}
}
}
/// A valid transaction in the pool.
///
/// This is used as the internal representation of a transaction inside the pool.