git.delta.rocks / unique-network / refs/commits / 2d2eac8ef8b2

difftreelog

chore fix `token_owner` weight

Grigoriy Simonov2022-08-11parent: #c7669db.patch.diff
in: master

3 files changed

modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -120,7 +120,7 @@
 	}
 
 	fn token_owner() -> Weight {
-		0 //<SelfWeightOf<T>>::token_owner()
+		<SelfWeightOf<T>>::token_owner()
 	}
 }
 
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -36,9 +36,7 @@
 fn create_max_item_data<CrossAccountId: Ord>(
 	users: impl IntoIterator<Item = (CrossAccountId, u128)>,
 ) -> CreateRefungibleExData<CrossAccountId> {
-	let const_data = create_data::<CUSTOM_DATA_LIMIT>();
 	CreateRefungibleExData {
-		const_data,
 		users: users
 			.into_iter()
 			.collect::<BTreeMap<_, _>>()
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
before · pallets/refungible/src/common.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/>.1617use core::marker::PhantomData;1819use sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};21use up_data_structs::{22	CollectionId, TokenId, CreateItemExData, budget::Budget, Property, PropertyKey, PropertyValue,23	PropertyKeyPermission, CollectionPropertiesVec, CreateRefungibleExMultipleOwners,24	CreateRefungibleExSingleOwner,25};26use pallet_common::{27	CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,28	weights::WeightInfo as _,29};30use pallet_structure::Error as StructureError;31use sp_runtime::{DispatchError};32use sp_std::{vec::Vec, vec};3334use crate::{35	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,36	SelfWeightOf, weights::WeightInfo, TokensMinted, TotalSupply, CreateItemData,37};3839macro_rules! max_weight_of {40	($($method:ident ($($args:tt)*)),*) => {41		042		$(43			.max(<SelfWeightOf<T>>::$method($($args)*))44		)*45	};46}4748fn properties_weight<T: Config>(properties: &CollectionPropertiesVec) -> u64 {49	if properties.len() > 0 {50		<CommonWeights<T>>::set_token_properties(properties.len() as u32)51	} else {52		053	}54}5556pub struct CommonWeights<T: Config>(PhantomData<T>);57impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {58	fn create_item() -> Weight {59		<SelfWeightOf<T>>::create_item()60	}6162	fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {63		<SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(64			data.iter()65				.map(|data| match data {66					up_data_structs::CreateItemData::ReFungible(rft_data) => {67						properties_weight::<T>(&rft_data.properties)68					}69					_ => 0,70				})71				.fold(0, |a, b| a.saturating_add(b)),72		)73	}7475	fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {76		match call {77			CreateItemExData::RefungibleMultipleOwners(i) => {78				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)79					.saturating_add(properties_weight::<T>(&i.properties))80			}81			CreateItemExData::RefungibleMultipleItems(i) => {82				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)83					.saturating_add(84						i.iter()85							.map(|d| properties_weight::<T>(&d.properties))86							.fold(0, |a, b| a.saturating_add(b)),87					)88			}89			_ => 0,90		}91	}9293	fn burn_item() -> Weight {94		max_weight_of!(burn_item_partial(), burn_item_fully())95	}9697	fn set_collection_properties(amount: u32) -> Weight {98		<pallet_common::SelfWeightOf<T>>::set_collection_properties(amount)99	}100101	fn delete_collection_properties(amount: u32) -> Weight {102		<pallet_common::SelfWeightOf<T>>::delete_collection_properties(amount)103	}104105	fn set_token_properties(amount: u32) -> Weight {106		<SelfWeightOf<T>>::set_token_properties(amount)107	}108109	fn delete_token_properties(amount: u32) -> Weight {110		<SelfWeightOf<T>>::delete_token_properties(amount)111	}112113	fn set_token_property_permissions(amount: u32) -> Weight {114		<SelfWeightOf<T>>::set_token_property_permissions(amount)115	}116117	fn transfer() -> Weight {118		max_weight_of!(119			transfer_normal(),120			transfer_creating(),121			transfer_removing(),122			transfer_creating_removing()123		)124	}125126	fn approve() -> Weight {127		<SelfWeightOf<T>>::approve()128	}129130	fn transfer_from() -> Weight {131		max_weight_of!(132			transfer_from_normal(),133			transfer_from_creating(),134			transfer_from_removing(),135			transfer_from_creating_removing()136		)137	}138139	fn burn_from() -> Weight {140		<SelfWeightOf<T>>::burn_from()141	}142143	fn burn_recursively_self_raw() -> Weight {144		// Read to get total balance145		Self::burn_item() + T::DbWeight::get().reads(1)146	}147	fn burn_recursively_breadth_raw(_amount: u32) -> Weight {148		// Refungible token can't have children149		0150	}151152	fn token_owner() -> Weight {153		0 //<SelfWeightOf<T>>::token_owner()154	}155}156157fn map_create_data<T: Config>(158	data: up_data_structs::CreateItemData,159	to: &T::CrossAccountId,160) -> Result<CreateItemData<T::CrossAccountId>, DispatchError> {161	match data {162		up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateItemData {163			users: {164				let mut out = BTreeMap::new();165				out.insert(to.clone(), data.pieces);166				out.try_into().expect("limit > 0")167			},168			properties: data.properties,169		}),170		_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),171	}172}173174/// Implementation of `CommonCollectionOperations` for `RefungibleHandle`. It wraps Refungible Pallete175/// methods and adds weight info.176impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {177	fn create_item(178		&self,179		sender: T::CrossAccountId,180		to: T::CrossAccountId,181		data: up_data_structs::CreateItemData,182		nesting_budget: &dyn Budget,183	) -> DispatchResultWithPostInfo {184		with_weight(185			<Pallet<T>>::create_item(186				self,187				&sender,188				map_create_data::<T>(data, &to)?,189				nesting_budget,190			),191			<CommonWeights<T>>::create_item(),192		)193	}194195	fn create_multiple_items(196		&self,197		sender: T::CrossAccountId,198		to: T::CrossAccountId,199		data: Vec<up_data_structs::CreateItemData>,200		nesting_budget: &dyn Budget,201	) -> DispatchResultWithPostInfo {202		let weight = <CommonWeights<T>>::create_multiple_items(&data);203		let data = data204			.into_iter()205			.map(|d| map_create_data::<T>(d, &to))206			.collect::<Result<Vec<_>, DispatchError>>()?;207208		with_weight(209			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),210			weight,211		)212	}213214	fn create_multiple_items_ex(215		&self,216		sender: <T>::CrossAccountId,217		data: CreateItemExData<T::CrossAccountId>,218		nesting_budget: &dyn Budget,219	) -> DispatchResultWithPostInfo {220		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);221		let data = match data {222			CreateItemExData::RefungibleMultipleOwners(CreateRefungibleExMultipleOwners {223				users,224				properties,225			}) => vec![CreateItemData { users, properties }],226			CreateItemExData::RefungibleMultipleItems(r) => r227				.into_inner()228				.into_iter()229				.map(230					|CreateRefungibleExSingleOwner {231					     user,232					     pieces,233					     properties,234					 }| CreateItemData {235						users: BTreeMap::from([(user, pieces)])236							.try_into()237							.expect("limit >= 1"),238						properties,239					},240				)241				.collect(),242			_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),243		};244245		with_weight(246			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),247			weight,248		)249	}250251	fn burn_item(252		&self,253		sender: T::CrossAccountId,254		token: TokenId,255		amount: u128,256	) -> DispatchResultWithPostInfo {257		with_weight(258			<Pallet<T>>::burn(self, &sender, token, amount),259			<CommonWeights<T>>::burn_item(),260		)261	}262263	fn burn_item_recursively(264		&self,265		sender: T::CrossAccountId,266		token: TokenId,267		self_budget: &dyn Budget,268		_breadth_budget: &dyn Budget,269	) -> DispatchResultWithPostInfo {270		ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);271		with_weight(272			<Pallet<T>>::burn(273				self,274				&sender,275				token,276				<Balance<T>>::get((self.id, token, &sender)),277			),278			<CommonWeights<T>>::burn_recursively_self_raw(),279		)280	}281282	fn transfer(283		&self,284		from: T::CrossAccountId,285		to: T::CrossAccountId,286		token: TokenId,287		amount: u128,288		nesting_budget: &dyn Budget,289	) -> DispatchResultWithPostInfo {290		with_weight(291			<Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),292			<CommonWeights<T>>::transfer(),293		)294	}295296	fn approve(297		&self,298		sender: T::CrossAccountId,299		spender: T::CrossAccountId,300		token: TokenId,301		amount: u128,302	) -> DispatchResultWithPostInfo {303		with_weight(304			<Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),305			<CommonWeights<T>>::approve(),306		)307	}308309	fn transfer_from(310		&self,311		sender: T::CrossAccountId,312		from: T::CrossAccountId,313		to: T::CrossAccountId,314		token: TokenId,315		amount: u128,316		nesting_budget: &dyn Budget,317	) -> DispatchResultWithPostInfo {318		with_weight(319			<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),320			<CommonWeights<T>>::transfer_from(),321		)322	}323324	fn burn_from(325		&self,326		sender: T::CrossAccountId,327		from: T::CrossAccountId,328		token: TokenId,329		amount: u128,330		nesting_budget: &dyn Budget,331	) -> DispatchResultWithPostInfo {332		with_weight(333			<Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),334			<CommonWeights<T>>::burn_from(),335		)336	}337338	fn set_collection_properties(339		&self,340		sender: T::CrossAccountId,341		properties: Vec<Property>,342	) -> DispatchResultWithPostInfo {343		let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);344345		with_weight(346			<Pallet<T>>::set_collection_properties(self, &sender, properties),347			weight,348		)349	}350351	fn delete_collection_properties(352		&self,353		sender: &T::CrossAccountId,354		property_keys: Vec<PropertyKey>,355	) -> DispatchResultWithPostInfo {356		let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);357358		with_weight(359			<Pallet<T>>::delete_collection_properties(self, sender, property_keys),360			weight,361		)362	}363364	fn set_token_properties(365		&self,366		sender: T::CrossAccountId,367		token_id: TokenId,368		properties: Vec<Property>,369		nesting_budget: &dyn Budget,370	) -> DispatchResultWithPostInfo {371		let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);372373		with_weight(374			<Pallet<T>>::set_token_properties(375				self,376				&sender,377				token_id,378				properties.into_iter(),379				false,380				nesting_budget,381			),382			weight,383		)384	}385386	fn set_token_property_permissions(387		&self,388		sender: &T::CrossAccountId,389		property_permissions: Vec<PropertyKeyPermission>,390	) -> DispatchResultWithPostInfo {391		let weight =392			<CommonWeights<T>>::set_token_property_permissions(property_permissions.len() as u32);393394		with_weight(395			<Pallet<T>>::set_token_property_permissions(self, sender, property_permissions),396			weight,397		)398	}399400	fn delete_token_properties(401		&self,402		sender: T::CrossAccountId,403		token_id: TokenId,404		property_keys: Vec<PropertyKey>,405		nesting_budget: &dyn Budget,406	) -> DispatchResultWithPostInfo {407		let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);408409		with_weight(410			<Pallet<T>>::delete_token_properties(411				self,412				&sender,413				token_id,414				property_keys.into_iter(),415				nesting_budget,416			),417			weight,418		)419	}420421	fn check_nesting(422		&self,423		_sender: <T>::CrossAccountId,424		_from: (CollectionId, TokenId),425		_under: TokenId,426		_nesting_budget: &dyn Budget,427	) -> sp_runtime::DispatchResult {428		fail!(<Error<T>>::RefungibleDisallowsNesting)429	}430431	fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}432433	fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}434435	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {436		<Owned<T>>::iter_prefix((self.id, account))437			.map(|(id, _)| id)438			.collect()439	}440441	fn collection_tokens(&self) -> Vec<TokenId> {442		<TotalSupply<T>>::iter_prefix((self.id,))443			.map(|(id, _)| id)444			.collect()445	}446447	fn token_exists(&self, token: TokenId) -> bool {448		<Pallet<T>>::token_exists(self, token)449	}450451	fn last_token_id(&self) -> TokenId {452		TokenId(<TokensMinted<T>>::get(self.id))453	}454455	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {456		<Pallet<T>>::token_owner(self.id, token)457	}458459	/// Returns 10 token in no particular order.460	fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {461		<Pallet<T>>::token_owners(self.id, token).unwrap_or_default()462	}463464	fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {465		<Pallet<T>>::token_properties((self.id, token_id))466			.get(key)467			.cloned()468	}469470	fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {471		let properties = <Pallet<T>>::token_properties((self.id, token_id));472473		keys.map(|keys| {474			keys.into_iter()475				.filter_map(|key| {476					properties.get(&key).map(|value| Property {477						key,478						value: value.clone(),479					})480				})481				.collect()482		})483		.unwrap_or_else(|| {484			properties485				.into_iter()486				.map(|(key, value)| Property { key, value })487				.collect()488		})489	}490491	fn total_supply(&self) -> u32 {492		<Pallet<T>>::total_supply(self)493	}494495	fn account_balance(&self, account: T::CrossAccountId) -> u32 {496		<AccountBalance<T>>::get((self.id, account))497	}498499	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {500		<Balance<T>>::get((self.id, token, account))501	}502503	fn allowance(504		&self,505		sender: T::CrossAccountId,506		spender: T::CrossAccountId,507		token: TokenId,508	) -> u128 {509		<Allowance<T>>::get((self.id, token, sender, spender))510	}511512	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {513		Some(self)514	}515516	fn total_pieces(&self, token: TokenId) -> Option<u128> {517		<Pallet<T>>::total_pieces(self.id, token)518	}519}520521impl<T: Config> RefungibleExtensions<T> for RefungibleHandle<T> {522	fn repartition(523		&self,524		owner: &T::CrossAccountId,525		token: TokenId,526		amount: u128,527	) -> DispatchResultWithPostInfo {528		with_weight(529			<Pallet<T>>::repartition(self, owner, token, amount),530			<SelfWeightOf<T>>::repartition_item(),531		)532	}533}
after · pallets/refungible/src/common.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/>.1617use core::marker::PhantomData;1819use sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};21use up_data_structs::{22	CollectionId, TokenId, CreateItemExData, budget::Budget, Property, PropertyKey, PropertyValue,23	PropertyKeyPermission, CollectionPropertiesVec, CreateRefungibleExMultipleOwners,24	CreateRefungibleExSingleOwner,25};26use pallet_common::{27	CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,28	weights::WeightInfo as _,29};30use pallet_structure::Error as StructureError;31use sp_runtime::{DispatchError};32use sp_std::{vec::Vec, vec};3334use crate::{35	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,36	SelfWeightOf, weights::WeightInfo, TokensMinted, TotalSupply, CreateItemData,37};3839macro_rules! max_weight_of {40	($($method:ident ($($args:tt)*)),*) => {41		042		$(43			.max(<SelfWeightOf<T>>::$method($($args)*))44		)*45	};46}4748fn properties_weight<T: Config>(properties: &CollectionPropertiesVec) -> u64 {49	if properties.len() > 0 {50		<CommonWeights<T>>::set_token_properties(properties.len() as u32)51	} else {52		053	}54}5556pub struct CommonWeights<T: Config>(PhantomData<T>);57impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {58	fn create_item() -> Weight {59		<SelfWeightOf<T>>::create_item()60	}6162	fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {63		<SelfWeightOf<T>>::create_multiple_items(data.len() as u32).saturating_add(64			data.iter()65				.map(|data| match data {66					up_data_structs::CreateItemData::ReFungible(rft_data) => {67						properties_weight::<T>(&rft_data.properties)68					}69					_ => 0,70				})71				.fold(0, |a, b| a.saturating_add(b)),72		)73	}7475	fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {76		match call {77			CreateItemExData::RefungibleMultipleOwners(i) => {78				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)79					.saturating_add(properties_weight::<T>(&i.properties))80			}81			CreateItemExData::RefungibleMultipleItems(i) => {82				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)83					.saturating_add(84						i.iter()85							.map(|d| properties_weight::<T>(&d.properties))86							.fold(0, |a, b| a.saturating_add(b)),87					)88			}89			_ => 0,90		}91	}9293	fn burn_item() -> Weight {94		max_weight_of!(burn_item_partial(), burn_item_fully())95	}9697	fn set_collection_properties(amount: u32) -> Weight {98		<pallet_common::SelfWeightOf<T>>::set_collection_properties(amount)99	}100101	fn delete_collection_properties(amount: u32) -> Weight {102		<pallet_common::SelfWeightOf<T>>::delete_collection_properties(amount)103	}104105	fn set_token_properties(amount: u32) -> Weight {106		<SelfWeightOf<T>>::set_token_properties(amount)107	}108109	fn delete_token_properties(amount: u32) -> Weight {110		<SelfWeightOf<T>>::delete_token_properties(amount)111	}112113	fn set_token_property_permissions(amount: u32) -> Weight {114		<SelfWeightOf<T>>::set_token_property_permissions(amount)115	}116117	fn transfer() -> Weight {118		max_weight_of!(119			transfer_normal(),120			transfer_creating(),121			transfer_removing(),122			transfer_creating_removing()123		)124	}125126	fn approve() -> Weight {127		<SelfWeightOf<T>>::approve()128	}129130	fn transfer_from() -> Weight {131		max_weight_of!(132			transfer_from_normal(),133			transfer_from_creating(),134			transfer_from_removing(),135			transfer_from_creating_removing()136		)137	}138139	fn burn_from() -> Weight {140		<SelfWeightOf<T>>::burn_from()141	}142143	fn burn_recursively_self_raw() -> Weight {144		// Read to get total balance145		Self::burn_item() + T::DbWeight::get().reads(1)146	}147	fn burn_recursively_breadth_raw(_amount: u32) -> Weight {148		// Refungible token can't have children149		0150	}151152	fn token_owner() -> Weight {153		<SelfWeightOf<T>>::token_owner()154	}155}156157fn map_create_data<T: Config>(158	data: up_data_structs::CreateItemData,159	to: &T::CrossAccountId,160) -> Result<CreateItemData<T::CrossAccountId>, DispatchError> {161	match data {162		up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateItemData {163			users: {164				let mut out = BTreeMap::new();165				out.insert(to.clone(), data.pieces);166				out.try_into().expect("limit > 0")167			},168			properties: data.properties,169		}),170		_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),171	}172}173174/// Implementation of `CommonCollectionOperations` for `RefungibleHandle`. It wraps Refungible Pallete175/// methods and adds weight info.176impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {177	fn create_item(178		&self,179		sender: T::CrossAccountId,180		to: T::CrossAccountId,181		data: up_data_structs::CreateItemData,182		nesting_budget: &dyn Budget,183	) -> DispatchResultWithPostInfo {184		with_weight(185			<Pallet<T>>::create_item(186				self,187				&sender,188				map_create_data::<T>(data, &to)?,189				nesting_budget,190			),191			<CommonWeights<T>>::create_item(),192		)193	}194195	fn create_multiple_items(196		&self,197		sender: T::CrossAccountId,198		to: T::CrossAccountId,199		data: Vec<up_data_structs::CreateItemData>,200		nesting_budget: &dyn Budget,201	) -> DispatchResultWithPostInfo {202		let weight = <CommonWeights<T>>::create_multiple_items(&data);203		let data = data204			.into_iter()205			.map(|d| map_create_data::<T>(d, &to))206			.collect::<Result<Vec<_>, DispatchError>>()?;207208		with_weight(209			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),210			weight,211		)212	}213214	fn create_multiple_items_ex(215		&self,216		sender: <T>::CrossAccountId,217		data: CreateItemExData<T::CrossAccountId>,218		nesting_budget: &dyn Budget,219	) -> DispatchResultWithPostInfo {220		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);221		let data = match data {222			CreateItemExData::RefungibleMultipleOwners(CreateRefungibleExMultipleOwners {223				users,224				properties,225			}) => vec![CreateItemData { users, properties }],226			CreateItemExData::RefungibleMultipleItems(r) => r227				.into_inner()228				.into_iter()229				.map(230					|CreateRefungibleExSingleOwner {231					     user,232					     pieces,233					     properties,234					 }| CreateItemData {235						users: BTreeMap::from([(user, pieces)])236							.try_into()237							.expect("limit >= 1"),238						properties,239					},240				)241				.collect(),242			_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),243		};244245		with_weight(246			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),247			weight,248		)249	}250251	fn burn_item(252		&self,253		sender: T::CrossAccountId,254		token: TokenId,255		amount: u128,256	) -> DispatchResultWithPostInfo {257		with_weight(258			<Pallet<T>>::burn(self, &sender, token, amount),259			<CommonWeights<T>>::burn_item(),260		)261	}262263	fn burn_item_recursively(264		&self,265		sender: T::CrossAccountId,266		token: TokenId,267		self_budget: &dyn Budget,268		_breadth_budget: &dyn Budget,269	) -> DispatchResultWithPostInfo {270		ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);271		with_weight(272			<Pallet<T>>::burn(273				self,274				&sender,275				token,276				<Balance<T>>::get((self.id, token, &sender)),277			),278			<CommonWeights<T>>::burn_recursively_self_raw(),279		)280	}281282	fn transfer(283		&self,284		from: T::CrossAccountId,285		to: T::CrossAccountId,286		token: TokenId,287		amount: u128,288		nesting_budget: &dyn Budget,289	) -> DispatchResultWithPostInfo {290		with_weight(291			<Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),292			<CommonWeights<T>>::transfer(),293		)294	}295296	fn approve(297		&self,298		sender: T::CrossAccountId,299		spender: T::CrossAccountId,300		token: TokenId,301		amount: u128,302	) -> DispatchResultWithPostInfo {303		with_weight(304			<Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),305			<CommonWeights<T>>::approve(),306		)307	}308309	fn transfer_from(310		&self,311		sender: T::CrossAccountId,312		from: T::CrossAccountId,313		to: T::CrossAccountId,314		token: TokenId,315		amount: u128,316		nesting_budget: &dyn Budget,317	) -> DispatchResultWithPostInfo {318		with_weight(319			<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),320			<CommonWeights<T>>::transfer_from(),321		)322	}323324	fn burn_from(325		&self,326		sender: T::CrossAccountId,327		from: T::CrossAccountId,328		token: TokenId,329		amount: u128,330		nesting_budget: &dyn Budget,331	) -> DispatchResultWithPostInfo {332		with_weight(333			<Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),334			<CommonWeights<T>>::burn_from(),335		)336	}337338	fn set_collection_properties(339		&self,340		sender: T::CrossAccountId,341		properties: Vec<Property>,342	) -> DispatchResultWithPostInfo {343		let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);344345		with_weight(346			<Pallet<T>>::set_collection_properties(self, &sender, properties),347			weight,348		)349	}350351	fn delete_collection_properties(352		&self,353		sender: &T::CrossAccountId,354		property_keys: Vec<PropertyKey>,355	) -> DispatchResultWithPostInfo {356		let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);357358		with_weight(359			<Pallet<T>>::delete_collection_properties(self, sender, property_keys),360			weight,361		)362	}363364	fn set_token_properties(365		&self,366		sender: T::CrossAccountId,367		token_id: TokenId,368		properties: Vec<Property>,369		nesting_budget: &dyn Budget,370	) -> DispatchResultWithPostInfo {371		let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);372373		with_weight(374			<Pallet<T>>::set_token_properties(375				self,376				&sender,377				token_id,378				properties.into_iter(),379				false,380				nesting_budget,381			),382			weight,383		)384	}385386	fn set_token_property_permissions(387		&self,388		sender: &T::CrossAccountId,389		property_permissions: Vec<PropertyKeyPermission>,390	) -> DispatchResultWithPostInfo {391		let weight =392			<CommonWeights<T>>::set_token_property_permissions(property_permissions.len() as u32);393394		with_weight(395			<Pallet<T>>::set_token_property_permissions(self, sender, property_permissions),396			weight,397		)398	}399400	fn delete_token_properties(401		&self,402		sender: T::CrossAccountId,403		token_id: TokenId,404		property_keys: Vec<PropertyKey>,405		nesting_budget: &dyn Budget,406	) -> DispatchResultWithPostInfo {407		let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);408409		with_weight(410			<Pallet<T>>::delete_token_properties(411				self,412				&sender,413				token_id,414				property_keys.into_iter(),415				nesting_budget,416			),417			weight,418		)419	}420421	fn check_nesting(422		&self,423		_sender: <T>::CrossAccountId,424		_from: (CollectionId, TokenId),425		_under: TokenId,426		_nesting_budget: &dyn Budget,427	) -> sp_runtime::DispatchResult {428		fail!(<Error<T>>::RefungibleDisallowsNesting)429	}430431	fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}432433	fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}434435	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {436		<Owned<T>>::iter_prefix((self.id, account))437			.map(|(id, _)| id)438			.collect()439	}440441	fn collection_tokens(&self) -> Vec<TokenId> {442		<TotalSupply<T>>::iter_prefix((self.id,))443			.map(|(id, _)| id)444			.collect()445	}446447	fn token_exists(&self, token: TokenId) -> bool {448		<Pallet<T>>::token_exists(self, token)449	}450451	fn last_token_id(&self) -> TokenId {452		TokenId(<TokensMinted<T>>::get(self.id))453	}454455	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {456		<Pallet<T>>::token_owner(self.id, token)457	}458459	/// Returns 10 token in no particular order.460	fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {461		<Pallet<T>>::token_owners(self.id, token).unwrap_or_default()462	}463464	fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {465		<Pallet<T>>::token_properties((self.id, token_id))466			.get(key)467			.cloned()468	}469470	fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {471		let properties = <Pallet<T>>::token_properties((self.id, token_id));472473		keys.map(|keys| {474			keys.into_iter()475				.filter_map(|key| {476					properties.get(&key).map(|value| Property {477						key,478						value: value.clone(),479					})480				})481				.collect()482		})483		.unwrap_or_else(|| {484			properties485				.into_iter()486				.map(|(key, value)| Property { key, value })487				.collect()488		})489	}490491	fn total_supply(&self) -> u32 {492		<Pallet<T>>::total_supply(self)493	}494495	fn account_balance(&self, account: T::CrossAccountId) -> u32 {496		<AccountBalance<T>>::get((self.id, account))497	}498499	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {500		<Balance<T>>::get((self.id, token, account))501	}502503	fn allowance(504		&self,505		sender: T::CrossAccountId,506		spender: T::CrossAccountId,507		token: TokenId,508	) -> u128 {509		<Allowance<T>>::get((self.id, token, sender, spender))510	}511512	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {513		Some(self)514	}515516	fn total_pieces(&self, token: TokenId) -> Option<u128> {517		<Pallet<T>>::total_pieces(self.id, token)518	}519}520521impl<T: Config> RefungibleExtensions<T> for RefungibleHandle<T> {522	fn repartition(523		&self,524		owner: &T::CrossAccountId,525		token: TokenId,526		amount: u128,527	) -> DispatchResultWithPostInfo {528		with_weight(529			<Pallet<T>>::repartition(self, owner, token, amount),530			<SelfWeightOf<T>>::repartition_item(),531		)532	}533}