awaken_contract/state/
snapshot.rs1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::sync::Arc;
4
5use crate::model::JsonValue;
6
7use super::{StateKey, StateMap};
8
9#[derive(Clone)]
10pub struct Snapshot {
11 pub revision: u64,
12 pub ext: Arc<StateMap>,
13}
14
15impl Snapshot {
16 pub fn new(revision: u64, ext: Arc<StateMap>) -> Self {
17 Self { revision, ext }
18 }
19
20 pub fn revision(&self) -> u64 {
21 self.revision
22 }
23
24 pub fn get<K: StateKey>(&self) -> Option<&K::Value> {
25 self.ext.get::<K>()
26 }
27
28 pub fn ext(&self) -> &StateMap {
29 self.ext.as_ref()
30 }
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34pub struct PersistedState {
35 pub revision: u64,
36 pub extensions: HashMap<String, JsonValue>,
37}