1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
use candid::{CandidType, Nat, Principal};
use serde::{Deserialize, Serialize};
/// Canister ID is Principal.
pub type CanisterId = Principal;
/// todo
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
)]
pub enum LogVisibility {
#[default]
#[serde(rename = "controllers")]
/// Only controllers of the canister can access the logs.
Controllers,
#[serde(rename = "public")]
/// Everyone is allowed to access the canister's logs.
Public,
}
/// Canister settings.
///
/// The settings are optional. If they are not explicitly set, the default values will be applied automatically.
///
/// See [`settings`](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-create_canister).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
)]
pub struct CanisterSettings {
/// A list of at most 10 principals.
///
/// The principals in this list become the *controllers* of the canister.
///
/// Default value: A list containing only the caller of the create_canister call.
pub controllers: Option<Vec<Principal>>,
/// Must be a number between 0 and 100, inclusively.
///
/// It indicates how much compute power should be guaranteed to this canister,
/// expressed as a percentage of the maximum compute power that a single canister can allocate.
///
/// If the IC cannot provide the requested allocation,
/// for example because it is oversubscribed, the call will be **rejected**.
///
/// Default value: 0
pub compute_allocation: Option<Nat>,
/// Must be a number between 0 and 2<sup>48</sup> (i.e 256TB), inclusively.
///
/// It indicates how much memory the canister is allowed to use in total.
///
/// If the IC cannot provide the requested allocation,
/// for example because it is oversubscribed, the call will be **rejected**.
///
/// If set to 0, then memory growth of the canister will be best-effort and subject to the available memory on the IC.
///
/// Default value: 0
pub memory_allocation: Option<Nat>,
/// Must be a number between 0 and 2<sup>64</sup>-1, inclusively.
///
/// It indicates a length of time in seconds.
///
/// Default value: 2592000 (approximately 30 days).
pub freezing_threshold: Option<Nat>,
/// Must be a number between 0 and 2<sup>128</sup>-1, inclusively.
///
/// It indicates the upper limit on `reserved_cycles` of the canister.
///
/// Default value: 5_000_000_000_000 (5 trillion cycles).
pub reserved_cycles_limit: Option<Nat>,
/// Defines who is allowed to read the canister's logs.
///
/// Default value: Controllers
pub log_visibility: Option<LogVisibility>,
/// Must be a number between 0 and 2<sup>48</sup>-1 (i.e 256TB), inclusively.
///
/// It indicates the upper limit on the WASM heap memory consumption of the canister.
///
/// Default value: 3_221_225_472 (3 GiB).
pub wasm_memory_limit: Option<Nat>,
}
/// Argument type of [create_canister](super::create_canister).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
)]
pub struct CreateCanisterArgument {
/// See [CanisterSettings].
pub settings: Option<CanisterSettings>,
}
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
)]
pub(crate) struct CreateCanisterArgumentExtended {
/// See [CanisterSettings].
pub settings: Option<CanisterSettings>,
/// sender_canister_version must be set to ic_cdk::api::canister_version()
pub sender_canister_version: Option<u64>,
}
/// Argument type of [update_settings](super::update_settings).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct UpdateSettingsArgument {
/// Principal of the canister.
pub canister_id: CanisterId,
/// See [CanisterSettings].
pub settings: CanisterSettings,
}
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub(crate) struct UpdateSettingsArgumentExtended {
/// Principal of the canister.
pub canister_id: CanisterId,
/// See [CanisterSettings].
pub settings: CanisterSettings,
/// sender_canister_version must be set to ic_cdk::api::canister_version()
pub sender_canister_version: Option<u64>,
}
/// Argument type of [update_chunk](super::upload_chunk).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct UploadChunkArgument {
/// The canister whose chunk store the chunk will be uploaded to
pub canister_id: CanisterId,
/// The chunk bytes (max size 1MB)
#[serde(with = "serde_bytes")]
pub chunk: Vec<u8>,
}
/// Return type of [upload_chunk](super::upload_chunk) and [stored_chunks](super::stored_chunks).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct ChunkHash {
/// The hash of an uploaded chunk
#[serde(with = "serde_bytes")]
pub hash: Vec<u8>,
}
/// Argument type of [clear_chunk_store](super::clear_chunk_store).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct ClearChunkStoreArgument {
/// The canister whose chunk store will be cleared
pub canister_id: CanisterId,
}
/// Argument type of [stored_chunks](super::stored_chunks).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct StoredChunksArgument {
/// The canister whose chunk store will be queried
pub canister_id: CanisterId,
}
/// The mode with which a canister is installed.
///
/// This second version of the mode allows someone to specify the
/// optional `SkipPreUpgrade` parameter in case of an upgrade
#[derive(
CandidType,
Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Clone,
Copy,
Default,
)]
pub enum CanisterInstallMode {
/// A fresh install of a new canister.
#[serde(rename = "install")]
#[default]
Install,
/// Reinstalling a canister that was already installed.
#[serde(rename = "reinstall")]
Reinstall,
/// Upgrade an existing canister.
#[serde(rename = "upgrade")]
Upgrade(Option<SkipPreUpgrade>),
}
/// If set to true, the pre_upgrade step will be skipped during the canister upgrade
#[derive(
CandidType,
Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Clone,
Copy,
Default,
)]
pub struct SkipPreUpgrade(pub Option<bool>);
/// WASM module.
pub type WasmModule = Vec<u8>;
/// Argument type of [install_code](super::install_code).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct InstallCodeArgument {
/// See [CanisterInstallMode].
pub mode: CanisterInstallMode,
/// Principal of the canister.
pub canister_id: CanisterId,
/// Code to be installed.
pub wasm_module: WasmModule,
/// The argument to be passed to `canister_init` or `canister_post_upgrade`.
pub arg: Vec<u8>,
}
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub(crate) struct InstallCodeArgumentExtended {
/// See [CanisterInstallMode].
pub mode: CanisterInstallMode,
/// Principal of the canister.
pub canister_id: CanisterId,
/// Code to be installed.
pub wasm_module: WasmModule,
/// The argument to be passed to `canister_init` or `canister_post_upgrade`.
pub arg: Vec<u8>,
/// sender_canister_version must be set to ic_cdk::api::canister_version()
pub sender_canister_version: Option<u64>,
}
/// Argument type of [install_chunked_code](super::install_chunked_code).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct InstallChunkedCodeArgument {
/// See [CanisterInstallMode].
pub mode: CanisterInstallMode,
/// Principal of the canister being installed
pub target_canister: CanisterId,
/// The canister in whose chunk storage the chunks are stored (defaults to target_canister if not specified)
pub store_canister: Option<CanisterId>,
/// The list of chunks that make up the canister wasm
pub chunk_hashes_list: Vec<ChunkHash>,
/// The sha256 hash of the wasm
#[serde(with = "serde_bytes")]
pub wasm_module_hash: Vec<u8>,
/// The argument to be passed to `canister_init` or `canister_post_upgrade`
#[serde(with = "serde_bytes")]
pub arg: Vec<u8>,
}
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub(crate) struct InstallChunkedCodeArgumentExtended {
/// See [CanisterInstallMode].
pub mode: CanisterInstallMode,
/// Principal of the canister being installed
pub target_canister: CanisterId,
/// The canister in whose chunk storage the chunks are stored (defaults to target_canister if not specified)
pub store_canister: Option<CanisterId>,
/// The list of chunks that make up the canister wasm
pub chunk_hashes_list: Vec<ChunkHash>,
/// The sha256 hash of the wasm
#[serde(with = "serde_bytes")]
pub wasm_module_hash: Vec<u8>,
/// The argument to be passed to `canister_init` or `canister_post_upgrade`.
#[serde(with = "serde_bytes")]
pub arg: Vec<u8>,
/// sender_canister_version must be set to ic_cdk::api::canister_version()
pub sender_canister_version: Option<u64>,
}
/// A wrapper of canister id.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy,
)]
pub struct CanisterIdRecord {
/// Principal of the canister.
pub canister_id: CanisterId,
}
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy,
)]
pub(crate) struct CanisterIdRecordExtended {
/// Principal of the canister.
pub canister_id: CanisterId,
/// sender_canister_version must be set to ic_cdk::api::canister_version()
pub sender_canister_version: Option<u64>,
}
/// Status of a canister.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy,
)]
pub enum CanisterStatusType {
/// The canister is running.
#[serde(rename = "running")]
Running,
/// The canister is stopping.
#[serde(rename = "stopping")]
Stopping,
/// The canister is stopped.
#[serde(rename = "stopped")]
Stopped,
}
/// Like [CanisterSettings].
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
)]
pub struct DefiniteCanisterSettings {
/// Controllers of the canister.
pub controllers: Vec<Principal>,
/// Compute allocation.
pub compute_allocation: Nat,
/// Memory allocation.
pub memory_allocation: Nat,
/// Freezing threshold.
pub freezing_threshold: Nat,
/// Reserved cycles limit.
pub reserved_cycles_limit: Nat,
/// Visibility of canister logs.
pub log_visibility: LogVisibility,
/// The Wasm memory limit.
pub wasm_memory_limit: Nat,
}
/// Query statistics, returned by [canister_status](super::canister_status).
#[derive(
CandidType, Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct QueryStats {
/// Total number of query calls.
pub num_calls_total: candid::Nat,
/// Total number of instructions executed by query calls.
pub num_instructions_total: candid::Nat,
/// Total number of payload bytes use for query call requests.
pub request_payload_bytes_total: candid::Nat,
/// Total number of payload bytes use for query call responses.
pub response_payload_bytes_total: candid::Nat,
}
/// Return type of [canister_status](super::canister_status).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct CanisterStatusResponse {
/// See [CanisterStatusType].
pub status: CanisterStatusType,
/// See [DefiniteCanisterSettings].
pub settings: DefiniteCanisterSettings,
/// A SHA256 hash of the module installed on the canister. This is null if the canister is empty.
pub module_hash: Option<Vec<u8>>,
/// The memory size taken by the canister.
pub memory_size: Nat,
/// The cycle balance of the canister.
pub cycles: Nat,
/// Amount of cycles burned per day.
pub idle_cycles_burned_per_day: Nat,
/// Query statistics
pub query_stats: QueryStats,
/// The reserved cycles balance of the canister.
/// These are cycles that are reserved by the resource reservation mechanism
/// on storage allocation. See also the `reserved_cycles_limit` parameter in
/// canister settings.
pub reserved_cycles: Nat,
}
/// Details about a canister change initiated by a user.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct FromUserRecord {
/// Principal of the user.
pub user_id: Principal,
}
/// Details about a canister change initiated by a canister (called _originator_).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct FromCanisterRecord {
/// Principal of the originator.
pub canister_id: Principal,
/// Canister version of the originator when the originator initiated the change.
/// This is null if the original does not include its canister version
/// in the field `sender_canister_version` of the management canister payload.
pub canister_version: Option<u64>,
}
/// Provides details on who initiated a canister change.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub enum CanisterChangeOrigin {
/// See [FromUserRecord].
#[serde(rename = "from_user")]
FromUser(FromUserRecord),
/// See [FromCanisterRecord].
#[serde(rename = "from_canister")]
FromCanister(FromCanisterRecord),
}
/// Details about a canister creation.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct CreationRecord {
/// Initial set of canister controllers.
pub controllers: Vec<Principal>,
}
/// The mode with which a canister is installed.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy,
)]
// #[serde(rename_all = "lowercase")]
pub enum CodeDeploymentMode {
/// A fresh install of a new canister.
#[serde(rename = "install")]
Install,
/// Reinstalling a canister that was already installed.
#[serde(rename = "reinstall")]
Reinstall,
/// Upgrade an existing canister.
#[serde(rename = "upgrade")]
Upgrade,
}
/// Details about a canister code deployment.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct CodeDeploymentRecord {
/// See [CodeDeploymentMode].
pub mode: CodeDeploymentMode,
/// A SHA256 hash of the new module installed on the canister.
pub module_hash: Vec<u8>,
}
/// Details about loading canister snapshot.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct LoadSnapshotRecord {
/// The version of the canister at the time that the snapshot was taken
pub canister_version: u64,
/// The ID of the snapshot that was loaded.
pub snapshot_id: SnapshotId,
/// The timestamp at which the snapshot was taken.
pub taken_at_timestamp: u64,
}
/// Details about updating canister controllers.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct ControllersChangeRecord {
/// The full new set of canister controllers.
pub controllers: Vec<Principal>,
}
/// Provides details on the respective canister change.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub enum CanisterChangeDetails {
/// See [CreationRecord].
#[serde(rename = "creation")]
Creation(CreationRecord),
/// Uninstalling canister's module.
#[serde(rename = "code_uninstall")]
CodeUninstall,
/// See [CodeDeploymentRecord].
#[serde(rename = "code_deployment")]
CodeDeployment(CodeDeploymentRecord),
/// See [LoadSnapshotRecord].
#[serde(rename = "load_snapshot")]
LoadSnapshot(LoadSnapshotRecord),
/// See [ControllersChangeRecord].
#[serde(rename = "controllers_change")]
ControllersChange(ControllersChangeRecord),
}
/// Represents a canister change as stored in the canister history.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct CanisterChange {
/// The system timestamp (in nanoseconds since Unix Epoch) at which the change was performed
pub timestamp_nanos: u64,
/// The canister version after performing the change.
pub canister_version: u64,
/// The change's origin (a user or a canister).
pub origin: CanisterChangeOrigin,
/// The change's details.
pub details: CanisterChangeDetails,
}
/// Argument type of [canister_info](super::canister_info).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct CanisterInfoRequest {
/// Principal of the canister.
pub canister_id: Principal,
/// Number of most recent changes requested to be retrieved from canister history.
/// No changes are retrieved if this field is null.
pub num_requested_changes: Option<u64>,
}
/// Return type of [canister_info](super::canister_info).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct CanisterInfoResponse {
/// Total number of changes ever recorded in canister history.
/// This might be higher than the number of canister changes in `recent_changes`
/// because the IC might drop old canister changes from its history
/// (with `20` most recent canister changes to always remain in the list).
pub total_num_changes: u64,
/// The canister changes stored in the order from the oldest to the most recent.
pub recent_changes: Vec<CanisterChange>,
/// A SHA256 hash of the module installed on the canister. This is null if the canister is empty.
pub module_hash: Option<Vec<u8>>,
/// Controllers of the canister.
pub controllers: Vec<Principal>,
}
/// ID of a canister snapshot.
pub type SnapshotId = Vec<u8>;
/// A snapshot of the state of the canister at a given point in time.
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
)]
pub struct Snapshot {
/// ID of the snapshot.
pub id: SnapshotId,
/// The timestamp at which the snapshot was taken.
pub taken_at_timestamp: u64,
/// The size of the snapshot in bytes.
pub total_size: u64,
}
/// Argument type of [take_canister_snapshot](super::take_canister_snapshot).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct TakeCanisterSnapshotArgs {
/// Principal of the canister.
pub canister_id: CanisterId,
/// An optional snapshot ID to be replaced by the new snapshot.
///
/// The snapshot identified by the specified ID will be deleted once a new snapshot has been successfully created.
pub replace_snapshot: Option<SnapshotId>,
}
/// Argument type of [load_canister_snapshot](super::load_canister_snapshot).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct LoadCanisterSnapshotArgs {
/// Principal of the canister.
pub canister_id: CanisterId,
/// ID of the snapshot to be loaded.
pub snapshot_id: SnapshotId,
/// sender_canister_version must be set to ic_cdk::api::canister_version().
pub sender_canister_version: Option<u64>,
}
/// Argument type of [delete_canister_snapshot](super::delete_canister_snapshot).
#[derive(
CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
)]
pub struct DeleteCanisterSnapshotArgs {
/// Principal of the canister.
pub canister_id: CanisterId,
/// ID of the snapshot to be deleted.
pub snapshot_id: SnapshotId,
}