Skip to main content

coven_protocol/store_commit/
device_state.rs

1use super::validation::{validate_commit_frontier, validate_store_device_state_ref};
2use super::*;
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(deny_unknown_fields)]
6pub struct StoreDeviceStateRef {
7    frontier: CommitFrontier,
8    recovery: Vec<OwnerRecoveryCursor>,
9    state_hash: ObjectHash,
10}
11
12impl StoreDeviceStateRef {
13    pub fn from_resolved(
14        frontier: CommitFrontier,
15        state: &ResolvedStoreDeviceState,
16    ) -> Result<Self, StoreProtocolError> {
17        validate_commit_frontier(&frontier)?;
18        validate_recovery_cursors(&state.recovery)?;
19        Ok(Self {
20            frontier,
21            recovery: state.recovery.clone(),
22            state_hash: state.state_hash,
23        })
24    }
25
26    pub fn state_hash(&self) -> ObjectHash {
27        self.state_hash
28    }
29
30    pub fn recovery(&self) -> &[OwnerRecoveryCursor] {
31        &self.recovery
32    }
33
34    pub fn frontier(&self) -> &CommitFrontier {
35        &self.frontier
36    }
37
38    pub fn with_frontier(&self, frontier: CommitFrontier) -> Result<Self, StoreProtocolError> {
39        validate_commit_frontier(&frontier)?;
40        Ok(Self {
41            frontier,
42            recovery: self.recovery.clone(),
43            state_hash: self.state_hash,
44        })
45    }
46}
47
48#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
49#[serde(rename_all = "snake_case", deny_unknown_fields)]
50pub enum StoreDeviceStatus {
51    Active,
52    Inactive {
53        terminals: Vec<StoreDeviceExclusionRef>,
54        accepted_cut: StoreHistoryCut,
55    },
56}
57
58mod exclusion;
59mod resolution;
60mod retained;
61
62pub use exclusion::*;
63pub use resolution::*;
64pub use retained::*;
65
66#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67#[serde(deny_unknown_fields)]
68pub struct StoreDeviceRecord {
69    pub registration: StoreDeviceRegistrationRef,
70    pub proposals: BTreeMap<StoreDeviceExclusionProposalId, StoreDeviceProposalState>,
71    pub status: StoreDeviceStatus,
72}
73
74impl OwnerRecoveryNodeRef {
75    pub fn slot(&self) -> &ObjectSlot {
76        self.object.slot()
77    }
78}