Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/consensus/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ where
}

/// EIP-2718 decode the signed transaction.
pub fn eip2718_decode(buf: &mut &[u8]) -> Eip2718Result<Self> {
pub fn eip2718_decode(self, buf: &mut &[u8]) -> Eip2718Result<Self> {
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<Self> {
pub fn network_decode_with_type(&self.tx, buf: &mut &[u8], ty: u8) -> Eip2718Result<Self> {
T::network_decode_with_type(buf, ty)
}

Expand Down
2 changes: 0 additions & 2 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion crates/consensus/src/transaction/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<Signed<Self>> {
fn eip2718_decode(&self, buf: &mut &[u8]) -> alloy_eips::eip2718::Eip2718Result<Signed<Self>> {
Self::rlp_decode_signed(buf).map_err(Into::into)
}

Expand Down
26 changes: 13 additions & 13 deletions crates/consensus/src/transaction/rlp.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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};

/// Helper trait for managing RLP encoding of transactions inside 2718
#[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;
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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<Signed<Self>> {
Self::eip2718_decode_with_type(buf, Self::DEFAULT_TX_TYPE)
fn eip2718_decode(self, buf: &mut &[u8]) -> Eip2718Result<Signed<Self>> {
Self::eip2718_decode_with_type(buf, slef.ty())
}

/// Decodes the transaction from network bytes.
Expand All @@ -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<Signed<Self>> {
Self::network_decode_with_type(buf, Self::DEFAULT_TX_TYPE)
fn network_decode(&self, buf: &mut &[u8]) -> Eip2718Result<Signed<Self>> {
Self::network_decode_with_type(buf, self.ty())
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/consensus/src/transaction/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ impl<Eip4844: Typed2718> Typed2718 for EthereumTypedTransaction<Eip4844> {
impl<Eip4844: RlpEcdsaEncodableTx + Typed2718> RlpEcdsaEncodableTx
for EthereumTypedTransaction<Eip4844>
{
const DEFAULT_TX_TYPE: u8 = 0;

fn rlp_encoded_fields_length(&self) -> usize {
match self {
Expand Down