Skip to main content

canic_core/api/
icts.rs

1use crate::{
2    cdk::api::canister_self,
3    dto::{canister::CanisterStatusResponse, error::Error, icts::CanisterMetadataResponse},
4    workflow::ic::mgmt::MgmtWorkflow,
5};
6
7///
8/// IctsApi
9///
10
11pub struct IctsApi;
12
13impl IctsApi {
14    #[must_use]
15    pub fn name() -> String {
16        env!("CARGO_PKG_NAME").to_string()
17    }
18
19    #[must_use]
20    pub fn version() -> String {
21        env!("CARGO_PKG_VERSION").to_string()
22    }
23
24    #[must_use]
25    pub fn description() -> String {
26        env!("CARGO_PKG_DESCRIPTION").to_string()
27    }
28
29    #[must_use]
30    pub fn metadata() -> CanisterMetadataResponse {
31        CanisterMetadataResponse {
32            name: Self::name(),
33            version: Self::version(),
34            description: Self::description(),
35        }
36    }
37
38    /// ICTS standard: return types and string errors are fixed by the spec.
39    pub async fn canister_status() -> Result<CanisterStatusResponse, Error> {
40        MgmtWorkflow::canister_status(canister_self())
41            .await
42            .map_err(Error::from)
43    }
44}