pallet_permission0/permission/
namespace.rs1use codec::{Decode, Encode, MaxEncodedLen};
2use pallet_torus0_api::NamespacePath;
3use polkadot_sdk::{
4 frame_support::{CloneNoBound, DebugNoBound},
5 sp_runtime::{BoundedBTreeMap, BoundedBTreeSet},
6};
7use scale_info::TypeInfo;
8
9use crate::{Config, Permissions};
10
11use super::PermissionId;
12
13#[derive(Encode, Decode, CloneNoBound, TypeInfo, MaxEncodedLen, DebugNoBound)]
15#[scale_info(skip_type_params(T))]
16pub struct NamespaceScope<T: Config> {
17 pub recipient: T::AccountId,
18 pub paths: BoundedBTreeMap<
20 Option<PermissionId>,
21 BoundedBTreeSet<NamespacePath, T::MaxNamespacesPerPermission>,
22 T::MaxNamespacesPerPermission,
23 >,
24 pub max_instances: u32,
26 pub children: BoundedBTreeSet<PermissionId, T::MaxChildrenPerPermission>,
28}
29
30impl<T: Config> NamespaceScope<T> {
31 pub(super) fn cleanup(
33 &self,
34 permission_id: polkadot_sdk::sp_core::H256,
35 _last_execution: &Option<crate::BlockNumberFor<T>>,
36 _delegator: &T::AccountId,
37 ) {
38 for pid in self.paths.keys().cloned().flatten() {
39 Permissions::<T>::mutate_extant(pid, |parent| {
40 if let Some(children) = parent.children_mut() {
41 children.remove(&permission_id);
42 }
43 });
44 }
45 }
46}