chore(reth-primitives): use derive_more::From when possible (#10917)

This commit is contained in:
nk_ysg
2024-09-17 17:53:27 +08:00
committed by GitHub
parent f04fc7c5b9
commit 30d8ec74ff
2 changed files with 2 additions and 50 deletions

View File

@ -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`).
@ -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

View File

@ -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<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()