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
169impl DocumentV0Setters for DocumentV0 {
170 /// Sets the document's unique identifier.
171 ///
172 /// # Parameters
173 /// - `id`: An `Identifier` to set as the document's unique ID.
174 fn set_id(&mut self, id: Identifier) {
175 self.id = id;
176 }
177
178 /// Sets the identifier of the document's owner.
179 ///
180 /// # Parameters
181 /// - `owner_id`: An `Identifier` to set as the document's owner ID.
182 fn set_owner_id(&mut self, owner_id: Identifier) {
183 self.owner_id = owner_id;
184 }
185
186 /// Sets the document's properties.
187 ///
188 /// # Parameters
189 /// - `properties`: A `BTreeMap<String, Value>` containing the properties to set for the document.
190 fn set_properties(&mut self, properties: BTreeMap<String, Value>) {
191 self.properties = properties;
192 }
193
194 /// Sets the document's revision. This is applicable if the document's schema indicates
195 /// the document type as mutable.
196 ///
197 /// # Parameters
198 /// - `revision`: An `Option<Revision>` to set as the document's revision. `None` indicates
199 /// the document does not have a revision.
200 fn set_revision(&mut self, revision: Option<Revision>) {
201 self.revision = revision;
202 }
203
204 /// Bumps the document's revision if it has one. This is applicable if the document's schema indicates
205 /// the document type as mutable.
206 ///
207 fn bump_revision(&mut self) {
208 if let Some(revision) = self.revision {
209 self.revision = Some(revision.saturating_add(1))
210 }
211 }
212
213 /// Sets the timestamp of when the document was created. This is applicable if the document's
214 /// schema requires a creation timestamp.
215 ///
216 /// # Parameters
217 /// - `created_at`: An `Option<TimestampMillis>` to set as the document's creation timestamp.
218 /// `None` indicates the timestamp is not available.
219 fn set_created_at(&mut self, created_at: Option<TimestampMillis>) {
220 self.created_at = created_at;
221 }
222
223 /// Sets the timestamp of the last update to the document. This is applicable if the document's
224 /// schema requires an update timestamp.
225 ///
226 /// # Parameters
227 /// - `updated_at`: An `Option<TimestampMillis>` to set as the document's last update timestamp.
228 /// `None` indicates the timestamp is not available.
229 fn set_updated_at(&mut self, updated_at: Option<TimestampMillis>) {
230 self.updated_at = updated_at;
231 }
232
233 fn set_transferred_at(&mut self, transferred_at: Option<TimestampMillis>) {
234 self.transferred_at = transferred_at;
235 }
236
237 /// Sets the block height at which the document was created. This is applicable if the document's
238 /// schema requires this information.
239 ///
240 /// # Parameters
241 /// - `created_at_block_height`: An `Option<u64>` to set as the document's creation block height.
242 /// `None` indicates the block height is not available.
243 fn set_created_at_block_height(&mut self, created_at_block_height: Option<u64>) {
244 self.created_at_block_height = created_at_block_height;
245 }
246
247 /// Sets the block height at which the document was last updated. This is applicable if the document's
248 /// schema requires this information.
249 ///
250 /// # Parameters
251 /// - `updated_at_block_height`: An `Option<u64>` to set as the document's last update block height.
252 /// `None` indicates the block height is not available.
253 fn set_updated_at_block_height(&mut self, updated_at_block_height: Option<u64>) {
254 self.updated_at_block_height = updated_at_block_height;
255 }
256
257 fn set_transferred_at_block_height(&mut self, transferred_at_block_height: Option<u64>) {
258 self.transferred_at_block_height = transferred_at_block_height;
259 }
260
261 /// Sets the core network block height at which the document was created. This is applicable if the
262 /// document's schema requires this information.
263 ///
264 /// # Parameters
265 /// - `created_at_core_block_height`: An `Option<u32>` to set as the document's creation core block height.
266 /// `None` indicates the core block height is not available.
267 fn set_created_at_core_block_height(&mut self, created_at_core_block_height: Option<u32>) {
268 self.created_at_core_block_height = created_at_core_block_height;
269 }
270
271 /// Sets the core network block height at which the document was last updated. This is applicable if the
272 /// document's schema requires this information.
273 ///
274 /// # Parameters
275 /// - `updated_at_core_block_height`: An `Option<u32>` to set as the document's last update core block height.
276 /// `None` indicates the core block height is not available.
277 fn set_updated_at_core_block_height(&mut self, updated_at_core_block_height: Option<u32>) {
278 self.updated_at_core_block_height = updated_at_core_block_height;
279 }
280
281 fn set_transferred_at_core_block_height(
282 &mut self,
283 transferred_at_core_block_height: Option<u32>,
284 ) {
285 self.transferred_at_core_block_height = transferred_at_core_block_height;
286 }
287
288 /// Sets the creator identifier of the document. This is applicable if the document's
289 /// schema requires this information.
290 ///
291 /// # Parameters
292 /// - `creator_id`: An `Option<Identifier>` to set as the document's creator ID.
293 /// `None` indicates the creator ID is not available.
294 fn set_creator_id(&mut self, creator_id: Option<Identifier>) {
295 self.creator_id = creator_id;
296 }
297
298 /// Sets the contract-version stamp: the data contract version this
299 /// document's bytes conform to. Assigned by Drive when document content
300 /// is (re-)supplied; `None` for pre-stamp documents.
301 fn set_contract_version(&mut self, contract_version: Option<u32>) {
302 self.contract_version = contract_version;
303 }
304}