canic_core/dto/
rpc.rs

1use crate::dto::prelude::*;
2
3///
4/// Request
5/// Root-directed orchestration commands.
6///
7
8#[derive(CandidType, Clone, Debug, Deserialize)]
9pub enum Request {
10    CreateCanister(CreateCanisterRequest),
11    UpgradeCanister(UpgradeCanisterRequest),
12    Cycles(CyclesRequest),
13}
14
15///
16/// CreateCanisterRequest
17/// Payload for [`Request::CreateCanister`]
18///
19
20#[derive(CandidType, Clone, Debug, Deserialize)]
21pub struct CreateCanisterRequest {
22    pub canister_role: CanisterRole,
23    pub parent: CreateCanisterParent,
24    pub extra_arg: Option<Vec<u8>>,
25}
26
27///
28/// CreateCanisterParent
29/// Parent-location choices for a new canister
30///
31
32#[derive(CandidType, Clone, Debug, Deserialize)]
33pub enum CreateCanisterParent {
34    Root,
35    /// Use the requesting canister as parent.
36    ThisCanister,
37    /// Use the requesting canister's parent (creates a sibling).
38    Parent,
39    Canister(Principal),
40    Directory(CanisterRole),
41}
42
43///
44/// UpgradeCanisterRequest
45/// Payload for [`Request::UpgradeCanister`]
46///
47
48#[derive(CandidType, Clone, Debug, Deserialize)]
49pub struct UpgradeCanisterRequest {
50    pub canister_pid: Principal,
51}
52
53///
54/// CyclesRequest
55/// Payload for [`Request::Cycles`]
56///
57
58#[derive(CandidType, Clone, Debug, Deserialize)]
59pub struct CyclesRequest {
60    pub cycles: u128,
61}
62
63///
64/// Response
65/// Response payloads produced by root for orchestration requests.
66///
67
68#[derive(CandidType, Clone, Debug, Deserialize)]
69pub enum Response {
70    CreateCanister(CreateCanisterResponse),
71    UpgradeCanister(UpgradeCanisterResponse),
72    Cycles(CyclesResponse),
73}
74
75///
76/// CreateCanisterResponse
77/// Result of creating and installing a new canister.
78///
79
80#[derive(CandidType, Clone, Debug, Deserialize)]
81pub struct CreateCanisterResponse {
82    pub new_canister_pid: Principal,
83}
84
85///
86/// UpgradeCanisterResponse
87/// Result of an upgrade request (currently empty, reserved for metadata)
88///
89
90#[derive(CandidType, Clone, Debug, Deserialize)]
91pub struct UpgradeCanisterResponse {}
92
93///
94/// CyclesResponse
95/// Result of transferring cycles to a child canister
96///
97
98#[derive(CandidType, Clone, Debug, Deserialize)]
99pub struct CyclesResponse {
100    pub cycles_transferred: u128,
101}