canic_core/macros/endpoints/
root.rs

1// Generate the endpoint surface for the root orchestrator canister.
2#[macro_export]
3macro_rules! canic_endpoints_root {
4    () => {
5        // canic_app
6        // root-only app-level state mutation endpoint
7        #[canic_update(auth_any(::canic::core::access::auth::is_controller))]
8        async fn canic_app(
9            cmd: ::canic::core::dto::state::AppCommand,
10        ) -> Result<(), ::canic::PublicError> {
11            $crate::api::state::AppStateApi::execute_command(cmd).await
12        }
13
14        // canic_canister_upgrade
15        #[canic_update(auth_any(::canic::core::access::auth::is_controller))]
16        async fn canic_canister_upgrade(
17            canister_pid: ::candid::Principal,
18        ) -> Result<::canic::core::dto::rpc::UpgradeCanisterResponse, ::canic::PublicError> {
19            let res = $crate::api::rpc::RpcApi::upgrade_canister_request(canister_pid).await?;
20
21            Ok(res)
22        }
23
24        // canic_response
25        // root's way to respond to a generic request from another canister
26        // has to come from a direct child canister
27        #[canic_update(auth_any(::canic::core::access::auth::is_registered_to_subnet))]
28        async fn canic_response(
29            request: ::canic::core::dto::rpc::Request,
30        ) -> Result<::canic::core::dto::rpc::Response, ::canic::PublicError> {
31            let response = $crate::api::rpc::RpcApi::response(request).await?;
32
33            Ok(response)
34        }
35
36        // canic_canister_status
37        // this can be called via root as root is the master controller
38        #[canic_update(auth_any(
39            ::canic::core::access::auth::is_root,
40            ::canic::core::access::auth::is_controller
41        ))]
42        async fn canic_canister_status(
43            pid: ::canic::cdk::candid::Principal,
44        ) -> Result<::canic::core::dto::canister::CanisterStatusView, ::canic::PublicError> {
45            $crate::api::ic::mgmt::MgmtApi::canister_status(pid).await
46        }
47
48        //
49        // CONFIG
50        //
51
52        #[canic_query(auth_any(::canic::core::access::auth::is_controller))]
53        async fn canic_config() -> Result<String, ::canic::PublicError> {
54            $crate::api::config::ConfigApi::export_toml()
55        }
56
57        //
58        // REGISTRIES
59        //
60
61        #[canic_query]
62        fn canic_app_registry() -> ::canic::core::dto::topology::AppRegistryView {
63            $crate::api::topology::registry::AppRegistryApi::view()
64        }
65
66        #[canic_query]
67        fn canic_subnet_registry() -> ::canic::core::dto::topology::SubnetRegistryView {
68            $crate::api::topology::registry::SubnetRegistryApi::view()
69        }
70
71        //
72        // CANISTER POOL
73        //
74
75        #[canic_query]
76        async fn canic_pool_list() -> ::canic::core::dto::pool::CanisterPoolView {
77            $crate::api::pool::CanisterPoolApi::list_view()
78        }
79
80        #[canic_update(auth_any(::canic::core::access::auth::is_controller))]
81        async fn canic_pool_admin(
82            cmd: ::canic::core::dto::pool::PoolAdminCommand,
83        ) -> Result<::canic::core::dto::pool::PoolAdminResponse, ::canic::PublicError> {
84            $crate::api::pool::CanisterPoolApi::admin(cmd).await
85        }
86    };
87}
88
89// Generate the endpoint surface for non-root canisters.
90#[macro_export]
91macro_rules! canic_endpoints_nonroot {
92    () => {
93        //
94        // SYNC
95        //
96
97        #[canic_update(auth_any(::canic::core::access::auth::is_parent))]
98        async fn canic_sync_state(
99            snapshot: ::canic::core::dto::cascade::StateSnapshotView,
100        ) -> Result<(), ::canic::PublicError> {
101            $crate::api::cascade::CascadeApi::sync_state(snapshot).await
102        }
103
104        #[canic_update(auth_any(::canic::core::access::auth::is_parent))]
105        async fn canic_sync_topology(
106            snapshot: ::canic::core::dto::cascade::TopologySnapshotView,
107        ) -> Result<(), ::canic::PublicError> {
108            $crate::api::cascade::CascadeApi::sync_topology(snapshot).await
109        }
110    };
111}