From 1ffa3d147df51328e27140faf7038b090c0b4955 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Sat, 27 Jul 2024 02:04:15 +0200 Subject: [PATCH] impl `TryFrom for TransactionSignedNoHash` (#9823) --- crates/primitives/src/alloy_compat.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/primitives/src/alloy_compat.rs b/crates/primitives/src/alloy_compat.rs index 02cdf93e48..2dfe7ea8cb 100644 --- a/crates/primitives/src/alloy_compat.rs +++ b/crates/primitives/src/alloy_compat.rs @@ -2,8 +2,8 @@ use crate::{ constants::EMPTY_TRANSACTIONS, transaction::extract_chain_id, Block, Signature, Transaction, - TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxLegacy, - TxType, + TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, TxEip1559, TxEip2930, + TxEip4844, TxLegacy, TxType, }; use alloy_primitives::TxKind; use alloy_rlp::Error as RlpError; @@ -296,6 +296,17 @@ impl TryFrom for Signature { } } +impl TryFrom for TransactionSignedNoHash { + type Error = alloy_rpc_types::ConversionError; + + fn try_from(tx: alloy_rpc_types::Transaction) -> Result { + Ok(Self { + signature: tx.signature.ok_or(Self::Error::MissingSignature)?.try_into()?, + transaction: tx.try_into()?, + }) + } +} + #[cfg(test)] #[cfg(feature = "optimism")] mod tests {