From 9b198b6b8a2243fc8c007d4779f4ff5fb6b4450c Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:36:27 +0200 Subject: [PATCH] chore: add conversions --- .../primitives/src/transaction/signed.rs | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/crates/optimism/primitives/src/transaction/signed.rs b/crates/optimism/primitives/src/transaction/signed.rs index c9b13bd0d7f8..1c0f69ca218c 100644 --- a/crates/optimism/primitives/src/transaction/signed.rs +++ b/crates/optimism/primitives/src/transaction/signed.rs @@ -3,8 +3,8 @@ use crate::OpTxType; use alloc::vec::Vec; use alloy_consensus::{ - transaction::RlpEcdsaTx, SignableTransaction, Transaction, TxEip1559, TxEip2930, TxEip7702, - TxLegacy, Typed2718, + transaction::RlpEcdsaTx, SignableTransaction, Signed, Transaction, TxEip1559, TxEip2930, + TxEip7702, TxLegacy, Typed2718, }; use alloy_eips::{ eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718}, @@ -22,7 +22,7 @@ use core::{ use derive_more::{AsRef, Deref}; #[cfg(not(feature = "std"))] use once_cell::sync::OnceCell as OnceLock; -use op_alloy_consensus::{OpTypedTransaction, TxDeposit}; +use op_alloy_consensus::{OpPooledTransaction, OpTypedTransaction, TxDeposit}; #[cfg(any(test, feature = "reth-codec"))] use proptest as _; use reth_primitives::transaction::{recover_signer, recover_signer_unchecked}; @@ -418,6 +418,45 @@ impl Hash for OpTransactionSigned { } } +impl From> for OpTransactionSigned { + fn from(value: Signed) -> Self { + let (tx, signature, hash) = value.into_parts(); + Self { hash: hash.into(), signature, transaction: tx.into() } + } +} + +impl From> for OpTransactionSigned { + fn from(value: Signed) -> Self { + let (tx, signature, hash) = value.into_parts(); + Self { hash: hash.into(), signature, transaction: tx.into() } + } +} + +impl From> for OpTransactionSigned { + fn from(value: Signed) -> Self { + let (tx, signature, hash) = value.into_parts(); + Self { hash: hash.into(), signature, transaction: tx.into() } + } +} + +impl From> for OpTransactionSigned { + fn from(value: Signed) -> Self { + let (tx, signature, hash) = value.into_parts(); + Self { hash: hash.into(), signature, transaction: tx.into() } + } +} + +impl From for OpTransactionSigned { + fn from(tx: OpPooledTransaction) -> Self { + match tx { + OpPooledTransaction::Legacy(signed) => signed.into(), + OpPooledTransaction::Eip2930(signed) => signed.into(), + OpPooledTransaction::Eip1559(signed) => signed.into(), + OpPooledTransaction::Eip7702(signed) => signed.into(), + } + } +} + #[cfg(any(test, feature = "arbitrary"))] impl<'a> arbitrary::Arbitrary<'a> for OpTransactionSigned { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result {