diff --git a/Cargo.lock b/Cargo.lock index 1838e814b9..358537201e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2832,6 +2832,7 @@ dependencies = [ name = "ic-frontend-canister" version = "0.2.5" dependencies = [ + "candid 0.10.2", "ic-cdk", "ic-certified-assets", ] diff --git a/src/canisters/frontend/ic-certified-assets/src/lib.rs b/src/canisters/frontend/ic-certified-assets/src/lib.rs index fd927de80f..6218966603 100644 --- a/src/canisters/frontend/ic-certified-assets/src/lib.rs +++ b/src/canisters/frontend/ic-certified-assets/src/lib.rs @@ -18,7 +18,7 @@ use crate::{ types::*, }; use asset_certification::types::{certification::AssetKey, rc_bytes::RcBytes}; -use candid::{candid_method, Principal}; +use candid::Principal; use ic_cdk::api::{call::ManualReply, caller, data_certificate, set_certified_data, time, trap}; use ic_cdk::{query, update}; use serde_bytes::ByteBuf; @@ -33,19 +33,16 @@ thread_local! { } #[query] -#[candid_method(query)] fn api_version() -> u16 { 1 } #[update(guard = "is_manager_or_controller")] -#[candid_method(update)] fn authorize(other: Principal) { STATE.with(|s| s.borrow_mut().grant_permission(other, &Permission::Commit)) } #[update(guard = "is_manager_or_controller")] -#[candid_method(update)] fn grant_permission(arg: GrantPermissionArguments) { STATE.with(|s| { s.borrow_mut() @@ -54,7 +51,6 @@ fn grant_permission(arg: GrantPermissionArguments) { } #[update] -#[candid_method(update)] async fn validate_grant_permission(arg: GrantPermissionArguments) -> Result { Ok(format!( "grant {} permission to principal {}", @@ -63,7 +59,6 @@ async fn validate_grant_permission(arg: GrantPermissionArguments) -> Result Result { Ok(format!( "revoke {} permission from principal {}", @@ -105,32 +98,27 @@ async fn validate_revoke_permission(arg: RevokePermissionArguments) -> Result ManualReply> { STATE.with(|s| ManualReply::one(s.borrow().list_permitted(&Permission::Commit))) } #[update(manual_reply = true)] -#[candid_method(update)] fn list_permitted(arg: ListPermittedArguments) -> ManualReply> { STATE.with(|s| ManualReply::one(s.borrow().list_permitted(&arg.permission))) } #[update(guard = "is_controller")] -#[candid_method(update)] async fn take_ownership() { let caller = ic_cdk::api::caller(); STATE.with(|s| s.borrow_mut().take_ownership(caller)) } #[update] -#[candid_method(update)] async fn validate_take_ownership() -> Result { Ok("revoke all permissions, then gives the caller Commit permissions".to_string()) } #[query] -#[candid_method(query)] fn retrieve(key: AssetKey) -> RcBytes { STATE.with(|s| match s.borrow().retrieve(&key) { Ok(bytes) => bytes, @@ -139,7 +127,6 @@ fn retrieve(key: AssetKey) -> RcBytes { } #[update(guard = "can_commit")] -#[candid_method(update)] fn store(arg: StoreArg) { STATE.with(move |s| { if let Err(msg) = s.borrow_mut().store(arg, time()) { @@ -150,7 +137,6 @@ fn store(arg: StoreArg) { } #[update(guard = "can_prepare")] -#[candid_method(update)] fn create_batch() -> CreateBatchResponse { STATE.with(|s| match s.borrow_mut().create_batch(time()) { Ok(batch_id) => CreateBatchResponse { batch_id }, @@ -159,7 +145,6 @@ fn create_batch() -> CreateBatchResponse { } #[update(guard = "can_prepare")] -#[candid_method(update)] fn create_chunk(arg: CreateChunkArg) -> CreateChunkResponse { STATE.with(|s| match s.borrow_mut().create_chunk(arg, time()) { Ok(chunk_id) => CreateChunkResponse { chunk_id }, @@ -168,7 +153,6 @@ fn create_chunk(arg: CreateChunkArg) -> CreateChunkResponse { } #[update(guard = "can_commit")] -#[candid_method(update)] fn create_asset(arg: CreateAssetArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().create_asset(arg) { @@ -179,7 +163,6 @@ fn create_asset(arg: CreateAssetArguments) { } #[update(guard = "can_commit")] -#[candid_method(update)] fn set_asset_content(arg: SetAssetContentArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().set_asset_content(arg, time()) { @@ -190,7 +173,6 @@ fn set_asset_content(arg: SetAssetContentArguments) { } #[update(guard = "can_commit")] -#[candid_method(update)] fn unset_asset_content(arg: UnsetAssetContentArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().unset_asset_content(arg) { @@ -201,7 +183,6 @@ fn unset_asset_content(arg: UnsetAssetContentArguments) { } #[update(guard = "can_commit")] -#[candid_method(update)] fn delete_asset(arg: DeleteAssetArguments) { STATE.with(|s| { s.borrow_mut().delete_asset(arg); @@ -210,7 +191,6 @@ fn delete_asset(arg: DeleteAssetArguments) { } #[update(guard = "can_commit")] -#[candid_method(update)] fn clear() { STATE.with(|s| { s.borrow_mut().clear(); @@ -219,7 +199,6 @@ fn clear() { } #[update(guard = "can_commit")] -#[candid_method(update)] fn commit_batch(arg: CommitBatchArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().commit_batch(arg, time()) { @@ -230,7 +209,6 @@ fn commit_batch(arg: CommitBatchArguments) { } #[update(guard = "can_prepare")] -#[candid_method(update)] fn propose_commit_batch(arg: CommitBatchArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().propose_commit_batch(arg) { @@ -240,7 +218,6 @@ fn propose_commit_batch(arg: CommitBatchArguments) { } #[update(guard = "can_prepare")] -#[candid_method(update)] fn compute_evidence(arg: ComputeEvidenceArguments) -> Option { STATE.with(|s| match s.borrow_mut().compute_evidence(arg) { Err(msg) => trap(&msg), @@ -249,7 +226,6 @@ fn compute_evidence(arg: ComputeEvidenceArguments) -> Option { } #[update(guard = "can_commit")] -#[candid_method(update)] fn commit_proposed_batch(arg: CommitProposedBatchArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().commit_proposed_batch(arg, time()) { @@ -260,13 +236,11 @@ fn commit_proposed_batch(arg: CommitProposedBatchArguments) { } #[update] -#[candid_method(update)] fn validate_commit_proposed_batch(arg: CommitProposedBatchArguments) -> Result { STATE.with(|s| s.borrow_mut().validate_commit_proposed_batch(arg)) } #[update(guard = "can_prepare")] -#[candid_method(update)] fn delete_batch(arg: DeleteBatchArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().delete_batch(arg) { @@ -276,7 +250,6 @@ fn delete_batch(arg: DeleteBatchArguments) { } #[query] -#[candid_method(query)] fn get(arg: GetArg) -> EncodedAsset { STATE.with(|s| match s.borrow().get(arg) { Ok(asset) => asset, @@ -285,7 +258,6 @@ fn get(arg: GetArg) -> EncodedAsset { } #[query] -#[candid_method(query)] fn get_chunk(arg: GetChunkArg) -> GetChunkResponse { STATE.with(|s| match s.borrow().get_chunk(arg) { Ok(content) => GetChunkResponse { content }, @@ -294,13 +266,11 @@ fn get_chunk(arg: GetChunkArg) -> GetChunkResponse { } #[query] -#[candid_method(query)] fn list() -> Vec { STATE.with(|s| s.borrow().list_assets()) } #[query] -#[candid_method(query)] fn certified_tree() -> CertifiedTree { let certificate = data_certificate().unwrap_or_else(|| trap("no data certificate available")); @@ -308,7 +278,6 @@ fn certified_tree() -> CertifiedTree { } #[query] -#[candid_method(query)] fn http_request(req: HttpRequest) -> HttpResponse { let certificate = data_certificate().unwrap_or_else(|| trap("no data certificate available")); @@ -322,7 +291,6 @@ fn http_request(req: HttpRequest) -> HttpResponse { } #[query] -#[candid_method(query)] fn http_request_streaming_callback(token: StreamingCallbackToken) -> StreamingCallbackHttpResponse { STATE.with(|s| { s.borrow() @@ -332,7 +300,6 @@ fn http_request_streaming_callback(token: StreamingCallbackToken) -> StreamingCa } #[query] -#[candid_method(query)] fn get_asset_properties(key: AssetKey) -> AssetProperties { STATE.with(|s| { s.borrow() @@ -342,7 +309,6 @@ fn get_asset_properties(key: AssetKey) -> AssetProperties { } #[update(guard = "can_commit")] -#[candid_method(update)] fn set_asset_properties(arg: SetAssetPropertiesArguments) { STATE.with(|s| { if let Err(msg) = s.borrow_mut().set_asset_properties(arg) { @@ -352,19 +318,16 @@ fn set_asset_properties(arg: SetAssetPropertiesArguments) { } #[update(guard = "can_prepare")] -#[candid_method(update)] fn get_configuration() -> ConfigurationResponse { STATE.with(|s| s.borrow().get_configuration()) } #[update(guard = "can_commit")] -#[candid_method(update)] fn configure(arg: ConfigureArguments) { STATE.with(|s| s.borrow_mut().configure(arg)) } #[update] -#[candid_method(update)] fn validate_configure(arg: ConfigureArguments) -> Result { Ok(format!("configure: {:?}", arg)) } diff --git a/src/canisters/frontend/ic-certified-assets/src/state_machine.rs b/src/canisters/frontend/ic-certified-assets/src/state_machine.rs index 3a41f358a6..4521a1eed8 100644 --- a/src/canisters/frontend/ic-certified-assets/src/state_machine.rs +++ b/src/canisters/frontend/ic-certified-assets/src/state_machine.rs @@ -472,8 +472,8 @@ impl State { self.assets.clear(); self.batches.clear(); self.chunks.clear(); - self.next_batch_id = Nat::from(1); - self.next_chunk_id = Nat::from(1); + self.next_batch_id = Nat::from(1u8); + self.next_chunk_id = Nat::from(1u8); } pub fn has_permission(&self, principal: &Principal, permission: &Permission) -> bool { @@ -566,7 +566,7 @@ impl State { } } let batch_id = self.next_batch_id.clone(); - self.next_batch_id += 1; + self.next_batch_id += 1u8; self.batches.insert( batch_id.clone(), @@ -607,7 +607,7 @@ impl State { batch.expires_at = Int::from(now + BATCH_EXPIRY_NANOS); let chunk_id = self.next_chunk_id.clone(); - self.next_chunk_id += 1; + self.next_chunk_id += 1u8; batch.chunk_content_total_size += arg.content.as_ref().len(); self.chunks.insert( @@ -1093,7 +1093,7 @@ impl From for State { prepare_principals, manage_permissions_principals, assets: stable_state.stable_assets, - next_batch_id: stable_state.next_batch_id.unwrap_or_else(|| Nat::from(1)), + next_batch_id: stable_state.next_batch_id.unwrap_or_else(|| Nat::from(1u8)), configuration: stable_state.configuration.unwrap_or_default(), ..Self::default() }; diff --git a/src/canisters/frontend/ic-frontend-canister/Cargo.toml b/src/canisters/frontend/ic-frontend-canister/Cargo.toml index 5947ab793d..cc1119adac 100644 --- a/src/canisters/frontend/ic-frontend-canister/Cargo.toml +++ b/src/canisters/frontend/ic-frontend-canister/Cargo.toml @@ -16,3 +16,4 @@ crate-type = ["cdylib"] [dependencies] ic-certified-assets = { path = "../ic-certified-assets" } ic-cdk.workspace = true +candid.workspace = true