Skip to content

Commit 7d0e83d

Browse files
chore: remove associated constant from RlpEcdsaEncodableTx (#2172)
* chore: remove associated constant from RlpEcdsaDecodableTx * move const to decode
1 parent 7bbca79 commit 7d0e83d

File tree

7 files changed

+25
-24
lines changed

7 files changed

+25
-24
lines changed

crates/consensus/src/transaction/eip1559.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ impl TxEip1559 {
9898
}
9999

100100
impl RlpEcdsaEncodableTx for TxEip1559 {
101-
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
102-
103101
/// Outputs the length of the transaction's fields, without a RLP header.
104102
fn rlp_encoded_fields_length(&self) -> usize {
105103
self.chain_id.length()
@@ -129,6 +127,8 @@ impl RlpEcdsaEncodableTx for TxEip1559 {
129127
}
130128

131129
impl RlpEcdsaDecodableTx for TxEip1559 {
130+
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
131+
132132
/// Decodes the inner [TxEip1559] fields from RLP bytes.
133133
///
134134
/// NOTE: This assumes a RLP header has already been decoded, and _just_

crates/consensus/src/transaction/eip2930.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ impl TxEip2930 {
8383
}
8484

8585
impl RlpEcdsaEncodableTx for TxEip2930 {
86-
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
87-
8886
/// Outputs the length of the transaction's fields, without a RLP header.
8987
fn rlp_encoded_fields_length(&self) -> usize {
9088
self.chain_id.length()
@@ -110,6 +108,8 @@ impl RlpEcdsaEncodableTx for TxEip2930 {
110108
}
111109

112110
impl RlpEcdsaDecodableTx for TxEip2930 {
111+
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
112+
113113
fn rlp_decode_fields(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
114114
Ok(Self {
115115
chain_id: Decodable::decode(buf)?,

crates/consensus/src/transaction/eip4844.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ impl Typed2718 for TxEip4844 {
287287
}
288288

289289
impl RlpEcdsaEncodableTx for TxEip4844Variant {
290-
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
291-
292290
fn rlp_encoded_fields_length(&self) -> usize {
293291
match self {
294292
Self::TxEip4844(inner) => inner.rlp_encoded_fields_length(),
@@ -326,6 +324,8 @@ impl RlpEcdsaEncodableTx for TxEip4844Variant {
326324
}
327325

328326
impl RlpEcdsaDecodableTx for TxEip4844Variant {
327+
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
328+
329329
fn rlp_decode_fields(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
330330
let needle = &mut &**buf;
331331

@@ -542,8 +542,6 @@ impl TxEip4844 {
542542
}
543543

544544
impl RlpEcdsaEncodableTx for TxEip4844 {
545-
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
546-
547545
fn rlp_encoded_fields_length(&self) -> usize {
548546
self.chain_id.length()
549547
+ self.nonce.length()
@@ -574,6 +572,8 @@ impl RlpEcdsaEncodableTx for TxEip4844 {
574572
}
575573

576574
impl RlpEcdsaDecodableTx for TxEip4844 {
575+
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
576+
577577
fn rlp_decode_fields(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
578578
Ok(Self {
579579
chain_id: Decodable::decode(buf)?,
@@ -916,8 +916,6 @@ impl Typed2718 for TxEip4844WithSidecar {
916916
}
917917

918918
impl RlpEcdsaEncodableTx for TxEip4844WithSidecar {
919-
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
920-
921919
fn rlp_encoded_fields_length(&self) -> usize {
922920
self.sidecar.rlp_encoded_fields_length() + self.tx.rlp_encoded_length()
923921
}
@@ -946,6 +944,8 @@ impl RlpEcdsaEncodableTx for TxEip4844WithSidecar {
946944
}
947945

948946
impl RlpEcdsaDecodableTx for TxEip4844WithSidecar {
947+
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
948+
949949
fn rlp_decode_fields(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
950950
let tx = TxEip4844::rlp_decode(buf)?;
951951
let sidecar = BlobTransactionSidecar::rlp_decode_fields(buf)?;

crates/consensus/src/transaction/eip7702.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ impl TxEip7702 {
107107
}
108108

109109
impl RlpEcdsaEncodableTx for TxEip7702 {
110-
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
111-
112110
/// Outputs the length of the transaction's fields, without a RLP header.
113111
#[doc(hidden)]
114112
fn rlp_encoded_fields_length(&self) -> usize {
@@ -139,6 +137,8 @@ impl RlpEcdsaEncodableTx for TxEip7702 {
139137
}
140138

141139
impl RlpEcdsaDecodableTx for TxEip7702 {
140+
const DEFAULT_TX_TYPE: u8 = { Self::tx_type() as u8 };
141+
142142
fn rlp_decode_fields(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
143143
Ok(Self {
144144
chain_id: Decodable::decode(buf)?,

crates/consensus/src/transaction/legacy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ impl TxLegacy {
112112
// Legacy transaction network and 2718 encodings are identical to the RLP
113113
// encoding.
114114
impl RlpEcdsaEncodableTx for TxLegacy {
115-
const DEFAULT_TX_TYPE: u8 = { Self::TX_TYPE as u8 };
116-
117115
fn rlp_encoded_fields_length(&self) -> usize {
118116
self.nonce.length()
119117
+ self.gas_price.length()
@@ -179,6 +177,8 @@ impl RlpEcdsaEncodableTx for TxLegacy {
179177
}
180178

181179
impl RlpEcdsaDecodableTx for TxLegacy {
180+
const DEFAULT_TX_TYPE: u8 = { Self::TX_TYPE as u8 };
181+
182182
fn rlp_decode_fields(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
183183
Ok(Self {
184184
nonce: Decodable::decode(buf)?,

crates/consensus/src/transaction/rlp.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use crate::Signed;
22
use alloc::vec::Vec;
3-
use alloy_eips::eip2718::{Eip2718Error, Eip2718Result};
3+
use alloy_eips::{
4+
eip2718::{Eip2718Error, Eip2718Result},
5+
Typed2718,
6+
};
47
use alloy_primitives::{keccak256, PrimitiveSignature as Signature, TxHash};
58
use alloy_rlp::{Buf, BufMut, Decodable, Encodable, Header};
69

710
/// Helper trait for managing RLP encoding of transactions inside 2718
811
#[doc(hidden)]
912
#[doc(alias = "RlpEncodableTx", alias = "RlpTxEncoding")]
1013
#[auto_impl::auto_impl(&, Arc)]
11-
pub trait RlpEcdsaEncodableTx: Sized {
12-
/// The default transaction type for this transaction.
13-
const DEFAULT_TX_TYPE: u8;
14-
14+
pub trait RlpEcdsaEncodableTx: Sized + Typed2718 {
1515
/// Calculate the encoded length of the transaction's fields, without a RLP
1616
/// header.
1717
fn rlp_encoded_fields_length(&self) -> usize;
@@ -71,7 +71,7 @@ pub trait RlpEcdsaEncodableTx: Sized {
7171
/// EIP-2718 encode the transaction with the given signature and the default
7272
/// type flag.
7373
fn eip2718_encode(&self, signature: &Signature, out: &mut dyn BufMut) {
74-
self.eip2718_encode_with_type(signature, Self::DEFAULT_TX_TYPE, out);
74+
self.eip2718_encode_with_type(signature, self.ty(), out);
7575
}
7676

7777
/// Create an rlp header for the network encoded transaction. This will
@@ -97,7 +97,7 @@ pub trait RlpEcdsaEncodableTx: Sized {
9797
/// Network encode the transaction with the given signature and the default
9898
/// type flag.
9999
fn network_encode(&self, signature: &Signature, out: &mut dyn BufMut) {
100-
self.network_encode_with_type(signature, Self::DEFAULT_TX_TYPE, out);
100+
self.network_encode_with_type(signature, self.ty(), out);
101101
}
102102

103103
/// Calculate the transaction hash for the given signature and type.
@@ -109,14 +109,17 @@ pub trait RlpEcdsaEncodableTx: Sized {
109109

110110
/// Calculate the transaction hash for the given signature.
111111
fn tx_hash(&self, signature: &Signature) -> TxHash {
112-
self.tx_hash_with_type(signature, Self::DEFAULT_TX_TYPE)
112+
self.tx_hash_with_type(signature, self.ty())
113113
}
114114
}
115115

116116
/// Helper trait for managing RLP decoding of transactions inside 2718 envelopes.
117117
#[doc(hidden)]
118118
#[doc(alias = "RlpDecodableTx", alias = "RlpTxDecoding")]
119119
pub trait RlpEcdsaDecodableTx: RlpEcdsaEncodableTx {
120+
/// The default transaction type for this transaction.
121+
const DEFAULT_TX_TYPE: u8;
122+
120123
/// Decodes the fields of the transaction from RLP bytes. Do not decode a
121124
/// header. You may assume the buffer is long enough to contain the
122125
/// transaction.

crates/consensus/src/transaction/typed.rs

-2
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ impl<Eip4844: Typed2718> Typed2718 for EthereumTypedTransaction<Eip4844> {
375375
impl<Eip4844: RlpEcdsaEncodableTx + Typed2718> RlpEcdsaEncodableTx
376376
for EthereumTypedTransaction<Eip4844>
377377
{
378-
const DEFAULT_TX_TYPE: u8 = 0;
379-
380378
fn rlp_encoded_fields_length(&self) -> usize {
381379
match self {
382380
Self::Legacy(tx) => tx.rlp_encoded_fields_length(),

0 commit comments

Comments
 (0)