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 into sealed for rpc header #1956

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
14 changes: 12 additions & 2 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ impl<H> Header<H> {
Self { hash, inner, total_difficulty: None, size: None }
}

/// Consumes the type and returns the [`Sealed`] header.
pub fn into_sealed(self) -> Sealed<H> {
Sealed::new_unchecked(self.inner, self.hash)
}

/// Consumes the type and returns the wrapped consensus header.
pub fn into_consensus(self) -> H {
self.inner
Expand Down Expand Up @@ -430,6 +435,12 @@ impl From<Header> for alloy_consensus::Header {
}
}

impl<H> From<Header<H>> for Sealed<H> {
fn from(value: Header<H>) -> Self {
value.into_sealed()
}
}

/// Error that can occur when converting other types to blocks
#[derive(Clone, Copy, Debug, thiserror::Error)]
pub enum BlockError {
Expand Down Expand Up @@ -551,13 +562,12 @@ pub struct BadBlock {

#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::{hex, keccak256, Bloom, B64};
use arbitrary::Arbitrary;
use rand::Rng;
use similar_asserts::assert_eq;

use super::*;

#[test]
fn arbitrary_header() {
let mut bytes = [0u8; 1024];
Expand Down
Loading