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