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

difftreelog

Merge branch 'develop' into feature/CORE-302-ss58Format

Igor Kozyrev2022-06-08parents: #0362d33 #c557492.patch.diff
in: master

17 files changed

modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -20,8 +20,8 @@
 use frame_benchmarking::{benchmarks, account};
 use up_data_structs::{
 	CollectionMode, CreateCollectionData, CollectionId, Property, PropertyKey, PropertyValue,
-	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
-	OFFCHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, MAX_PROPERTIES_PER_ITEM,
+	CollectionPermissions, NestingRule, MAX_COLLECTION_NAME_LENGTH,
+	MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, MAX_PROPERTIES_PER_ITEM,
 };
 use frame_support::{
 	traits::{Currency, Get},
@@ -74,15 +74,15 @@
 }
 
 pub fn create_collection_raw<T: Config, R>(
-	owner: T::AccountId,
+	owner: T::CrossAccountId,
 	mode: CollectionMode,
 	handler: impl FnOnce(
-		T::AccountId,
+		T::CrossAccountId,
 		CreateCollectionData<T::AccountId>,
 	) -> Result<CollectionId, DispatchError>,
 	cast: impl FnOnce(CollectionHandle<T>) -> R,
 ) -> Result<R, DispatchError> {
-	T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
+	<T as Config>::Currency::deposit_creating(&owner.as_sub(), T::CollectionCreationPrice::get());
 	let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
 	let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
 	let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
@@ -93,13 +93,19 @@
 			name,
 			description,
 			token_prefix,
+			permissions: Some(CollectionPermissions {
+				nesting: Some(NestingRule::Permissive),
+				..Default::default()
+			}),
 			..Default::default()
 		},
 	)
 	.and_then(CollectionHandle::try_get)
 	.map(cast)
 }
-fn create_collection<T: Config>(owner: T::AccountId) -> Result<CollectionHandle<T>, DispatchError> {
+fn create_collection<T: Config>(
+	owner: T::CrossAccountId,
+) -> Result<CollectionHandle<T>, DispatchError> {
 	create_collection_raw(
 		owner,
 		CollectionMode::NFT,
@@ -127,7 +133,7 @@
 		bench_init!($($rest)*);
 	};
 	($name:ident: collection($owner:ident); $($rest:tt)*) => {
-		let $name = create_collection::<T>($owner.clone())?;
+		let $name = create_collection::<T>(T::CrossAccountId::from_sub($owner.clone()))?;
 		bench_init!($($rest)*);
 	};
 	($name:ident: cross; $($rest:tt)*) => {
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1168,8 +1168,9 @@
 		);
 		Ok(new_limit)
 	}
+
 	pub fn clamp_permissions(
-		mode: CollectionMode,
+		_mode: CollectionMode,
 		old_limit: &CollectionPermissions,
 		mut new_limit: CollectionPermissions,
 	) -> Result<CollectionPermissions, DispatchError> {
@@ -1204,6 +1205,22 @@
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
 	fn burn_from() -> Weight;
+
+	/// Differs from burn_item in case of Fungible and Refungible, as it should burn
+	/// whole users's balance
+	///
+	/// This method shouldn't be used directly, as it doesn't count breadth price, use `burn_recursively` instead
+	fn burn_recursively_self_raw() -> Weight;
+	/// Cost of iterating over `amount` children while burning, without counting child burning itself
+	///
+	/// This method shouldn't be used directly, as it doesn't count depth price, use `burn_recursively` instead
+	fn burn_recursively_breadth_raw(amount: u32) -> Weight;
+
+	fn burn_recursively(max_selfs: u32, max_breadth: u32) -> Weight {
+		Self::burn_recursively_self_raw()
+			.saturating_mul(max_selfs.max(1) as u64)
+			.saturating_add(Self::burn_recursively_breadth_raw(max_breadth))
+	}
 }
 
 pub trait CommonCollectionOperations<T: Config> {
@@ -1233,6 +1250,13 @@
 		token: TokenId,
 		amount: u128,
 	) -> DispatchResultWithPostInfo;
+	fn burn_item_recursively(
+		&self,
+		sender: T::CrossAccountId,
+		token: TokenId,
+		self_budget: &dyn Budget,
+		breadth_budget: &dyn Budget,
+	) -> DispatchResultWithPostInfo;
 	fn set_collection_properties(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -25,7 +25,9 @@
 
 const SEED: u32 = 1;
 
-fn create_collection<T: Config>(owner: T::AccountId) -> Result<FungibleHandle<T>, DispatchError> {
+fn create_collection<T: Config>(
+	owner: T::CrossAccountId,
+) -> Result<FungibleHandle<T>, DispatchError> {
 	create_collection_raw(
 		owner,
 		CollectionMode::Fungible(0),
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -16,9 +16,10 @@
 
 use core::marker::PhantomData;
 
-use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};
+use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
 use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData};
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
+use pallet_structure::Error as StructureError;
 use sp_runtime::ArithmeticError;
 use sp_std::{vec::Vec, vec};
 use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};
@@ -91,6 +92,16 @@
 	fn burn_from() -> Weight {
 		<SelfWeightOf<T>>::burn_from()
 	}
+
+	fn burn_recursively_self_raw() -> Weight {
+		// Read to get total balance
+		Self::burn_item() + T::DbWeight::get().reads(1)
+	}
+
+	fn burn_recursively_breadth_raw(_amount: u32) -> Weight {
+		// Fungible tokens can't have children
+		0
+	}
 }
 
 impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
@@ -170,6 +181,26 @@
 		)
 	}
 
