emv: add BlockHeader trait and default fill_block_env (#10993)

This commit is contained in:
Thomas Coratger
2024-09-18 19:36:55 +02:00
committed by GitHub
parent c2019e35de
commit 06b9792792
9 changed files with 85 additions and 83 deletions

View File

@ -527,3 +527,64 @@ impl<'a> arbitrary::Arbitrary<'a> for Header {
))
}
}
/// Trait for extracting specific Ethereum block data from a header
pub trait BlockHeader {
/// Retrieves the beneficiary (miner) of the block
fn beneficiary(&self) -> Address;
/// Retrieves the difficulty of the block
fn difficulty(&self) -> U256;
/// Retrieves the block number
fn number(&self) -> BlockNumber;
/// Retrieves the gas limit of the block
fn gas_limit(&self) -> u64;
/// Retrieves the timestamp of the block
fn timestamp(&self) -> u64;
/// Retrieves the mix hash of the block
fn mix_hash(&self) -> B256;
/// Retrieves the base fee per gas of the block, if available
fn base_fee_per_gas(&self) -> Option<u64>;
/// Retrieves the excess blob gas of the block, if available
fn excess_blob_gas(&self) -> Option<u64>;
}
impl BlockHeader for Header {
fn beneficiary(&self) -> Address {
self.beneficiary
}
fn difficulty(&self) -> U256 {
self.difficulty
}
fn number(&self) -> BlockNumber {
self.number
}
fn gas_limit(&self) -> u64 {
self.gas_limit
}
fn timestamp(&self) -> u64 {
self.timestamp
}
fn mix_hash(&self) -> B256 {
self.mix_hash
}
fn base_fee_per_gas(&self) -> Option<u64> {
self.base_fee_per_gas
}
fn excess_blob_gas(&self) -> Option<u64> {
self.excess_blob_gas
}
}

View File

@ -45,4 +45,4 @@ pub use storage::StorageEntry;
pub mod header;
#[cfg(any(test, feature = "arbitrary", feature = "test-utils"))]
pub use header::test_utils;
pub use header::{Header, HeaderError, SealedHeader};
pub use header::{BlockHeader, Header, HeaderError, SealedHeader};