dpp/data_contract/created_data_contract/v0/
mod.rs1use crate::data_contract::DataContract;
2use bincode::{Decode, Encode};
3
4use crate::data_contract::serialized_version::DataContractInSerializationFormat;
5use crate::prelude::IdentityNonce;
6#[cfg(feature = "value-conversion")]
7use crate::{
8 data_contract::{
9 conversion::value::v0::DataContractValueConversionMethodsV0,
10 created_data_contract::fields::property_names::{DATA_CONTRACT, IDENTITY_NONCE},
11 },
12 version::PlatformVersion,
13 ProtocolError,
14};
15#[cfg(feature = "value-conversion")]
16use platform_value::{btreemap_extensions::BTreeValueRemoveFromMapHelper, Error, Value};
17
18#[derive(Clone, Debug, PartialEq)]
20pub struct CreatedDataContractV0 {
21 pub data_contract: DataContract,
22 pub identity_nonce: IdentityNonce,
23}
24
25#[derive(Clone, Debug, Encode, Decode)]
26pub struct CreatedDataContractInSerializationFormatV0 {
27 pub data_contract: DataContractInSerializationFormat,
28 pub identity_nonce: IdentityNonce,
29}
30
31impl CreatedDataContractV0 {
32 #[cfg(feature = "value-conversion")]
33 pub fn from_object(
34 raw_object: Value,
35 full_validation: bool,
36 platform_version: &PlatformVersion,
37 ) -> Result<Self, ProtocolError> {
38 let mut raw_map = raw_object
39 .into_btree_string_map()
40 .map_err(ProtocolError::ValueError)?;
41
42 let raw_data_contract = raw_map.remove(DATA_CONTRACT).ok_or_else(|| {
43 Error::StructureError("unable to remove property dataContract".to_string())
44 })?;
45
46 let identity_nonce = raw_map
47 .remove_integer(IDENTITY_NONCE)
48 .map_err(ProtocolError::ValueError)?;
49
50 let data_contract =
51 DataContract::from_value(raw_data_contract, full_validation, platform_version)?;
52
53 Ok(Self {
54 data_contract,
55 identity_nonce,
56 })
57 }
58}