From 771cd3ce5850aa7acaa374d6f1e64fe19050513d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 7 Mar 2025 14:27:08 +0100 Subject: [PATCH] chore: impl encodable for tx (#14893) --- crates/ethereum/primitives/src/transaction.rs | 67 ++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/crates/ethereum/primitives/src/transaction.rs b/crates/ethereum/primitives/src/transaction.rs index 0db9788414..6187f61437 100644 --- a/crates/ethereum/primitives/src/transaction.rs +++ b/crates/ethereum/primitives/src/transaction.rs @@ -13,7 +13,8 @@ use alloy_eips::{ }; use alloy_evm::FromRecoveredTx; use alloy_primitives::{ - keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, B256, U256, + bytes::BufMut, keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, + TxKind, B256, U256, }; use alloy_rlp::{Decodable, Encodable}; use core::hash::{Hash, Hasher}; @@ -180,14 +181,6 @@ impl alloy_consensus::Transaction for Transaction { delegate!(self => tx.kind()) } - fn access_list(&self) -> Option<&alloy_eips::eip2930::AccessList> { - delegate!(self => tx.access_list()) - } - - fn authorization_list(&self) -> Option<&[alloy_eips::eip7702::SignedAuthorization]> { - delegate!(self => tx.authorization_list()) - } - fn is_create(&self) -> bool { delegate!(self => tx.is_create()) } @@ -200,9 +193,17 @@ impl alloy_consensus::Transaction for Transaction { delegate!(self => tx.input()) } + fn access_list(&self) -> Option<&alloy_eips::eip2930::AccessList> { + delegate!(self => tx.access_list()) + } + fn blob_versioned_hashes(&self) -> Option<&[B256]> { delegate!(self => tx.blob_versioned_hashes()) } + + fn authorization_list(&self) -> Option<&[alloy_eips::eip7702::SignedAuthorization]> { + delegate!(self => tx.authorization_list()) + } } impl SignableTransaction for Transaction { @@ -291,6 +292,42 @@ impl From for Transaction { } } +impl RlpEcdsaEncodableTx for Transaction { + const DEFAULT_TX_TYPE: u8 = 0; + + fn rlp_encoded_fields_length(&self) -> usize { + delegate!(self => tx.rlp_encoded_fields_length()) + } + + fn rlp_encode_fields(&self, out: &mut dyn BufMut) { + delegate!(self => tx.rlp_encode_fields(out)) + } + + fn eip2718_encode_with_type(&self, signature: &Signature, _ty: u8, out: &mut dyn BufMut) { + delegate!(self => tx.eip2718_encode_with_type(signature, tx.ty(), out)) + } + + fn eip2718_encode(&self, signature: &Signature, out: &mut dyn BufMut) { + delegate!(self => tx.eip2718_encode(signature, out)) + } + + fn network_encode_with_type(&self, signature: &Signature, _ty: u8, out: &mut dyn BufMut) { + delegate!(self => tx.network_encode_with_type(signature, tx.ty(), out)) + } + + fn network_encode(&self, signature: &Signature, out: &mut dyn BufMut) { + delegate!(self => tx.network_encode(signature, out)) + } + + fn tx_hash_with_type(&self, signature: &Signature, _ty: u8) -> TxHash { + delegate!(self => tx.tx_hash_with_type(signature, tx.ty())) + } + + fn tx_hash(&self, signature: &Signature) -> TxHash { + delegate!(self => tx.tx_hash(signature)) + } +} + /// Signed Ethereum transaction. #[derive(Debug, Clone, Eq, Serialize, Deserialize, derive_more::AsRef, derive_more::Deref)] #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(rlp))] @@ -502,12 +539,12 @@ impl alloy_consensus::Transaction for TransactionSigned { impl_from_signed!(TxLegacy, TxEip2930, TxEip1559, TxEip7702, TxEip4844, TypedTransaction); -// impl From> for TransactionSigned { -// fn from(value: Signed) -> Self { -// let (tx, sig, hash) = value.into_parts(); -// Self::new(tx, sig, hash) -// } -// } +impl From> for TransactionSigned { + fn from(value: Signed) -> Self { + let (tx, sig, hash) = value.into_parts(); + Self::new(tx, sig, hash) + } +} impl From> for TransactionSigned { fn from(value: Signed) -> Self {