feat: add validate transactions function (#5010)

This commit is contained in:
Matthias Seitz
2023-10-13 21:58:16 +02:00
committed by GitHub
parent 92ceb2fca9
commit 411893eba2
2 changed files with 24 additions and 2 deletions

View File

@ -56,9 +56,9 @@ where
/// See also [Self::validate_one]
pub fn validate_all(
&self,
transaction: Vec<(TransactionOrigin, Tx)>,
transactions: Vec<(TransactionOrigin, Tx)>,
) -> Vec<TransactionValidationOutcome<Tx>> {
transaction.into_iter().map(|(origin, tx)| self.validate_one(origin, tx)).collect()
transactions.into_iter().map(|(origin, tx)| self.validate_one(origin, tx)).collect()
}
}
@ -78,6 +78,13 @@ where
self.validate_one(origin, transaction)
}
async fn validate_transactions(
&self,
transactions: Vec<(TransactionOrigin, Self::Transaction)>,
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
self.validate_all(transactions)
}
fn on_new_head_block(&self, new_tip_block: &SealedBlock) {
self.inner.on_new_head_block(new_tip_block)
}

View File

@ -168,6 +168,21 @@ pub trait TransactionValidator: Send + Sync {
transaction: Self::Transaction,
) -> TransactionValidationOutcome<Self::Transaction>;
/// Validates a batch of transactions.
///
/// Must return all outcomes for the given transactions in the same order.
///
/// See also [Self::validate_transaction].
async fn validate_transactions(
&self,
transactions: Vec<(TransactionOrigin, Self::Transaction)>,
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
futures_util::future::join_all(
transactions.into_iter().map(|(origin, tx)| self.validate_transaction(origin, tx)),
)
.await
}
/// Invoked when the head block changes.
///
/// This can be used to update fork specific values (timestamp).