isp_sdk/isp_certified_log/
icsp_certified_log_backend_did.rs1use candid::{Nat, Principal};
2use ic_cdk::api::call::CallResult;
3use ic_cdk::export::candid::{CandidType, Deserialize};
4
5#[derive(CandidType, Deserialize, Debug)]
6pub struct LiveBucket {
7 pub bucket_id: String,
8 pub used_memory: Nat,
9}
10
11#[derive(CandidType, Deserialize, Debug)]
12pub struct Buckets {
13 pub old_buckets: Vec<Principal>,
14 pub live_buckets: LiveBucket,
15}
16
17#[derive(CandidType, Deserialize)]
18pub struct StoreLog {
19 pub context: String,
20}
21
22struct SERVICE(Principal);
23impl SERVICE {
24 pub async fn add_admin(&self, new_admin: Principal) -> CallResult<()> {
25 ic_cdk::call(self.0, "addAdmin", (new_admin,)).await
26 }
27 pub async fn delete_admin(&self, old_admin: Principal) -> CallResult<()> {
28 ic_cdk::call(self.0, "deleteAdmin", (old_admin,)).await
29 }
30 pub async fn get_admins(&self) -> CallResult<(Vec<Principal>,)> {
31 ic_cdk::call(self.0, "getAdmins", ()).await
32 }
33 pub async fn get_buckets(&self) -> CallResult<(Option<Buckets>,)> {
34 ic_cdk::call(self.0, "getBuckets", ()).await
35 }
36 pub async fn get_log_num(&self) -> CallResult<(Nat,)> {
37 ic_cdk::call(self.0, "getLogNum", ()).await
38 }
39 pub async fn get_logs(
40 &self,
41 start: Nat,
42 end: Nat,
43 ) -> CallResult<(Option<Vec<(u64, u64, Principal)>>,)> {
44 ic_cdk::call(self.0, "getLogs", (start, end)).await
45 }
46 pub async fn init(&self) -> CallResult<(LiveBucket,)> {
47 ic_cdk::call(self.0, "init", ()).await
48 }
49 pub async fn store(&self, args: StoreLog) -> CallResult<()> {
50 ic_cdk::call(self.0, "store", (args,)).await
51 }
52 pub async fn top_up_bucket(&self, amount: Nat) -> CallResult<()> {
53 ic_cdk::call(self.0, "topUpBucket", (amount,)).await
54 }
55 pub async fn update_bucket_canister_controller(
56 &self,
57 canister_id: ic_cdk::export::Principal,
58 contoller: Vec<ic_cdk::export::Principal>,
59 ) -> CallResult<(bool,)> {
60 ic_cdk::call(
61 self.0,
62 "updateBucketCanisterController",
63 (canister_id, contoller),
64 )
65 .await
66 }
67}