dpp/identity/conversion/platform_value/
mod.rs

1mod v0;
2
3use crate::identity::{Identity, IdentityV0};
4use crate::version::PlatformVersion;
5use crate::ProtocolError;
6use platform_value::Value;
7use platform_version::TryFromPlatformVersioned;
8pub use v0::IdentityPlatformValueConversionMethodsV0;
9
10impl IdentityPlatformValueConversionMethodsV0 for Identity {}
11
12impl TryFromPlatformVersioned<Value> for Identity {
13    type Error = ProtocolError;
14
15    fn try_from_platform_versioned(
16        value: Value,
17        platform_version: &PlatformVersion,
18    ) -> Result<Self, Self::Error> {
19        match platform_version
20            .dpp
21            .identity_versions
22            .identity_structure_version
23        {
24            0 => {
25                let identity_v0: IdentityV0 =
26                    platform_value::from_value(value).map_err(ProtocolError::ValueError)?;
27                Ok(identity_v0.into())
28            }
29            version => Err(ProtocolError::UnknownVersionMismatch {
30                method: "Identity::try_from_owned_value".to_string(),
31                known_versions: vec![0],
32                received: version,
33            }),
34        }
35    }
36}
37
38impl TryFromPlatformVersioned<&Value> for Identity {
39    type Error = ProtocolError;
40
41    fn try_from_platform_versioned(
42        value: &Value,
43        platform_version: &PlatformVersion,
44    ) -> Result<Self, Self::Error> {
45        match platform_version
46            .dpp
47            .identity_versions
48            .identity_structure_version
49        {
50            0 => {
51                let identity_v0: IdentityV0 =
52                    platform_value::from_value(value.clone()).map_err(ProtocolError::ValueError)?;
53                Ok(identity_v0.into())
54            }
55            version => Err(ProtocolError::UnknownVersionMismatch {
56                method: "Identity::try_from_owned_value".to_string(),
57                known_versions: vec![0],
58                received: version,
59            }),
60        }
61    }
62}