Skip to main content

libkeri/keri/db/basing/
habitat_record.rs

1use serde::{Deserialize, Serialize};
2
3/// Habitat application state information keyed by habitat name (baser.habs)
4///
5/// Corresponds to HabitatRecord dataclass from keripy
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct HabitatRecord {
9    /// Habitat own identifier prefix qb64
10    #[serde(default)]
11    pub hid: String,
12
13    /// Habitat name
14    #[serde(default)]
15    pub name: Option<String>,
16
17    /// Domain
18    #[serde(default)]
19    pub domain: Option<String>,
20
21    /// Group member identifier qb64 when hid is group
22    #[serde(default)]
23    pub mid: Option<String>,
24
25    /// Group signing member identifiers qb64 when hid is group
26    #[serde(default)]
27    pub smids: Option<Vec<String>>,
28
29    /// Group rotating member identifiers qb64 when hid is group
30    #[serde(default)]
31    pub rmids: Option<Vec<String>>,
32
33    /// Signify identifier qb64 when hid is Signify
34    #[serde(default)]
35    pub sid: Option<String>,
36
37    /// List of id prefixes qb64 of watchers
38    #[serde(default)]
39    pub watchers: Vec<String>,
40}
41
42impl Default for HabitatRecord {
43    fn default() -> Self {
44        HabitatRecord {
45            hid: "".to_string(),
46            name: None,
47            domain: None,
48            mid: None,
49            smids: None,
50            rmids: None,
51            sid: None,
52            watchers: Vec::new(),
53        }
54    }
55}
56
57impl HabitatRecord {
58    /// Create a new HabitatRecord with required hid field
59    pub fn new(hid: String) -> Self {
60        HabitatRecord {
61            hid,
62            ..Default::default()
63        }
64    }
65
66    /// Create a new HabitatRecord with hid and watchers
67    pub fn new_with_watchers(hid: String, watchers: Vec<String>) -> Self {
68        HabitatRecord {
69            hid,
70            watchers,
71            ..Default::default()
72        }
73    }
74}