radix_common/types/entity_type.rs
1use crate::prelude::*;
2use sbor::Sbor;
3use strum::FromRepr;
4use strum::IntoStaticStr;
5
6//=========================================================================
7// Please update REP-60 after updating types/configs defined in this file!
8// Please use and update REP-71 for choosing an entity type prefix
9//=========================================================================
10
11/// An enum which represents the different addressable entities.
12#[repr(u8)]
13#[derive(
14 Clone, Copy, Debug, PartialEq, Eq, Ord, Hash, PartialOrd, FromRepr, Sbor, IntoStaticStr,
15)]
16#[sbor(use_repr_discriminators)]
17pub enum EntityType {
18 //=========================================================================
19 // Package (start with char p for package)
20 //=========================================================================
21 /// A global package entity (13 in decimal). Gives Bech32 prefix: `p` followed by one of `5`, `4`, `k` or `h`.
22 GlobalPackage = 0b00001101, //------------------- 00001 => p, 101xx => 54kh [pkg vanity prefix]
23
24 //=========================================================================
25 // System Components (start with char s for system)
26 //=========================================================================
27 /// The global consensus manager entity (134 in decimal). Gives Bech32 prefix: `s` followed by one of `c`, `e`, `6` or `m`.
28 GlobalConsensusManager = 0b10000110, //-------------- 10000 => s, 110xx => ce6m [se vanity prefix]
29
30 /// A global validator entity (131 in decimal). Gives Bech32 prefix: `s` followed by one of `v`, `d`, `w` or `0`.
31 GlobalValidator = 0b10000011, //--------------------- 10000 => s, 011xx => vdw0
32
33 /// A global transaction tracker (130 in decimal). Gives Bech32 prefix: `s` followed by one of `g`, `f`, `2` or `t`.
34 GlobalTransactionTracker = 0b10000010, //-------- 10000 => s, 010xx => gf2t [st vanity prefix]
35
36 //=========================================================================
37 // Standard Global Components (start with char c for component)
38 //=========================================================================
39 /// A global generic (eg scrypto) component entity (192 in decimal). Gives Bech32 prefix: `c` followed by one of `q`, `p`, `z` or `r`.
40 GlobalGenericComponent = 0b11000000, //---------- 11000 => c, 000xx => qpzr [cpt vanity prefix] (000 = generic component)
41
42 /// A global allocated native account component entity (193 in decimal). Gives Bech32 prefix: `c` followed by one of `y`, `9`, `x` or `8`.
43 GlobalAccount = 0b11000001, //------------------- 11000 => c, 001xx => y9x8 (001 = account)
44
45 /// A global allocated native identity component entity (194 in decimal). Gives Bech32 prefix: `c` followed by one of `g`, `f`, `2` or `t`.
46 GlobalIdentity = 0b11000010, //------------------ 11000 => c, 010xx => gf2t (010 = identity)
47
48 /// A global native access controller entity (195 in decimal). Gives Bech32 prefix: `c` followed by one of `v`, `d`, `w` or `0`.
49 GlobalAccessController = 0b11000011, //---------- 11000 => c, 011xx => vdw0 (011 = access controller)
50
51 /// A global native pool entity (196 in decimal). Gives Bech32 prefix: `c` followed by one of `s`, `3`, `j` or `n`.
52 GlobalOneResourcePool = 0b11000100, //----------- 11000 => c, 100xx => s3jn (100 = pool)
53
54 /// A global native pool entity (197 in decimal). Gives Bech32 prefix: `c` followed by one of `5`, `4`, `k` or `h`.
55 GlobalTwoResourcePool = 0b11000101, //----------- 11000 => c, 101xx => 54kh (101 = pool)
56
57 /// A global native pool entity (198 in decimal). Gives Bech32 prefix: `c` followed by one of `c`, `e`, `6` or `m`.
58 GlobalMultiResourcePool = 0b11000110, //--------- 11000 => c, 110xx => ce6m (101 = pool)
59
60 //=========================================================================
61 // Standard Global Components (start with char d since c is fully taken)
62 //=========================================================================
63 /// A global native locker component (104 in decimal). Gives Bech32 prefix: `d` followed by one of `q`, `p`, `z` or `r`.
64 GlobalAccountLocker = 0b01101000, //--------- 01101 => d, 000xx => qpzr (000 = account locker)
65
66 //=========================================================================
67 // Secp256k1 Preallocated Global Components (start with char 6 for Secp256k1)
68 //=========================================================================
69 /// A global preallocated Secp256k1 account component entity (209 in decimal). Gives Bech32 prefix: `6` followed by one of `y`, `9`, `x` or `8`.
70 GlobalPreallocatedSecp256k1Account = 0b11010001, //--- 11010 => 6, 001xx => y9x8 (001 = account)
71
72 /// A global preallocated Secp256k1 identity component entity (210 in decimal). Gives Bech32 prefix: `6` followed by one of `g`, `f`, `2` or `t`.
73 GlobalPreallocatedSecp256k1Identity = 0b11010010, //-- 11010 => 6, 010xx => gf2t (010 = identity)
74
75 //=========================================================================
76 // Ed25519 Preallocated Global Components (start with char 2 for Ed25519)
77 //=========================================================================
78 /// A global preallocated Ed25519 account component entity (81 in decimal). Gives Bech32 prefix: `2` followed by one of `y`, `9`, `x` or `8`.
79 GlobalPreallocatedEd25519Account = 0b01010001, //----- 01010 => 2, 001xx => y9x8 (001 = account)
80
81 /// A global preallocated Ed25519 identity component entity (82 in decimal). Gives Bech32 prefix: `2` followed by one of `g`, `f`, `2` or `t`.
82 GlobalPreallocatedEd25519Identity = 0b01010010, //---- 01010 => 2, 010xx => gf2t (010 = identity)
83
84 //=========================================================================
85 // Fungible-related (start with letter t for token)
86 //=========================================================================
87 /// A global fungible resource entity (93 in decimal). Gives Bech32 prefix: `t` followed by one of `5`, `4`, `k` or `h`.
88 GlobalFungibleResourceManager = 0b01011101, //---------- 01011 => t, 101xx => 54kh [tkn vanity prefix]
89 /// An internal fungible vault entity (88 in decimal). Gives Bech32 prefix: `t` followed by one of `q`, `p`, `z` or `r`.
90 InternalFungibleVault = 0b01011000, //------------------ 01011 => t, 000xx => qpzr (000 = vault under t/f prefix)
91
92 //=========================================================================
93 // Non-fungible-related (start with letter n for non-fungible)
94 //=========================================================================
95 /// A global non-fungible resource entity (154 in decimal). Gives Bech32 prefix: `n` followed by one of `g`, `f`, `2` or `t`.
96 GlobalNonFungibleResourceManager = 0b10011010, //------- 10011 => n, 010xx => gf2t [nf vanity prefix]
97
98 /// An internal non-fungible vault entity (152 in decimal). Gives Bech32 prefix: `n` followed by one of `q`, `p`, `z` or `r`.
99 InternalNonFungibleVault = 0b10011000, //-------- 10011 => n, 000xx => qpzr (000 = vault under t/f prefix)
100
101 //=========================================================================
102 // Internal misc components (start with letter l for ..? local)
103 //=========================================================================
104 /// An internal generic (eg scrypto) component entity (248 in decimal). Gives Bech32 prefix: `l` followed by one of `q`, `p`, `z` or `r`.
105 InternalGenericComponent = 0b11111000, //-------- 11111 => l, 000xx => qpzr (000 = generic component)
106
107 //=========================================================================
108 // Internal key-value-store-like entities (start with k for key-value)
109 //=========================================================================
110 /// An internal key-value store entity (176 in decimal). Gives Bech32 prefix: `k` followed by one of `q`, `p`, `z` or `r`.
111 ///
112 /// A key value store allows access to substates, but not on-ledger iteration.
113 /// The substates are considered independent for contention/locking/versioning.
114 InternalKeyValueStore = 0b10110000, //----------- 10110 => k, 000xx => qpzr
115}
116
117impl EntityType {
118 pub const fn is_global(&self) -> bool {
119 match self {
120 EntityType::GlobalPackage
121 | EntityType::GlobalFungibleResourceManager
122 | EntityType::GlobalNonFungibleResourceManager
123 | EntityType::GlobalConsensusManager
124 | EntityType::GlobalValidator
125 | EntityType::GlobalAccessController
126 | EntityType::GlobalAccount
127 | EntityType::GlobalIdentity
128 | EntityType::GlobalGenericComponent
129 | EntityType::GlobalPreallocatedSecp256k1Account
130 | EntityType::GlobalPreallocatedEd25519Account
131 | EntityType::GlobalPreallocatedSecp256k1Identity
132 | EntityType::GlobalPreallocatedEd25519Identity
133 | EntityType::GlobalOneResourcePool
134 | EntityType::GlobalTwoResourcePool
135 | EntityType::GlobalMultiResourcePool
136 | EntityType::GlobalTransactionTracker
137 | EntityType::GlobalAccountLocker => true,
138 EntityType::InternalFungibleVault
139 | EntityType::InternalNonFungibleVault
140 | EntityType::InternalGenericComponent
141 | EntityType::InternalKeyValueStore => false,
142 }
143 }
144
145 pub const fn is_internal(&self) -> bool {
146 !self.is_global()
147 }
148
149 pub const fn is_global_component(&self) -> bool {
150 match self {
151 EntityType::GlobalConsensusManager
152 | EntityType::GlobalValidator
153 | EntityType::GlobalAccessController
154 | EntityType::GlobalAccount
155 | EntityType::GlobalIdentity
156 | EntityType::GlobalGenericComponent
157 | EntityType::GlobalPreallocatedSecp256k1Account
158 | EntityType::GlobalPreallocatedEd25519Account
159 | EntityType::GlobalPreallocatedSecp256k1Identity
160 | EntityType::GlobalPreallocatedEd25519Identity
161 | EntityType::GlobalOneResourcePool
162 | EntityType::GlobalTwoResourcePool
163 | EntityType::GlobalMultiResourcePool
164 | EntityType::GlobalTransactionTracker
165 | EntityType::GlobalAccountLocker => true,
166 EntityType::GlobalPackage
167 | EntityType::GlobalFungibleResourceManager
168 | EntityType::GlobalNonFungibleResourceManager
169 | EntityType::InternalFungibleVault
170 | EntityType::InternalNonFungibleVault
171 | EntityType::InternalGenericComponent
172 | EntityType::InternalKeyValueStore => false,
173 }
174 }
175
176 pub const fn is_global_package(&self) -> bool {
177 matches!(self, EntityType::GlobalPackage)
178 }
179
180 pub const fn is_global_account(&self) -> bool {
181 matches!(
182 self,
183 EntityType::GlobalAccount
184 | EntityType::GlobalPreallocatedSecp256k1Account
185 | EntityType::GlobalPreallocatedEd25519Account
186 )
187 }
188
189 pub const fn is_global_consensus_manager(&self) -> bool {
190 matches!(self, EntityType::GlobalConsensusManager)
191 }
192
193 pub const fn is_global_validator(&self) -> bool {
194 matches!(self, EntityType::GlobalValidator)
195 }
196
197 pub const fn is_global_resource_manager(&self) -> bool {
198 matches!(
199 self,
200 EntityType::GlobalFungibleResourceManager
201 | EntityType::GlobalNonFungibleResourceManager
202 )
203 }
204
205 pub const fn is_global_fungible_resource_manager(&self) -> bool {
206 matches!(self, EntityType::GlobalFungibleResourceManager)
207 }
208
209 pub const fn is_global_non_fungible_resource_manager(&self) -> bool {
210 matches!(self, EntityType::GlobalNonFungibleResourceManager)
211 }
212
213 pub const fn is_global_preallocated(&self) -> bool {
214 match self {
215 EntityType::GlobalPreallocatedSecp256k1Account
216 | EntityType::GlobalPreallocatedEd25519Account
217 | EntityType::GlobalPreallocatedSecp256k1Identity
218 | EntityType::GlobalPreallocatedEd25519Identity => true,
219 _ => false,
220 }
221 }
222
223 pub const fn is_internal_kv_store(&self) -> bool {
224 matches!(self, EntityType::InternalKeyValueStore)
225 }
226
227 pub const fn is_internal_fungible_vault(&self) -> bool {
228 matches!(self, EntityType::InternalFungibleVault)
229 }
230
231 pub const fn is_internal_non_fungible_vault(&self) -> bool {
232 matches!(self, EntityType::InternalNonFungibleVault)
233 }
234
235 pub const fn is_internal_vault(&self) -> bool {
236 matches!(
237 self,
238 EntityType::InternalFungibleVault | EntityType::InternalNonFungibleVault
239 )
240 }
241}