holochain_types/
metadata.rs

1//! Types for getting and storing metadata
2
3use holo_hash::ActionHash;
4use holochain_serialized_bytes::prelude::*;
5pub use holochain_zome_types::metadata::EntryDhtStatus;
6use holochain_zome_types::prelude::*;
7use std::collections::BTreeSet;
8
9/// Timestamp of when the action was created with the actions hash.
10#[derive(Debug, Hash, PartialOrd, Ord, PartialEq, Eq, Clone, Serialize, Deserialize)]
11pub struct TimedActionHash {
12    /// Time when this action was created
13    pub timestamp: Timestamp,
14    /// Hash of the action
15    pub action_hash: ActionHash,
16}
17
18/// Metadata returned from a GetMeta request.
19/// The Ord derive on TimedActionHash means each set is ordered by time.
20#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, SerializedBytes)]
21pub struct MetadataSet {
22    /// Actions that created or updated an entry.
23    /// These are the actions that show the entry exists.
24    pub actions: BTreeSet<TimedActionHash>,
25    // TODO: Implement after validation
26    /// Placeholder
27    pub invalid_actions: BTreeSet<TimedActionHash>,
28    /// Deletes on an action
29    pub deletes: BTreeSet<TimedActionHash>,
30    /// Updates on an action or entry
31    pub updates: BTreeSet<TimedActionHash>,
32    /// The status of an entry from an authority.
33    /// This is simply a faster way of determining if
34    /// there are any live actions on an entry.
35    pub entry_dht_status: Option<EntryDhtStatus>,
36}
37
38impl From<ActionHashed> for TimedActionHash {
39    fn from(h: ActionHashed) -> Self {
40        let (action, hash) = h.into_inner();
41        TimedActionHash {
42            timestamp: action.timestamp(),
43            action_hash: hash,
44        }
45    }
46}
47
48impl From<ActionHash> for TimedActionHash {
49    fn from(h: ActionHash) -> Self {
50        TimedActionHash {
51            timestamp: Timestamp::now(),
52            action_hash: h,
53        }
54    }
55}