1use context_interface::block::{BlobExcessGasAndPrice, Block};
3use primitives::{eip4844::BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE, Address, B256, U256};
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct BlockEnv {
9 pub number: U256,
11 pub beneficiary: Address,
15
16 pub timestamp: U256,
18 pub gas_limit: u64,
20 pub basefee: u64,
24 pub difficulty: U256,
28 pub prevrandao: Option<B256>,
36 pub blob_excess_gas_and_price: Option<BlobExcessGasAndPrice>,
43}
44
45impl BlockEnv {
46 pub fn set_blob_excess_gas_and_price(
49 &mut self,
50 excess_blob_gas: u64,
51 base_fee_update_fraction: u64,
52 ) {
53 self.blob_excess_gas_and_price = Some(BlobExcessGasAndPrice::new(
54 excess_blob_gas,
55 base_fee_update_fraction,
56 ));
57 }
58}
59
60impl Block for BlockEnv {
61 #[inline]
62 fn number(&self) -> U256 {
63 self.number
64 }
65
66 #[inline]
67 fn beneficiary(&self) -> Address {
68 self.beneficiary
69 }
70
71 #[inline]
72 fn timestamp(&self) -> U256 {
73 self.timestamp
74 }
75
76 #[inline]
77 fn gas_limit(&self) -> u64 {
78 self.gas_limit
79 }
80
81 #[inline]
82 fn basefee(&self) -> u64 {
83 self.basefee
84 }
85
86 #[inline]
87 fn difficulty(&self) -> U256 {
88 self.difficulty
89 }
90
91 #[inline]
92 fn prevrandao(&self) -> Option<B256> {
93 self.prevrandao
94 }
95
96 #[inline]
97 fn blob_excess_gas_and_price(&self) -> Option<BlobExcessGasAndPrice> {
98 self.blob_excess_gas_and_price
99 }
100}
101
102impl Default for BlockEnv {
103 fn default() -> Self {
104 Self {
105 number: U256::ZERO,
106 beneficiary: Address::ZERO,
107 timestamp: U256::ONE,
108 gas_limit: u64::MAX,
109 basefee: 0,
110 difficulty: U256::ZERO,
111 prevrandao: Some(B256::ZERO),
112 blob_excess_gas_and_price: Some(BlobExcessGasAndPrice::new(
113 0,
114 BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE,
115 )),
116 }
117 }
118}