mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: implement tx validator for either (#10328)
This commit is contained in:
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user