feat: Extend Maybeconditional with helper fn (#14511)

This commit is contained in:
Joseph Zhao
2025-02-16 00:22:38 +08:00
committed by GitHub
parent cb615cf5e1
commit 22badc8155
2 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,6 @@
//! Additional support for pooled transactions with [`TransactionConditional`]
use alloy_consensus::conditional::BlockConditionalAttributes;
use alloy_rpc_types_eth::erc4337::TransactionConditional;
/// Helper trait that allows attaching a [`TransactionConditional`].
@ -10,6 +11,11 @@ pub trait MaybeConditionalTransaction {
/// Get attached [`TransactionConditional`] if any.
fn conditional(&self) -> Option<&TransactionConditional>;
/// Check if the conditional has exceeded the block attributes.
fn has_exceeded_block_attributes(&self, block_attr: &BlockConditionalAttributes) -> bool {
self.conditional().map(|tc| tc.has_exceeded_block_attributes(block_attr)).unwrap_or(false)
}
/// Helper that sets the conditional and returns the instance again
fn with_conditional(mut self, conditional: TransactionConditional) -> Self
where

View File

@ -47,10 +47,8 @@ where
};
let mut to_remove = Vec::new();
for tx in &pool.pooled_transactions() {
if let Some(conditional) = tx.transaction.conditional() {
if conditional.has_exceeded_block_attributes(&block_attr) {
to_remove.push(*tx.hash());
}
if tx.transaction.has_exceeded_block_attributes(&block_attr) {
to_remove.push(*tx.hash());
}
}
let _ = pool.remove_transactions(to_remove);