From e9be471160db720399c0389a678043913c1fa65a Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Fri, 30 Aug 2024 09:49:48 +0200 Subject: [PATCH 1/2] eip2930: add payload methods for TxEip2930 --- crates/consensus/src/transaction/eip2930.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 5917f3d741c..95fb15d67dc 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -223,6 +223,19 @@ impl TxEip2930 { pub const fn tx_type(&self) -> TxType { TxType::Eip2930 } + + /// Output the length of the RLP signed transaction encoding, _without_ a RLP string header. + pub fn payload_len_with_signature_without_header(&self, signature: &Signature) -> usize { + let payload_length = self.fields_len() + signature.rlp_vrs_len(); + // 'transaction type byte length' + 'header length' + 'payload length' + 1 + length_of_length(payload_length) + payload_length + } + + /// Output the length of the RLP signed transaction encoding. This encodes with a RLP header. + pub fn payload_len_with_signature(&self, signature: &Signature) -> usize { + let len = self.payload_len_with_signature_without_header(signature); + length_of_length(len) + len + } } impl Transaction for TxEip2930 { From 8402f4f886e131ea60f017c109402b6ce13044df Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Fri, 30 Aug 2024 11:43:15 +0200 Subject: [PATCH 2/2] make methods more generic --- crates/consensus/src/transaction/eip2930.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 95fb15d67dc..c7eec8da009 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -225,14 +225,20 @@ impl TxEip2930 { } /// Output the length of the RLP signed transaction encoding, _without_ a RLP string header. - pub fn payload_len_with_signature_without_header(&self, signature: &Signature) -> usize { + pub fn payload_len_with_signature_without_header(&self, signature: &S) -> usize + where + S: EncodableSignature, + { let payload_length = self.fields_len() + signature.rlp_vrs_len(); // 'transaction type byte length' + 'header length' + 'payload length' 1 + length_of_length(payload_length) + payload_length } /// Output the length of the RLP signed transaction encoding. This encodes with a RLP header. - pub fn payload_len_with_signature(&self, signature: &Signature) -> usize { + pub fn payload_len_with_signature(&self, signature: &S) -> usize + where + S: EncodableSignature, + { let len = self.payload_len_with_signature_without_header(signature); length_of_length(len) + len }