dpp/data_contract/accessors/v0/
mod.rs

1use crate::data_contract::config::DataContractConfig;
2use crate::data_contract::document_type::{DocumentType, DocumentTypeRef};
3use crate::data_contract::errors::DataContractError;
4use crate::data_contract::DocumentName;
5
6use platform_value::Identifier;
7use std::collections::BTreeMap;
8
9pub trait DataContractV0Getters {
10    /// Returns the unique identifier for the data contract.
11    fn id(&self) -> Identifier;
12
13    fn id_ref(&self) -> &Identifier;
14    fn system_version_type(&self) -> u16;
15
16    /// Returns the version of this data contract.
17    fn version(&self) -> u32;
18
19    /// Returns the identifier of the contract owner.
20    fn owner_id(&self) -> Identifier;
21    fn document_type_cloned_for_name(&self, name: &str) -> Result<DocumentType, DataContractError>;
22    fn document_type_borrowed_for_name(
23        &self,
24        name: &str,
25    ) -> Result<&DocumentType, DataContractError>;
26
27    /// Returns the document type for the given document name.
28    fn document_type_for_name(&self, name: &str) -> Result<DocumentTypeRef<'_>, DataContractError>;
29
30    fn document_type_optional_for_name(&self, name: &str) -> Option<DocumentTypeRef<'_>>;
31    fn document_type_cloned_optional_for_name(&self, name: &str) -> Option<DocumentType>;
32
33    fn has_document_type_for_name(&self, name: &str) -> bool;
34    fn document_types_with_contested_indexes(&self) -> BTreeMap<&DocumentName, &DocumentType>;
35
36    /// Returns a mapping of document names to their corresponding document types.
37    fn document_types(&self) -> &BTreeMap<DocumentName, DocumentType>;
38
39    /// Returns a mapping of document names to their corresponding document types as mutable.
40    fn document_types_mut(&mut self) -> &mut BTreeMap<DocumentName, DocumentType>;
41
42    /// Returns the internal configuration for the contract.
43    fn config(&self) -> &DataContractConfig;
44
45    /// Returns the internal configuration for the contract as mutable.
46    fn config_mut(&mut self) -> &mut DataContractConfig;
47}
48
49pub trait DataContractV0Setters {
50    /// Sets the unique identifier for the data contract.
51    fn set_id(&mut self, id: Identifier);
52
53    /// Sets the version of this data contract.
54    fn set_version(&mut self, version: u32);
55
56    fn increment_version(&mut self);
57
58    /// Sets the identifier of the contract owner.
59    fn set_owner_id(&mut self, owner_id: Identifier);
60
61    /// Sets the internal configuration for the contract.
62    fn set_config(&mut self, config: DataContractConfig);
63}