radix_common/data/manifest/
custom_extension.rs

1use crate::internal_prelude::*;
2
3#[derive(Debug, Clone, PartialEq, Eq, Copy)]
4pub enum ManifestCustomExtension {}
5
6impl CustomExtension for ManifestCustomExtension {
7    const PAYLOAD_PREFIX: u8 = MANIFEST_SBOR_V1_PAYLOAD_PREFIX;
8
9    type CustomValueKind = ManifestCustomValueKind;
10    type CustomTraversal = ManifestCustomTraversal;
11    // NOTE: ManifestSbor is actually validated against Scrypto schemas
12    type CustomSchema = ScryptoCustomSchema;
13
14    fn custom_value_kind_matches_type_kind(
15        schema: &Schema<Self::CustomSchema>,
16        custom_value_kind: Self::CustomValueKind,
17        type_kind: &LocalTypeKind<Self::CustomSchema>,
18    ) -> bool {
19        match custom_value_kind {
20            ManifestCustomValueKind::Address => matches!(
21                type_kind,
22                TypeKind::Custom(ScryptoCustomTypeKind::Reference)
23            ),
24            ManifestCustomValueKind::Bucket => {
25                matches!(type_kind, TypeKind::Custom(ScryptoCustomTypeKind::Own))
26            }
27            ManifestCustomValueKind::Proof => {
28                matches!(type_kind, TypeKind::Custom(ScryptoCustomTypeKind::Own))
29            }
30            ManifestCustomValueKind::AddressReservation => {
31                matches!(type_kind, TypeKind::Custom(ScryptoCustomTypeKind::Own))
32            }
33            // An Expression can only be a Vec<Proof> or Vec<Manifest> at the moment
34            // - in other words they're both a Vec<Own> at the TypeKind level
35            ManifestCustomValueKind::Expression => matches!(
36                type_kind,
37                TypeKind::Array { element_type }
38                    if matches!(schema.resolve_type_kind(*element_type), Some(TypeKind::Custom(ScryptoCustomTypeKind::Own)))
39            ),
40            ManifestCustomValueKind::Blob => matches!(
41                type_kind,
42                TypeKind::Array { element_type }
43                    if matches!(schema.resolve_type_kind(*element_type), Some(TypeKind::U8))
44            ),
45            ManifestCustomValueKind::Decimal => {
46                matches!(type_kind, TypeKind::Custom(ScryptoCustomTypeKind::Decimal))
47            }
48            ManifestCustomValueKind::PreciseDecimal => matches!(
49                type_kind,
50                TypeKind::Custom(ScryptoCustomTypeKind::PreciseDecimal)
51            ),
52            ManifestCustomValueKind::NonFungibleLocalId => matches!(
53                type_kind,
54                TypeKind::Custom(ScryptoCustomTypeKind::NonFungibleLocalId)
55            ),
56        }
57    }
58
59    fn custom_type_kind_matches_non_custom_value_kind(
60        _: &Schema<Self::CustomSchema>,
61        _: &<Self::CustomSchema as CustomSchema>::CustomLocalTypeKind,
62        _: ValueKind<Self::CustomValueKind>,
63    ) -> bool {
64        // No custom type kinds can match non-custom value kinds
65        false
66    }
67}