reth_ethereum_forks/
head.rsuse alloy_primitives::{BlockNumber, B256, U256};
use core::fmt;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Head {
pub number: BlockNumber,
pub hash: B256,
pub difficulty: U256,
pub total_difficulty: U256,
pub timestamp: u64,
}
impl Head {
pub const fn new(
number: BlockNumber,
hash: B256,
difficulty: U256,
total_difficulty: U256,
timestamp: u64,
) -> Self {
Self { number, hash, difficulty, total_difficulty, timestamp }
}
pub fn update(
&mut self,
number: BlockNumber,
hash: B256,
difficulty: U256,
total_difficulty: U256,
timestamp: u64,
) {
*self = Self { number, hash, difficulty, total_difficulty, timestamp };
}
pub fn is_empty(&self) -> bool {
*self == Self::default()
}
}
impl fmt::Display for Head {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Head Block:\n Number: {}\n Hash: {}\n Difficulty: {:?}\n Total Difficulty: {:?}\n Timestamp: {}",
self.number, self.hash, self.difficulty, self.total_difficulty, self.timestamp
)
}
}