mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(sdk): define new BlockHeader trait (#12452)
This commit is contained in:
49
crates/primitives-traits/src/block/header.rs
Normal file
49
crates/primitives-traits/src/block/header.rs
Normal file
@ -0,0 +1,49 @@
|
||||
//! Block header data primitive.
|
||||
|
||||
use core::fmt;
|
||||
|
||||
use alloy_primitives::Sealable;
|
||||
use reth_codecs::Compact;
|
||||
|
||||
/// Helper trait that unifies all behaviour required by block header to support full node
|
||||
/// operations.
|
||||
pub trait FullBlockHeader: BlockHeader + Compact {}
|
||||
|
||||
impl<T> FullBlockHeader for T where T: BlockHeader + Compact {}
|
||||
|
||||
/// Abstraction of a block header.
|
||||
pub trait BlockHeader:
|
||||
Send
|
||||
+ Sync
|
||||
+ Unpin
|
||||
+ Clone
|
||||
+ Default
|
||||
+ fmt::Debug
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ serde::Serialize
|
||||
+ for<'de> serde::Deserialize<'de>
|
||||
+ alloy_rlp::Encodable
|
||||
+ alloy_rlp::Decodable
|
||||
+ alloy_consensus::BlockHeader
|
||||
+ Sealable
|
||||
{
|
||||
}
|
||||
|
||||
impl<T> BlockHeader for T where
|
||||
T: Send
|
||||
+ Sync
|
||||
+ Unpin
|
||||
+ Clone
|
||||
+ Default
|
||||
+ fmt::Debug
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ serde::Serialize
|
||||
+ for<'de> serde::Deserialize<'de>
|
||||
+ alloy_rlp::Encodable
|
||||
+ alloy_rlp::Decodable
|
||||
+ alloy_consensus::BlockHeader
|
||||
+ Sealable
|
||||
{
|
||||
}
|
||||
@ -1,19 +1,19 @@
|
||||
//! Block abstraction.
|
||||
|
||||
pub mod body;
|
||||
pub mod header;
|
||||
|
||||
use alloc::{fmt, vec::Vec};
|
||||
|
||||
use alloy_consensus::BlockHeader;
|
||||
use alloy_primitives::{Address, Sealable, B256};
|
||||
use alloy_primitives::{Address, B256};
|
||||
use reth_codecs::Compact;
|
||||
|
||||
use crate::BlockBody;
|
||||
use crate::{BlockBody, BlockHeader, FullBlockHeader};
|
||||
|
||||
/// Helper trait that unifies all behaviour required by block to support full node operations.
|
||||
pub trait FullBlock: Block<Header: Compact> + Compact {}
|
||||
|
||||
impl<T> FullBlock for T where T: Block<Header: Compact> + Compact {}
|
||||
impl<T> FullBlock for T where T: Block<Header: FullBlockHeader> + Compact {}
|
||||
|
||||
/// Abstraction of block data type.
|
||||
// todo: make sealable super-trait, depends on <https://github.com/paradigmxyz/reth/issues/11449>
|
||||
@ -34,7 +34,7 @@ pub trait Block:
|
||||
+ Into<(Self::Header, Self::Body)>
|
||||
{
|
||||
/// Header part of the block.
|
||||
type Header: BlockHeader + Sealable;
|
||||
type Header: BlockHeader;
|
||||
|
||||
/// The block's body contains the transactions in the block.
|
||||
type Body: BlockBody;
|
||||
|
||||
@ -34,7 +34,11 @@ mod integer_list;
|
||||
pub use integer_list::{IntegerList, IntegerListError};
|
||||
|
||||
pub mod block;
|
||||
pub use block::{body::BlockBody, Block, FullBlock};
|
||||
pub use block::{
|
||||
body::BlockBody,
|
||||
header::{BlockHeader, FullBlockHeader},
|
||||
Block, FullBlock,
|
||||
};
|
||||
|
||||
mod withdrawal;
|
||||
pub use withdrawal::Withdrawal;
|
||||
@ -56,7 +60,7 @@ pub use tx_type::TxType;
|
||||
pub mod header;
|
||||
#[cfg(any(test, feature = "arbitrary", feature = "test-utils"))]
|
||||
pub use header::test_utils;
|
||||
pub use header::{BlockHeader, Header, HeaderError, SealedHeader};
|
||||
pub use header::{Header, HeaderError, SealedHeader};
|
||||
|
||||
/// Bincode-compatible serde implementations for common abstracted types in Reth.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user