diff --git a/crates/consensus/src/signed.rs b/crates/consensus/src/signed.rs index 9a4bc6b87c0..cb215ff475f 100644 --- a/crates/consensus/src/signed.rs +++ b/crates/consensus/src/signed.rs @@ -184,12 +184,12 @@ where } /// EIP-2718 decode the signed transaction. - pub fn eip2718_decode(buf: &mut &[u8]) -> Eip2718Result { + pub fn eip2718_decode(self, buf: &mut &[u8]) -> Eip2718Result { T::eip2718_decode(buf) } /// Network decode the signed transaction with a specified type flag. - pub fn network_decode_with_type(buf: &mut &[u8], ty: u8) -> Eip2718Result { + pub fn network_decode_with_type(&self.tx, buf: &mut &[u8], ty: u8) -> Eip2718Result { T::network_decode_with_type(buf, ty) } diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index 92a02a3e566..4699e892d6d 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -98,8 +98,6 @@ impl TxEip1559 { } impl RlpEcdsaEncodableTx for TxEip1559 { - const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 }; - /// Outputs the length of the transaction's fields, without a RLP header. fn rlp_encoded_fields_length(&self) -> usize { self.chain_id.length() diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 4a796b7cbce..e1d78f73735 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -83,8 +83,6 @@ impl TxEip2930 { } impl RlpEcdsaEncodableTx for TxEip2930 { - const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 }; - /// Outputs the length of the transaction's fields, without a RLP header. fn rlp_encoded_fields_length(&self) -> usize { self.chain_id.length() diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index c0b5971f084..26f7f93f3f4 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -287,7 +287,6 @@ impl Typed2718 for TxEip4844 { } impl RlpEcdsaEncodableTx for TxEip4844Variant { - const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 }; fn rlp_encoded_fields_length(&self) -> usize { match self { @@ -542,7 +541,6 @@ impl TxEip4844 { } impl RlpEcdsaEncodableTx for TxEip4844 { - const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 }; fn rlp_encoded_fields_length(&self) -> usize { self.chain_id.length() @@ -916,7 +914,6 @@ impl Typed2718 for TxEip4844WithSidecar { } impl RlpEcdsaEncodableTx for TxEip4844WithSidecar { - const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 }; fn rlp_encoded_fields_length(&self) -> usize { self.sidecar.rlp_encoded_fields_length() + self.tx.rlp_encoded_length() diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index a2a861ef13f..e8616a80b2e 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -107,7 +107,6 @@ impl TxEip7702 { } impl RlpEcdsaEncodableTx for TxEip7702 { - const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 }; /// Outputs the length of the transaction's fields, without a RLP header. #[doc(hidden)] diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 9281fb7611a..23ecb7a6fdb 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -112,7 +112,6 @@ impl TxLegacy { // Legacy transaction network and 2718 encodings are identical to the RLP // encoding. impl RlpEcdsaEncodableTx for TxLegacy { - const DEFAULT_TX_TYPE: u8 = { Self::TX_TYPE as u8 }; fn rlp_encoded_fields_length(&self) -> usize { self.nonce.length() @@ -224,7 +223,7 @@ impl RlpEcdsaDecodableTx for TxLegacy { Self::rlp_decode_signed(buf).map_err(Into::into) } - fn eip2718_decode(buf: &mut &[u8]) -> alloy_eips::eip2718::Eip2718Result> { + fn eip2718_decode(&self, buf: &mut &[u8]) -> alloy_eips::eip2718::Eip2718Result> { Self::rlp_decode_signed(buf).map_err(Into::into) } diff --git a/crates/consensus/src/transaction/rlp.rs b/crates/consensus/src/transaction/rlp.rs index 31131268184..ccf5157c831 100644 --- a/crates/consensus/src/transaction/rlp.rs +++ b/crates/consensus/src/transaction/rlp.rs @@ -1,6 +1,9 @@ use crate::Signed; use alloc::vec::Vec; -use alloy_eips::eip2718::{Eip2718Error, Eip2718Result}; +use alloy_eips::{ + eip2718::{Eip2718Error, Eip2718Result}, + Typed2718, +}; use alloy_primitives::{keccak256, PrimitiveSignature as Signature, TxHash}; use alloy_rlp::{Buf, BufMut, Decodable, Encodable, Header}; @@ -8,10 +11,7 @@ use alloy_rlp::{Buf, BufMut, Decodable, Encodable, Header}; #[doc(hidden)] #[doc(alias = "RlpEncodableTx", alias = "RlpTxEncoding")] #[auto_impl::auto_impl(&, Arc)] -pub trait RlpEcdsaEncodableTx: Sized { - /// The default transaction type for this transaction. - const DEFAULT_TX_TYPE: u8; - +pub trait RlpEcdsaEncodableTx: Sized + Typed2718 { /// Calculate the encoded length of the transaction's fields, without a RLP /// header. fn rlp_encoded_fields_length(&self) -> usize; @@ -71,7 +71,7 @@ pub trait RlpEcdsaEncodableTx: Sized { /// EIP-2718 encode the transaction with the given signature and the default /// type flag. fn eip2718_encode(&self, signature: &Signature, out: &mut dyn BufMut) { - self.eip2718_encode_with_type(signature, Self::DEFAULT_TX_TYPE, out); + self.eip2718_encode_with_type(signature, self.ty(), out); } /// Create an rlp header for the network encoded transaction. This will @@ -97,7 +97,7 @@ pub trait RlpEcdsaEncodableTx: Sized { /// Network encode the transaction with the given signature and the default /// type flag. fn network_encode(&self, signature: &Signature, out: &mut dyn BufMut) { - self.network_encode_with_type(signature, Self::DEFAULT_TX_TYPE, out); + self.network_encode_with_type(signature, self.ty(), out); } /// Calculate the transaction hash for the given signature and type. @@ -109,14 +109,14 @@ pub trait RlpEcdsaEncodableTx: Sized { /// Calculate the transaction hash for the given signature. fn tx_hash(&self, signature: &Signature) -> TxHash { - self.tx_hash_with_type(signature, Self::DEFAULT_TX_TYPE) + self.tx_hash_with_type(signature, self.ty()) } } /// Helper trait for managing RLP decoding of transactions inside 2718 envelopes. #[doc(hidden)] #[doc(alias = "RlpDecodableTx", alias = "RlpTxDecoding")] -pub trait RlpEcdsaDecodableTx: RlpEcdsaEncodableTx { +pub trait RlpEcdsaDecodableTx: RlpEcdsaEncodableTx + Typed2718 { /// Decodes the fields of the transaction from RLP bytes. Do not decode a /// header. You may assume the buffer is long enough to contain the /// transaction. @@ -195,8 +195,8 @@ pub trait RlpEcdsaDecodableTx: RlpEcdsaEncodableTx { /// Decodes the transaction from eip2718 bytes, expecting the default type /// flag. - fn eip2718_decode(buf: &mut &[u8]) -> Eip2718Result> { - Self::eip2718_decode_with_type(buf, Self::DEFAULT_TX_TYPE) + fn eip2718_decode(self, buf: &mut &[u8]) -> Eip2718Result> { + Self::eip2718_decode_with_type(buf, slef.ty()) } /// Decodes the transaction from network bytes. @@ -218,8 +218,8 @@ pub trait RlpEcdsaDecodableTx: RlpEcdsaEncodableTx { /// Decodes the transaction from network bytes, expecting the default type /// flag. - fn network_decode(buf: &mut &[u8]) -> Eip2718Result> { - Self::network_decode_with_type(buf, Self::DEFAULT_TX_TYPE) + fn network_decode(&self, buf: &mut &[u8]) -> Eip2718Result> { + Self::network_decode_with_type(buf, self.ty()) } } diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 1751ee86bbd..79144363d1b 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -375,7 +375,6 @@ impl Typed2718 for EthereumTypedTransaction { impl RlpEcdsaEncodableTx for EthereumTypedTransaction { - const DEFAULT_TX_TYPE: u8 = 0; fn rlp_encoded_fields_length(&self) -> usize { match self {