use crate::candid::encode::{Encode, Writer};
use crate::candid::{
self, Decode, Error, Limits, Reader, Schema,
projection::{absent, projection},
};
pub use crate::candid::{Nat, encode::EncodeError};
pub use crate::management_snapshots::{
CanisterArgs, CanisterStatus, decode_canister_status, decode_empty_response,
};
use candidate_types::Principal;
use serde::{Deserialize, Serialize};
projection! {
both enum LogVisibility {
#[serde(rename = "controllers")]
570880087 => Controllers,
#[serde(rename = "public")]
1727234217 => Public,
#[serde(rename = "allowed_viewers")]
2235716810 => AllowedViewers(Vec<Principal>),
}
}
projection! {
encoding EnvironmentVariable {
834174833 => value: String,
1224700491 => name: String,
}
}
projection! {
#[derive(Default)]
encoding CreationSettings {
238856128 => freezing_threshold: Option<Nat>,
241629288 => wasm_memory_threshold: Option<Nat>,
356749323 => environment_variables: Option<Vec<EnvironmentVariable>>,
570880087 => controllers: Option<Vec<Principal>>,
1095112320 => reserved_cycles_limit: Option<Nat>,
2033331437 => log_visibility: Option<LogVisibility>,
3380736376 => wasm_memory_limit: Option<Nat>,
3844961758 => memory_allocation: Option<Nat>,
4174053672 => compute_allocation: Option<Nat>,
}
}
projection! {
encoding ProvisionalCreateArgs {
2336062691 => settings: Option<CreationSettings>,
3348853450 => specified_id: Option<Principal>,
3573748184 => amount: Option<Nat>,
3599109322 => sender_canister_version: Option<u64>,
}
}
projection! {
encoding UpdateSettingsArgs {
1313628723 => canister_id: Principal,
2336062691 => settings: CreationSettings,
3599109322 => sender_canister_version: Option<u64>,
}
}
projection! {
both enum MemoryPersistence {
#[serde(rename = "keep")]
1191628933 => Keep,
#[serde(rename = "replace")]
2871543860 => Replace,
}
}
projection! {
both UpgradeFlags {
793490780 => wasm_memory_persistence: Option<MemoryPersistence> [strict_optional],
1539756096 => skip_pre_upgrade: Option<bool> [strict_optional],
}
}
projection! {
both enum InstallMode {
#[serde(rename = "reinstall")]
235052488 => Reinstall,
#[serde(rename = "upgrade")]
1664201884 => Upgrade(Option<UpgradeFlags>),
#[serde(rename = "install")]
2375734555 => Install,
}
}
projection! {
encoding InstallCodeArgs {
4849238 => arg: Vec<u8>,
265441191 => wasm_module: Vec<u8>,
1214305123 => mode: InstallMode,
1313628723 => canister_id: Principal,
3599109322 => sender_canister_version: Option<u64>,
}
}
projection! {
CreatedCanister {
1313628723 => canister_id: Principal [required],
}
}
pub fn decode_created(bytes: &[u8], limits: Limits) -> Result<CreatedCanister, Error> {
candid::decode(bytes, limits)
}