Skip to content

Commit

Permalink
feat: Encodable2718::network_len (#1431)
Browse files Browse the repository at this point in the history
* feat: Encodable2718::network_len

* clippy
  • Loading branch information
klkvr authored Oct 4, 2024
1 parent a173307 commit 8ef8ab7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 2 additions & 6 deletions crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Eip658Value, Receipt, ReceiptWithBloom, TxReceipt, TxType};
use alloy_eips::eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718};
use alloy_primitives::{Bloom, Log};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable};
use alloy_rlp::{BufMut, Decodable, Encodable};

/// Receipt envelope, as defined in [EIP-2718].
///
Expand Down Expand Up @@ -158,11 +158,7 @@ impl Encodable for ReceiptEnvelope {
}

fn length(&self) -> usize {
let mut payload_length = self.rlp_payload_length();
if !self.is_legacy() {
payload_length += length_of_length(payload_length);
}
payload_length
self.network_len()
}
}

Expand Down
7 changes: 1 addition & 6 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,7 @@ impl Encodable for TxEnvelope {
}

fn length(&self) -> usize {
let mut payload_length = self.rlp_payload_length();
if !self.is_legacy() {
payload_length += Header { list: false, payload_length }.length();
}

payload_length
self.network_len()
}
}

Expand Down
11 changes: 11 additions & 0 deletions crates/eips/src/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ pub trait Encodable2718: Sized + Send + Sync + 'static {
Sealed::new_unchecked(self, hash)
}

/// The length of the 2718 encoded envelope in network format. This is the length of the header
/// + the length of the type flag and inner encoding.
fn network_len(&self) -> usize {
let mut payload_length = self.encode_2718_len();
if !self.is_legacy() {
payload_length += Header { list: false, payload_length }.length();
}

payload_length
}

/// Encode in the network format. The network format is used ONLY by the
/// Ethereum p2p protocol. Do not call this method unless you are building
/// a p2p protocol client.
Expand Down

0 comments on commit 8ef8ab7

Please sign in to comment.