radix_common/address/
hrpset.rs

1use crate::network::NetworkDefinition;
2use crate::types::EntityType;
3use sbor::rust::prelude::*;
4
5/// Represents an HRP set (typically corresponds to a network).
6#[derive(Debug, Clone)]
7pub struct HrpSet {
8    /* Entities */
9    pub package: String,
10    pub resource: String,
11    pub component: String,
12    pub account: String,
13    pub identity: String,
14    pub consensus_manager: String,
15    pub validator: String,
16    pub access_controller: String,
17    pub pool: String,
18    pub locker: String,
19    pub transaction_tracker: String,
20    pub internal_vault: String,
21    pub internal_component: String,
22    pub internal_key_value_store: String,
23
24    /* Transaction Parts */
25    pub transaction_intent: String,
26    pub signed_transaction_intent: String,
27    pub subintent: String,
28    pub notarized_transaction: String,
29    pub round_update_transaction: String,
30    pub system_transaction: String,
31    pub ledger_transaction: String,
32}
33
34impl HrpSet {
35    pub fn get_entity_hrp(&self, entity: &EntityType) -> &str {
36        match entity {
37            EntityType::GlobalPackage => &self.package,
38            EntityType::GlobalFungibleResourceManager => &self.resource,
39            EntityType::GlobalNonFungibleResourceManager => &self.resource,
40            EntityType::GlobalConsensusManager => &self.consensus_manager,
41            EntityType::GlobalValidator => &self.validator,
42            EntityType::GlobalAccessController => &self.access_controller,
43            EntityType::GlobalAccount => &self.account,
44            EntityType::GlobalIdentity => &self.identity,
45            EntityType::GlobalGenericComponent => &self.component,
46            EntityType::GlobalPreallocatedSecp256k1Account => &self.account,
47            EntityType::GlobalPreallocatedEd25519Account => &self.account,
48            EntityType::GlobalPreallocatedSecp256k1Identity => &self.identity,
49            EntityType::GlobalPreallocatedEd25519Identity => &self.identity,
50            EntityType::InternalFungibleVault => &self.internal_vault,
51            EntityType::InternalNonFungibleVault => &self.internal_vault,
52            EntityType::InternalGenericComponent => &self.internal_component,
53            EntityType::InternalKeyValueStore => &self.internal_key_value_store,
54            EntityType::GlobalOneResourcePool
55            | EntityType::GlobalTwoResourcePool
56            | EntityType::GlobalMultiResourcePool => &self.pool,
57            EntityType::GlobalAccountLocker => &self.locker,
58            EntityType::GlobalTransactionTracker => &self.transaction_tracker,
59        }
60    }
61}
62
63impl From<&NetworkDefinition> for HrpSet {
64    fn from(network_definition: &NetworkDefinition) -> Self {
65        let suffix = &network_definition.hrp_suffix;
66        HrpSet {
67            /* Entities */
68            package: format!("package_{}", suffix),
69            resource: format!("resource_{}", suffix),
70            component: format!("component_{}", suffix),
71            account: format!("account_{}", suffix),
72            identity: format!("identity_{}", suffix),
73            consensus_manager: format!("consensusmanager_{}", suffix),
74            validator: format!("validator_{}", suffix),
75            access_controller: format!("accesscontroller_{}", suffix),
76            pool: format!("pool_{}", suffix),
77            locker: format!("locker_{}", suffix),
78            transaction_tracker: format!("transactiontracker_{}", suffix),
79            internal_vault: format!("internal_vault_{}", suffix),
80            internal_component: format!("internal_component_{}", suffix),
81            internal_key_value_store: format!("internal_keyvaluestore_{}", suffix),
82
83            /* Transaction Parts */
84            transaction_intent: format!("txid_{}", suffix),
85            signed_transaction_intent: format!("signedintent_{}", suffix),
86            subintent: format!("subtxid_{}", suffix),
87            notarized_transaction: format!("notarizedtransaction_{}", suffix),
88            round_update_transaction: format!("roundupdatetransaction_{}", suffix),
89            system_transaction: format!("systemtransaction_{}", suffix),
90            ledger_transaction: format!("ledgertransaction_{}", suffix),
91        }
92    }
93}