canic/ops/root/
mod.rs

1pub mod reserve;
2
3use crate::{
4    Error,
5    interface::ic::get_current_subnet_pid,
6    memory::{Env, topology::SubnetCanisterRegistry},
7    ops::{
8        context::cfg_current_subnet,
9        prelude::*,
10        request::{CreateCanisterParent, create_canister_request},
11    },
12};
13
14pub async fn root_set_subnet_id() {
15    // set subnet_id asynchrously, but before its needed
16    if let Ok(Some(subnet_pid)) = get_current_subnet_pid().await {
17        Env::set_subnet_pid(subnet_pid);
18    }
19}
20
21/// Ensure all auto-create canisters exist and log the current topology.
22pub async fn root_create_canisters() -> Result<(), Error> {
23    // Top-up pass
24    let subnet_cfg = cfg_current_subnet()?;
25    for ty in &subnet_cfg.auto_create {
26        create_canister_request::<()>(ty, CreateCanisterParent::Root, None).await?;
27    }
28
29    // Report pass
30    for canister in SubnetCanisterRegistry::export() {
31        log!(Log::Info, "🥫 {} ({})", canister.ty, canister.pid);
32    }
33
34    Ok(())
35}