Skip to content

Commit

Permalink
Remove unnecessary candid annotations (#2601)
Browse files Browse the repository at this point in the history
The `candid_method` annotations are no longer necessary, so they
are removed in this PR.
  • Loading branch information
frederikrothenberger authored Sep 11, 2024
1 parent b56092d commit 33e58d6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 62 deletions.
14 changes: 2 additions & 12 deletions demos/vc_issuer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::consent_message::{get_vc_consent_message, SupportedLanguage};
use candid::{candid_method, CandidType, Deserialize, Principal};
use candid::{CandidType, Deserialize, Principal};
use ic_canister_sig_creation::signature_map::{CanisterSigInputs, SignatureMap, LABEL_SIG};
use ic_canister_sig_creation::{
extract_raw_root_pk_from_der, CanisterSigPublicKey, IC_ROOT_PUBLIC_KEY,
Expand Down Expand Up @@ -142,7 +142,6 @@ struct IssuerInit {
}

#[init]
#[candid_method(init)]
fn init(init_arg: Option<IssuerInit>) {
if let Some(init) = init_arg {
apply_config(IssuerConfig::from(init));
Expand All @@ -157,7 +156,6 @@ fn post_upgrade(init_arg: Option<IssuerInit>) {
}

#[update]
#[candid_method]
fn configure(init: IssuerInit) {
apply_config(IssuerConfig::from(init));
}
Expand Down Expand Up @@ -202,7 +200,6 @@ fn authorize_vc_request(
}

#[update]
#[candid_method]
async fn prepare_credential(
req: PrepareCredentialRequest,
) -> Result<PreparedCredentialData, IssueCredentialError> {
Expand Down Expand Up @@ -247,7 +244,6 @@ fn update_root_hash() {
}

#[query]
#[candid_method(query)]
fn get_credential(req: GetCredentialRequest) -> Result<IssuedCredentialData, IssueCredentialError> {
if let Err(err) = authorize_vc_request(&req.signed_id_alias, &caller(), time().into()) {
return Result::<IssuedCredentialData, IssueCredentialError>::Err(err);
Expand Down Expand Up @@ -304,7 +300,6 @@ fn get_credential(req: GetCredentialRequest) -> Result<IssuedCredentialData, Iss
}

#[update]
#[candid_method]
async fn vc_consent_message(
req: Icrc21VcConsentMessageRequest,
) -> Result<Icrc21ConsentInfo, Icrc21Error> {
Expand All @@ -315,7 +310,6 @@ async fn vc_consent_message(
}

#[update]
#[candid_method]
async fn derivation_origin(
req: DerivationOriginRequest,
) -> Result<DerivationOriginData, DerivationOriginError> {
Expand Down Expand Up @@ -409,28 +403,24 @@ fn verify_single_argument(
}

#[update]
#[candid_method]
fn add_employee(employee_id: Principal) -> String {
EMPLOYEES.with_borrow_mut(|employees| employees.insert(employee_id));
format!("Added employee {}", employee_id)
}

#[update]
#[candid_method]
fn add_graduate(graduate_id: Principal) -> String {
GRADUATES.with_borrow_mut(|graduates| graduates.insert(graduate_id));
format!("Added graduate {}", graduate_id)
}

#[update]
#[candid_method]
fn add_adult(adult_id: Principal) -> String {
ADULTS.with_borrow_mut(|adults| adults.insert(adult_id));
format!("Added adult {}", adult_id)
}

#[query]
#[candid_method(query)]
pub fn http_request(req: HttpRequest) -> HttpResponse {
let parts: Vec<&str> = req.url.split('?').collect();
let path = parts[0];
Expand Down Expand Up @@ -596,7 +586,7 @@ fn hash_bytes(value: impl AsRef<[u8]>) -> Hash {
hasher.finalize().into()
}

// Order dependent: do not move above any function annotated with #[candid_method]!
// Order dependent: do not move above any exposed canister method!
candid::export_service!();

// Assets
Expand Down
10 changes: 2 additions & 8 deletions src/archive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! - prefix scan with anchor to retrieve entries by anchor
//! - prefix scan with (anchor, timestamp) to narrow down on the time period for a specific anchor
//! - prefix scan with (anchor, timestamp, log index) to do pagination (with the key of the first entry not included in the previous set)
use candid::{candid_method, CandidType, Deserialize, Principal};
use candid::{CandidType, Deserialize, Principal};
use ic_cdk::api::call::CallResult;
use ic_cdk::api::management_canister::main::{canister_status, CanisterIdRecord};
use ic_cdk::api::stable::stable_size;
Expand Down Expand Up @@ -239,7 +239,6 @@ impl Storable for AnchorIndexKey {
/// I.e. this allows rolling back Internet Identity from pull to push without rolling back the
/// archive.
#[update]
#[candid_method]
fn write_entry(anchor_number: AnchorNumber, timestamp: Timestamp, entry: ByteBuf) {
with_config(|config| {
if config.ii_canister != caller() {
Expand Down Expand Up @@ -378,7 +377,6 @@ fn store_call_error(call_error: CallErrorInfo) {
}

#[query]
#[candid_method(query)]
fn get_entries(index: Option<u64>, limit: Option<u16>) -> Entries {
let limit = limit_or_default(limit);

Expand All @@ -404,7 +402,6 @@ fn get_entries(index: Option<u64>, limit: Option<u16>) -> Entries {
}

#[query]
#[candid_method(query)]
fn get_anchor_entries(
anchor: AnchorNumber,
cursor: Option<Cursor>,
Expand Down Expand Up @@ -509,7 +506,6 @@ fn set_highest_archived_sequence_number(sequence_number: u64) {
}

#[init]
#[candid_method(init)]
fn initialize(arg: ArchiveInit) {
write_config(ArchiveConfig {
ii_canister: arg.ii_canister,
Expand Down Expand Up @@ -539,7 +535,6 @@ fn write_config(config: ArchiveConfig) {
}

#[query]
#[candid_method(query)]
fn http_request(req: HttpRequest) -> HttpResponse {
let parts: Vec<&str> = req.url.split('?').collect();
match parts[0] {
Expand Down Expand Up @@ -660,7 +655,6 @@ fn encode_metrics(w: &mut MetricsEncoder<Vec<u8>>) -> std::io::Result<()> {
/// Publicly exposes the status of the archive canister.
/// This is useful to check operations or for debugging purposes.
#[update]
#[candid_method]
async fn status() -> ArchiveStatus {
let canister_id = id();
let (ic_cdk_canister_status,) = canister_status(CanisterIdRecord { canister_id })
Expand Down Expand Up @@ -700,7 +694,7 @@ async fn status() -> ArchiveStatus {

fn main() {}

// Order dependent: do not move above any function annotated with #[candid_method]!
// Order dependent: do not move above any exposed canister method!
candid::export_service!();

#[cfg(test)]
Expand Down
Loading

0 comments on commit 33e58d6

Please sign in to comment.