Skip to main content

dpp/document/v0/
accessors.rs

1use crate::document::{DocumentV0, DocumentV0Getters, DocumentV0Setters};
2use crate::identity::TimestampMillis;
3use crate::prelude::Revision;
4use platform_value::{Identifier, Value};
5use std::collections::BTreeMap;
6
7impl DocumentV0Getters for DocumentV0 {
8    /// Returns the document's unique identifier.
9    ///
10    /// # Returns
11    /// An `Identifier` representing the unique ID of the document.
12    fn id(&self) -> Identifier {
13        self.id
14    }
15
16    /// Returns the identifier of the document's owner.
17    ///
18    /// # Returns
19    /// An `Identifier` representing the owner's ID.
20    fn owner_id(&self) -> Identifier {
21        self.owner_id
22    }
23
24    /// Provides a reference to the document's properties.
25    ///
26    /// # Returns
27    /// A reference to a `BTreeMap<String, Value>` containing the document's properties.
28    fn properties(&self) -> &BTreeMap<String, Value> {
29        &self.properties
30    }
31
32    /// Provides a mutable reference to the document's properties.
33    ///
34    /// # Returns
35    /// A mutable reference to a `BTreeMap<String, Value>` containing the document's properties.
36    fn properties_mut(&mut self) -> &mut BTreeMap<String, Value> {
37        &mut self.properties
38    }
39
40    /// Returns the document's revision, if it is part
41    /// of the document. The document will have this field if it's schema has this document type
42    /// as mutable.
43    ///
44    /// # Returns
45    /// An `Option<Revision>` which is `Some(Revision)` if the document has a revision, or `None` if not.
46    fn revision(&self) -> Option<Revision> {
47        self.revision
48    }
49
50    /// Returns the timestamp of when the document was created, if it is part
51    /// of the document. The document will have this field if it's schema has it set as required.
52    ///
53    /// # Returns
54    /// An `Option<TimestampMillis>` representing the creation time in milliseconds, or `None` if not available.
55    fn created_at(&self) -> Option<TimestampMillis> {
56        self.created_at
57    }
58
59    /// Returns the timestamp of the last update to the document, if it is part
60    /// of the document. The document will have this field if it's schema has it set as required.
61    ///
62    /// # Returns
63    /// An `Option<TimestampMillis>` representing the update time in milliseconds, or `None` if not available.
64    fn updated_at(&self) -> Option<TimestampMillis> {
65        self.updated_at
66    }
67
68    /// Returns the timestamp of the last time the document was transferred, if it is part
69    /// of the document. The document will have this field if it's schema has it set as required.
70    ///
71    /// # Returns
72    /// An `Option<TimestampMillis>` representing the transferred at time in milliseconds, or `None` if not available.
73    fn transferred_at(&self) -> Option<TimestampMillis> {
74        self.transferred_at
75    }
76
77    /// Provides a reference to the document's unique identifier.
78    ///
79    /// # Returns
80    /// A reference to an `Identifier` representing the unique ID of the document.
81    fn id_ref(&self) -> &Identifier {
82        &self.id
83    }
84
85    /// Provides a reference to the document's owner identifier.
86    ///
87    /// # Returns
88    /// A reference to an `Identifier` representing the owner's ID.
89    fn owner_id_ref(&self) -> &Identifier {
90        &self.owner_id
91    }
92
93    /// Consumes the document and returns its properties.
94    ///
95    /// # Returns
96    /// A `BTreeMap<String, Value>` containing the document's properties.
97    fn properties_consumed(self) -> BTreeMap<String, Value> {
98        self.properties
99    }
100
101    /// Returns the block height at which the document was created, if it is part
102    /// of the document. The document will have this field if it's schema has it set as required.
103    ///
104    /// # Returns
105    /// An `Option<u64>` representing the creation block height, or `None` if not available.
106    fn created_at_block_height(&self) -> Option<u64> {
107        self.created_at_block_height
108    }
109
110    /// Returns the block height at which the document was last updated, if it is part
111    /// of the document. The document will have this field if it's schema has it set as required.
112    ///
113    /// # Returns
114    /// An `Option<u64>` representing the update block height, or `None` if not available.
115    fn updated_at_block_height(&self) -> Option<u64> {
116        self.updated_at_block_height
117    }
118
119    /// Returns the block height of the last time the document was transferred, if it is part
120    /// of the document. The document will have this field if it's schema has it set as required.
121    ///
122    /// # Returns
123    /// An `Option<u64>` representing the transfer block height, or `None` if not available.
124    fn transferred_at_block_height(&self) -> Option<u64> {
125        self.transferred_at_block_height
126    }
127
128    /// Returns the core network block height at which the document was created, if it is part
129    /// of the document. The document will have this field if it's schema has it set as required.
130    ///
131    /// # Returns
132    /// An `Option<u32>` representing the creation core block height, or `None` if not available.
133    fn created_at_core_block_height(&self) -> Option<u32> {
134        self.created_at_core_block_height
135    }
136
137    /// Returns the core network block height at which the document was last updated, if it is part
138    /// of the document. The document will have this field if it's schema has it set as required.
139    ///
140    /// # Returns
141    /// An `Option<u32>` representing the update core block height, or `None` if not available.
142    fn updated_at_core_block_height(&self) -> Option<u32> {
143        self.updated_at_core_block_height
144    }
145
146    /// Returns the core network block height of the last time the document was transferred, if it is part
147    /// of the document. The document will have this field if it's schema has it set as required.
148    ///
149    /// # Returns
150    /// An `Option<u32>` representing the transfer core block height, or `None` if not available.
151    fn transferred_at_core_block_height(&self) -> Option<u32> {
152        self.transferred_at_core_block_height
153    }
154
155    /// Returns the creator identifier of the document, if it is part
156    /// of the document. The document will have this field if it's schema has it set as required.
157    ///
158    /// # Returns
159    /// An `Option<Identifier>` representing the creator's ID, or `None` if not available.
160    fn creator_id(&self) -> Option<Identifier> {
161        self.creator_id
162    }
163
164    fn contract_version(&self) -> Option<u32> {
165        self.contract_version
166    }
167
168    fn moderated_at(&self) -> Option<TimestampMillis> {
169        self.moderated_at
170    }
171
172    fn moderated_by(&self) -> Option<Identifier> {
173        self.moderated_by
174    }
175}
176
177impl DocumentV0Setters for DocumentV0 {
178    /// Sets the document's unique identifier.
179    ///
180    /// # Parameters
181    /// - `id`: An `Identifier` to set as the document's unique ID.
182    fn set_id(&mut self, id: Identifier) {
183        self.id = id;
184    }
185
186    /// Sets the identifier of the document's owner.
187    ///
188    /// # Parameters
189    /// - `owner_id`: An `Identifier` to set as the document's owner ID.
190    fn set_owner_id(&mut self, owner_id: Identifier) {
191        self.owner_id = owner_id;
192    }
193
194    /// Sets the document's properties.
195    ///
196    /// # Parameters
197    /// - `properties`: A `BTreeMap<String, Value>` containing the properties to set for the document.
198    fn set_properties(&mut self, properties: BTreeMap<String, Value>) {
199        self.properties = properties;
200    }
201
202    /// Sets the document's revision. This is applicable if the document's schema indicates
203    /// the document type as mutable.
204    ///
205    /// # Parameters
206    /// - `revision`: An `Option<Revision>` to set as the document's revision. `None` indicates
207    ///   the document does not have a revision.
208    fn set_revision(&mut self, revision: Option<Revision>) {
209        self.revision = revision;
210    }
211
212    /// Bumps the document's revision if it has one. This is applicable if the document's schema indicates
213    /// the document type as mutable.
214    ///
215    fn bump_revision(&mut self) {
216        if let Some(revision) = self.revision {
217            self.revision = Some(revision.saturating_add(1))
218        }
219    }
220
221    /// Sets the timestamp of when the document was created. This is applicable if the document's
222    /// schema requires a creation timestamp.
223    ///
224    /// # Parameters
225    /// - `created_at`: An `Option<TimestampMillis>` to set as the document's creation timestamp.
226    ///   `None` indicates the timestamp is not available.
227    fn set_created_at(&mut self, created_at: Option<TimestampMillis>) {
228        self.created_at = created_at;
229    }
230
231    /// Sets the timestamp of the last update to the document. This is applicable if the document's
232    /// schema requires an update timestamp.
233    ///
234    /// # Parameters
235    /// - `updated_at`: An `Option<TimestampMillis>` to set as the document's last update timestamp.
236    ///   `None` indicates the timestamp is not available.
237    fn set_updated_at(&mut self, updated_at: Option<TimestampMillis>) {
238        self.updated_at = updated_at;
239    }
240
241    fn set_transferred_at(&mut self, transferred_at: Option<TimestampMillis>) {
242        self.transferred_at = transferred_at;
243    }
244
245    /// Sets the block height at which the document was created. This is applicable if the document's
246    /// schema requires this information.
247    ///
248    /// # Parameters
249    /// - `created_at_block_height`: An `Option<u64>` to set as the document's creation block height.
250    ///   `None` indicates the block height is not available.
251    fn set_created_at_block_height(&mut self, created_at_block_height: Option<u64>) {
252        self.created_at_block_height = created_at_block_height;
253    }
254
255    /// Sets the block height at which the document was last updated. This is applicable if the document's
256    /// schema requires this information.
257    ///
258    /// # Parameters
259    /// - `updated_at_block_height`: An `Option<u64>` to set as the document's last update block height.
260    ///   `None` indicates the block height is not available.
261    fn set_updated_at_block_height(&mut self, updated_at_block_height: Option<u64>) {
262        self.updated_at_block_height = updated_at_block_height;
263    }
264
265    fn set_transferred_at_block_height(&mut self, transferred_at_block_height: Option<u64>) {
266        self.transferred_at_block_height = transferred_at_block_height;
267    }
268
269    /// Sets the core network block height at which the document was created. This is applicable if the
270    /// document's schema requires this information.
271    ///
272    /// # Parameters
273    /// - `created_at_core_block_height`: An `Option<u32>` to set as the document's creation core block height.
274    ///   `None` indicates the core block height is not available.
275    fn set_created_at_core_block_height(&mut self, created_at_core_block_height: Option<u32>) {
276        self.created_at_core_block_height = created_at_core_block_height;
277    }
278
279    /// Sets the core network block height at which the document was last updated. This is applicable if the
280    /// document's schema requires this information.
281    ///
282    /// # Parameters
283    /// - `updated_at_core_block_height`: An `Option<u32>` to set as the document's last update core block height.
284    ///   `None` indicates the core block height is not available.
285    fn set_updated_at_core_block_height(&mut self, updated_at_core_block_height: Option<u32>) {
286        self.updated_at_core_block_height = updated_at_core_block_height;
287    }
288
289    fn set_transferred_at_core_block_height(
290        &mut self,
291        transferred_at_core_block_height: Option<u32>,
292    ) {
293        self.transferred_at_core_block_height = transferred_at_core_block_height;
294    }
295
296    /// Sets the creator identifier of the document. This is applicable if the document's
297    /// schema requires this information.
298    ///
299    /// # Parameters
300    /// - `creator_id`: An `Option<Identifier>` to set as the document's creator ID.
301    ///   `None` indicates the creator ID is not available.
302    fn set_creator_id(&mut self, creator_id: Option<Identifier>) {
303        self.creator_id = creator_id;
304    }
305
306    /// Sets the contract-version stamp: the data contract version this
307    /// document's bytes conform to. Assigned by Drive when document content
308    /// is (re-)supplied; `None` for pre-stamp documents.
309    fn set_contract_version(&mut self, contract_version: Option<u32>) {
310        self.contract_version = contract_version;
311    }
312
313    fn set_moderated_at(&mut self, moderated_at: Option<TimestampMillis>) {
314        self.moderated_at = moderated_at;
315    }
316
317    fn set_moderated_by(&mut self, moderated_by: Option<Identifier>) {
318        self.moderated_by = moderated_by;
319    }
320}