Repository: paradigmxyz/reth (language: rust)

Issue:
Add helper trait for Op pooledtransaction for conditionals
with https://github.com/paradigmxyz/reth/pull/14311 we now have the conditional endpoint, but we still need a way to attach the conditional to the transaction before we add the tx to the pool.

This can be solved with a simple helper trait for setting the extension

```rust
trait MaybeConditionalTransaction {
  
  fn set_conditional(&mut self, conditional: TransactionConditional)
}
```

we need this for:

https://github.com/paradigmxyz/reth/blob/feeb92d5781f40b13074350aa22178d2839a7c55/crates/optimism/txpool/src/transaction.rs#L22-L22

## TODO

* introduce trait in op-transaction-pool crat 
* implement for OpPooledTransaction




Discussion / hints:
@mattsse i would like to work on this
assigned, although this is somewhat urgend so please open a draft shortly if you have bandwidth, ty

Fix patch:
diff --git a/crates/optimism/txpool/src/conditional.rs b/crates/optimism/txpool/src/conditional.rs
new file mode 100644
index 000000000000..7103feb8ae5e
--- /dev/null
+++ b/crates/optimism/txpool/src/conditional.rs
@@ -0,0 +1,18 @@
+//! Additional support for pooled transactions with [`TransactionConditional`]
+
+use alloy_rpc_types_eth::erc4337::TransactionConditional;
+
+/// Helper trait that allows attaching a [`TransactionConditional`].
+pub trait MaybeConditionalTransaction {
+    /// Attach a [`TransactionConditional`].
+    fn set_conditional(&mut self, conditional: TransactionConditional);
+
+    /// Helper that sets the conditional and returns the instance again
+    fn with_conditional(mut self, conditional: TransactionConditional) -> Self
+    where
+        Self: Sized,
+    {
+        self.set_conditional(conditional);
+        self
+    }
+}
diff --git a/crates/optimism/txpool/src/lib.rs b/crates/optimism/txpool/src/lib.rs
index f9c1165f3452..2055852549ea 100644
--- a/crates/optimism/txpool/src/lib.rs
+++ b/crates/optimism/txpool/src/lib.rs
@@ -13,6 +13,7 @@
 mod validator;
 pub use validator::{OpL1BlockInfo, OpTransactionValidator};
 
+pub mod conditional;
 mod transaction;
 pub use transaction::OpPooledTransaction;
 
diff --git a/crates/optimism/txpool/src/transaction.rs b/crates/optimism/txpool/src/transaction.rs
index 3cc83ed70720..55ebd0226093 100644
--- a/crates/optimism/txpool/src/transaction.rs
+++ b/crates/optimism/txpool/src/transaction.rs
@@ -1,3 +1,4 @@
+use crate::conditional::MaybeConditionalTransaction;
 use alloy_consensus::{
     transaction::Recovered, BlobTransactionSidecar, BlobTransactionValidationError, Typed2718,
 };
@@ -66,6 +67,12 @@ impl<Cons: SignedTransaction, Pooled> OpPooledTransaction<Cons, Pooled> {
     }
 }
 
+impl<Cons, Pooled> MaybeConditionalTransaction for OpPooledTransaction<Cons, Pooled> {
+    fn set_conditional(&mut self, conditional: TransactionConditional) {
+        self.conditional = Some(Box::new(conditional))
+    }
+}
+
 impl<Cons, Pooled> PoolTransaction for OpPooledTransaction<Cons, Pooled>
 where
     Cons: SignedTransaction + From<Pooled>,


Test patch: