Skip to content

Commit

Permalink
chore: add Optxenvelope conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Dec 14, 2024
1 parent 75bcc8c commit 78f9f28
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions crates/consensus/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Defines the exact transaction variants that are allowed to be propagated over the eth p2p
//! protocol in op.
use crate::OpTxType;
use crate::{OpTxEnvelope, OpTxType};
use alloy_consensus::{
transaction::{RlpEcdsaTx, TxEip1559, TxEip2930, TxLegacy},
SignableTransaction, Signed, Transaction, TxEip7702, TxEnvelope, Typed2718,
Expand Down Expand Up @@ -104,7 +104,7 @@ impl OpPooledTransaction {
}
}

/// Converts the transaction into [`TxEnvelope`].
/// Converts the transaction into the ethereum [`TxEnvelope`].
pub fn into_envelope(self) -> TxEnvelope {
match self {
Self::Legacy(tx) => tx.into(),
Expand All @@ -114,6 +114,16 @@ impl OpPooledTransaction {
}
}

/// Converts the transaction into the optimism [`OpTxEnvelope`].
pub fn into_op_envelope(self) -> OpTxEnvelope {
match self {
Self::Legacy(tx) => tx.into(),
Self::Eip2930(tx) => tx.into(),
Self::Eip1559(tx) => tx.into(),
Self::Eip7702(tx) => tx.into(),
}
}

/// Returns the [`TxLegacy`] variant if the transaction is a legacy transaction.
pub const fn as_legacy(&self) -> Option<&TxLegacy> {
match self {
Expand Down Expand Up @@ -425,6 +435,12 @@ impl From<OpPooledTransaction> for TxEnvelope {
}
}

impl From<OpPooledTransaction> for OpTxEnvelope {
fn from(tx: OpPooledTransaction) -> Self {
tx.into_op_envelope()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 78f9f28

Please sign in to comment.