Skip to content

Commit

Permalink
feat: make Receipt rlp methods pub (#1731)
Browse files Browse the repository at this point in the history
* make receipt rlp methods pub

* fmt

* doc
  • Loading branch information
klkvr authored Dec 2, 2024
1 parent d6fe2e1 commit bc46e64
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,24 @@ where
}

impl<T: Encodable> Receipt<T> {
fn rlp_encoded_fields_length_with_bloom(&self, bloom: &Bloom) -> usize {
/// Returns length of RLP-encoded receipt fields with the given [`Bloom`] without an RLP header.
pub fn rlp_encoded_fields_length_with_bloom(&self, bloom: &Bloom) -> usize {
self.status.length()
+ self.cumulative_gas_used.length()
+ bloom.length()
+ self.logs.length()
}

fn rlp_encode_fields_with_bloom(&self, bloom: &Bloom, out: &mut dyn BufMut) {
/// RLP-encodes receipt fields with the given [`Bloom`] without an RLP header.
pub fn rlp_encode_fields_with_bloom(&self, bloom: &Bloom, out: &mut dyn BufMut) {
self.status.encode(out);
self.cumulative_gas_used.encode(out);
bloom.encode(out);
self.logs.encode(out);
}

fn rlp_header_with_bloom(&self, bloom: &Bloom) -> Header {
/// Returns RLP header for this receipt encoding with the given [`Bloom`].
pub fn rlp_header_with_bloom(&self, bloom: &Bloom) -> Header {
Header { list: true, payload_length: self.rlp_encoded_fields_length_with_bloom(bloom) }
}
}
Expand All @@ -103,7 +106,12 @@ impl<T: Encodable> RlpEncodableReceipt for Receipt<T> {
}

impl<T: Decodable> Receipt<T> {
fn rlp_decode_fields_with_bloom(buf: &mut &[u8]) -> alloy_rlp::Result<ReceiptWithBloom<Self>> {
/// RLP-decodes receipt's field with a [`Bloom`].
///
/// Does not expect an RLP header.
pub fn rlp_decode_fields_with_bloom(
buf: &mut &[u8],
) -> alloy_rlp::Result<ReceiptWithBloom<Self>> {
let status = Decodable::decode(buf)?;
let cumulative_gas_used = Decodable::decode(buf)?;
let logs_bloom = Decodable::decode(buf)?;
Expand Down

0 comments on commit bc46e64

Please sign in to comment.