canic_core/api/rpc/
mod.rs1mod capability;
2
3use crate::{
4 cdk::{candid::CandidType, types::Principal},
5 dto::{
6 capability::{RootCapabilityEnvelopeV1, RootCapabilityResponseV1},
7 error::Error,
8 rpc::{
9 CreateCanisterParent, CreateCanisterResponse, CyclesResponse, UpgradeCanisterResponse,
10 },
11 },
12 ids::CanisterRole,
13 workflow::rpc::request::RpcRequestWorkflow,
14};
15
16pub struct RpcApi;
36
37impl RpcApi {
38 pub async fn response_capability_v1_root(
40 envelope: RootCapabilityEnvelopeV1,
41 ) -> Result<RootCapabilityResponseV1, Error> {
42 capability::response_capability_v1_root(envelope).await
43 }
44
45 pub async fn response_capability_v1_nonroot(
47 envelope: RootCapabilityEnvelopeV1,
48 ) -> Result<RootCapabilityResponseV1, Error> {
49 capability::response_capability_v1_nonroot(envelope).await
50 }
51
52 pub async fn create_canister_request<A>(
53 canister_role: &CanisterRole,
54 parent: CreateCanisterParent,
55 extra: Option<A>,
56 ) -> Result<CreateCanisterResponse, Error>
57 where
58 A: CandidType + Send + Sync,
59 {
60 RpcRequestWorkflow::create_canister_request(canister_role, parent, extra)
61 .await
62 .map_err(Error::from)
63 }
64
65 pub async fn upgrade_canister_request(
66 canister_pid: Principal,
67 ) -> Result<UpgradeCanisterResponse, Error> {
68 RpcRequestWorkflow::upgrade_canister_request(canister_pid)
69 .await
70 .map_err(Error::from)
71 }
72
73 pub async fn request_cycles(cycles: u128) -> Result<CyclesResponse, Error> {
74 RpcRequestWorkflow::request_cycles(cycles)
75 .await
76 .map_err(Error::from)
77 }
78
79 pub async fn response_capability_v1(
80 envelope: RootCapabilityEnvelopeV1,
81 ) -> Result<RootCapabilityResponseV1, Error> {
82 capability::response_capability_v1_root(envelope).await
83 }
84}