git.delta.rocks / unique-network / refs/commits / 1c4a2b39d6b9

difftreelog

Use Error::from when needed

Daniel Shiposha2022-05-12parent: #599b514.patch.diff
in: master

2 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -674,7 +674,7 @@
 		let mut collection_properties = up_data_structs::CollectionProperties::get();
 		collection_properties
 			.try_set_from_iter(data.properties.into_iter().map(|p| (p.key, p.value)))
-			.map_err(|e| -> Error<T> { e.into() })?;
+			.map_err(<Error<T>>::from)?;
 
 		CollectionProperties::<T>::insert(id, collection_properties);
 
@@ -685,7 +685,7 @@
 					.into_iter()
 					.map(|property| (property.key, property.permission)),
 			)
-			.map_err(|e| -> Error<T> { e.into() })?;
+			.map_err(<Error<T>>::from)?;
 
 		CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);
 
@@ -765,7 +765,7 @@
 			let property = property.clone();
 			properties.try_set(property.key, property.value)
 		})
-		.map_err(|e| -> Error<T> { e.into() })?;
+		.map_err(<Error<T>>::from)?;
 
 		Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));
 
@@ -794,7 +794,7 @@
 		CollectionProperties::<T>::try_mutate(collection.id, |properties| {
 			properties.remove(&property_key)
 		})
-		.map_err(|e| -> Error<T> { e.into() })?;
+		.map_err(<Error<T>>::from)?;
 
 		Self::deposit_event(Event::CollectionPropertyDeleted(
 			collection.id,
@@ -836,7 +836,7 @@
 			let property_permission = property_permission.clone();
 			permissions.try_set(property_permission.key, property_permission.permission)
 		})
