cfx_executor/state/state_object/
save.rs

1use std::collections::HashMap;
2
3use crate::state::{global_stat::GlobalStat, overlay_account::AccountEntry};
4use cfx_types::AddressWithSpace;
5
6use super::State;
7
8pub struct SavedState {
9    committed_cache: HashMap<AddressWithSpace, AccountEntry>,
10    global_stat: GlobalStat,
11}
12
13impl State {
14    pub fn save(&mut self) -> SavedState {
15        self.commit_cache(false);
16        let committed_cache = self
17            .committed_cache
18            .iter()
19            .map(|(k, v)| (*k, v.clone_account()))
20            .collect();
21        SavedState {
22            committed_cache,
23            global_stat: self.global_stat.clone(),
24        }
25    }
26
27    pub fn restore(&mut self, saved: SavedState) {
28        assert!(self.no_checkpoint());
29        self.cache = Default::default();
30        self.committed_cache = saved.committed_cache;
31        self.global_stat = saved.global_stat;
32    }
33}