Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace receipt envelope encoded with trait #11742

Merged
merged 22 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ use derive_more::{DerefMut, From, IntoIterator};
use reth_codecs::{Compact, CompactZstd};
use serde::{Deserialize, Serialize};

pub trait Encodable2718: Encodable {
fn encode_envelope(&self, out: &mut dyn BufMut);
fn envelope_length(&self) -> usize;
}
hoank101 marked this conversation as resolved.
Show resolved Hide resolved

/// Receipt containing result of transaction execution.
#[derive(
Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable, Serialize, Deserialize,
Expand Down Expand Up @@ -205,14 +210,6 @@ impl<'a> arbitrary::Arbitrary<'a> for Receipt {
}

impl ReceiptWithBloom {
/// Returns the enveloped encoded receipt.
///
/// See also [`ReceiptWithBloom::encode_enveloped`]
pub fn envelope_encoded(&self) -> Bytes {
let mut buf = Vec::new();
self.encode_enveloped(&mut buf);
buf.into()
}

/// Encodes the receipt into its "raw" format.
hoank101 marked this conversation as resolved.
Show resolved Hide resolved
/// This format is also referred to as "binary" encoding.
Expand Down Expand Up @@ -289,6 +286,16 @@ impl ReceiptWithBloom {
}
}

impl Encodable2718 for ReceiptWithBloom {
fn encode_envelope(&self, out: &mut dyn BufMut) {
self.encode_enveloped(out)
}

fn envelope_length(&self) -> usize {
self.as_encoder().length()
}
}

impl Encodable for ReceiptWithBloom {
fn encode(&self, out: &mut dyn BufMut) {
self.encode_inner(out, true)
Expand Down
6 changes: 5 additions & 1 deletion crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,11 @@ where
.to_rpc_result()?
.unwrap_or_default()
.into_iter()
.map(|receipt| receipt.with_bloom().envelope_encoded())
.map(|receipt| {
let mut buf = Vec::new();
receipt.with_bloom().encode(&mut buf);
buf.into()
})
.collect())
}

Expand Down