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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use super::*;
use crate::{common::IntermediateError, deposit_indexed_event};
impl<T: Config> Pallet<T> {
pub(super) fn new_registry_(
AddRegistry { new_registry, id }: AddRegistry<T>,
registry_opt: &mut Option<RevocationRegistry<T>>,
) -> Result<(), IntermediateError<T>> {
new_registry.policy.ensure_valid()?;
ensure!(
registry_opt.replace(new_registry).is_none(),
IntermediateError::<T>::dispatch(Error::<T>::RegExists)
);
deposit_indexed_event!(RegistryAdded(id));
Ok(())
}
pub(super) fn revoke_(
RevokeRaw {
registry_id,
revoke_ids,
..
}: RevokeRaw<T>,
_: RevocationRegistry<T>,
_: BTreeSet<PolicyExecutor>,
) -> DispatchResult {
for cred_id in &revoke_ids {
Revocations::<T>::insert(registry_id, cred_id, ());
}
deposit_indexed_event!(RevokedInRegistry(registry_id));
Ok(())
}
pub(super) fn unrevoke_(
UnRevokeRaw {
revoke_ids,
registry_id,
..
}: UnRevokeRaw<T>,
registry: RevocationRegistry<T>,
_: BTreeSet<PolicyExecutor>,
) -> DispatchResult {
ensure!(!registry.add_only, Error::<T>::AddOnly);
for cred_id in &revoke_ids {
Revocations::<T>::remove(registry_id, cred_id);
}
deposit_indexed_event!(UnrevokedInRegistry(registry_id));
Ok(())
}
pub(super) fn remove_registry_(
RemoveRegistryRaw { registry_id, .. }: RemoveRegistryRaw<T>,
registry: &mut Option<RevocationRegistry<T>>,
_: BTreeSet<PolicyExecutor>,
) -> DispatchResult {
let registry = registry.take().ok_or(Error::<T>::RegistryDoesntExist)?;
ensure!(!registry.add_only, Error::<T>::AddOnly);
let _ = Revocations::<T>::clear_prefix(registry_id, u32::MAX, None);
deposit_indexed_event!(RegistryRemoved(registry_id));
Ok(())
}
}