+	fn burn_item_recursively(
+		&self,
+		sender: T::CrossAccountId,
+		token: TokenId,
+		self_budget: &dyn Budget,
+		_breadth_budget: &dyn Budget,
+	) -> DispatchResultWithPostInfo {
+		// Should not happen?
+		ensure!(
+			token == TokenId::default(),
+			<Error<T>>::FungibleItemsHaveNoId
+		);
+		ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);
+
+		with_weight(
+			<Pallet<T>>::burn(self, &sender, <Balance<T>>::get((self.id, &sender))),
+			<CommonWeights<T>>::burn_recursively_self_raw(),
+		)
+	}
+
 	fn transfer(
 		&self,
 		from: T::CrossAccountId,
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -18,12 +18,9 @@
 use crate::{Pallet, Config, NonfungibleHandle};
 
 use sp_std::prelude::*;
-use pallet_common::benchmarking::{create_collection_raw, create_data, property_key, property_value};
+use pallet_common::benchmarking::{create_collection_raw, property_key, property_value};
 use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{
-	CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, CUSTOM_DATA_LIMIT,
-	budget::Unlimited,
-};
+use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, budget::Unlimited};
 use pallet_common::bench_init;
 
 const SEED: u32 = 1;
@@ -49,7 +46,7 @@
 }
 
 fn create_collection<T: Config>(
-	owner: T::AccountId,
+	owner: T::CrossAccountId,
 ) -> Result<NonfungibleHandle<T>, DispatchError> {
 	create_collection_raw(
 		owner,
@@ -96,6 +93,26 @@
 		let item = create_max_item(&collection, &sender, burner.clone())?;
 	}: {<Pallet<T>>::burn(&collection, &burner, item)?}
 
+	burn_recursively_self_raw {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			sender: cross_from_sub(owner); burner: cross_sub;
+		};
+		let item = create_max_item(&collection, &sender, burner.clone())?;
+	}: {<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)}
+
+	burn_recursively_breadth_plus_self_plus_self_per_each_raw {
+		let b in 0..200;
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			sender: cross_from_sub(owner); burner: cross_sub;
+		};
+		let item = create_max_item(&collection, &sender, burner.clone())?;
+		for i in 0..b {
+			create_max_item(&collection, &sender, T::CrossTokenAddressMapping::token_to_address(collection.id, item))?;
+		}
+	}: {<Pallet<T>>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)}
+
 	transfer {
 		bench_init!{
 			owner: sub; collection: collection(owner);
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -108,6 +108,15 @@
 	fn burn_from() -> Weight {
 		<SelfWeightOf<T>>::burn_from()
 	}
+
+	fn burn_recursively_self_raw() -> Weight {
+		<SelfWeightOf<T>>::burn_recursively_self_raw()
+	}
+
+	fn burn_recursively_breadth_raw(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::burn_recursively_breadth_plus_self_plus_self_per_each_raw(amount)
+			.saturating_sub(Self::burn_recursively_self_raw().saturating_mul(amount as u64 + 1))
+	}
 }
 
 fn map_create_data<T: Config>(
@@ -264,6 +273,16 @@
 		}
 	}
 
