radix_engine/blueprints/access_controller/v2/
state.rs

1use super::internal_prelude::*;
2use crate::blueprints::access_controller::v1::{
3    AccessControllerStateV1, AccessControllerV1Substate,
4};
5use crate::internal_prelude::*;
6use crate::*;
7use radix_blueprint_schema_init::*;
8use radix_engine_interface::api::*;
9use radix_engine_interface::blueprints::resource::*;
10use radix_engine_interface::object_modules::metadata::*;
11use sbor::rust::prelude::*;
12
13#[derive(Debug, PartialEq, Eq, ScryptoSbor)]
14#[sbor(type_name = "AccessControllerSubstate")]
15pub struct AccessControllerV2Substate {
16    /// A vault where the asset controlled by the access controller lives.
17    pub controlled_asset: Vault,
18
19    /// A vault that stores some XRD that can be used by any of the three roles for locking fees.
20    pub xrd_fee_vault: Option<Vault>,
21
22    /// The amount of time (in minutes) that it takes for timed recovery to be done. Maximum is
23    /// 4,294,967,295 minutes which is 8171.5511700913 years. When this is [`None`], then timed
24    /// recovery can not be performed through this access controller.
25    pub timed_recovery_delay_in_minutes: Option<u32>,
26
27    /// The resource address of the recovery badge that will be used by the wallet and optionally
28    /// by other clients as well.
29    pub recovery_badge: ResourceAddress,
30
31    /// The states of the Access Controller.
32    pub state: (
33        // Controls whether the primary role is locked or unlocked
34        PrimaryRoleLockingState,
35        // Primary role recovery and withdraw states
36        PrimaryRoleRecoveryAttemptState,
37        PrimaryRoleBadgeWithdrawAttemptState,
38        // Recovery role recovery and withdraw states
39        RecoveryRoleRecoveryAttemptState,
40        RecoveryRoleBadgeWithdrawAttemptState,
41    ),
42}
43
44impl AccessControllerV2Substate {
45    pub fn new(
46        controlled_asset: Vault,
47        xrd_fee_vault: Option<Vault>,
48        timed_recovery_delay_in_minutes: Option<u32>,
49        recovery_badge: ResourceAddress,
50    ) -> Self {
51        Self {
52            controlled_asset,
53            xrd_fee_vault,
54            timed_recovery_delay_in_minutes,
55            recovery_badge,
56            state: Default::default(),
57        }
58    }
59}
60
61impl From<AccessControllerV1Substate> for AccessControllerV2Substate {
62    fn from(
63        AccessControllerV1Substate {
64            controlled_asset,
65            timed_recovery_delay_in_minutes,
66            recovery_badge,
67            state,
68        }: AccessControllerV1Substate,
69    ) -> Self {
70        Self {
71            controlled_asset,
72            xrd_fee_vault: None,
73            timed_recovery_delay_in_minutes,
74            recovery_badge,
75            state,
76        }
77    }
78}
79
80declare_native_blueprint_state! {
81    blueprint_ident: AccessControllerV2,
82    blueprint_snake_case: access_controller,
83    features: {
84    },
85    fields: {
86        state:  {
87            ident: State,
88            field_type: {
89                kind: StaticMultiVersioned,
90                previous_versions: [
91                    1 => { updates_to: 2 }
92                ],
93                latest_version: 2,
94            },
95            condition: Condition::Always,
96        }
97    },
98    collections: {}
99}
100
101pub type AccessControllerV2PartitionOffset = AccessControllerPartitionOffset;
102pub type AccessControllerV2StateV1 = AccessControllerStateV1;
103pub type AccessControllerV2StateV2 = AccessControllerV2Substate;