reth_primitives_traits/header/
header_mut.rs

1//! Mutable header utilities.
2
3use crate::BlockHeader;
4use alloy_consensus::Header;
5use alloy_primitives::{BlockHash, BlockNumber, B256, U256};
6
7/// A helper trait for [`Header`]s that allows for mutable access to the headers values.
8///
9/// This allows for modifying the header for testing and mocking purposes.
10pub trait HeaderMut: BlockHeader {
11    /// Updates the parent block hash.
12    fn set_parent_hash(&mut self, hash: BlockHash);
13
14    /// Updates the block number.
15    fn set_block_number(&mut self, number: BlockNumber);
16
17    /// Updates the block's timestamp.
18    fn set_timestamp(&mut self, number: BlockNumber);
19
20    /// Updates the block state root.
21    fn set_state_root(&mut self, state_root: B256);
22
23    /// Updates the block difficulty.
24    fn set_difficulty(&mut self, difficulty: U256);
25
26    /// Updates the block number (alias for CLI compatibility).
27    fn set_number(&mut self, number: u64) {
28        self.set_block_number(number);
29    }
30}
31
32impl HeaderMut for Header {
33    fn set_parent_hash(&mut self, hash: BlockHash) {
34        self.parent_hash = hash;
35    }
36
37    fn set_block_number(&mut self, number: BlockNumber) {
38        self.number = number;
39    }
40
41    fn set_timestamp(&mut self, number: BlockNumber) {
42        self.timestamp = number;
43    }
44
45    fn set_state_root(&mut self, state_root: B256) {
46        self.state_root = state_root;
47    }
48
49    fn set_difficulty(&mut self, difficulty: U256) {
50        self.difficulty = difficulty;
51    }
52}