daedalus_runtime/
snapshot.rs

1//! Snapshot/restore scaffolding (feature-gated via `snapshots` when wiring real storage).
2use crate::state::StateStore;
3
4/// Represents a serialized snapshot of runtime state.
5#[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
16/// Snapshot manager; currently JSON-serializes the StateStore for deterministic tests.
17pub 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}