From 1ba17f23b9a077f29fd42e1818c3e0edecc95b78 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 11 Jan 2025 10:14:24 +0100 Subject: [PATCH] feat: add rlp length helper --- crates/consensus/src/block/mod.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/consensus/src/block/mod.rs b/crates/consensus/src/block/mod.rs index 1c58d774721..c901c518252 100644 --- a/crates/consensus/src/block/mod.rs +++ b/crates/consensus/src/block/mod.rs @@ -95,6 +95,21 @@ impl Block { }, }) } + + /// Returns the RLP encoded length of the block's header and body. + pub fn rlp_length_for(header: &H, body: &BlockBody) -> usize + where + H: Encodable, + T: Encodable, + { + block_rlp::HelperRef { + header, + transactions: &body.transactions, + ommers: &body.ommers, + withdrawals: body.withdrawals.as_ref(), + } + .length() + } } impl Default for Block @@ -214,11 +229,11 @@ mod block_rlp { #[derive(RlpEncodable)] #[rlp(trailing)] - struct HelperRef<'a, T, H> { - header: &'a H, - transactions: &'a Vec, - ommers: &'a Vec
, - withdrawals: Option<&'a Withdrawals>, + pub(crate) struct HelperRef<'a, T, H> { + pub(crate) header: &'a H, + pub(crate) transactions: &'a Vec, + pub(crate) ommers: &'a Vec
, + pub(crate) withdrawals: Option<&'a Withdrawals>, } impl<'a, T, H> From<&'a Block> for HelperRef<'a, T, H> {