From 4f00ed7bed2dece42182560a96dd9f50980a5b59 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 10 May 2025 10:00:13 +0200 Subject: [PATCH] chore: put op conversions in mod op (#16147) --- crates/primitives-traits/src/extended.rs | 101 +++++++++++------------ 1 file changed, 49 insertions(+), 52 deletions(-) diff --git a/crates/primitives-traits/src/extended.rs b/crates/primitives-traits/src/extended.rs index 4986485fa7..ddf339e7f1 100644 --- a/crates/primitives-traits/src/extended.rs +++ b/crates/primitives-traits/src/extended.rs @@ -14,15 +14,6 @@ use alloy_primitives::{ChainId, TxHash}; use alloy_rlp::{BufMut, Decodable, Encodable, Result as RlpResult}; use revm_primitives::{Address, Bytes, TxKind, B256, U256}; -#[cfg(feature = "op")] -use op_alloy_consensus::{OpPooledTransaction, OpTxEnvelope}; - -#[cfg(feature = "op")] -use alloy_primitives::Signature; - -#[cfg(feature = "op")] -use alloy_consensus::error::ValueError; - macro_rules! delegate { ($self:expr => $tx:ident.$method:ident($($arg:expr),*)) => { match $self { @@ -48,49 +39,6 @@ pub enum ExtendedTxEnvelope { Other(Other), } -#[cfg(feature = "op")] -impl TryFrom> - for ExtendedTxEnvelope -{ - type Error = OpTxEnvelope; - - fn try_from(value: ExtendedTxEnvelope) -> Result { - match value { - ExtendedTxEnvelope::BuiltIn(tx) => { - let converted_tx: OpPooledTransaction = tx.clone().try_into().map_err(|_| tx)?; - Ok(Self::BuiltIn(converted_tx)) - } - ExtendedTxEnvelope::Other(tx) => Ok(Self::Other(tx)), - } - } -} - -#[cfg(feature = "op")] -impl From for ExtendedTxEnvelope { - fn from(tx: OpPooledTransaction) -> Self { - Self::BuiltIn(tx.into()) - } -} - -#[cfg(feature = "op")] -impl TryFrom> for OpPooledTransaction { - type Error = ValueError; - - fn try_from(_tx: ExtendedTxEnvelope) -> Result { - match _tx { - ExtendedTxEnvelope::BuiltIn(inner) => inner.try_into(), - ExtendedTxEnvelope::Other(_tx) => Err(ValueError::new( - OpTxEnvelope::Legacy(alloy_consensus::Signed::new_unchecked( - alloy_consensus::TxLegacy::default(), - Signature::decode_rlp_vrs(&mut &[0u8; 65][..], |_| Ok(false)).unwrap(), - B256::default(), - )), - "Cannot convert custom transaction to OpPooledTransaction", - )), - } - } -} - impl Transaction for ExtendedTxEnvelope where B: Transaction, @@ -309,6 +257,55 @@ where } } +#[cfg(feature = "op")] +mod op { + use crate::ExtendedTxEnvelope; + use alloy_consensus::error::ValueError; + use alloy_primitives::{Signature, B256}; + use op_alloy_consensus::{OpPooledTransaction, OpTxEnvelope}; + + impl TryFrom> + for ExtendedTxEnvelope + { + type Error = OpTxEnvelope; + + fn try_from(value: ExtendedTxEnvelope) -> Result { + match value { + ExtendedTxEnvelope::BuiltIn(tx) => { + let converted_tx: OpPooledTransaction = + tx.clone().try_into().map_err(|_| tx)?; + Ok(Self::BuiltIn(converted_tx)) + } + ExtendedTxEnvelope::Other(tx) => Ok(Self::Other(tx)), + } + } + } + + impl From for ExtendedTxEnvelope { + fn from(tx: OpPooledTransaction) -> Self { + Self::BuiltIn(tx.into()) + } + } + + impl TryFrom> for OpPooledTransaction { + type Error = ValueError; + + fn try_from(_tx: ExtendedTxEnvelope) -> Result { + match _tx { + ExtendedTxEnvelope::BuiltIn(inner) => inner.try_into(), + ExtendedTxEnvelope::Other(_tx) => Err(ValueError::new( + OpTxEnvelope::Legacy(alloy_consensus::Signed::new_unchecked( + alloy_consensus::TxLegacy::default(), + Signature::decode_rlp_vrs(&mut &[0u8; 65][..], |_| Ok(false)).unwrap(), + B256::default(), + )), + "Cannot convert custom transaction to OpPooledTransaction", + )), + } + } + } +} + #[cfg(feature = "serde-bincode-compat")] mod serde_bincode_compat { use super::*;