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