Skip to main content

reth_trie_common/bundle_state/
transition_state.rs

1use super::TransitionAccount;
2use alloy_primitives::{
3    map::{AddressMap, HashMap},
4    Address,
5};
6
7/// State of accounts in transition between transaction executions.
8#[derive(Clone, Default, Debug, PartialEq, Eq)]
9pub struct TransitionState {
10    /// Block state account with account state
11    pub transitions: AddressMap<TransitionAccount>,
12}
13
14impl TransitionState {
15    /// Create new transition state containing one [`TransitionAccount`].
16    pub fn single(address: Address, transition: TransitionAccount) -> Self {
17        let mut transitions = HashMap::default();
18        transitions.insert(address, transition);
19        TransitionState { transitions }
20    }
21
22    /// Take the contents of this [`TransitionState`] and replace it with an
23    /// empty one.
24    ///
25    /// See [core::mem::take].
26    pub fn take(&mut self) -> TransitionState {
27        core::mem::take(self)
28    }
29
30    /// Clear the transition state.
31    pub fn clear(&mut self) {
32        self.transitions.clear();
33    }
34}