Skip to main content

reth_primitives_traits/header/
header_mut.rs

1//! Mutable header utilities.
2
3use crate::BlockHeader;
4use alloy_consensus::Header;
5use alloy_primitives::{BlockHash, BlockNumber, Bytes, 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, timestamp: u64);
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 mix hash.
27    fn set_mix_hash(&mut self, mix_hash: B256);
28
29    /// Updates the extra data.
30    fn set_extra_data(&mut self, extra_data: Bytes);
31
32    /// Updates the parent beacon block root.
33    fn set_parent_beacon_block_root(&mut self, parent_beacon_block_root: Option<B256>);
34
35    /// Updates the block number (alias for CLI compatibility).
36    fn set_number(&mut self, number: u64) {
37        self.set_block_number(number);
38    }
39}
40
41impl HeaderMut for Header {
42    fn set_parent_hash(&mut self, hash: BlockHash) {
43        self.parent_hash = hash;
44    }
45
46    fn set_block_number(&mut self, number: BlockNumber) {
47        self.number = number;
48    }
49
50    fn set_timestamp(&mut self, timestamp: u64) {
51        self.timestamp = timestamp;
52    }
53
54    fn set_state_root(&mut self, state_root: B256) {
55        self.state_root = state_root;
56    }
57
58    fn set_difficulty(&mut self, difficulty: U256) {
59        self.difficulty = difficulty;
60    }
61
62    fn set_mix_hash(&mut self, mix_hash: B256) {
63        self.mix_hash = mix_hash;
64    }
65
66    fn set_extra_data(&mut self, extra_data: Bytes) {
67        self.extra_data = extra_data;
68    }
69
70    fn set_parent_beacon_block_root(&mut self, parent_beacon_block_root: Option<B256>) {
71        self.parent_beacon_block_root = parent_beacon_block_root;
72    }
73}