1use crate::{
2 cdk::{candid::CandidType, types::Principal},
3 dto::{
4 error::Error,
5 rpc::{
6 CreateCanisterParent, CreateCanisterResponse, Request, Response,
7 UpgradeCanisterResponse,
8 },
9 },
10 ids::CanisterRole,
11 workflow::rpc::request::{RpcRequestWorkflow, handler::RootResponseWorkflow},
12};
13
14pub struct RpcApi;
34
35impl RpcApi {
36 pub async fn create_canister_request<A>(
37 canister_role: &CanisterRole,
38 parent: CreateCanisterParent,
39 extra: Option<A>,
40 ) -> Result<CreateCanisterResponse, Error>
41 where
42 A: CandidType + Send + Sync,
43 {
44 RpcRequestWorkflow::create_canister_request(canister_role, parent, extra)
45 .await
46 .map_err(Error::from)
47 }
48
49 pub async fn upgrade_canister_request(
50 canister_pid: Principal,
51 ) -> Result<UpgradeCanisterResponse, Error> {
52 RpcRequestWorkflow::upgrade_canister_request(canister_pid)
53 .await
54 .map_err(Error::from)
55 }
56
57 pub async fn response(request: Request) -> Result<Response, Error> {
58 RootResponseWorkflow::response(request)
59 .await
60 .map_err(Error::from)
61 }
62}