source.rs (2989B)
1 //! Source progress metadata, independent of physical inventory progress. 2 use super::{StockAuthorizationRef, WorkspaceError}; 3 use radroots_domain::{AuthorityRef, CheckpointDigest, Sequence}; 4 /// A caller-retained acknowledged source minimum. It establishes neither 5 /// protected provenance nor source completeness, actionability or authority. 6 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 7 pub struct StockSourceCheckpointRef { 8 authority: AuthorityRef, 9 revision: Sequence, 10 head: Option<CheckpointDigest>, 11 authorization: Option<StockAuthorizationRef>, 12 } 13 impl StockSourceCheckpointRef { 14 pub fn from_host_metadata( 15 authority: AuthorityRef, 16 revision: Sequence, 17 head: Option<CheckpointDigest>, 18 ) -> Result<Self, WorkspaceError> { 19 if (revision.get() == 0) != head.is_none() { 20 return Err(WorkspaceError::InvalidInput); 21 } 22 Ok(Self { 23 authority, 24 revision, 25 head, 26 authorization: None, 27 }) 28 } 29 pub const fn authority(self) -> AuthorityRef { 30 self.authority 31 } 32 pub const fn revision(self) -> Sequence { 33 self.revision 34 } 35 pub const fn head(self) -> Option<CheckpointDigest> { 36 self.head 37 } 38 pub const fn authorization(self) -> Option<StockAuthorizationRef> { 39 self.authorization 40 } 41 pub const fn with_authorization(mut self, state: StockAuthorizationRef) -> Self { 42 self.authorization = Some(state); 43 self 44 } 45 pub const fn with_optional_authorization( 46 mut self, 47 state: Option<StockAuthorizationRef>, 48 ) -> Self { 49 self.authorization = state; 50 self 51 } 52 } 53 54 /// Independently retained public-listing observation progress. This metadata 55 /// proves neither a global current head nor permission to request or accept. 56 /// Its distinct type prevents accidentally passing private-record progress. 57 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 58 pub struct StockListingCheckpointRef(StockSourceCheckpointRef); 59 impl StockListingCheckpointRef { 60 pub fn from_host_metadata( 61 authority: AuthorityRef, 62 revision: Sequence, 63 head: Option<CheckpointDigest>, 64 ) -> Result<Self, WorkspaceError> { 65 StockSourceCheckpointRef::from_host_metadata(authority, revision, head).map(Self) 66 } 67 pub const fn authority(self) -> AuthorityRef { 68 self.0.authority() 69 } 70 pub const fn revision(self) -> Sequence { 71 self.0.revision() 72 } 73 pub const fn head(self) -> Option<CheckpointDigest> { 74 self.0.head() 75 } 76 pub const fn authorization(self) -> Option<StockAuthorizationRef> { 77 self.0.authorization() 78 } 79 pub const fn with_authorization(self, state: StockAuthorizationRef) -> Self { 80 Self(self.0.with_authorization(state)) 81 } 82 pub const fn with_optional_authorization(self, state: Option<StockAuthorizationRef>) -> Self { 83 Self(self.0.with_optional_authorization(state)) 84 } 85 }