daedalus_runtime/
snapshot.rs1use crate::state::StateStore;
3
4#[derive(Clone, Debug)]
6pub struct Snapshot {
7 pub state: String,
8}
9
10impl Snapshot {
11 pub fn new(state: String) -> Self {
12 Self { state }
13 }
14}
15
16pub struct SnapshotManager {
18 store: StateStore,
19}
20
21impl SnapshotManager {
22 pub fn new(store: StateStore) -> Self {
23 Self { store }
24 }
25
26 pub fn take(&self) -> Snapshot {
27 let state = self.store.dump_json().unwrap_or_else(|_| "{}".into());
28 Snapshot::new(state)
29 }
30
31 pub fn restore(&self, snapshot: &Snapshot) {
32 let _ = self.store.load_json(&snapshot.state);
33 }
34}