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
//! This module provides access control functions for the indexer canister.

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

/// 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;
}

/// Checks if the caller is a controller of the canister.
/// 
/// # 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;
}