Skip to main content

reth_execution_types/
execute.rs

1use alloy_primitives::{Address, B256, U256};
2use reth_primitives_traits::{Account, Bytecode};
3use revm::database::BundleState;
4
5pub use alloy_evm::block::BlockExecutionResult;
6
7/// [`BlockExecutionResult`] combined with state.
8#[derive(
9    Debug,
10    Clone,
11    PartialEq,
12    Eq,
13    derive_more::AsRef,
14    derive_more::AsMut,
15    derive_more::Deref,
16    derive_more::DerefMut,
17)]
18pub struct BlockExecutionOutput<T> {
19    /// All the receipts of the transactions in the block.
20    #[as_ref]
21    #[as_mut]
22    #[deref]
23    #[deref_mut]
24    pub result: BlockExecutionResult<T>,
25    /// The changed state of the block after execution.
26    pub state: BundleState,
27}
28
29impl<T> BlockExecutionOutput<T> {
30    /// Return bytecode if known.
31    pub fn bytecode(&self, code_hash: &B256) -> Option<Bytecode> {
32        self.state.bytecode(code_hash).map(Bytecode)
33    }
34
35    /// Get account if account is known.
36    pub fn account(&self, address: &Address) -> Option<Option<Account>> {
37        self.state.account(address).map(|a| a.info.as_ref().map(Into::into))
38    }
39
40    /// Get storage if value is known.
41    ///
42    /// This means that depending on status we can potentially return `U256::ZERO`.
43    pub fn storage(&self, address: &Address, storage_key: U256) -> Option<U256> {
44        self.state.account(address).and_then(|a| a.storage_slot(storage_key))
45    }
46}
47
48impl<T> Default for BlockExecutionOutput<T> {
49    fn default() -> Self {
50        Self {
51            result: BlockExecutionResult {
52                receipts: Default::default(),
53                requests: Default::default(),
54                gas_used: 0,
55                blob_gas_used: 0,
56            },
57            state: Default::default(),
58        }
59    }
60}