+	fn burn_item_recursively(
+		&self,
+		sender: T::CrossAccountId,
+		token: TokenId,
+		self_budget: &dyn Budget,
+		breadth_budget: &dyn Budget,
+	) -> DispatchResultWithPostInfo {
+		<Pallet<T>>::burn_recursively(self, &sender, token, self_budget, breadth_budget)
+	}
+
 	fn transfer(
 		&self,
 		from: T::CrossAccountId,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -18,7 +18,13 @@
 
 use erc::ERC721Events;
 use evm_coder::ToLog;
-use frame_support::{BoundedVec, ensure, fail, transactional, storage::with_transaction};
+use frame_support::{
+	BoundedVec, ensure, fail, transactional,
+	storage::with_transaction,
+	pallet_prelude::DispatchResultWithPostInfo,
+	pallet_prelude::Weight,
+	weights::{PostDispatchInfo, Pays},
+};
 use up_data_structs::{
 	AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
 	mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
@@ -29,7 +35,7 @@
 	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
 	eth::collection_id_to_address,
 };
-use pallet_structure::Pallet as PalletStructure;
+use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
 use sp_core::H160;
 use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
@@ -39,6 +45,7 @@
 use scale_info::TypeInfo;
 
 pub use pallet::*;
+use weights::WeightInfo;
 #[cfg(feature = "runtime-benchmarks")]
 pub mod benchmarking;
 pub mod common;
@@ -373,7 +380,7 @@
 			<PalletCommon<T>>::deposit_event(CommonEvent::Approved(
 				collection.id,
 				token,
-				sender.clone(),
+				token_data.owner.clone(),
 				old_spender,
 				0,
 			));
@@ -396,6 +403,45 @@
 		Ok(())
 	}
 
+	#[transactional]
+	pub fn burn_recursively(
+		collection: &NonfungibleHandle<T>,
+		sender: &T::CrossAccountId,
+		token: TokenId,
+		self_budget: &dyn Budget,
+		breadth_budget: &dyn Budget,
+	) -> DispatchResultWithPostInfo {
+		ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);
+
+		let current_token_account =
+			T::CrossTokenAddressMapping::token_to_address(collection.id, token);
+
+		let mut weight = 0 as Weight;
+
+		// This method is transactional, if user in fact doesn't have permissions to remove token -
+		// tokens removed here will be restored after rejected transaction
+		for ((collection, token), _) in <TokenChildren<T>>::iter_prefix((collection.id, token)) {
+			ensure!(breadth_budget.consume(), <StructureError<T>>::BreadthLimit,);
+			let PostDispatchInfo { actual_weight, .. } =
+				<PalletStructure<T>>::burn_item_recursively(
+					current_token_account.clone(),
+					collection,
+					token,
+					self_budget,
+					breadth_budget,
+				)?;
+			if let Some(actual_weight) = actual_weight {
+				weight = weight.saturating_add(actual_weight);
+			}
+		}
+
+		Self::burn(collection, sender, token)?;
+		DispatchResultWithPostInfo::Ok(PostDispatchInfo {
+			actual_weight: Some(weight + <SelfWeightOf<T>>::burn_item()),
+			pays_fee: Pays::Yes,
+		})
+	}
+
 	pub fn set_token_property(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -964,6 +1010,7 @@
 				);
 				ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?
 			}
+			NestingRule::Permissive => {}
 		}
 		Ok(())
 	}
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -36,6 +36,8 @@
 	fn create_multiple_items(b: u32, ) -> Weight;
 	fn create_multiple_items_ex(b: u32, ) -> Weight;
 	fn burn_item() -> Weight;
+	fn burn_recursively_self_raw() -> Weight;
+	fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -92,7 +94,35 @@
 			.saturating_add(T::DbWeight::get().reads(4 as Weight))
 			.saturating_add(T::DbWeight::get().writes(4 as Weight))
 	}
-
+	// Storage: Nonfungible TokenChildren (r:1 w:0)
+	// Storage: Nonfungible TokenData (r:1 w:1)
+	// Storage: Nonfungible TokensBurnt (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible Allowance (r:1 w:0)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	// Storage: Nonfungible TokenProperties (r:0 w:1)
+	fn burn_recursively_self_raw() -> Weight {
+		(86_136_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(5 as Weight))
+			.saturating_add(T::DbWeight::get().writes(5 as Weight))
+	}
+	// Storage: Nonfungible TokenChildren (r:1 w:0)
+	// Storage: Nonfungible TokenData (r:1 w:1)
+	// Storage: Nonfungible TokensBurnt (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible Allowance (r:1 w:0)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	// Storage: Nonfungible TokenProperties (r:0 w:1)
+	// Storage: Common CollectionById (r:1 w:0)
+	fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {
+		(0 as Weight)
+			// Standard Error: 42_828_000
+			.saturating_add((381_478_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(T::DbWeight::get().reads(6 as Weight))
+			.saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(b as Weight)))
+			.saturating_add(T::DbWeight::get().writes(5 as Weight))
+			.saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
+	}
 	// Storage: Nonfungible TokenData (r:1 w:1)
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Allowance (r:1 w:0)
@@ -204,7 +234,35 @@
 			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
 	}
