verity_ic/whitelist/
mod.rs

1//! The 'whitelist' module provides CRUD operations for managing a whitelist.
2//! The whitelist is a HashMap where each principal is mapped to a boolean value.
3//! A principal is considered whitelisted if it maps to `true`.
4
5use std::{cell::RefCell, collections::HashMap};
6
7use candid::Principal;
8
9thread_local! {
10    /// A thread-local storage for the whitelist, mapping principals to their whitelisted status.
11    pub static WHITE_LIST: RefCell<HashMap<Principal, bool>> = RefCell::default();
12}
13
14/// Adds a principal to the whitelist.
15pub fn add_to_whitelist(principal: Principal) {
16    WHITE_LIST.with(|rc| rc.borrow_mut().insert(principal, true));
17}
18
19/// Removes a principal from the whitelist.
20pub fn remove_from_whitelist(principal: Principal) {
21    WHITE_LIST.with(|rc| rc.borrow_mut().remove(&principal));
22}
23
24/// Checks if a principal is whitelisted.
25/// Returns `true` if the principal is whitelisted, otherwise `false`.
26pub fn is_whitelisted(principal: Principal) -> bool {
27    WHITE_LIST.with(|rc| rc.borrow().clone().contains_key(&principal))
28}