use super::{
MgmtInfra,
types::{InfraCanisterIdRecord, InfraCanisterSnapshot, InfraDeleteCanisterSnapshotArgs},
};
use crate::{
cdk::types::Principal,
infra::ic::{IcInfraError, call::Call},
};
impl MgmtInfra {
pub async fn list_canister_snapshot_ids(
canister_id: Principal,
) -> Result<Vec<Vec<u8>>, IcInfraError> {
let response =
Call::bounded_wait(Principal::management_canister(), "list_canister_snapshots")
.with_arg(InfraCanisterIdRecord { canister_id })?
.execute()
.await?;
let (snapshots,): (Vec<InfraCanisterSnapshot>,) = response.candid_tuple()?;
Ok(snapshots.into_iter().map(|snapshot| snapshot.id).collect())
}
pub async fn delete_canister_snapshot(
canister_id: Principal,
snapshot_id: Vec<u8>,
) -> Result<(), IcInfraError> {
Call::unbounded_wait(Principal::management_canister(), "delete_canister_snapshot")
.with_arg(InfraDeleteCanisterSnapshotArgs {
canister_id,
snapshot_id,
})?
.execute()
.await?;
Ok(())
}
}