1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! This module provides access control functions for checking if the caller is a controller
//! and for retrieving the caller's principal ID.

use ic_cdk::query;
use candid::Principal;

/// Checks if the caller is a controller.
///
/// This function retrieves the caller's ID and checks if the caller is a controller.
///
/// # Returns
///
/// * `bool` - `true` if the caller is a controller, `false` otherwise.
#[query(name = "isController")]
pub fn is_controller() -> bool {
    let id = ic_cdk::api::caller();
    let is_controller = ic_cdk::api::is_controller(&id);

    return is_controller;
}

/// Retrieves the caller's principal ID.
///
/// This function returns the principal ID of the caller.
///
/// # Returns
///
/// * `Principal` - The principal ID of the caller.
#[query(name = "caller")]
pub fn caller() -> Principal {
    let id = ic_cdk::api::caller();

    return id;
}