verity_ic/remittance/external_router/
permissions.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use candid::Principal;
use ic_cdk::caller;
use std::{ cell::RefCell, collections::HashMap };

thread_local! {
	pub static WHITELISTED_PUBLISHERS: RefCell<HashMap<Principal, bool>> = RefCell::default();
}

pub fn add_publisher(principal: Principal) {
	WHITELISTED_PUBLISHERS.with(|rc| rc.borrow_mut().insert(principal, true));
}

pub fn remove_publisher(principal: Principal) {
	WHITELISTED_PUBLISHERS.with(|rc| rc.borrow_mut().remove(&principal));
}

pub fn only_whitelisted_publishers() {
	let caller_principal_id = caller();
	let whitelisted = WHITELISTED_PUBLISHERS.with(|rc| rc.borrow().clone());

	if !whitelisted.contains_key(&caller_principal_id) {
		panic!("PRINCPAL NOT WHITELISTED")
	}
}