Skip to content

Commit

Permalink
chore(reth-primitives): use derive_more::From when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Sep 15, 2024
1 parent 1c20e0e commit bf1050d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
32 changes: 1 addition & 31 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) static PARALLEL_SENDER_RECOVERY_THRESHOLD: Lazy<usize> =
/// 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`).
Expand Down Expand Up @@ -690,36 +690,6 @@ impl Transaction {
}
}

impl From<TxLegacy> for Transaction {
fn from(tx: TxLegacy) -> Self {
Self::Legacy(tx)
}
}

impl From<TxEip2930> for Transaction {
fn from(tx: TxEip2930) -> Self {
Self::Eip2930(tx)
}
}

impl From<TxEip1559> for Transaction {
fn from(tx: TxEip1559) -> Self {
Self::Eip1559(tx)
}
}

impl From<TxEip4844> for Transaction {
fn from(tx: TxEip4844) -> Self {
Self::Eip4844(tx)
}
}

impl From<TxEip7702> 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
Expand Down
20 changes: 1 addition & 19 deletions crates/primitives/src/transaction/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -130,24 +130,6 @@ impl TransactionSignedVariant {
}
}

impl From<TransactionSignedNoHash> for TransactionSignedVariant {
fn from(tx: TransactionSignedNoHash) -> Self {
Self::SignedNoHash(tx)
}
}

impl From<TransactionSigned> for TransactionSignedVariant {
fn from(tx: TransactionSigned) -> Self {
Self::Signed(tx)
}
}

impl From<TransactionSignedEcRecovered> for TransactionSignedVariant {
fn from(tx: TransactionSignedEcRecovered) -> Self {
Self::SignedEcRecovered(tx)
}
}

impl AsRef<Transaction> for TransactionSignedVariant {
fn as_ref(&self) -> &Transaction {
self.as_raw()
Expand Down

0 comments on commit bf1050d

Please sign in to comment.