coven_protocol/store_commit/
device_state.rs1use super::validation::validate_commit_frontier;
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 },
55}
56
57mod exclusion;
58mod resolution;
59mod retained;
60
61pub use exclusion::*;
62pub use resolution::*;
63pub use retained::*;
64
65#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
66#[serde(deny_unknown_fields)]
67pub struct StoreDeviceRecord {
68 pub registration: StoreDeviceRegistrationRef,
69 pub proposals: BTreeMap<StoreDeviceExclusionProposalId, StoreDeviceProposalState>,
70 pub status: StoreDeviceStatus,
71}
72
73impl OwnerRecoveryNodeRef {
74 pub fn slot(&self) -> &ObjectSlot {
75 self.object.slot()
76 }
77}