radix_engine/system/
type_info.rs

1use crate::errors::*;
2use crate::internal_prelude::*;
3use crate::kernel::kernel_api::KernelSubstateApi;
4use radix_engine_interface::api::field_api::LockFlags;
5
6#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor, ScryptoSborAssertion)]
7#[sbor_assert(backwards_compatible(cuttlefish = "FILE:type_info_substate_cuttlefish_schema.bin",))]
8pub enum TypeInfoSubstate {
9    Object(ObjectInfo),
10    KeyValueStore(KeyValueStoreInfo),
11    /// Represents the ownership of an allocated global address.
12    GlobalAddressReservation(GlobalAddress),
13    /// Represents a phantom global object, to make allocated global address usable.
14    GlobalAddressPhantom(GlobalAddressPhantom),
15}
16
17impl TypeInfoSubstate {
18    pub fn outer_object(&self) -> Option<GlobalAddress> {
19        match self {
20            TypeInfoSubstate::Object(ObjectInfo {
21                blueprint_info:
22                    BlueprintInfo {
23                        outer_obj_info: OuterObjectInfo::Some { outer_object },
24                        ..
25                    },
26                ..
27            }) => Some(*outer_object),
28            _ => None,
29        }
30    }
31}
32
33pub struct TypeInfoBlueprint;
34
35impl TypeInfoBlueprint {
36    pub(crate) fn get_type<Y: KernelSubstateApi<L>, L: Default>(
37        receiver: &NodeId,
38        api: &mut Y,
39    ) -> Result<TypeInfoSubstate, RuntimeError> {
40        let handle = api.kernel_open_substate(
41            receiver,
42            TYPE_INFO_FIELD_PARTITION,
43            &TypeInfoField::TypeInfo.into(),
44            LockFlags::read_only(),
45            L::default(),
46        )?;
47        let info: TypeInfoSubstate = api.kernel_read_substate(handle)?.as_typed().unwrap();
48        api.kernel_close_substate(handle)?;
49        Ok(info)
50    }
51}