#![warn(missing_docs)]
mod receipt;
pub use receipt::{AccumulateReceipt, LogsBloom};
mod hash_builder;
pub use hash_builder::{BuilderPhase, IncrementalHashBuilder, IncrementalHashBuilderIR};
mod block_builder;
pub use block_builder::{EthereumBlockBuilder, EthereumBlockBuilderIR};
use crate::evm::Block;
use alloc::vec::Vec;
use alloy_core::primitives::{bytes::BufMut, B256};
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_core::{H256, U256};
#[derive(Encode, Decode, TypeInfo, Clone, Debug, Default, PartialEq, Eq)]
pub struct ReceiptGasInfo {
pub gas_used: U256,
pub effective_gas_price: U256,
}
impl Block {
pub fn compute_trie_root(items: &[Vec<u8>]) -> B256 {
alloy_consensus::proofs::ordered_trie_root_with_encoder(items, |item, buf| {
buf.put_slice(item)
})
}
pub fn header_hash(&self) -> H256 {
let gas_limit = self.gas_limit.try_into().unwrap_or(u64::MAX);
let alloy_header = alloy_consensus::Header {
state_root: self.state_root.0.into(),
transactions_root: self.transactions_root.0.into(),
receipts_root: self.receipts_root.0.into(),
parent_hash: self.parent_hash.0.into(),
beneficiary: self.miner.0.into(),
number: self.number.as_u64(),
logs_bloom: self.logs_bloom.0.into(),
gas_limit,
gas_used: self.gas_used.as_u64(),
timestamp: self.timestamp.as_u64(),
ommers_hash: self.sha_3_uncles.0.into(),
extra_data: self.extra_data.clone().0.into(),
mix_hash: self.mix_hash.0.into(),
nonce: self.nonce.0.into(),
base_fee_per_gas: Some(self.base_fee_per_gas.as_u64()),
withdrawals_root: Some(self.withdrawals_root.0.into()),
blob_gas_used: Some(self.blob_gas_used.as_u64()),
excess_blob_gas: Some(self.excess_blob_gas.as_u64()),
parent_beacon_block_root: self.parent_beacon_block_root.map(|root| root.0.into()),
requests_hash: self.requests_hash.map(|hash| hash.0.into()),
..Default::default()
};
alloy_header.hash_slow().0.into()
}
}