use serde::Deserialize;
use crate::candid::{CandidType, Nat};
use crate::interfaces::Method;
use crate::Principal;
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct WithCanisterId {
pub canister_id: Principal,
}
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct CanisterSettings {
pub controllers: Option<Vec<Principal>>,
pub compute_allocation: Option<Nat>,
pub memory_allocation: Option<Nat>,
pub freezing_threshold: Option<Nat>,
}
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct DefiniteCanisterSettings {
pub controllers: Vec<Principal>,
pub compute_allocation: Nat,
pub memory_allocation: Nat,
pub freezing_threshold: Nat,
}
pub struct CreateCanister;
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct CreateCanisterArgument {
pub settings: Option<CanisterSettings>,
}
impl Method for CreateCanister {
const NAME: &'static str = "create_canister";
type Arguments = (CreateCanisterArgument,);
type Response = (WithCanisterId,);
}
pub struct UpdateSettings;
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct UpdateSettingsArgument {
pub canister_id: Principal,
pub settings: CanisterSettings,
}
impl Method for UpdateSettings {
const NAME: &'static str = "update_settings";
type Arguments = (UpdateSettingsArgument,);
type Response = ();
}
pub struct InstallCode;
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub enum InstallMode {
#[serde(rename = "install")]
Install,
#[serde(rename = "reinstall")]
Reinstall,
#[serde(rename = "upgrade")]
Upgrade,
}
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct InstallCodeArgument {
pub mode: InstallMode,
pub canister_id: Principal,
#[serde(with = "serde_bytes")]
pub wasm_module: Vec<u8>,
pub arg: Vec<u8>,
}
impl Method for InstallCode {
const NAME: &'static str = "install_code";
type Arguments = (InstallCodeArgument,);
type Response = ();
}
pub struct UninstallCode;
impl Method for UninstallCode {
const NAME: &'static str = "uninstall_code";
type Arguments = (WithCanisterId,);
type Response = ();
}
pub struct StartCanister;
impl Method for StartCanister {
const NAME: &'static str = "start_canister";
type Arguments = (WithCanisterId,);
type Response = ();
}
pub struct StopCanister;
impl Method for StopCanister {
const NAME: &'static str = "stop_canister";
type Arguments = (WithCanisterId,);
type Response = ();
}
pub struct CanisterStatus;
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub enum Status {
#[serde(rename = "running")]
Running,
#[serde(rename = "stopping")]
Stopping,
#[serde(rename = "stopped")]
Stopped,
}
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct CanisterStatusResponse {
pub status: Status,
pub settings: DefiniteCanisterSettings,
pub module_hash: Option<Vec<u8>>,
pub memory_size: Nat,
pub cycles: Nat,
}
impl Method for CanisterStatus {
const NAME: &'static str = "canister_status";
type Arguments = (WithCanisterId,);
type Response = (CanisterStatusResponse,);
}
pub struct DeleteCanister;
impl Method for DeleteCanister {
const NAME: &'static str = "delete_canister";
type Arguments = (WithCanisterId,);
type Response = ();
}
pub struct DepositCycles;
impl Method for DepositCycles {
const NAME: &'static str = "deposit_cycles";
type Arguments = (WithCanisterId,);
type Response = ();
}
pub struct RawRand;
impl Method for RawRand {
const NAME: &'static str = "raw_rand";
type Arguments = ();
type Response = (Vec<u8>,);
}
pub struct ProvisionalCreateCanisterWithCycles;
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct ProvisionalCreateCanisterWithCyclesArgument {
pub amount: Option<Nat>,
pub settings: Option<CanisterSettings>,
}
impl Method for ProvisionalCreateCanisterWithCycles {
const NAME: &'static str = "provisional_create_canister_with_cycles";
type Arguments = (ProvisionalCreateCanisterWithCyclesArgument,);
type Response = (WithCanisterId,);
}
pub struct ProvisionalTopUpCanister;
#[derive(Deserialize, Debug, Clone, PartialOrd, PartialEq, CandidType)]
pub struct ProvisionalTopUpCanisterArgument {
pub canister_id: Principal,
pub amount: Nat,
}
impl Method for ProvisionalTopUpCanister {
const NAME: &'static str = "provisional_top_up_canister";
type Arguments = (ProvisionalTopUpCanisterArgument,);
type Response = ();
}