Skip to content

Commit

Permalink
feat: add rlp length helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jan 11, 2025
1 parent e3651c9 commit 1ba17f2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions crates/consensus/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ impl<T, H> Block<T, H> {
},
})
}

/// Returns the RLP encoded length of the block's header and body.
pub fn rlp_length_for(header: &H, body: &BlockBody<T>) -> usize
where
H: Encodable,
T: Encodable,
{
block_rlp::HelperRef {
header,
transactions: &body.transactions,
ommers: &body.ommers,
withdrawals: body.withdrawals.as_ref(),
}
.length()
}
}

impl<T, H> Default for Block<T, H>
Expand Down Expand Up @@ -214,11 +229,11 @@ mod block_rlp {

#[derive(RlpEncodable)]
#[rlp(trailing)]
struct HelperRef<'a, T, H> {
header: &'a H,
transactions: &'a Vec<T>,
ommers: &'a Vec<Header>,
withdrawals: Option<&'a Withdrawals>,
pub(crate) struct HelperRef<'a, T, H> {
pub(crate) header: &'a H,
pub(crate) transactions: &'a Vec<T>,
pub(crate) ommers: &'a Vec<Header>,
pub(crate) withdrawals: Option<&'a Withdrawals>,
}

impl<'a, T, H> From<&'a Block<T, H>> for HelperRef<'a, T, H> {
Expand Down

0 comments on commit 1ba17f2

Please sign in to comment.