Skip to content

Commit

Permalink
refactor: use length_with_payload
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Oct 23, 2024
1 parent bef3d45 commit 8de9c9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 2 additions & 3 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ impl RlpEcdsaTx for TxLegacy {
fn rlp_encoded_length_with_signature(&self, signature: &Signature) -> usize {
// Enforce correct parity for legacy transactions (EIP-155, 27 or 28).
let signature = legacy_sig!(signature);
let header = self.rlp_header_signed(signature);
header.length() + header.payload_length
self.rlp_header_signed(signature).length_with_payload()
}

fn rlp_encode_signed(&self, signature: &Signature, out: &mut dyn BufMut) {
Expand Down Expand Up @@ -310,7 +309,7 @@ impl SignableTransaction<Signature> for TxLegacy {
fn payload_len_for_signature(&self) -> usize {
let payload_length = self.rlp_encoded_fields_length() + self.eip155_fields_len();
// 'header length' + 'payload length'
Header { list: true, payload_length }.length() + payload_length
Header { list: true, payload_length }.length_with_payload()
}

fn into_signed(self, signature: Signature) -> Signed<Self> {
Expand Down
9 changes: 3 additions & 6 deletions crates/consensus/src/transaction/rlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub trait RlpEcdsaTx: SignableTransaction<Signature> + Sized {

/// Get the length of the transaction when RLP encoded.
fn rlp_encoded_length(&self) -> usize {
let payload_length = self.rlp_encoded_fields_length();
self.rlp_header().length() + payload_length
self.rlp_header().length_with_payload()
}

/// RLP encodes the transaction.
Expand All @@ -45,8 +44,7 @@ pub trait RlpEcdsaTx: SignableTransaction<Signature> + Sized {
/// Get the length of the transaction when RLP encoded with the given
/// signature.
fn rlp_encoded_length_with_signature(&self, signature: &Signature) -> usize {
let header = self.rlp_header_signed(signature);
header.length() + header.payload_length
self.rlp_header_signed(signature).length_with_payload()
}

/// RLP encodes the transaction with the given signature.
Expand Down Expand Up @@ -83,8 +81,7 @@ pub trait RlpEcdsaTx: SignableTransaction<Signature> + Sized {
/// Get the length of the transaction when network encoded. This is the
/// EIP-2718 encoded length with an outer RLP header.
fn network_encoded_length(&self, signature: &Signature) -> usize {
let header = self.network_header(signature);
header.length() + header.payload_length
self.network_header(signature).length_with_payload()
}

/// Network encode the transaction with the given signature.
Expand Down

0 comments on commit 8de9c9f

Please sign in to comment.