Skip to main content

canic_core/api/lifecycle/
nonroot.rs

1use crate::{
2    config::RoleRuntimeAuthority,
3    dto::{
4        abi::v1::CanisterInitPayload, env::EnvBootstrapArgs,
5        fleet_subnet_root::FleetSubnetWasmStoreInitArgs,
6    },
7    ids::{CanisterRole, ManagedCanisterBinding},
8    lifecycle,
9};
10
11///
12/// LifecycleApi
13///
14
15pub struct LifecycleApi;
16
17impl LifecycleApi {
18    #[doc(hidden)]
19    pub fn configure_component_runtime_with_automatic_topup(
20        request: crate::dto::component_registry::ComponentRuntimeDirectoryPreparationRequest,
21    ) -> Result<
22        crate::view::fleet_activation::ComponentRuntimeActivationTransition,
23        crate::dto::error::Error,
24    > {
25        crate::workflow::component_runtime::configure_with_automatic_topup(request)
26            .map_err(Into::into)
27    }
28
29    /// Return the immutable Registry-issued identity retained by this application Canister.
30    pub fn managed_binding() -> Result<ManagedCanisterBinding, crate::dto::error::Error> {
31        crate::ops::runtime::env::EnvOps::managed_binding().map_err(Into::into)
32    }
33
34    pub fn init_nonroot_canister_before_bootstrap(
35        role: CanisterRole,
36        payload: CanisterInitPayload,
37        application_init_args: Option<Vec<u8>>,
38        embedded_release_build_id: Option<&str>,
39        authority: RoleRuntimeAuthority,
40    ) {
41        lifecycle::init::nonroot::init_nonroot_canister_before_bootstrap(
42            role,
43            payload,
44            application_init_args,
45            embedded_release_build_id,
46            authority,
47        );
48    }
49
50    /// Initialize a managed actor with its compile-selected admission store.
51    pub fn init_nonroot_canister_with_fleet_admission_before_bootstrap(
52        role: CanisterRole,
53        payload: CanisterInitPayload,
54        application_init_args: Option<Vec<u8>>,
55        embedded_release_build_id: Option<&str>,
56        authority: RoleRuntimeAuthority,
57    ) {
58        lifecycle::init::nonroot::init_nonroot_canister_with_fleet_admission_before_bootstrap(
59            role,
60            payload,
61            application_init_args,
62            embedded_release_build_id,
63            authority,
64        );
65    }
66
67    pub fn init_wasm_store_before_bootstrap(
68        input: FleetSubnetWasmStoreInitArgs,
69        embedded_release_build_id: Option<&str>,
70        authority: RoleRuntimeAuthority,
71    ) {
72        lifecycle::init::nonroot::init_wasm_store_before_bootstrap(
73            input,
74            embedded_release_build_id,
75            authority,
76        );
77    }
78
79    pub fn schedule_init_nonroot_bootstrap() {
80        lifecycle::init::nonroot::schedule_init_nonroot_bootstrap();
81    }
82
83    pub fn init_local_nonroot_canister_before_bootstrap(
84        role: CanisterRole,
85        env: EnvBootstrapArgs,
86        authority: RoleRuntimeAuthority,
87    ) {
88        lifecycle::init::nonroot::init_local_nonroot_canister_before_bootstrap(
89            role, env, authority,
90        );
91    }
92
93    #[doc(hidden)]
94    pub fn init_local_nonroot_canister_with_automatic_topup_before_bootstrap(
95        role: CanisterRole,
96        env: EnvBootstrapArgs,
97        authority: RoleRuntimeAuthority,
98    ) {
99        lifecycle::init::nonroot::init_local_nonroot_canister_with_automatic_topup_before_bootstrap(
100            role, env, authority,
101        );
102    }
103
104    #[must_use]
105    pub fn post_upgrade_nonroot_canister_before_bootstrap(
106        role: CanisterRole,
107        embedded_release_build_id: Option<&str>,
108        authority: RoleRuntimeAuthority,
109    ) -> bool {
110        lifecycle::upgrade::nonroot::post_upgrade_nonroot_canister_before_bootstrap(
111            role,
112            embedded_release_build_id,
113            authority,
114        )
115    }
116
117    /// Restore selected admission before runtime services and lifecycle participants.
118    #[must_use]
119    pub fn post_upgrade_nonroot_canister_with_fleet_admission_before_bootstrap(
120        role: CanisterRole,
121        embedded_release_build_id: Option<&str>,
122        authority: RoleRuntimeAuthority,
123    ) -> bool {
124        lifecycle::upgrade::nonroot::post_upgrade_nonroot_canister_with_fleet_admission_before_bootstrap(
125            role,
126            embedded_release_build_id,
127            authority,
128        )
129    }
130
131    #[doc(hidden)]
132    #[must_use]
133    pub fn post_upgrade_nonroot_canister_with_automatic_topup_before_bootstrap(
134        role: CanisterRole,
135        embedded_release_build_id: Option<&str>,
136        authority: RoleRuntimeAuthority,
137    ) -> bool {
138        lifecycle::upgrade::nonroot::post_upgrade_nonroot_canister_with_automatic_topup_before_bootstrap(
139            role,
140            embedded_release_build_id,
141            authority,
142        )
143    }
144
145    /// Restore selected admission before runtime services and lifecycle participants.
146    #[must_use]
147    pub fn post_upgrade_nonroot_canister_with_automatic_topup_and_fleet_admission_before_bootstrap(
148        role: CanisterRole,
149        embedded_release_build_id: Option<&str>,
150        authority: RoleRuntimeAuthority,
151    ) -> bool {
152        lifecycle::upgrade::nonroot::post_upgrade_nonroot_canister_with_automatic_topup_and_fleet_admission_before_bootstrap(
153            role,
154            embedded_release_build_id,
155            authority,
156        )
157    }
158
159    pub fn schedule_post_upgrade_nonroot_bootstrap() {
160        lifecycle::upgrade::nonroot::schedule_post_upgrade_nonroot_bootstrap();
161    }
162
163    #[must_use]
164    pub fn post_upgrade_local_nonroot_canister_before_bootstrap(
165        role: CanisterRole,
166        authority: RoleRuntimeAuthority,
167    ) -> bool {
168        lifecycle::upgrade::nonroot::post_upgrade_local_nonroot_canister_before_bootstrap(
169            role, authority,
170        )
171    }
172
173    #[doc(hidden)]
174    #[must_use]
175    pub fn post_upgrade_local_nonroot_canister_with_automatic_topup_before_bootstrap(
176        role: CanisterRole,
177        authority: RoleRuntimeAuthority,
178    ) -> bool {
179        lifecycle::upgrade::nonroot::post_upgrade_local_nonroot_canister_with_automatic_topup_before_bootstrap(
180            role,
181            authority,
182        )
183    }
184}