From 777a113f01b3222ed7784f12f43520dee7d46b36 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 3 Jan 2025 13:43:49 +0100 Subject: [PATCH] feat: add missing helper fns --- crates/consensus/src/block/header.rs | 10 +++++++++- crates/consensus/src/block/mod.rs | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/consensus/src/block/header.rs b/crates/consensus/src/block/header.rs index fb2f8a1eb70..272c240d3d4 100644 --- a/crates/consensus/src/block/header.rs +++ b/crates/consensus/src/block/header.rs @@ -1,4 +1,7 @@ -use crate::constants::{EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH}; +use crate::{ + constants::{EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH}, + Block, BlockBody, +}; use alloc::vec::Vec; use alloy_eips::{ eip1559::{calc_next_block_base_fee, BaseFeeParams}, @@ -168,6 +171,11 @@ impl Sealable for Header { } impl Header { + /// Create a [`Block`] from the body and its header. + pub const fn into_block(self, body: BlockBody) -> Block { + body.into_block(self) + } + /// Heavy function that will calculate hash of data and will *not* save the change to metadata. /// /// Use [`Header::seal_slow`] and unlock if you need the hash to be persistent. diff --git a/crates/consensus/src/block/mod.rs b/crates/consensus/src/block/mod.rs index 0864ee6d409..1c58d774721 100644 --- a/crates/consensus/src/block/mod.rs +++ b/crates/consensus/src/block/mod.rs @@ -30,6 +30,11 @@ pub struct Block { } impl Block { + /// Creates a new block with the given header and body. + pub const fn new(header: H, body: BlockBody) -> Self { + Self { header, body } + } + /// Creates a new empty uncle block. pub fn uncle(header: H) -> Self { Self { header, body: Default::default() }