radix_engine/system/
id_allocation.rs1use crate::blueprints::pool::v1::constants::*;
2use radix_common::types::EntityType;
3use radix_common::{constants::*, ScryptoSbor};
4use radix_engine_interface::blueprints::access_controller::*;
5use radix_engine_interface::blueprints::account::*;
6use radix_engine_interface::blueprints::consensus_manager::*;
7use radix_engine_interface::blueprints::identity::*;
8use radix_engine_interface::blueprints::locker::*;
9use radix_engine_interface::blueprints::package::*;
10use radix_engine_interface::blueprints::resource::*;
11use radix_engine_interface::types::BlueprintId;
12
13#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
14pub enum IDAllocation {
15 Object {
16 blueprint_id: BlueprintId,
17 global: bool,
18 },
19 KeyValueStore,
20 GlobalAddressReservation,
21 GlobalAddressPhantom {
22 blueprint_id: BlueprintId,
23 },
24}
25
26impl IDAllocation {
27 pub fn entity_type(&self) -> EntityType {
28 match self {
29 IDAllocation::Object {
30 blueprint_id,
31 global,
32 } => {
33 if *global {
34 get_global_entity_type(&blueprint_id)
35 } else {
36 get_internal_entity_type(&blueprint_id)
37 }
38 }
39 IDAllocation::KeyValueStore => EntityType::InternalKeyValueStore,
40 IDAllocation::GlobalAddressReservation => EntityType::InternalGenericComponent,
41 IDAllocation::GlobalAddressPhantom { blueprint_id } => {
42 get_global_entity_type(&blueprint_id)
43 }
44 }
45 }
46}
47
48pub fn get_internal_entity_type(blueprint_id: &BlueprintId) -> EntityType {
49 match (
50 blueprint_id.package_address,
51 blueprint_id.blueprint_name.as_str(),
52 ) {
53 (RESOURCE_PACKAGE, FUNGIBLE_VAULT_BLUEPRINT) => EntityType::InternalFungibleVault,
54 (RESOURCE_PACKAGE, NON_FUNGIBLE_VAULT_BLUEPRINT) => EntityType::InternalNonFungibleVault,
55 _ => EntityType::InternalGenericComponent,
56 }
57}
58
59pub fn get_global_entity_type(blueprint_id: &BlueprintId) -> EntityType {
60 match (
61 blueprint_id.package_address,
62 blueprint_id.blueprint_name.as_str(),
63 ) {
64 (PACKAGE_PACKAGE, PACKAGE_BLUEPRINT) => EntityType::GlobalPackage,
65 (RESOURCE_PACKAGE, FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT) => {
66 EntityType::GlobalFungibleResourceManager
67 }
68 (RESOURCE_PACKAGE, NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT) => {
69 EntityType::GlobalNonFungibleResourceManager
70 }
71 (CONSENSUS_MANAGER_PACKAGE, CONSENSUS_MANAGER_BLUEPRINT) => {
72 EntityType::GlobalConsensusManager
73 }
74 (CONSENSUS_MANAGER_PACKAGE, VALIDATOR_BLUEPRINT) => EntityType::GlobalValidator,
75 (ACCESS_CONTROLLER_PACKAGE, ACCESS_CONTROLLER_BLUEPRINT) => {
76 EntityType::GlobalAccessController
77 }
78 (ACCOUNT_PACKAGE, ACCOUNT_BLUEPRINT) => EntityType::GlobalAccount,
79 (IDENTITY_PACKAGE, IDENTITY_BLUEPRINT) => EntityType::GlobalIdentity,
80 (POOL_PACKAGE, ONE_RESOURCE_POOL_BLUEPRINT_IDENT) => EntityType::GlobalOneResourcePool,
81 (POOL_PACKAGE, TWO_RESOURCE_POOL_BLUEPRINT_IDENT) => EntityType::GlobalTwoResourcePool,
82 (POOL_PACKAGE, MULTI_RESOURCE_POOL_BLUEPRINT_IDENT) => EntityType::GlobalMultiResourcePool,
83 (LOCKER_PACKAGE, ACCOUNT_LOCKER_BLUEPRINT) => EntityType::GlobalAccountLocker,
84 _ => EntityType::GlobalGenericComponent,
85 }
86}