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

feat: add missing helper fns #1880

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion crates/consensus/src/block/header.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -168,6 +171,11 @@ impl Sealable for Header {
}

impl Header {
/// Create a [`Block`] from the body and its header.
pub const fn into_block<T>(self, body: BlockBody<T>) -> Block<T> {
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.
Expand Down
5 changes: 5 additions & 0 deletions crates/consensus/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub struct Block<T, H = Header> {
}

impl<T, H> Block<T, H> {
/// Creates a new block with the given header and body.
pub const fn new(header: H, body: BlockBody<T>) -> Self {
Self { header, body }
}

/// Creates a new empty uncle block.
pub fn uncle(header: H) -> Self {
Self { header, body: Default::default() }
Expand Down
Loading