pallet_revive/evm/
block_hash.rs1#![warn(missing_docs)]
20
21mod receipt;
22use pallet_revive_types::runtime_api::*;
23pub use receipt::{AccumulateReceipt, LogsBloom};
24
25mod hash_builder;
26pub use hash_builder::{BuilderPhase, IncrementalHashBuilder, IncrementalHashBuilderIR};
27
28mod block_builder;
29pub use block_builder::{EthereumBlockBuilder, EthereumBlockBuilderIR};
30
31use crate::evm::Block;
32
33use alloc::vec::Vec;
34use alloy_core::primitives::{B256, bytes::BufMut};
35
36use codec::{Decode, Encode};
37use scale_info::TypeInfo;
38use sp_core::{H256, U256};
39
40#[derive(Encode, Decode, TypeInfo, Clone, Debug, Default, PartialEq, Eq)]
43pub struct ReceiptGasInfo {
44 pub gas_used: U256,
46
47 pub effective_gas_price: U256,
49}
50
51impl From<ReceiptGasInfo> for ReceiptGasInfoV1 {
52 fn from(value: ReceiptGasInfo) -> Self {
53 Self { gas_used: value.gas_used, effective_gas_price: value.effective_gas_price }
54 }
55}
56
57impl Block {
58 pub fn compute_trie_root(items: &[Vec<u8>]) -> B256 {
60 alloy_consensus::proofs::ordered_trie_root_with_encoder(items, |item, buf| {
61 buf.put_slice(item)
62 })
63 }
64
65 pub fn header_hash(&self) -> H256 {
67 let gas_limit = self.gas_limit.try_into().unwrap_or(u64::MAX);
71
72 let alloy_header = alloy_consensus::Header {
73 state_root: self.state_root.0.into(),
74 transactions_root: self.transactions_root.0.into(),
75 receipts_root: self.receipts_root.0.into(),
76
77 parent_hash: self.parent_hash.0.into(),
78 beneficiary: self.miner.0.into(),
79 number: self.number.as_u64(),
80 logs_bloom: self.logs_bloom.0.into(),
81 gas_limit,
82 gas_used: self.gas_used.as_u64(),
83 timestamp: self.timestamp.as_u64(),
84
85 ommers_hash: self.sha_3_uncles.0.into(),
86 extra_data: self.extra_data.clone().0.into(),
87 mix_hash: self.mix_hash.0.into(),
88 nonce: self.nonce.0.into(),
89
90 base_fee_per_gas: Some(self.base_fee_per_gas.as_u64()),
91 withdrawals_root: Some(self.withdrawals_root.0.into()),
92 blob_gas_used: Some(self.blob_gas_used.as_u64()),
93 excess_blob_gas: Some(self.excess_blob_gas.as_u64()),
94 parent_beacon_block_root: self.parent_beacon_block_root.map(|root| root.0.into()),
95 requests_hash: self.requests_hash.map(|hash| hash.0.into()),
96
97 ..Default::default()
98 };
99
100 alloy_header.hash_slow().0.into()
101 }
102}