dpp/data_contract/
data_contract_facade.rs1use crate::data_contract::{DataContract, DataContractFactory};
2
3use crate::data_contract::created_data_contract::CreatedDataContract;
4use crate::prelude::{Identifier, IdentityNonce};
5#[cfg(feature = "state-transitions")]
6use crate::state_transition::data_contract_create_transition::DataContractCreateTransition;
7#[cfg(feature = "state-transitions")]
8use crate::state_transition::data_contract_update_transition::DataContractUpdateTransition;
9
10use crate::ProtocolError;
11use platform_value::Value;
12
13pub struct DataContractFacade {
27 factory: DataContractFactory,
28}
29
30impl DataContractFacade {
31 pub fn new(protocol_version: u32) -> Result<Self, ProtocolError> {
32 Ok(Self {
33 factory: DataContractFactory::new(protocol_version)?,
34 })
35 }
36
37 pub fn create(
39 &self,
40 owner_id: Identifier,
41 identity_nonce: IdentityNonce,
42 documents: Value,
43 config: Option<Value>,
44 definitions: Option<Value>,
45 ) -> Result<CreatedDataContract, ProtocolError> {
46 self.factory.create_with_value_config(
47 owner_id,
48 identity_nonce,
49 documents,
50 config,
51 definitions,
52 )
53 }
54
55 #[cfg(all(feature = "identity-serialization", feature = "client"))]
57 pub fn create_from_object(
58 &self,
59 raw_data_contract: Value,
60 #[cfg(feature = "validation")] skip_validation: bool,
61 ) -> Result<DataContract, ProtocolError> {
62 self.factory.create_from_object(
63 raw_data_contract,
64 #[cfg(feature = "validation")]
65 skip_validation,
66 )
67 }
68
69 #[cfg(all(feature = "identity-serialization", feature = "client"))]
71 pub fn create_from_buffer(
72 &self,
73 buffer: Vec<u8>,
74 #[cfg(feature = "validation")] skip_validation: bool,
75 ) -> Result<DataContract, ProtocolError> {
76 self.factory.create_from_buffer(
77 buffer,
78 #[cfg(feature = "validation")]
79 skip_validation,
80 )
81 }
82
83 #[cfg(feature = "state-transitions")]
84 pub fn create_data_contract_create_transition(
86 &self,
87 created_data_contract: CreatedDataContract,
88 ) -> Result<DataContractCreateTransition, ProtocolError> {
89 self.factory
90 .create_data_contract_create_transition(created_data_contract)
91 }
92
93 #[cfg(feature = "state-transitions")]
94 pub fn create_data_contract_update_transition(
96 &self,
97 data_contract: DataContract,
98 identity_contract_nonce: IdentityNonce,
99 ) -> Result<DataContractUpdateTransition, ProtocolError> {
100 self.factory
101 .create_data_contract_update_transition(data_contract, identity_contract_nonce)
102 }
103}