Skip to main content

dpp/document/document_methods/
mod.rs

1use crate::data_contract::document_type::DocumentTypeRef;
2use crate::data_contract::DataContract;
3use crate::version::PlatformVersion;
4use crate::ProtocolError;
5
6mod get_raw_array_elements_for_document_type;
7mod get_raw_for_contract;
8mod get_raw_for_document_type;
9mod hash;
10mod is_equal_ignoring_timestamps;
11
12pub(in crate::document) use get_raw_array_elements_for_document_type::*;
13pub(in crate::document) use get_raw_for_contract::*;
14pub(in crate::document) use get_raw_for_document_type::*;
15pub(in crate::document) use hash::*;
16pub(in crate::document) use is_equal_ignoring_timestamps::*;
17
18pub trait DocumentMethodsV0 {
19    /// Return a value given the path to its key and the document type for a contract.
20    fn get_raw_for_contract(
21        &self,
22        key: &str,
23        document_type_name: &str,
24        contract: &DataContract,
25        owner_id: Option<[u8; 32]>,
26        platform_version: &PlatformVersion,
27    ) -> Result<Option<Vec<u8>>, ProtocolError>;
28
29    /// Return a value given the path to its key for a document type.
30    fn get_raw_for_document_type(
31        &self,
32        key_path: &str,
33        document_type: DocumentTypeRef,
34        owner_id: Option<[u8; 32]>,
35        platform_version: &PlatformVersion,
36    ) -> Result<Option<Vec<u8>>, ProtocolError>;
37
38    /// The distinct index keys of the elements of the typed array at `key_path`, sorted: the
39    /// keys an index naming the array enters the document under.
40    fn get_raw_array_elements_for_document_type(
41        &self,
42        key_path: &str,
43        document_type: DocumentTypeRef,
44        platform_version: &PlatformVersion,
45    ) -> Result<Vec<Vec<u8>>, ProtocolError>;
46
47    fn hash(
48        &self,
49        contract: &DataContract,
50        document_type: DocumentTypeRef,
51        platform_version: &PlatformVersion,
52    ) -> Result<Vec<u8>, ProtocolError>;
53
54    fn increment_revision(&mut self) -> Result<(), ProtocolError>;
55
56    /// Checks to see if a document is equal without time based fields.
57    /// Since these fields are set on the network this function can be useful to make sure that
58    /// fields that were supplied have not changed, while ignoring those that are set network side.
59    /// Time based fields that are ignored are
60    ///     created_at/updated_at
61    ///     created_at_block_height/updated_at_block_height
62    ///     created_at_core_block_height/updated_at_core_block_height
63    fn is_equal_ignoring_time_based_fields(
64        &self,
65        rhs: &Self,
66        also_ignore_fields: Option<Vec<&str>>,
67        platform_version: &PlatformVersion,
68    ) -> Result<bool, ProtocolError>;
69}