From 39ae9af77abb7733a80155bad7c23cd08f145988 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Sat, 16 Nov 2024 04:41:02 +0100 Subject: [PATCH] consensus: add `BlockWithParent` (#1650) * consensus: add BlockWithParent * mv BlockWithParent --- crates/eips/src/eip1898.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 2f8d517740c..ebe73fd07b1 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -11,6 +11,24 @@ use core::{ #[cfg(feature = "serde")] use serde::ser::SerializeStruct; +/// A helper struct to store the block number/hash and its parent hash. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +pub struct BlockWithParent { + /// Parent hash. + pub parent: B256, + /// Block number/hash. + pub block: BlockNumHash, +} + +impl BlockWithParent { + /// Creates a new [`BlockWithParent`] instance. + pub const fn new(parent: B256, block: BlockNumHash) -> Self { + Self { parent, block } + } +} + /// A block hash which may have a boolean `requireCanonical` field. /// /// - If false, a RPC call should raise if a block matching the hash is not found.