-		.map_err(|e| -> Error<T> { e.into() })?;
+		.map_err(<Error<T>>::from)?;
 
 		Self::deposit_event(Event::PropertyPermissionSet(
 			collection.id,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
before · pallets/nonfungible/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use erc::ERC721Events;20use frame_support::{BoundedVec, ensure, fail};21use up_data_structs::{22	AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,23	mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,24	PropertyKey, PropertyKeyPermission, Properties, TrySet,25};26use pallet_evm::account::CrossAccountId;27use pallet_common::{28	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,29	dispatch::CollectionDispatch,30};31use pallet_structure::Pallet as PalletStructure;32use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};33use sp_core::H160;34use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};35use sp_std::{vec::Vec, vec};36use core::ops::Deref;37use sp_std::collections::btree_map::BTreeMap;38use codec::{Encode, Decode, MaxEncodedLen};39use scale_info::TypeInfo;4041pub use pallet::*;42#[cfg(feature = "runtime-benchmarks")]43pub mod benchmarking;44pub mod common;45pub mod erc;46pub mod weights;4748pub type CreateItemData<T> = CreateNftExData<<T as pallet_evm::account::Config>::CrossAccountId>;49pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;5051#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]52pub struct ItemData<CrossAccountId> {53	pub const_data: BoundedVec<u8, CustomDataLimit>,54	pub variable_data: BoundedVec<u8, CustomDataLimit>,55	pub owner: CrossAccountId,56}5758#[frame_support::pallet]59pub mod pallet {60	use super::*;61	use frame_support::{Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};62	use up_data_structs::{CollectionId, TokenId};63	use super::weights::WeightInfo;6465	#[pallet::error]66	pub enum Error<T> {67		/// Not Nonfungible item data used to mint in Nonfungible collection.68		NotNonfungibleDataUsedToMintFungibleCollectionToken,69		/// Used amount > 1 with NFT70		NonfungibleItemsHaveNoAmount,71	}7273	#[pallet::config]74	pub trait Config:75		frame_system::Config + pallet_common::Config + pallet_structure::Config76	{77		type WeightInfo: WeightInfo;78	}7980	#[pallet::pallet]81	#[pallet::generate_store(pub(super) trait Store)]82	pub struct Pallet<T>(_);8384	#[pallet::storage]85	pub type TokensMinted<T: Config> =86		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;87	#[pallet::storage]88	pub type TokensBurnt<T: Config> =89		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;9091	#[pallet::storage]92	pub type TokenData<T: Config> = StorageNMap<93		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),94		Value = ItemData<T::CrossAccountId>,95		QueryKind = OptionQuery,96	>;9798	#[pallet::storage]99	#[pallet::getter(fn token_properties)]100	pub type TokenProperties<T: Config> = StorageNMap<101		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),102		Value = Properties,103		QueryKind = ValueQuery,104		OnEmpty = up_data_structs::TokenProperties,105	>;106107	/// Used to enumerate tokens owned by account108	#[pallet::storage]109	pub type Owned<T: Config> = StorageNMap<110		Key = (111			Key<Twox64Concat, CollectionId>,112			Key<Blake2_128Concat, T::CrossAccountId>,113			Key<Twox64Concat, TokenId>,114		),115		Value = bool,116		QueryKind = ValueQuery,117	>;118119	#[pallet::storage]120	pub type AccountBalance<T: Config> = StorageNMap<121		Key = (122			Key<Twox64Concat, CollectionId>,123			Key<Blake2_128Concat, T::CrossAccountId>,124		),125		Value = u32,126		QueryKind = ValueQuery,127	>;128129	#[pallet::storage]130	pub type Allowance<T: Config> = StorageNMap<131		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),132		Value = T::CrossAccountId,133		QueryKind = OptionQuery,134	>;135}136137pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);138impl<T: Config> NonfungibleHandle<T> {139	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {140		Self(inner)141	}142	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {143		self.0144	}145	pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {146		&mut self.0147	}148}149impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {150	fn recorder(&self) -> &SubstrateRecorder<T> {151		self.0.recorder()152	}153	fn into_recorder(self) -> SubstrateRecorder<T> {154		self.0.into_recorder()155	}156}157impl<T: Config> Deref for NonfungibleHandle<T> {158	type Target = pallet_common::CollectionHandle<T>;159160	fn deref(&self) -> &Self::Target {161		&self.0162	}163}164165impl<T: Config> Pallet<T> {166	pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {167		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)168	}169	pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {170		<TokenData<T>>::contains_key((collection.id, token))171	}172}173174// unchecked calls skips any permission checks175impl<T: Config> Pallet<T> {176	pub fn init_collection(177		owner: T::AccountId,178		data: CreateCollectionData<T::AccountId>,179	) -> Result<CollectionId, DispatchError> {180		<PalletCommon<T>>::init_collection(owner, data)181	}182	pub fn destroy_collection(183		collection: NonfungibleHandle<T>,184		sender: &T::CrossAccountId,185	) -> DispatchResult {186		let id = collection.id;187188		// =========189190		PalletCommon::destroy_collection(collection.0, sender)?;191192		<TokenData<T>>::remove_prefix((id,), None);193		<Owned<T>>::remove_prefix((id,), None);194		<TokensMinted<T>>::remove(id);195		<TokensBurnt<T>>::remove(id);196		<Allowance<T>>::remove_prefix((id,), None);197		<AccountBalance<T>>::remove_prefix((id,), None);198		Ok(())199	}200201	pub fn burn(202		collection: &NonfungibleHandle<T>,203		sender: &T::CrossAccountId,204		token: TokenId,205	) -> DispatchResult {206		let token_data =207			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;208		ensure!(209			&token_data.owner == sender210				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),211			<CommonError<T>>::NoPermission212		);213214		if collection.access == AccessMode::AllowList {215			collection.check_allowlist(sender)?;216		}217218		let burnt = <TokensBurnt<T>>::get(collection.id)219			.checked_add(1)220			.ok_or(ArithmeticError::Overflow)?;221222		let balance = <AccountBalance<T>>::get((collection.id, token_data.owner.clone()))223			.checked_sub(1)224			.ok_or(ArithmeticError::Overflow)?;225226		if balance == 0 {227			<AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));228		} else {229			<AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);230		}231		// =========232233		<Owned<T>>::remove((collection.id, &token_data.owner, token));234		<TokensBurnt<T>>::insert(collection.id, burnt);235		<TokenData<T>>::remove((collection.id, token));236		let old_spender = <Allowance<T>>::take((collection.id, token));237238		if let Some(old_spender) = old_spender {239			<PalletCommon<T>>::deposit_event(CommonEvent::Approved(240				collection.id,241				token,242				sender.clone(),243				old_spender,244				0,245			));246		}247248		collection.log_mirrored(ERC721Events::Transfer {249			from: *token_data.owner.as_eth(),250			to: H160::default(),251			token_id: token.into(),252		});253		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(254			collection.id,255			token,256			token_data.owner,257			1,258		));259		Ok(())260	}261262	pub fn set_token_property(263		collection: &NonfungibleHandle<T>,264		sender: &T::CrossAccountId,265		token_id: TokenId,266		property: Property,267	) -> DispatchResult {268		Self::check_token_change_permission(collection, sender, token_id, &property.key)?;269270		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {271			let property = property.clone();272			properties.try_set(property.key, property.value)273		})274		.map_err(|e| -> CommonError<T> { e.into() })?;275276		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(277			collection.id,278			token_id,279			property.key,280		));281282		Ok(())283	}284285	pub fn set_token_properties(286		collection: &NonfungibleHandle<T>,287		sender: &T::CrossAccountId,288		token_id: TokenId,289		properties: Vec<Property>,290	) -> DispatchResult {291		for property in properties {292			Self::set_token_property(collection, sender, token_id, property)?;293		}294295		Ok(())296	}297298	pub fn delete_token_property(299		collection: &NonfungibleHandle<T>,300		sender: &T::CrossAccountId,301		token_id: TokenId,302		property_key: PropertyKey,303	) -> DispatchResult {304		Self::check_token_change_permission(collection, sender, token_id, &property_key)?;305306		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {307			properties.remove(&property_key)308		})309		.map_err(|e| -> CommonError<T> { e.into() })?;310311		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(312			collection.id,313			token_id,314			property_key,315		));316317		Ok(())318	}319320	fn check_token_change_permission(321		collection: &NonfungibleHandle<T>,322		sender: &T::CrossAccountId,323		token_id: TokenId,324		property_key: &PropertyKey,325	) -> DispatchResult {326		let permission = <PalletCommon<T>>::property_permissions(collection.id)327			.get(property_key)328			.map(|p| p.clone())329			.unwrap_or(PropertyPermission::none());330331		let token_data = <TokenData<T>>::get((collection.id, token_id))332			.ok_or(<CommonError<T>>::TokenNotFound)?;333334		let check_token_owner = || -> DispatchResult {335			ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);336			Ok(())337		};338339		let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))340			.get(property_key)341			.is_some();342343		match permission {344			PropertyPermission { mutable: false, .. } if is_property_exists => {345				Err(<CommonError<T>>::NoPermission.into())346			}347348			PropertyPermission {349				collection_admin,350				token_owner,351				..352			} => {353				let mut check_result = Err(<CommonError<T>>::NoPermission.into());354355				if collection_admin {356					check_result = collection.check_is_owner_or_admin(sender);357				}358359				if token_owner {360					check_result.or(check_token_owner())361				} else {362					check_result363				}364			}365		}366	}367368	pub fn delete_token_properties(369		collection: &NonfungibleHandle<T>,370		sender: &T::CrossAccountId,371		token_id: TokenId,372		property_keys: Vec<PropertyKey>,373	) -> DispatchResult {374		for key in property_keys {375			Self::delete_token_property(collection, sender, token_id, key)?;376		}377378		Ok(())379	}380381	pub fn set_collection_properties(382		collection: &NonfungibleHandle<T>,383		sender: &T::CrossAccountId,384		properties: Vec<Property>,385	) -> DispatchResult {386		<PalletCommon<T>>::set_collection_properties(collection, sender, properties)387	}388389	pub fn delete_collection_properties(390		collection: &CollectionHandle<T>,391		sender: &T::CrossAccountId,392		property_keys: Vec<PropertyKey>,393	) -> DispatchResult {394		<PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)395	}396397	pub fn set_property_permissions(398		collection: &CollectionHandle<T>,399		sender: &T::CrossAccountId,400		property_permissions: Vec<PropertyKeyPermission>,401	) -> DispatchResult {402		<PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)403	}404405	pub fn transfer(406		collection: &NonfungibleHandle<T>,407		from: &T::CrossAccountId,408		to: &T::CrossAccountId,409		token: TokenId,410		nesting_budget: &dyn Budget,411	) -> DispatchResult {412		ensure!(413			collection.limits.transfers_enabled(),414			<CommonError<T>>::TransferNotAllowed415		);416417		let token_data =418			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;419		// TODO: require sender to be token, owner, require admins to go through transfer_from420		ensure!(421			&token_data.owner == from422				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),423			<CommonError<T>>::NoPermission424		);425426		if collection.access == AccessMode::AllowList {427			collection.check_allowlist(from)?;428			collection.check_allowlist(to)?;429		}430		<PalletCommon<T>>::ensure_correct_receiver(to)?;431432		let balance_from = <AccountBalance<T>>::get((collection.id, from))433			.checked_sub(1)434			.ok_or(<CommonError<T>>::TokenValueTooLow)?;435		let balance_to = if from != to {436			let balance_to = <AccountBalance<T>>::get((collection.id, to))437				.checked_add(1)438				.ok_or(ArithmeticError::Overflow)?;439440			ensure!(441				balance_to < collection.limits.account_token_ownership_limit(),442				<CommonError<T>>::AccountTokenLimitExceeded,443			);444445			Some(balance_to)446		} else {447			None448		};449450		if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {451			let handle = <CollectionHandle<T>>::try_get(target.0)?;452			let dispatch = T::CollectionDispatch::dispatch(handle);453			let dispatch = dispatch.as_dyn();454455			dispatch.check_nesting(456				from.clone(),457				(collection.id, token),458				target.1,459				nesting_budget,460			)?;461		}462463		// =========464465		<TokenData<T>>::insert(466			(collection.id, token),467			ItemData {468				owner: to.clone(),469				..token_data470			},471		);472473		if let Some(balance_to) = balance_to {474			// from != to475			if balance_from == 0 {476				<AccountBalance<T>>::remove((collection.id, from));477			} else {478				<AccountBalance<T>>::insert((collection.id, from), balance_from);479			}480			<AccountBalance<T>>::insert((collection.id, to), balance_to);481			<Owned<T>>::remove((collection.id, from, token));482			<Owned<T>>::insert((collection.id, to, token), true);483		}484		Self::set_allowance_unchecked(collection, from, token, None, true);485486		collection.log_mirrored(ERC721Events::Transfer {487			from: *from.as_eth(),488			to: *to.as_eth(),489			token_id: token.into(),490		});491		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(492			collection.id,493			token,494			from.clone(),495			to.clone(),496			1,497		));498		Ok(())499	}500501	pub fn create_multiple_items(502		collection: &NonfungibleHandle<T>,503		sender: &T::CrossAccountId,504		data: Vec<CreateItemData<T>>,505		nesting_budget: &dyn Budget,506	) -> DispatchResult {507		if !collection.is_owner_or_admin(sender) {508			ensure!(509				collection.mint_mode,510				<CommonError<T>>::PublicMintingNotAllowed511			);512			collection.check_allowlist(sender)?;513514			for item in data.iter() {515				collection.check_allowlist(&item.owner)?;516			}517		}518519		for data in data.iter() {520			<PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;521		}522523		let first_token = <TokensMinted<T>>::get(collection.id);524		let tokens_minted = first_token525			.checked_add(data.len() as u32)526			.ok_or(ArithmeticError::Overflow)?;527		ensure!(528			tokens_minted <= collection.limits.token_limit(),529			<CommonError<T>>::CollectionTokenLimitExceeded530		);531532		let mut balances = BTreeMap::new();533		for data in &data {534			let balance = balances535				.entry(&data.owner)536				.or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));537			*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;538539			ensure!(540				*balance <= collection.limits.account_token_ownership_limit(),541				<CommonError<T>>::AccountTokenLimitExceeded,542			);543		}544545		for (i, data) in data.iter().enumerate() {546			let token = TokenId(first_token + i as u32 + 1);547			if let Some(target) = T::CrossTokenAddressMapping::address_to_token(&data.owner) {548				let handle = <CollectionHandle<T>>::try_get(target.0)?;549				let dispatch = T::CollectionDispatch::dispatch(handle);550				let dispatch = dispatch.as_dyn();551				dispatch.check_nesting(552					sender.clone(),553					(collection.id, token),554					target.1,555					nesting_budget,556				)?;557			}558		}559560		// =========561562		<TokensMinted<T>>::insert(collection.id, tokens_minted);563		for (account, balance) in balances {564			<AccountBalance<T>>::insert((collection.id, account), balance);565		}566		for (i, data) in data.into_iter().enumerate() {567			let token = first_token + i as u32 + 1;568569			<TokenData<T>>::insert(570				(collection.id, token),571				ItemData {572					const_data: data.const_data,573					variable_data: data.variable_data,574					owner: data.owner.clone(),575				},576			);577			<Owned<T>>::insert((collection.id, &data.owner, token), true);578579			Self::set_token_properties(580				collection,581				sender,582				TokenId(token),583				data.properties.into_inner(),584			)?;585586			collection.log_mirrored(ERC721Events::Transfer {587				from: H160::default(),588				to: *data.owner.as_eth(),589				token_id: token.into(),590			});591			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(592				collection.id,593				TokenId(token),594				data.owner.clone(),595				1,596			));597		}598		Ok(())599	}600601	pub fn set_allowance_unchecked(602		collection: &NonfungibleHandle<T>,603		sender: &T::CrossAccountId,604		token: TokenId,605		spender: Option<&T::CrossAccountId>,606		assume_implicit_eth: bool,607	) {608		if let Some(spender) = spender {609			let old_spender = <Allowance<T>>::get((collection.id, token));610			<Allowance<T>>::insert((collection.id, token), spender);611			// In ERC721 there is only one possible approved user of token, so we set612			// approved user to spender613			collection.log_mirrored(ERC721Events::Approval {614				owner: *sender.as_eth(),615				approved: *spender.as_eth(),616				token_id: token.into(),617			});618			// In Unique chain, any token can have any amount of approved users, so we need to619			// set allowance of old owner to 0, and allowance of new owner to 1620			if old_spender.as_ref() != Some(spender) {621				if let Some(old_owner) = old_spender {622					<PalletCommon<T>>::deposit_event(CommonEvent::Approved(623						collection.id,624						token,625						sender.clone(),626						old_owner,627						0,628					));629				}630				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(631					collection.id,632					token,633					sender.clone(),634					spender.clone(),635					1,636				));637			}638		} else {639			let old_spender = <Allowance<T>>::take((collection.id, token));640			if !assume_implicit_eth {641				// In ERC721 there is only one possible approved user of token, so we set642				// approved user to zero address643				collection.log_mirrored(ERC721Events::Approval {644					owner: *sender.as_eth(),645					approved: H160::default(),646					token_id: token.into(),647				});648			}649			// In Unique chain, any token can have any amount of approved users, so we need to650			// set allowance of old owner to 0651			if let Some(old_spender) = old_spender {652				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(653					collection.id,654					token,655					sender.clone(),656					old_spender,657					0,658				));659			}660		}661	}662663	pub fn set_allowance(664		collection: &NonfungibleHandle<T>,665		sender: &T::CrossAccountId,666		token: TokenId,667		spender: Option<&T::CrossAccountId>,668	) -> DispatchResult {669		if collection.access == AccessMode::AllowList {670			collection.check_allowlist(sender)?;671			if let Some(spender) = spender {672				collection.check_allowlist(spender)?;673			}674		}675676		if let Some(spender) = spender {677			<PalletCommon<T>>::ensure_correct_receiver(spender)?;678		}679		let token_data =680			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;681		if &token_data.owner != sender {682			ensure!(683				collection.ignores_owned_amount(sender),684				<CommonError<T>>::CantApproveMoreThanOwned685			);686		}687688		// =========689690		Self::set_allowance_unchecked(collection, sender, token, spender, false);691		Ok(())692	}693694	fn check_allowed(695		collection: &NonfungibleHandle<T>,696		spender: &T::CrossAccountId,697		from: &T::CrossAccountId,698		token: TokenId,699		nesting_budget: &dyn Budget,700	) -> DispatchResult {701		if spender.conv_eq(from) {702			return Ok(());703		}704		if collection.access == AccessMode::AllowList {705			// `from`, `to` checked in [`transfer`]706			collection.check_allowlist(spender)?;707		}708		if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {709			// TODO: should collection owner be allowed to perform this transfer?710			ensure!(711				<PalletStructure<T>>::check_indirectly_owned(712					spender.clone(),713					source.0,714					source.1,715					None,716					nesting_budget717				)?,718				<CommonError<T>>::ApprovedValueTooLow,719			);720			return Ok(());721		}722		if <Allowance<T>>::get((collection.id, token)).as_ref() == Some(spender) {723			return Ok(());724		}725		ensure!(726			collection.ignores_allowance(spender),727			<CommonError<T>>::ApprovedValueTooLow728		);729		Ok(())730	}731732	pub fn transfer_from(733		collection: &NonfungibleHandle<T>,734		spender: &T::CrossAccountId,735		from: &T::CrossAccountId,736		to: &T::CrossAccountId,737		token: TokenId,738		nesting_budget: &dyn Budget,739	) -> DispatchResult {740		Self::check_allowed(collection, spender, from, token, nesting_budget)?;741742		// =========743744		// Allowance is reset in [`transfer`]745		Self::transfer(collection, from, to, token, nesting_budget)746	}747748	pub fn burn_from(749		collection: &NonfungibleHandle<T>,750		spender: &T::CrossAccountId,751		from: &T::CrossAccountId,752		token: TokenId,753		nesting_budget: &dyn Budget,754	) -> DispatchResult {755		Self::check_allowed(collection, spender, from, token, nesting_budget)?;756757		// =========758759		Self::burn(collection, from, token)760	}761762	pub fn set_variable_metadata(763		collection: &NonfungibleHandle<T>,764		sender: &T::CrossAccountId,765		token: TokenId,766		data: BoundedVec<u8, CustomDataLimit>,767	) -> DispatchResult {768		let token_data =769			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;770		collection.check_can_update_meta(sender, &token_data.owner)?;771772		// =========773774		<TokenData<T>>::insert(775			(collection.id, token),776			ItemData {777				variable_data: data,778				..token_data779			},780		);781		Ok(())782	}783784	pub fn check_nesting(785		handle: &NonfungibleHandle<T>,786		sender: T::CrossAccountId,787		from: (CollectionId, TokenId),788		under: TokenId,789		nesting_budget: &dyn Budget,790	) -> DispatchResult {791		fn ensure_sender_allowed<T: Config>(792			collection: CollectionId,793			token: TokenId,794			for_nest: (CollectionId, TokenId),795			sender: T::CrossAccountId,796			budget: &dyn Budget,797		) -> DispatchResult {798			ensure!(799				<PalletStructure<T>>::check_indirectly_owned(800					sender,801					collection,802					token,803					Some(for_nest),804					budget805				)?,806				<CommonError<T>>::OnlyOwnerAllowedToNest,807			);808			Ok(())809		}810		match handle.limits.nesting_rule() {811			NestingRule::Disabled => fail!(<CommonError<T>>::NestingIsDisabled),812			NestingRule::Owner => {813				ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?814			}815			NestingRule::OwnerRestricted(whitelist) => {816				ensure!(817					whitelist.contains(&from.0),818					<CommonError<T>>::SourceCollectionIsNotAllowedToNest819				);820				ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?821			}822		}823		Ok(())824	}825826	/// Delegated to `create_multiple_items`827	pub fn create_item(828		collection: &NonfungibleHandle<T>,829		sender: &T::CrossAccountId,830		data: CreateItemData<T>,831		nesting_budget: &dyn Budget,832	) -> DispatchResult {833		Self::create_multiple_items(collection, sender, vec![data], nesting_budget)834	}835}