git.delta.rocks / unique-network / refs/commits / c4304c12b419

difftreelog

fix warnings

Igor Kozyrev2022-02-17parent: #4664e20.patch.diff
in: master

4 files changed

modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -2,7 +2,7 @@
 
 use core::ops::Deref;
 use frame_support::{ensure};
-use up_data_structs::{AccessMode, Collection, CollectionId, TokenId, CreateCollectionData};
+use up_data_structs::{AccessMode, CollectionId, TokenId, CreateCollectionData};
 use pallet_common::{
 	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,
 };
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
before · pallets/nonfungible/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23use erc::ERC721Events;4use frame_support::{BoundedVec, ensure};5use up_data_structs::{6	AccessMode, Collection, CollectionId, CustomDataLimit, TokenId, CreateCollectionData,7};8use pallet_common::{9	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, account::CrossAccountId,10};11use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};12use sp_core::H160;13use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};14use sp_std::{vec::Vec, vec};15use core::ops::Deref;16use sp_std::collections::btree_map::BTreeMap;17use codec::{Encode, Decode, MaxEncodedLen};18use scale_info::TypeInfo;1920pub use pallet::*;21#[cfg(feature = "runtime-benchmarks")]22pub mod benchmarking;23pub mod common;24pub mod erc;25pub mod weights;2627pub struct CreateItemData<T: Config> {28	pub const_data: BoundedVec<u8, CustomDataLimit>,29	pub variable_data: BoundedVec<u8, CustomDataLimit>,30	pub owner: T::CrossAccountId,31}32pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;3334#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]35pub struct ItemData<CrossAccountId> {36	pub const_data: BoundedVec<u8, CustomDataLimit>,37	pub variable_data: BoundedVec<u8, CustomDataLimit>,38	pub owner: CrossAccountId,39}4041#[frame_support::pallet]42pub mod pallet {43	use super::*;44	use frame_support::{Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};45	use up_data_structs::{CollectionId, TokenId};46	use super::weights::WeightInfo;4748	#[pallet::error]49	pub enum Error<T> {50		/// Not Nonfungible item data used to mint in Nonfungible collection.51		NotNonfungibleDataUsedToMintFungibleCollectionToken,52		/// Used amount > 1 with NFT53		NonfungibleItemsHaveNoAmount,54	}5556	#[pallet::config]57	pub trait Config: frame_system::Config + pallet_common::Config {58		type WeightInfo: WeightInfo;59	}6061	#[pallet::pallet]62	#[pallet::generate_store(pub(super) trait Store)]63	pub struct Pallet<T>(_);6465	#[pallet::storage]66	pub type TokensMinted<T: Config> =67		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;68	#[pallet::storage]69	pub type TokensBurnt<T: Config> =70		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;7172	#[pallet::storage]73	pub type TokenData<T: Config> = StorageNMap<74		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),75		Value = ItemData<T::CrossAccountId>,76		QueryKind = OptionQuery,77	>;7879	/// Used to enumerate tokens owned by account80	#[pallet::storage]81	pub type Owned<T: Config> = StorageNMap<82		Key = (83			Key<Twox64Concat, CollectionId>,84			Key<Blake2_128Concat, T::CrossAccountId>,85			Key<Twox64Concat, TokenId>,86		),87		Value = bool,88		QueryKind = ValueQuery,89	>;9091	#[pallet::storage]92	pub type AccountBalance<T: Config> = StorageNMap<93		Key = (94			Key<Twox64Concat, CollectionId>,95			Key<Blake2_128Concat, T::CrossAccountId>,96		),97		Value = u32,98		QueryKind = ValueQuery,99	>;100101	#[pallet::storage]102	pub type Allowance<T: Config> = StorageNMap<103		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),104		Value = T::CrossAccountId,105		QueryKind = OptionQuery,106	>;107}108109pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);110impl<T: Config> NonfungibleHandle<T> {111	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {112		Self(inner)113	}114	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {115		self.0116	}117}118impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {119	fn recorder(&self) -> &SubstrateRecorder<T> {120		self.0.recorder()121	}122	fn into_recorder(self) -> SubstrateRecorder<T> {123		self.0.into_recorder()124	}125}126impl<T: Config> Deref for NonfungibleHandle<T> {127	type Target = pallet_common::CollectionHandle<T>;128129	fn deref(&self) -> &Self::Target {130		&self.0131	}132}133134impl<T: Config> Pallet<T> {135	pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {136		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)137	}138	pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {139		<TokenData<T>>::contains_key((collection.id, token))140	}141}142143// unchecked calls skips any permission checks144impl<T: Config> Pallet<T> {145	pub fn init_collection(146		owner: T::AccountId,147		data: CreateCollectionData<T::AccountId>,148	) -> Result<CollectionId, DispatchError> {149		<PalletCommon<T>>::init_collection(owner, data)150	}151	pub fn destroy_collection(152		collection: NonfungibleHandle<T>,153		sender: &T::CrossAccountId,154	) -> DispatchResult {155		let id = collection.id;156157		// =========158159		PalletCommon::destroy_collection(collection.0, sender)?;160161		<TokenData<T>>::remove_prefix((id,), None);162		<Owned<T>>::remove_prefix((id,), None);163		<TokensMinted<T>>::remove(id);164		<TokensBurnt<T>>::remove(id);165		<Allowance<T>>::remove_prefix((id,), None);166		<AccountBalance<T>>::remove_prefix((id,), None);167		Ok(())168	}169170	pub fn burn(171		collection: &NonfungibleHandle<T>,172		sender: &T::CrossAccountId,173		token: TokenId,174	) -> DispatchResult {175		let token_data =176			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;177		ensure!(178			&token_data.owner == sender179				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),180			<CommonError<T>>::NoPermission181		);182183		if collection.access == AccessMode::AllowList {184			collection.check_allowlist(sender)?;185		}186187		let burnt = <TokensBurnt<T>>::get(collection.id)188			.checked_add(1)189			.ok_or(ArithmeticError::Overflow)?;190191		let balance = <AccountBalance<T>>::get((collection.id, token_data.owner.clone()))192			.checked_sub(1)193			.ok_or(ArithmeticError::Overflow)?;194195		if balance == 0 {196			<AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));197		} else {198			<AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);199		}200		// =========201202		<Owned<T>>::remove((collection.id, &token_data.owner, token));203		<TokensBurnt<T>>::insert(collection.id, burnt);204		<TokenData<T>>::remove((collection.id, token));205		let old_spender = <Allowance<T>>::take((collection.id, token));206207		if let Some(old_spender) = old_spender {208			<PalletCommon<T>>::deposit_event(CommonEvent::Approved(209				collection.id,210				token,211				sender.clone(),212				old_spender,213				0,214			));215		}216217		collection.log_mirrored(ERC721Events::Transfer {218			from: *token_data.owner.as_eth(),219			to: H160::default(),220			token_id: token.into(),221		});222		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(223			collection.id,224			token,225			token_data.owner,226			1,227		));228		Ok(())229	}230231	pub fn transfer(232		collection: &NonfungibleHandle<T>,233		from: &T::CrossAccountId,234		to: &T::CrossAccountId,235		token: TokenId,236	) -> DispatchResult {237		ensure!(238			collection.limits.transfers_enabled(),239			<CommonError<T>>::TransferNotAllowed240		);241242		let token_data =243			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;244		ensure!(245			&token_data.owner == from246				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),247			<CommonError<T>>::NoPermission248		);249250		if collection.access == AccessMode::AllowList {251			collection.check_allowlist(from)?;252			collection.check_allowlist(to)?;253		}254		<PalletCommon<T>>::ensure_correct_receiver(to)?;255256		let balance_from = <AccountBalance<T>>::get((collection.id, from))257			.checked_sub(1)258			.ok_or(<CommonError<T>>::TokenValueTooLow)?;259		let balance_to = if from != to {260			let balance_to = <AccountBalance<T>>::get((collection.id, to))261				.checked_add(1)262				.ok_or(ArithmeticError::Overflow)?;263264			ensure!(265				balance_to < collection.limits.account_token_ownership_limit(),266				<CommonError<T>>::AccountTokenLimitExceeded,267			);268269			Some(balance_to)270		} else {271			None272		};273274		// =========275276		<TokenData<T>>::insert(277			(collection.id, token),278			ItemData {279				owner: to.clone(),280				..token_data281			},282		);283284		if let Some(balance_to) = balance_to {285			// from != to286			if balance_from == 0 {287				<AccountBalance<T>>::remove((collection.id, from));288			} else {289				<AccountBalance<T>>::insert((collection.id, from), balance_from);290			}291			<AccountBalance<T>>::insert((collection.id, to), balance_to);292			<Owned<T>>::remove((collection.id, from, token));293			<Owned<T>>::insert((collection.id, to, token), true);294		}295		Self::set_allowance_unchecked(collection, from, token, None, true);296297		collection.log_mirrored(ERC721Events::Transfer {298			from: *from.as_eth(),299			to: *to.as_eth(),300			token_id: token.into(),301		});302		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(303			collection.id,304			token,305			from.clone(),306			to.clone(),307			1,308		));309		Ok(())310	}311312	pub fn create_multiple_items(313		collection: &NonfungibleHandle<T>,314		sender: &T::CrossAccountId,315		data: Vec<CreateItemData<T>>,316	) -> DispatchResult {317		if !collection.is_owner_or_admin(sender) {318			ensure!(319				collection.mint_mode,320				<CommonError<T>>::PublicMintingNotAllowed321			);322			collection.check_allowlist(sender)?;323324			for item in data.iter() {325				collection.check_allowlist(&item.owner)?;326			}327		}328329		for data in data.iter() {330			<PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;331		}332333		let first_token = <TokensMinted<T>>::get(collection.id);334		let tokens_minted = first_token335			.checked_add(data.len() as u32)336			.ok_or(ArithmeticError::Overflow)?;337		ensure!(338			tokens_minted <= collection.limits.token_limit(),339			<CommonError<T>>::CollectionTokenLimitExceeded340		);341342		let mut balances = BTreeMap::new();343		for data in &data {344			let balance = balances345				.entry(&data.owner)346				.or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));347			*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;348349			ensure!(350				*balance <= collection.limits.account_token_ownership_limit(),351				<CommonError<T>>::AccountTokenLimitExceeded,352			);353		}354355		// =========356357		<TokensMinted<T>>::insert(collection.id, tokens_minted);358		for (account, balance) in balances {359			<AccountBalance<T>>::insert((collection.id, account), balance);360		}361		for (i, data) in data.into_iter().enumerate() {362			let token = first_token + i as u32 + 1;363364			<TokenData<T>>::insert(365				(collection.id, token),366				ItemData {367					const_data: data.const_data,368					variable_data: data.variable_data,369					owner: data.owner.clone(),370				},371			);372			<Owned<T>>::insert((collection.id, &data.owner, token), true);373374			collection.log_mirrored(ERC721Events::Transfer {375				from: H160::default(),376				to: *data.owner.as_eth(),377				token_id: token.into(),378			});379			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(380				collection.id,381				TokenId(token),382				data.owner.clone(),383				1,384			));385		}386		Ok(())387	}388389	pub fn set_allowance_unchecked(390		collection: &NonfungibleHandle<T>,391		sender: &T::CrossAccountId,392		token: TokenId,393		spender: Option<&T::CrossAccountId>,394		assume_implicit_eth: bool,395	) {396		if let Some(spender) = spender {397			let old_spender = <Allowance<T>>::get((collection.id, token));398			<Allowance<T>>::insert((collection.id, token), spender);399			// In ERC721 there is only one possible approved user of token, so we set400			// approved user to spender401			collection.log_mirrored(ERC721Events::Approval {402				owner: *sender.as_eth(),403				approved: *spender.as_eth(),404				token_id: token.into(),405			});406			// In Unique chain, any token can have any amount of approved users, so we need to407			// set allowance of old owner to 0, and allowance of new owner to 1408			if old_spender.as_ref() != Some(spender) {409				if let Some(old_owner) = old_spender {410					<PalletCommon<T>>::deposit_event(CommonEvent::Approved(411						collection.id,412						token,413						sender.clone(),414						old_owner,415						0,416					));417				}418				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(419					collection.id,420					token,421					sender.clone(),422					spender.clone(),423					1,424				));425			}426		} else {427			let old_spender = <Allowance<T>>::take((collection.id, token));428			if !assume_implicit_eth {429				// In ERC721 there is only one possible approved user of token, so we set430				// approved user to zero address431				collection.log_mirrored(ERC721Events::Approval {432					owner: *sender.as_eth(),433					approved: H160::default(),434					token_id: token.into(),435				});436			}437			// In Unique chain, any token can have any amount of approved users, so we need to438			// set allowance of old owner to 0439			if let Some(old_spender) = old_spender {440				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(441					collection.id,442					token,443					sender.clone(),444					old_spender,445					0,446				));447			}448		}449	}450451	pub fn set_allowance(452		collection: &NonfungibleHandle<T>,453		sender: &T::CrossAccountId,454		token: TokenId,455		spender: Option<&T::CrossAccountId>,456	) -> DispatchResult {457		if collection.access == AccessMode::AllowList {458			collection.check_allowlist(sender)?;459			if let Some(spender) = spender {460				collection.check_allowlist(spender)?;461			}462		}463464		if let Some(spender) = spender {465			<PalletCommon<T>>::ensure_correct_receiver(spender)?;466		}467		let token_data =468			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;469		if &token_data.owner != sender {470			ensure!(471				collection.ignores_owned_amount(sender),472				<CommonError<T>>::CantApproveMoreThanOwned473			);474		}475476		// =========477478		Self::set_allowance_unchecked(collection, sender, token, spender, false);479		Ok(())480	}481482	pub fn transfer_from(483		collection: &NonfungibleHandle<T>,484		spender: &T::CrossAccountId,485		from: &T::CrossAccountId,486		to: &T::CrossAccountId,487		token: TokenId,488	) -> DispatchResult {489		if spender.conv_eq(from) {490			return Self::transfer(collection, from, to, token);491		}492		if collection.access == AccessMode::AllowList {493			// `from`, `to` checked in [`transfer`]494			collection.check_allowlist(spender)?;495		}496497		if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {498			ensure!(499				collection.ignores_allowance(spender),500				<CommonError<T>>::ApprovedValueTooLow501			);502		}503504		// =========505506		Self::transfer(collection, from, to, token)?;507		// Allowance is reset in [`transfer`]508		Ok(())509	}510511	pub fn burn_from(512		collection: &NonfungibleHandle<T>,513		spender: &T::CrossAccountId,514		from: &T::CrossAccountId,515		token: TokenId,516	) -> DispatchResult {517		if spender.conv_eq(from) {518			return Self::burn(collection, from, token);519		}520		if collection.access == AccessMode::AllowList {521			// `from` checked in [`burn`]522			collection.check_allowlist(spender)?;523		}524525		if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {526			ensure!(527				collection.ignores_allowance(spender),528				<CommonError<T>>::ApprovedValueTooLow529			);530		}531532		// =========533534		Self::burn(collection, from, token)535	}536537	pub fn set_variable_metadata(538		collection: &NonfungibleHandle<T>,539		sender: &T::CrossAccountId,540		token: TokenId,541		data: BoundedVec<u8, CustomDataLimit>,542	) -> DispatchResult {543		let token_data =544			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;545		collection.check_can_update_meta(sender, &token_data.owner)?;546547		// =========548549		<TokenData<T>>::insert(550			(collection.id, token),551			ItemData {552				variable_data: data,553				..token_data554			},555		);556		Ok(())557	}558559	/// Delegated to `create_multiple_items`560	pub fn create_item(561		collection: &NonfungibleHandle<T>,562		sender: &T::CrossAccountId,563		data: CreateItemData<T>,564	) -> DispatchResult {565		Self::create_multiple_items(collection, sender, vec![data])566	}567}
after · pallets/nonfungible/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23use erc::ERC721Events;4use frame_support::{BoundedVec, ensure};5use up_data_structs::{AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData};6use pallet_common::{7	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, account::CrossAccountId,8};9use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};10use sp_core::H160;11use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};12use sp_std::{vec::Vec, vec};13use core::ops::Deref;14use sp_std::collections::btree_map::BTreeMap;15use codec::{Encode, Decode, MaxEncodedLen};16use scale_info::TypeInfo;1718pub use pallet::*;19#[cfg(feature = "runtime-benchmarks")]20pub mod benchmarking;21pub mod common;22pub mod erc;23pub mod weights;2425pub struct CreateItemData<T: Config> {26	pub const_data: BoundedVec<u8, CustomDataLimit>,27	pub variable_data: BoundedVec<u8, CustomDataLimit>,28	pub owner: T::CrossAccountId,29}30pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;3132#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]33pub struct ItemData<CrossAccountId> {34	pub const_data: BoundedVec<u8, CustomDataLimit>,35	pub variable_data: BoundedVec<u8, CustomDataLimit>,36	pub owner: CrossAccountId,37}3839#[frame_support::pallet]40pub mod pallet {41	use super::*;42	use frame_support::{Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};43	use up_data_structs::{CollectionId, TokenId};44	use super::weights::WeightInfo;4546	#[pallet::error]47	pub enum Error<T> {48		/// Not Nonfungible item data used to mint in Nonfungible collection.49		NotNonfungibleDataUsedToMintFungibleCollectionToken,50		/// Used amount > 1 with NFT51		NonfungibleItemsHaveNoAmount,52	}5354	#[pallet::config]55	pub trait Config: frame_system::Config + pallet_common::Config {56		type WeightInfo: WeightInfo;57	}5859	#[pallet::pallet]60	#[pallet::generate_store(pub(super) trait Store)]61	pub struct Pallet<T>(_);6263	#[pallet::storage]64	pub type TokensMinted<T: Config> =65		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;66	#[pallet::storage]67	pub type TokensBurnt<T: Config> =68		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;6970	#[pallet::storage]71	pub type TokenData<T: Config> = StorageNMap<72		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),73		Value = ItemData<T::CrossAccountId>,74		QueryKind = OptionQuery,75	>;7677	/// Used to enumerate tokens owned by account78	#[pallet::storage]79	pub type Owned<T: Config> = StorageNMap<80		Key = (81			Key<Twox64Concat, CollectionId>,82			Key<Blake2_128Concat, T::CrossAccountId>,83			Key<Twox64Concat, TokenId>,84		),85		Value = bool,86		QueryKind = ValueQuery,87	>;8889	#[pallet::storage]90	pub type AccountBalance<T: Config> = StorageNMap<91		Key = (92			Key<Twox64Concat, CollectionId>,93			Key<Blake2_128Concat, T::CrossAccountId>,94		),95		Value = u32,96		QueryKind = ValueQuery,97	>;9899	#[pallet::storage]100	pub type Allowance<T: Config> = StorageNMap<101		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),102		Value = T::CrossAccountId,103		QueryKind = OptionQuery,104	>;105}106107pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);108impl<T: Config> NonfungibleHandle<T> {109	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {110		Self(inner)111	}112	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {113		self.0114	}115}116impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {117	fn recorder(&self) -> &SubstrateRecorder<T> {118		self.0.recorder()119	}120	fn into_recorder(self) -> SubstrateRecorder<T> {121		self.0.into_recorder()122	}123}124impl<T: Config> Deref for NonfungibleHandle<T> {125	type Target = pallet_common::CollectionHandle<T>;126127	fn deref(&self) -> &Self::Target {128		&self.0129	}130}131132impl<T: Config> Pallet<T> {133	pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {134		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)135	}136	pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {137		<TokenData<T>>::contains_key((collection.id, token))138	}139}140141// unchecked calls skips any permission checks142impl<T: Config> Pallet<T> {143	pub fn init_collection(144		owner: T::AccountId,145		data: CreateCollectionData<T::AccountId>,146	) -> Result<CollectionId, DispatchError> {147		<PalletCommon<T>>::init_collection(owner, data)148	}149	pub fn destroy_collection(150		collection: NonfungibleHandle<T>,151		sender: &T::CrossAccountId,152	) -> DispatchResult {153		let id = collection.id;154155		// =========156157		PalletCommon::destroy_collection(collection.0, sender)?;158159		<TokenData<T>>::remove_prefix((id,), None);160		<Owned<T>>::remove_prefix((id,), None);161		<TokensMinted<T>>::remove(id);162		<TokensBurnt<T>>::remove(id);163		<Allowance<T>>::remove_prefix((id,), None);164		<AccountBalance<T>>::remove_prefix((id,), None);165		Ok(())166	}167168	pub fn burn(169		collection: &NonfungibleHandle<T>,170		sender: &T::CrossAccountId,171		token: TokenId,172	) -> DispatchResult {173		let token_data =174			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;175		ensure!(176			&token_data.owner == sender177				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),178			<CommonError<T>>::NoPermission179		);180181		if collection.access == AccessMode::AllowList {182			collection.check_allowlist(sender)?;183		}184185		let burnt = <TokensBurnt<T>>::get(collection.id)186			.checked_add(1)187			.ok_or(ArithmeticError::Overflow)?;188189		let balance = <AccountBalance<T>>::get((collection.id, token_data.owner.clone()))190			.checked_sub(1)191			.ok_or(ArithmeticError::Overflow)?;192193		if balance == 0 {194			<AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));195		} else {196			<AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);197		}198		// =========199200		<Owned<T>>::remove((collection.id, &token_data.owner, token));201		<TokensBurnt<T>>::insert(collection.id, burnt);202		<TokenData<T>>::remove((collection.id, token));203		let old_spender = <Allowance<T>>::take((collection.id, token));204205		if let Some(old_spender) = old_spender {206			<PalletCommon<T>>::deposit_event(CommonEvent::Approved(207				collection.id,208				token,209				sender.clone(),210				old_spender,211				0,212			));213		}214215		collection.log_mirrored(ERC721Events::Transfer {216			from: *token_data.owner.as_eth(),217			to: H160::default(),218			token_id: token.into(),219		});220		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(221			collection.id,222			token,223			token_data.owner,224			1,225		));226		Ok(())227	}228229	pub fn transfer(230		collection: &NonfungibleHandle<T>,231		from: &T::CrossAccountId,232		to: &T::CrossAccountId,233		token: TokenId,234	) -> DispatchResult {235		ensure!(236			collection.limits.transfers_enabled(),237			<CommonError<T>>::TransferNotAllowed238		);239240		let token_data =241			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;242		ensure!(243			&token_data.owner == from244				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),245			<CommonError<T>>::NoPermission246		);247248		if collection.access == AccessMode::AllowList {249			collection.check_allowlist(from)?;250			collection.check_allowlist(to)?;251		}252		<PalletCommon<T>>::ensure_correct_receiver(to)?;253254		let balance_from = <AccountBalance<T>>::get((collection.id, from))255			.checked_sub(1)256			.ok_or(<CommonError<T>>::TokenValueTooLow)?;257		let balance_to = if from != to {258			let balance_to = <AccountBalance<T>>::get((collection.id, to))259				.checked_add(1)260				.ok_or(ArithmeticError::Overflow)?;261262			ensure!(263				balance_to < collection.limits.account_token_ownership_limit(),264				<CommonError<T>>::AccountTokenLimitExceeded,265			);266267			Some(balance_to)268		} else {269			None270		};271272		// =========273274		<TokenData<T>>::insert(275			(collection.id, token),276			ItemData {277				owner: to.clone(),278				..token_data279			},280		);281282		if let Some(balance_to) = balance_to {283			// from != to284			if balance_from == 0 {285				<AccountBalance<T>>::remove((collection.id, from));286			} else {287				<AccountBalance<T>>::insert((collection.id, from), balance_from);288			}289			<AccountBalance<T>>::insert((collection.id, to), balance_to);290			<Owned<T>>::remove((collection.id, from, token));291			<Owned<T>>::insert((collection.id, to, token), true);292		}293		Self::set_allowance_unchecked(collection, from, token, None, true);294295		collection.log_mirrored(ERC721Events::Transfer {296			from: *from.as_eth(),297			to: *to.as_eth(),298			token_id: token.into(),299		});300		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(301			collection.id,302			token,303			from.clone(),304			to.clone(),305			1,306		));307		Ok(())308	}309310	pub fn create_multiple_items(311		collection: &NonfungibleHandle<T>,312		sender: &T::CrossAccountId,313		data: Vec<CreateItemData<T>>,314	) -> DispatchResult {315		if !collection.is_owner_or_admin(sender) {316			ensure!(317				collection.mint_mode,318				<CommonError<T>>::PublicMintingNotAllowed319			);320			collection.check_allowlist(sender)?;321322			for item in data.iter() {323				collection.check_allowlist(&item.owner)?;324			}325		}326327		for data in data.iter() {328			<PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;329		}330331		let first_token = <TokensMinted<T>>::get(collection.id);332		let tokens_minted = first_token333			.checked_add(data.len() as u32)334			.ok_or(ArithmeticError::Overflow)?;335		ensure!(336			tokens_minted <= collection.limits.token_limit(),337			<CommonError<T>>::CollectionTokenLimitExceeded338		);339340		let mut balances = BTreeMap::new();341		for data in &data {342			let balance = balances343				.entry(&data.owner)344				.or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));345			*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;346347			ensure!(348				*balance <= collection.limits.account_token_ownership_limit(),349				<CommonError<T>>::AccountTokenLimitExceeded,350			);351		}352353		// =========354355		<TokensMinted<T>>::insert(collection.id, tokens_minted);356		for (account, balance) in balances {357			<AccountBalance<T>>::insert((collection.id, account), balance);358		}359		for (i, data) in data.into_iter().enumerate() {360			let token = first_token + i as u32 + 1;361362			<TokenData<T>>::insert(363				(collection.id, token),364				ItemData {365					const_data: data.const_data,366					variable_data: data.variable_data,367					owner: data.owner.clone(),368				},369			);370			<Owned<T>>::insert((collection.id, &data.owner, token), true);371372			collection.log_mirrored(ERC721Events::Transfer {373				from: H160::default(),374				to: *data.owner.as_eth(),375				token_id: token.into(),376			});377			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(378				collection.id,379				TokenId(token),380				data.owner.clone(),381				1,382			));383		}384		Ok(())385	}386387	pub fn set_allowance_unchecked(388		collection: &NonfungibleHandle<T>,389		sender: &T::CrossAccountId,390		token: TokenId,391		spender: Option<&T::CrossAccountId>,392		assume_implicit_eth: bool,393	) {394		if let Some(spender) = spender {395			let old_spender = <Allowance<T>>::get((collection.id, token));396			<Allowance<T>>::insert((collection.id, token), spender);397			// In ERC721 there is only one possible approved user of token, so we set398			// approved user to spender399			collection.log_mirrored(ERC721Events::Approval {400				owner: *sender.as_eth(),401				approved: *spender.as_eth(),402				token_id: token.into(),403			});404			// In Unique chain, any token can have any amount of approved users, so we need to405			// set allowance of old owner to 0, and allowance of new owner to 1406			if old_spender.as_ref() != Some(spender) {407				if let Some(old_owner) = old_spender {408					<PalletCommon<T>>::deposit_event(CommonEvent::Approved(409						collection.id,410						token,411						sender.clone(),412						old_owner,413						0,414					));415				}416				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(417					collection.id,418					token,419					sender.clone(),420					spender.clone(),421					1,422				));423			}424		} else {425			let old_spender = <Allowance<T>>::take((collection.id, token));426			if !assume_implicit_eth {427				// In ERC721 there is only one possible approved user of token, so we set428				// approved user to zero address429				collection.log_mirrored(ERC721Events::Approval {430					owner: *sender.as_eth(),431					approved: H160::default(),432					token_id: token.into(),433				});434			}435			// In Unique chain, any token can have any amount of approved users, so we need to436			// set allowance of old owner to 0437			if let Some(old_spender) = old_spender {438				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(439					collection.id,440					token,441					sender.clone(),442					old_spender,443					0,444				));445			}446		}447	}448449	pub fn set_allowance(450		collection: &NonfungibleHandle<T>,451		sender: &T::CrossAccountId,452		token: TokenId,453		spender: Option<&T::CrossAccountId>,454	) -> DispatchResult {455		if collection.access == AccessMode::AllowList {456			collection.check_allowlist(sender)?;457			if let Some(spender) = spender {458				collection.check_allowlist(spender)?;459			}460		}461462		if let Some(spender) = spender {463			<PalletCommon<T>>::ensure_correct_receiver(spender)?;464		}465		let token_data =466			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;467		if &token_data.owner != sender {468			ensure!(469				collection.ignores_owned_amount(sender),470				<CommonError<T>>::CantApproveMoreThanOwned471			);472		}473474		// =========475476		Self::set_allowance_unchecked(collection, sender, token, spender, false);477		Ok(())478	}479480	pub fn transfer_from(481		collection: &NonfungibleHandle<T>,482		spender: &T::CrossAccountId,483		from: &T::CrossAccountId,484		to: &T::CrossAccountId,485		token: TokenId,486	) -> DispatchResult {487		if spender.conv_eq(from) {488			return Self::transfer(collection, from, to, token);489		}490		if collection.access == AccessMode::AllowList {491			// `from`, `to` checked in [`transfer`]492			collection.check_allowlist(spender)?;493		}494495		if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {496			ensure!(497				collection.ignores_allowance(spender),498				<CommonError<T>>::ApprovedValueTooLow499			);500		}501502		// =========503504		Self::transfer(collection, from, to, token)?;505		// Allowance is reset in [`transfer`]506		Ok(())507	}508509	pub fn burn_from(510		collection: &NonfungibleHandle<T>,511		spender: &T::CrossAccountId,512		from: &T::CrossAccountId,513		token: TokenId,514	) -> DispatchResult {515		if spender.conv_eq(from) {516			return Self::burn(collection, from, token);517		}518		if collection.access == AccessMode::AllowList {519			// `from` checked in [`burn`]520			collection.check_allowlist(spender)?;521		}522523		if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {524			ensure!(525				collection.ignores_allowance(spender),526				<CommonError<T>>::ApprovedValueTooLow527			);528		}529530		// =========531532		Self::burn(collection, from, token)533	}534535	pub fn set_variable_metadata(536		collection: &NonfungibleHandle<T>,537		sender: &T::CrossAccountId,538		token: TokenId,539		data: BoundedVec<u8, CustomDataLimit>,540	) -> DispatchResult {541		let token_data =542			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;543		collection.check_can_update_meta(sender, &token_data.owner)?;544545		// =========546547		<TokenData<T>>::insert(548			(collection.id, token),549			ItemData {550				variable_data: data,551				..token_data552			},553		);554		Ok(())555	}556557	/// Delegated to `create_multiple_items`558	pub fn create_item(559		collection: &NonfungibleHandle<T>,560		sender: &T::CrossAccountId,561		data: CreateItemData<T>,562	) -> DispatchResult {563		Self::create_multiple_items(collection, sender, vec![data])564	}565}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -2,8 +2,7 @@
 
 use frame_support::{ensure, BoundedVec};
 use up_data_structs::{
-	AccessMode, Collection, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,
-	CreateCollectionData,
+	AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId, CreateCollectionData,
 };
 use pallet_common::{
 	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -38,8 +38,8 @@
 use up_data_structs::{
 	MAX_DECIMAL_POINTS, VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,
 	OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,
-	MAX_TOKEN_PREFIX_LENGTH, AccessMode, Collection, CreateItemData, CollectionLimits,
-	CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,
+	MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,
+	CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,
 	CreateCollectionData, CustomDataLimit,
 };
 use pallet_common::{