1use super::*;23pub struct PropertyGuard<'a, T: Config> {4 pub sender: &'a T::CrossAccountId,5 pub collection: &'a NonfungibleHandle<T>,6 pub token_id: TokenId,7 pub is_token_create: bool,8 nesting_budget: &'a dyn Budget,910 collection_admin_result: Option<DispatchResult>,11 token_owner_result: Option<DispatchResult>,12}1314pub struct PropertyGuardData<'a, T: Config> {15 pub sender: &'a T::CrossAccountId,16 pub collection: &'a NonfungibleHandle<T>,17 pub token_id: TokenId,18 pub is_token_create: bool,19 pub nesting_budget: &'a dyn Budget,20}2122impl<'a, T: Config> PropertyGuard<'a, T> {23 pub fn new(data: PropertyGuardData<'a, T>) -> Self {24 Self {25 sender: data.sender,26 collection: data.collection,27 token_id: data.token_id,28 is_token_create: data.is_token_create,29 nesting_budget: data.nesting_budget,3031 collection_admin_result: None,32 token_owner_result: None,33 }34 }3536 pub fn check_collection_admin(&mut self) -> DispatchResult {37 *self38 .collection_admin_result39 .get_or_insert_with(|| self.collection.check_is_owner_or_admin(self.sender))40 }4142 pub fn check_token_owner(&mut self) -> DispatchResult {43 *self.token_owner_result.get_or_insert_with(|| {44 let is_owned = <PalletStructure<T>>::check_indirectly_owned(45 self.sender.clone(),46 self.collection.id,47 self.token_id,48 None,49 self.nesting_budget,50 )?;5152 if is_owned {53 Ok(())54 } else {55 Err(<CommonError<T>>::NoPermission.into())56 }57 })58 }59}