reth_ethereum_forks/
head.rs1use alloy_primitives::{BlockNumber, B256, U256};
2use core::fmt;
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct Head {
15 pub number: BlockNumber,
17 pub hash: B256,
19 pub difficulty: U256,
21 pub total_difficulty: U256,
23 pub timestamp: u64,
25}
26impl Head {
27 pub const fn new(
29 number: BlockNumber,
30 hash: B256,
31 difficulty: U256,
32 total_difficulty: U256,
33 timestamp: u64,
34 ) -> Self {
35 Self { number, hash, difficulty, total_difficulty, timestamp }
36 }
37
38 pub fn update(
40 &mut self,
41 number: BlockNumber,
42 hash: B256,
43 difficulty: U256,
44 total_difficulty: U256,
45 timestamp: u64,
46 ) {
47 *self = Self { number, hash, difficulty, total_difficulty, timestamp };
48 }
49
50 pub fn is_empty(&self) -> bool {
52 *self == Self::default()
53 }
54}
55
56impl fmt::Display for Head {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 write!(
59 f,
60 "Head Block:\n Number: {}\n Hash: {}\n Difficulty: {:?}\n Total Difficulty: {:?}\n Timestamp: {}",
61 self.number, self.hash, self.difficulty, self.total_difficulty, self.timestamp
62 )
63 }
64}