pallet_governance/
whitelist.rs1use polkadot_sdk::frame_support::dispatch::DispatchResult;
2
3use crate::{application, AccountIdOf};
4
5pub fn add_to_whitelist<T: crate::Config>(key: AccountIdOf<T>) -> DispatchResult {
7 if is_whitelisted::<T>(&key) {
8 return Err(crate::Error::<T>::AlreadyWhitelisted.into());
9 }
10
11 if application::exists_for_agent_key::<T>(&key, &application::ApplicationAction::Add) {
12 return Err(crate::Error::<T>::ApplicationKeyAlreadyUsed.into());
13 }
14
15 crate::Whitelist::<T>::insert(key.clone(), ());
16 crate::Pallet::<T>::deposit_event(crate::Event::<T>::WhitelistAdded(key));
17 Ok(())
18}
19
20pub fn remove_from_whitelist<T: crate::Config>(key: AccountIdOf<T>) -> DispatchResult {
23 if !is_whitelisted::<T>(&key) {
24 return Err(crate::Error::<T>::NotWhitelisted.into());
25 }
26
27 if application::exists_for_agent_key::<T>(&key, &application::ApplicationAction::Remove) {
28 return Err(crate::Error::<T>::ApplicationKeyAlreadyUsed.into());
29 }
30
31 crate::Whitelist::<T>::remove(&key);
32 let _ = pallet_torus0::agent::unregister::<T>(key.clone());
33 crate::Pallet::<T>::deposit_event(crate::Event::<T>::WhitelistRemoved(key));
34 Ok(())
35}
36
37pub fn is_whitelisted<T: crate::Config>(key: &AccountIdOf<T>) -> bool {
38 crate::Whitelist::<T>::contains_key(key)
39}