From 30d8ec74ffe530fc27b784b43d9fc423ef70f3de Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Tue, 17 Sep 2024 17:53:27 +0800 Subject: [PATCH] chore(reth-primitives): use derive_more::From when possible (#10917) --- crates/primitives/src/transaction/mod.rs | 32 +------------------- crates/primitives/src/transaction/variant.rs | 20 +----------- 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 42b590cc32..8d574a9bf8 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -75,7 +75,7 @@ pub(crate) static PARALLEL_SENDER_RECOVERY_THRESHOLD: Lazy = /// A raw transaction. /// /// Transaction types were introduced in [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718). -#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, derive_more::From)] #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))] pub enum Transaction { /// Legacy transaction (type `0x0`). @@ -690,36 +690,6 @@ impl Transaction { } } -impl From for Transaction { - fn from(tx: TxLegacy) -> Self { - Self::Legacy(tx) - } -} - -impl From for Transaction { - fn from(tx: TxEip2930) -> Self { - Self::Eip2930(tx) - } -} - -impl From for Transaction { - fn from(tx: TxEip1559) -> Self { - Self::Eip1559(tx) - } -} - -impl From for Transaction { - fn from(tx: TxEip4844) -> Self { - Self::Eip4844(tx) - } -} - -impl From for Transaction { - fn from(tx: TxEip7702) -> Self { - Self::Eip7702(tx) - } -} - #[cfg(any(test, feature = "reth-codec"))] impl reth_codecs::Compact for Transaction { // Serializes the TxType to the buffer if necessary, returning 2 bits of the type as an diff --git a/crates/primitives/src/transaction/variant.rs b/crates/primitives/src/transaction/variant.rs index 5bff5215d7..3e96b6dda8 100644 --- a/crates/primitives/src/transaction/variant.rs +++ b/crates/primitives/src/transaction/variant.rs @@ -11,7 +11,7 @@ use core::ops::Deref; /// /// All variants are based on a the raw [Transaction] data and can contain additional information /// extracted (expensive) from that transaction, like the hash and the signer. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, derive_more::From)] pub enum TransactionSignedVariant { /// A signed transaction without a hash. SignedNoHash(TransactionSignedNoHash), @@ -130,24 +130,6 @@ impl TransactionSignedVariant { } } -impl From for TransactionSignedVariant { - fn from(tx: TransactionSignedNoHash) -> Self { - Self::SignedNoHash(tx) - } -} - -impl From for TransactionSignedVariant { - fn from(tx: TransactionSigned) -> Self { - Self::Signed(tx) - } -} - -impl From for TransactionSignedVariant { - fn from(tx: TransactionSignedEcRecovered) -> Self { - Self::SignedEcRecovered(tx) - } -} - impl AsRef for TransactionSignedVariant { fn as_ref(&self) -> &Transaction { self.as_raw()