-
+	// Storage: Nonfungible TokenChildren (r:1 w:0)
+	// Storage: Nonfungible TokenData (r:1 w:1)
+	// Storage: Nonfungible TokensBurnt (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible Allowance (r:1 w:0)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	// Storage: Nonfungible TokenProperties (r:0 w:1)
+	fn burn_recursively_self_raw() -> Weight {
+		(86_136_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(5 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
+	}
+	// Storage: Nonfungible TokenChildren (r:1 w:0)
+	// Storage: Nonfungible TokenData (r:1 w:1)
+	// Storage: Nonfungible TokensBurnt (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible Allowance (r:1 w:0)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	// Storage: Nonfungible TokenProperties (r:0 w:1)
+	// Storage: Common CollectionById (r:1 w:0)
+	fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {
+		(0 as Weight)
+			// Standard Error: 42_828_000
+			.saturating_add((381_478_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(RocksDbWeight::get().reads(6 as Weight))
+			.saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(b as Weight)))
+			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
+			.saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
+	}
 	// Storage: Nonfungible TokenData (r:1 w:1)
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Allowance (r:1 w:0)
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -50,7 +50,9 @@
 	Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
 }
 
-fn create_collection<T: Config>(owner: T::AccountId) -> Result<RefungibleHandle<T>, DispatchError> {
+fn create_collection<T: Config>(
+	owner: T::CrossAccountId,
+) -> Result<RefungibleHandle<T>, DispatchError> {
 	create_collection_raw(
 		owner,
 		CollectionMode::NFT,
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -17,12 +17,13 @@
 use core::marker::PhantomData;
 
 use sp_std::collections::btree_map::BTreeMap;
-use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight};
+use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
 use up_data_structs::{
 	CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property,
 	PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData,
 };
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
+use pallet_structure::Error as StructureError;
 use sp_runtime::DispatchError;
 use sp_std::{vec::Vec, vec};
 
@@ -113,6 +114,15 @@
 	fn burn_from() -> Weight {
 		<SelfWeightOf<T>>::burn_from()
 	}
+
+	fn burn_recursively_self_raw() -> Weight {
+		// Read to get total balance
+		Self::burn_item() + T::DbWeight::get().reads(1)
+	}
+	fn burn_recursively_breadth_raw(_amount: u32) -> Weight {
+		// Refungible token can't have children
+		0
+	}
 }
 
 fn map_create_data<T: Config>(
@@ -205,6 +215,25 @@
 		)
 	}
 
+	fn burn_item_recursively(
+		&self,
+		sender: T::CrossAccountId,
+		token: TokenId,
+		self_budget: &dyn Budget,
+		_breadth_budget: &dyn Budget,
+	) -> DispatchResultWithPostInfo {
+		ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);
+		with_weight(
+			<Pallet<T>>::burn(
+				self,
+				&sender,
+				token,
+				<Balance<T>>::get((self.id, token, &sender)),
+			),
+			<CommonWeights<T>>::burn_recursively_self_raw(),
+		)
+	}
+
 	fn transfer(
 		&self,
 		from: T::CrossAccountId,
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -60,8 +60,9 @@
 // Ensure we're `no_std` when compiling for Wasm.
 #![cfg_attr(not(feature = "std"), no_std)]
 
-#[cfg(feature = "runtime-benchmarks")]
-mod benchmarking;
+// FIXME
+// #[cfg(feature = "runtime-benchmarks")]
+// mod benchmarking;
 
 pub mod weights;
 
modifiedpallets/structure/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/structure/src/benchmarking.rs
+++ b/pallets/structure/src/benchmarking.rs
@@ -5,6 +5,7 @@
 use up_data_structs::{
 	CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,
 };
+use pallet_common::Config as CommonConfig;
 use pallet_evm::account::CrossAccountId;
 
 const SEED: u32 = 1;
@@ -14,8 +15,8 @@
 		let caller: T::AccountId = account("caller", 0, SEED);
 		let caller_cross = T::CrossAccountId::from_sub(caller.clone());
 
-		T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
-		T::CollectionDispatch::create(caller, CreateCollectionData {
+		<T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
+		T::CollectionDispatch::create(caller_cross.clone(), CreateCollectionData {
 			mode: CollectionMode::NFT,
 			..Default::default()
 		})?;
modifiedpallets/structure/src/lib.rsdiffbeforeafterboth
--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -3,7 +3,7 @@
 use pallet_common::CommonCollectionOperations;
 use sp_std::collections::btree_set::BTreeSet;
 
-use frame_support::dispatch::{DispatchError, DispatchResult};
+use frame_support::dispatch::{DispatchError, DispatchResult, DispatchResultWithPostInfo};
 use frame_support::fail;
 pub use pallet::*;
 use pallet_common::{dispatch::CollectionDispatch, CollectionHandle};
@@ -29,6 +29,8 @@
 		OuroborosDetected,
 		/// While searched for owner, encountered depth limit
 		DepthLimit,
+		/// While iterating over children, encountered breadth limit
+		BreadthLimit,
 		/// While searched for owner, found token owner by not-yet-existing token
 		TokenNotFound,
 	}
@@ -184,6 +186,19 @@
 		Err(<Error<T>>::DepthLimit.into())
 	}
 
+	pub fn burn_item_recursively(
+		from: T::CrossAccountId,
+		collection: CollectionId,
+		token: TokenId,
+		self_budget: &dyn Budget,
+		breadth_budget: &dyn Budget,
+	) -> DispatchResultWithPostInfo {
+		let handle = <CollectionHandle<T>>::try_get(collection)?;
+		let dispatch = T::CollectionDispatch::dispatch(handle);
+		let dispatch = dispatch.as_dyn();
+		dispatch.burn_item_recursively(from.clone(), token, self_budget, breadth_budget)
+	}
+
 	pub fn check_nesting(
 		from: T::CrossAccountId,
 		under: &T::CrossAccountId,
modifiedpallets/unique/src/benchmarking.rsdiffbeforeafterboth
before · pallets/unique/src/benchmarking.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(feature = "runtime-benchmarks")]1819use super::*;20use crate::Pallet;21use frame_system::RawOrigin;22use frame_support::traits::{tokens::currency::Currency, Get};23use frame_benchmarking::{benchmarks, account};24use sp_runtime::DispatchError;25use pallet_common::benchmarking::{create_data, create_var_data, create_u16_data};2627const SEED: u32 = 1;2829fn create_collection_helper<T: Config>(30	owner: T::AccountId,31	mode: CollectionMode,32) -> Result<CollectionId, DispatchError> {33	T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());34	let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();35	let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();36	let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();37	<Pallet<T>>::create_collection(38		RawOrigin::Signed(owner).into(),39		col_name,40		col_desc,41		token_prefix,42		mode,43	)?;44	Ok(<pallet_common::CreatedCollectionCount<T>>::get())45}46fn create_nft_collection<T: Config>(owner: T::AccountId) -> Result<CollectionId, DispatchError> {47	create_collection_helper::<T>(owner, CollectionMode::NFT)48}4950benchmarks! {51	create_collection {52		let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();53		let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();54		let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();55		let mode: CollectionMode = CollectionMode::NFT;56		let caller: T::AccountId = account("caller", 0, SEED);57		T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());58	}: _(RawOrigin::Signed(caller.clone()), col_name.clone(), col_desc.clone(), token_prefix.clone(), mode)59	verify {60		assert_eq!(<pallet_common::CollectionById<T>>::get(CollectionId(1)).unwrap().owner, caller);61	}6263	destroy_collection {64		let caller: T::AccountId = account("caller", 0, SEED);65		let collection = create_nft_collection::<T>(caller.clone())?;66	}: _(RawOrigin::Signed(caller.clone()), collection)6768	add_to_allow_list {69		let caller: T::AccountId = account("caller", 0, SEED);70		let allowlist_account: T::AccountId = account("admin", 0, SEED);71		let collection = create_nft_collection::<T>(caller.clone())?;72	}: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account))7374	remove_from_allow_list {75		let caller: T::AccountId = account("caller", 0, SEED);76		let allowlist_account: T::AccountId = account("admin", 0, SEED);77		let collection = create_nft_collection::<T>(caller.clone())?;78		<Pallet<T>>::add_to_allow_list(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(allowlist_account.clone()))?;79	}: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(allowlist_account))8081	set_public_access_mode {82		let caller: T::AccountId = account("caller", 0, SEED);83		let collection = create_nft_collection::<T>(caller.clone())?;84	}: _(RawOrigin::Signed(caller.clone()), collection, AccessMode::AllowList)8586	set_mint_permission {87		let caller: T::AccountId = account("caller", 0, SEED);88		let collection = create_nft_collection::<T>(caller.clone())?;89	}: _(RawOrigin::Signed(caller.clone()), collection, true)9091	change_collection_owner {92		let caller: T::AccountId = account("caller", 0, SEED);93		let collection = create_nft_collection::<T>(caller.clone())?;94		let new_owner: T::AccountId = account("admin", 0, SEED);95	}: _(RawOrigin::Signed(caller.clone()), collection, new_owner)9697	add_collection_admin {98		let caller: T::AccountId = account("caller", 0, SEED);99		let collection = create_nft_collection::<T>(caller.clone())?;100		let new_admin: T::AccountId = account("admin", 0, SEED);101	}: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(new_admin))102103	remove_collection_admin {104		let caller: T::AccountId = account("caller", 0, SEED);105		let collection = create_nft_collection::<T>(caller.clone())?;106		let new_admin: T::AccountId = account("admin", 0, SEED);107		<Pallet<T>>::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), collection, T::CrossAccountId::from_sub(new_admin.clone()))?;108	}: _(RawOrigin::Signed(caller.clone()), collection, T::CrossAccountId::from_sub(new_admin))109110	set_collection_sponsor {111		let caller: T::AccountId = account("caller", 0, SEED);112		let collection = create_nft_collection::<T>(caller.clone())?;113	}: _(RawOrigin::Signed(caller.clone()), collection, caller.clone())114115	confirm_sponsorship {116		let caller: T::AccountId = account("caller", 0, SEED);117		let collection = create_nft_collection::<T>(caller.clone())?;118		<Pallet<T>>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), collection, caller.clone())?;119	}: _(RawOrigin::Signed(caller.clone()), collection)120121	remove_collection_sponsor {122		let caller: T::AccountId = account("caller", 0, SEED);123		let collection = create_nft_collection::<T>(caller.clone())?;124		<Pallet<T>>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), collection, caller.clone())?;125		<Pallet<T>>::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), collection)?;126	}: _(RawOrigin::Signed(caller.clone()), collection)127128	set_transfers_enabled_flag {129		let caller: T::AccountId = account("caller", 0, SEED);130		let collection = create_nft_collection::<T>(caller.clone())?;131	}: _(RawOrigin::Signed(caller.clone()), collection, false)132133134	set_collection_limits{135		let caller: T::AccountId = account("caller", 0, SEED);136		let collection = create_nft_collection::<T>(caller.clone())?;137138		let cl = CollectionLimits {139			account_token_ownership_limit: Some(0),140			sponsored_data_size: Some(0),141			token_limit: Some(1),142			sponsor_transfer_timeout: Some(0),143			sponsor_approve_timeout: None,144			owner_can_destroy: Some(true),145			owner_can_transfer: Some(true),146			sponsored_data_rate_limit: None,147			transfers_enabled: Some(true),148			nesting_rule: None,149		};150	}: set_collection_limits(RawOrigin::Signed(caller.clone()), collection, cl)151}
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -469,6 +469,8 @@
 		#[derivative(Debug(format_with = "bounded::set_debug"))]
 		BoundedBTreeSet<CollectionId, ConstU32<16>>,
 	),
+	/// Used for tests
+	Permissive,
 }
 
 #[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -89,4 +89,12 @@
 	fn burn_from() -> Weight {
 		dispatch_weight::<T>() + max_weight_of!(burn_from())
 	}
+
+	fn burn_recursively_self_raw() -> Weight {
+		max_weight_of!(burn_recursively_self_raw())
+	}
+
+	fn burn_recursively_breadth_raw(amount: u32) -> Weight {
+		max_weight_of!(burn_recursively_breadth_raw(amount))
+	}
 }
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -73,6 +73,7 @@
 	CollectionId, TokenId, TokenData, Property, PropertyKeyPermission, CollectionLimits,
 	CollectionStats, RpcCollection,
 	mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
+	TokenChild,
 };
 
 // use pallet_contracts::weights::WeightInfo;