git.delta.rocks / unique-network / refs/commits / 73817f448a72

difftreelog

test upgrade benchmarks for new substrate

Yaroslav Bolyukin2022-02-26parent: #c9e84df.patch.diff
in: master

12 files changed

modified.maintain/frame-weight-template.hbsdiffbeforeafterboth
--- a/.maintain/frame-weight-template.hbs
+++ b/.maintain/frame-weight-template.hbs
@@ -7,7 +7,7 @@
 //! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}
 
 // Executed Command:
-{{#each args as |arg|~}}
+{{#each args as |arg|}}
 // {{arg}}
 {{/each}}
 
@@ -21,76 +21,80 @@
 
 /// Weight functions needed for {{pallet}}.
 pub trait WeightInfo {
-	{{~#each benchmarks as |benchmark|}}
+	{{#each benchmarks as |benchmark|}}
 	fn {{benchmark.name~}}
 	(
 		{{~#each benchmark.components as |c| ~}}
 		{{c.name}}: u32, {{/each~}}
 	) -> Weight;
-	{{~/each}}
+	{{/each}}
 }
 
 /// Weights for {{pallet}} using the Substrate node and recommended hardware.
 pub struct SubstrateWeight<T>(PhantomData<T>);
+{{#if (eq pallet "frame_system")}}
+impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
+{{else}}
 impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
-	{{~#each benchmarks as |benchmark|}}
-	{{~#each benchmark.comments as |comment|}}
+{{/if}}
+	{{#each benchmarks as |benchmark|}}
+	{{#each benchmark.comments as |comment|}}
 	// {{comment}}
-	{{~/each}}
+	{{/each}}
 	fn {{benchmark.name~}}
 	(
 		{{~#each benchmark.components as |c| ~}}
 		{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
 	) -> Weight {
 		({{underscore benchmark.base_weight}} as Weight)
-			{{~#each benchmark.component_weight as |cw|}}
+			{{#each benchmark.component_weight as |cw|}}
 			// Standard Error: {{underscore cw.error}}
 			.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
-			{{~/each}}
-			{{~#if (ne benchmark.base_reads "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_reads "0")}}
 			.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_reads as |cr|}}
+			{{/if}}
+			{{#each benchmark.component_reads as |cr|}}
 			.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
-			{{~/each}}
-			{{~#if (ne benchmark.base_writes "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_writes "0")}}
 			.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_writes as |cw|}}
+			{{/if}}
+			{{#each benchmark.component_writes as |cw|}}
 			.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
-			{{~/each}}
+			{{/each}}
 	}
-	{{~/each}}
+	{{/each}}
 }
 
 // For backwards compatibility and tests
 impl WeightInfo for () {
-	{{~#each benchmarks as |benchmark|}}
-	{{~#each benchmark.comments as |comment|}}
+	{{#each benchmarks as |benchmark|}}
+	{{#each benchmark.comments as |comment|}}
 	// {{comment}}
-	{{~/each}}
+	{{/each}}
 	fn {{benchmark.name~}}
 	(
 		{{~#each benchmark.components as |c| ~}}
 		{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
 	) -> Weight {
 		({{underscore benchmark.base_weight}} as Weight)
-			{{~#each benchmark.component_weight as |cw|}}
+			{{#each benchmark.component_weight as |cw|}}
 			// Standard Error: {{underscore cw.error}}
 			.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
-			{{~/each}}
-			{{~#if (ne benchmark.base_reads "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_reads "0")}}
 			.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_reads as |cr|}}
+			{{/if}}
+			{{#each benchmark.component_reads as |cr|}}
 			.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
-			{{~/each}}
-			{{~#if (ne benchmark.base_writes "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_writes "0")}}
 			.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_writes as |cw|}}
+			{{/if}}
+			{{#each benchmark.component_writes as |cw|}}
 			.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
-			{{~/each}}
+			{{/each}}
 	}
-	{{~/each}}
+	{{/each}}
 }
modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -1,64 +1,87 @@
 use sp_std::vec::Vec;
 use crate::{Config, CollectionHandle};
 use up_data_structs::{
-	CollectionMode, Collection, CollectionId, MAX_COLLECTION_NAME_LENGTH,
+	CollectionMode, CreateCollectionData, CollectionId, MAX_COLLECTION_NAME_LENGTH,
 	MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, OFFCHAIN_SCHEMA_LIMIT,
 	VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,
 };
-use frame_support::traits::{Currency, Get};
+use frame_support::{
+	traits::{Currency, Get},
+	pallet_prelude::ConstU32,
+	BoundedVec,
+};
 use core::convert::TryInto;
 use sp_runtime::DispatchError;
 
-pub fn create_data(size: usize) -> Vec<u8> {
-	(0..size).map(|v| (v & 0xff) as u8).collect()
+pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {
+	create_var_data::<S>(S)
 }
-pub fn create_u16_data(size: usize) -> Vec<u16> {
-	(0..size).map(|v| (v & 0xffff) as u16).collect()
+pub fn create_u16_data<const S: u32>() -> BoundedVec<u16, ConstU32<S>> {
+	(0..S)
+		.map(|v| (v & 0xffff) as u16)
+		.collect::<Vec<_>>()
+		.try_into()
+		.unwrap()
+}
+pub fn create_var_data<const S: u32>(size: u32) -> BoundedVec<u8, ConstU32<S>> {
+	assert!(
+		size <= S,
+		"size ({}) should be less within bound ({})",
+		size,
+		S
+	);
+	(0..size)
+		.map(|v| (v & 0xff) as u8)
+		.collect::<Vec<_>>()
+		.try_into()
+		.unwrap()
 }
 
 pub fn create_collection_raw<T: Config, R>(
 	owner: T::AccountId,
 	mode: CollectionMode,
-	handler: impl FnOnce(Collection<T::AccountId>) -> Result<CollectionId, DispatchError>,
+	handler: impl FnOnce(
+		T::AccountId,
+		CreateCollectionData<T::AccountId>,
+	) -> Result<CollectionId, DispatchError>,
 	cast: impl FnOnce(CollectionHandle<T>) -> R,
 ) -> Result<R, DispatchError> {
 	T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
-	let name = create_u16_data(MAX_COLLECTION_NAME_LENGTH)
-		.try_into()
-		.unwrap();
-	let description = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH)
-		.try_into()
-		.unwrap();
-	let token_prefix = create_data(MAX_TOKEN_PREFIX_LENGTH).try_into().unwrap();
-	let offchain_schema = create_data(OFFCHAIN_SCHEMA_LIMIT as usize)
-		.try_into()
-		.unwrap();
-	let variable_on_chain_schema = create_data(VARIABLE_ON_CHAIN_SCHEMA_LIMIT as usize)
-		.try_into()
-		.unwrap();
-	let const_on_chain_schema = create_data(CONST_ON_CHAIN_SCHEMA_LIMIT as usize)
-		.try_into()
-		.unwrap();
-	handler(Collection {
+	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>();
+	let offchain_schema = create_data::<OFFCHAIN_SCHEMA_LIMIT>();
+	let variable_on_chain_schema = create_data::<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>();
+	let const_on_chain_schema = create_data::<CONST_ON_CHAIN_SCHEMA_LIMIT>();
+	handler(
 		owner,
-		mode,
-		access: Default::default(),
-		name,
-		description,
-		token_prefix,
-		mint_mode: true,
-		offchain_schema,
-		schema_version: Default::default(),
-		sponsorship: Default::default(),
-		limits: Default::default(),
-		variable_on_chain_schema,
-		const_on_chain_schema,
-		meta_update_permission: Default::default(),
-	})
+		CreateCollectionData {
+			mode,
+			name,
+			description,
+			token_prefix,
+			offchain_schema,
+			variable_on_chain_schema,
+			const_on_chain_schema,
+			..Default::default()
+		},
+	)
 	.and_then(CollectionHandle::try_get)
 	.map(cast)
 }
 
+/// Helper macros, which handles all benchmarking preparation in semi-declarative way
+///
+/// `name` is a substrate account
+/// - name: sub[(id)]
+/// `name` is a collection with owner `owner`
+/// - name: collection(owner)
+/// `name` is a cross account based on substrate
+/// - name: cross_sub[(id)]
+/// `name` is a cross account, which maps to substrate account `name`
+/// - name: cross_from_sub
+/// `name` is a cross account, which maps to substrate account `other_name`
+/// - name: cross_from_sub(other_name)
 #[macro_export]
 macro_rules! bench_init {
 	($name:ident: sub $(($id:expr))?; $($rest:tt)*) => {
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -12,7 +12,7 @@
 };
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
-impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
 	fn create_item() -> Weight {
 		<SelfWeightOf<T>>::create_item()
 	}
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -9,7 +9,7 @@
 use pallet_evm_coder_substrate::WithRecorder;
 use sp_core::H160;
 use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
-use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
+use sp_std::collections::btree_map::BTreeMap;
 
 pub use pallet::*;
 
@@ -222,7 +222,7 @@
 	pub fn create_multiple_items(
 		collection: &FungibleHandle<T>,
 		sender: &T::CrossAccountId,
-		data: Vec<CreateItemData<T>>,
+		data: BTreeMap<T::CrossAccountId, u128>,
 	) -> DispatchResult {
 		if !collection.is_owner_or_admin(sender) {
 			ensure!(
@@ -236,22 +236,18 @@
 			}
 		}
 
-		let mut balances = BTreeMap::new();
-
 		let total_supply = data
 			.iter()
-			.map(|u| u.1)
+			.map(|(_, v)| *v)
 			.try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {
 				acc.checked_add(v)
 			})
 			.ok_or(ArithmeticError::Overflow)?;
 
-		for (user, amount) in data.into_iter() {
-			let balance = balances
-				.entry(user.clone())
-				.or_insert_with(|| <Balance<T>>::get((collection.id, user)));
-			*balance = (*balance)
-				.checked_add(amount)
+		let mut balances = data;
+		for (k, v) in balances.iter_mut() {
+			*v = <Balance<T>>::get((collection.id, &k))
+				.checked_add(*v)
 				.ok_or(ArithmeticError::Overflow)?;
 		}
 
modifiedpallets/inflation/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/inflation/src/benchmarking.rs
+++ b/pallets/inflation/src/benchmarking.rs
@@ -1,7 +1,7 @@
 #![cfg(feature = "runtime-benchmarks")]
 
 use super::*;
-use crate::Module as Inflation;
+use crate::Pallet as Inflation;
 
 use frame_benchmarking::{benchmarks};
 use frame_support::traits::OnInitialize;
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -2,18 +2,18 @@
 use crate::{Pallet, Config, NonfungibleHandle};
 
 use sp_std::prelude::*;
-use pallet_common::benchmarking::{create_collection_raw, create_data};
+use pallet_common::benchmarking::{create_collection_raw, create_data, create_var_data};
 use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH};
+use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT};
 use pallet_common::bench_init;
 use core::convert::TryInto;
 
 const SEED: u32 = 1;
 
 fn create_max_item_data<T: Config>(owner: T::CrossAccountId) -> CreateItemData<T> {
-	let const_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	let variable_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	CreateItemData {
+	let const_data = create_data::<CUSTOM_DATA_LIMIT>();
+	let variable_data = create_data::<CUSTOM_DATA_LIMIT>();
+	CreateItemData::<T> {
 		const_data,
 		variable_data,
 		owner,
@@ -24,7 +24,7 @@
 	sender: &T::CrossAccountId,
 	owner: T::CrossAccountId,
 ) -> Result<TokenId, DispatchError> {
-	<Pallet<T>>::create_item(&collection, sender, create_max_item_data(owner))?;
+	<Pallet<T>>::create_item(&collection, sender, create_max_item_data::<T>(owner))?;
 	Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
 }
 
@@ -53,7 +53,9 @@
 			owner: sub; collection: collection(owner);
 			sender: cross_from_sub(owner); to: cross_sub;
 		};
-		let data = (0..b).map(|_| create_max_item_data(to.clone())).collect();
+		let data = (0..b).map(|_| create_max_item_data::<T>(to.clone())).collect();
+	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
+
 	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
 
 	burn_item {
@@ -105,6 +107,6 @@
 			owner: cross_from_sub; sender: cross_sub;
 		};
 		let item = create_max_item(&collection, &owner, sender.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b).try_into().unwrap();
 	}: {<Pallet<T>>::set_variable_metadata(&collection, &sender, item, data)?}
 }
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -12,7 +12,7 @@
 };
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
-impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
 	fn create_item() -> Weight {
 		<SelfWeightOf<T>>::create_item()
 	}
@@ -51,7 +51,7 @@
 	to: &T::CrossAccountId,
 ) -> Result<CreateItemData<T>, DispatchError> {
 	match data {
-		up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData {
+		up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {
 			const_data: data.const_data,
 			variable_data: data.variable_data,
 			owner: to.clone(),
@@ -68,7 +68,7 @@
 		data: up_data_structs::CreateItemData,
 	) -> DispatchResultWithPostInfo {
 		with_weight(
-			<Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),
+			<Pallet<T>>::create_item(self, &sender, map_create_data::<T>(data, &to)?),
 			<CommonWeights<T>>::create_item(),
 		)
 	}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
before · pallets/nonfungible/src/erc.rs
1use core::{2	char::{REPLACEMENT_CHARACTER, decode_utf16},3	convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};6use frame_support::BoundedVec;7use up_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{12	account::CrossAccountId,13	erc::{CommonEvmHandler, PrecompileResult},14};15use pallet_evm_coder_substrate::call;1617use crate::{18	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,19	SelfWeightOf, weights::WeightInfo,20};2122#[derive(ToLog)]23pub enum ERC721Events {24	Transfer {25		#[indexed]26		from: address,27		#[indexed]28		to: address,29		#[indexed]30		token_id: uint256,31	},32	Approval {33		#[indexed]34		owner: address,35		#[indexed]36		approved: address,37		#[indexed]38		token_id: uint256,39	},40	#[allow(dead_code)]41	ApprovalForAll {42		#[indexed]43		owner: address,44		#[indexed]45		operator: address,46		approved: bool,47	},48}4950#[derive(ToLog)]51pub enum ERC721MintableEvents {52	#[allow(dead_code)]53	MintingFinished {},54}5556#[solidity_interface(name = "ERC721Metadata")]57impl<T: Config> NonfungibleHandle<T> {58	fn name(&self) -> Result<string> {59		Ok(decode_utf16(self.name.iter().copied())60			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))61			.collect::<string>())62	}63	fn symbol(&self) -> Result<string> {64		Ok(string::from_utf8_lossy(&self.token_prefix).into())65	}6667	/// Returns token's const_metadata68	#[solidity(rename_selector = "tokenURI")]69	fn token_uri(&self, token_id: uint256) -> Result<string> {70		self.consume_store_reads(1)?;71		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;72		Ok(string::from_utf8_lossy(73			&<TokenData<T>>::get((self.id, token_id))74				.ok_or("token not found")?75				.const_data,76		)77		.into())78	}79}8081#[solidity_interface(name = "ERC721Enumerable")]82impl<T: Config> NonfungibleHandle<T> {83	fn token_by_index(&self, index: uint256) -> Result<uint256> {84		Ok(index)85	}8687	/// Not implemented88	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {89		// TODO: Not implemetable90		Err("not implemented".into())91	}9293	fn total_supply(&self) -> Result<uint256> {94		self.consume_store_reads(1)?;95		Ok(<Pallet<T>>::total_supply(self).into())96	}97}9899#[solidity_interface(name = "ERC721", events(ERC721Events))]100impl<T: Config> NonfungibleHandle<T> {101	fn balance_of(&self, owner: address) -> Result<uint256> {102		self.consume_store_reads(1)?;103		let owner = T::CrossAccountId::from_eth(owner);104		let balance = <AccountBalance<T>>::get((self.id, owner));105		Ok(balance.into())106	}107	fn owner_of(&self, token_id: uint256) -> Result<address> {108		self.consume_store_reads(1)?;109		let token: TokenId = token_id.try_into()?;110		Ok(*<TokenData<T>>::get((self.id, token))111			.ok_or("token not found")?112			.owner113			.as_eth())114	}115	/// Not implemented116	fn safe_transfer_from_with_data(117		&mut self,118		_from: address,119		_to: address,120		_token_id: uint256,121		_data: bytes,122		_value: value,123	) -> Result<void> {124		// TODO: Not implemetable125		Err("not implemented".into())126	}127	/// Not implemented128	fn safe_transfer_from(129		&mut self,130		_from: address,131		_to: address,132		_token_id: uint256,133		_value: value,134	) -> Result<void> {135		// TODO: Not implemetable136		Err("not implemented".into())137	}138139	#[weight(<SelfWeightOf<T>>::transfer_from())]140	fn transfer_from(141		&mut self,142		caller: caller,143		from: address,144		to: address,145		token_id: uint256,146		_value: value,147	) -> Result<void> {148		let caller = T::CrossAccountId::from_eth(caller);149		let from = T::CrossAccountId::from_eth(from);150		let to = T::CrossAccountId::from_eth(to);151		let token = token_id.try_into()?;152153		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token)154			.map_err(dispatch_to_evm::<T>)?;155		Ok(())156	}157158	#[weight(<SelfWeightOf<T>>::approve())]159	fn approve(160		&mut self,161		caller: caller,162		approved: address,163		token_id: uint256,164		_value: value,165	) -> Result<void> {166		let caller = T::CrossAccountId::from_eth(caller);167		let approved = T::CrossAccountId::from_eth(approved);168		let token = token_id.try_into()?;169170		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))171			.map_err(dispatch_to_evm::<T>)?;172		Ok(())173	}174175	/// Not implemented176	fn set_approval_for_all(177		&mut self,178		_caller: caller,179		_operator: address,180		_approved: bool,181	) -> Result<void> {182		// TODO: Not implemetable183		Err("not implemented".into())184	}185186	/// Not implemented187	fn get_approved(&self, _token_id: uint256) -> Result<address> {188		// TODO: Not implemetable189		Err("not implemented".into())190	}191192	/// Not implemented193	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {194		// TODO: Not implemetable195		Err("not implemented".into())196	}197}198199#[solidity_interface(name = "ERC721Burnable")]200impl<T: Config> NonfungibleHandle<T> {201	#[weight(<SelfWeightOf<T>>::burn_item())]202	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {203		let caller = T::CrossAccountId::from_eth(caller);204		let token = token_id.try_into()?;205206		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;207		Ok(())208	}209}210211#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]212impl<T: Config> NonfungibleHandle<T> {213	fn minting_finished(&self) -> Result<bool> {214		Ok(false)215	}216217	/// `token_id` should be obtained with `next_token_id` method,218	/// unlike standard, you can't specify it manually219	#[weight(<SelfWeightOf<T>>::create_item())]220	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {221		let caller = T::CrossAccountId::from_eth(caller);222		let to = T::CrossAccountId::from_eth(to);223		let token_id: u32 = token_id.try_into()?;224		if <TokensMinted<T>>::get(self.id)225			.checked_add(1)226			.ok_or("item id overflow")?227			!= token_id228		{229			return Err("item id should be next".into());230		}231232		<Pallet<T>>::create_item(233			self,234			&caller,235			CreateItemData {236				const_data: BoundedVec::default(),237				variable_data: BoundedVec::default(),238				owner: to,239			},240		)241		.map_err(dispatch_to_evm::<T>)?;242243		Ok(true)244	}245246	/// `token_id` should be obtained with `next_token_id` method,247	/// unlike standard, you can't specify it manually248	#[solidity(rename_selector = "mintWithTokenURI")]249	#[weight(<SelfWeightOf<T>>::create_item())]250	fn mint_with_token_uri(251		&mut self,252		caller: caller,253		to: address,254		token_id: uint256,255		token_uri: string,256	) -> Result<bool> {257		let caller = T::CrossAccountId::from_eth(caller);258		let to = T::CrossAccountId::from_eth(to);259		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;260		if <TokensMinted<T>>::get(self.id)261			.checked_add(1)262			.ok_or("item id overflow")?263			!= token_id264		{265			return Err("item id should be next".into());266		}267268		<Pallet<T>>::create_item(269			self,270			&caller,271			CreateItemData {272				const_data: Vec::<u8>::from(token_uri)273					.try_into()274					.map_err(|_| "token uri is too long")?,275				variable_data: BoundedVec::default(),276				owner: to,277			},278		)279		.map_err(dispatch_to_evm::<T>)?;280		Ok(true)281	}282283	/// Not implemented284	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {285		Err("not implementable".into())286	}287}288289#[solidity_interface(name = "ERC721UniqueExtensions")]290impl<T: Config> NonfungibleHandle<T> {291	#[weight(<SelfWeightOf<T>>::transfer())]292	fn transfer(293		&mut self,294		caller: caller,295		to: address,296		token_id: uint256,297		_value: value,298	) -> Result<void> {299		let caller = T::CrossAccountId::from_eth(caller);300		let to = T::CrossAccountId::from_eth(to);301		let token = token_id.try_into()?;302303		<Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;304		Ok(())305	}306307	#[weight(<SelfWeightOf<T>>::burn_from())]308	fn burn_from(309		&mut self,310		caller: caller,311		from: address,312		token_id: uint256,313		_value: value,314	) -> Result<void> {315		let caller = T::CrossAccountId::from_eth(caller);316		let from = T::CrossAccountId::from_eth(from);317		let token = token_id.try_into()?;318319		<Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;320		Ok(())321	}322323	fn next_token_id(&self) -> Result<uint256> {324		self.consume_store_reads(1)?;325		Ok(<TokensMinted<T>>::get(self.id)326			.checked_add(1)327			.ok_or("item id overflow")?328			.into())329	}330331	#[weight(<SelfWeightOf<T>>::set_variable_metadata(data.len() as u32))]332	fn set_variable_metadata(333		&mut self,334		caller: caller,335		token_id: uint256,336		data: bytes,337	) -> Result<void> {338		let caller = T::CrossAccountId::from_eth(caller);339		let token = token_id.try_into()?;340341		<Pallet<T>>::set_variable_metadata(342			self,343			&caller,344			token,345			data.try_into()346				.map_err(|_| "metadata size exceeded limit")?,347		)348		.map_err(dispatch_to_evm::<T>)?;349		Ok(())350	}351352	fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {353		self.consume_store_reads(1)?;354		let token: TokenId = token_id.try_into()?;355356		Ok(<TokenData<T>>::get((self.id, token))357			.ok_or("token not found")?358			.variable_data359			.into_inner())360	}361362	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]363	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {364		let caller = T::CrossAccountId::from_eth(caller);365		let to = T::CrossAccountId::from_eth(to);366		let mut expected_index = <TokensMinted<T>>::get(self.id)367			.checked_add(1)368			.ok_or("item id overflow")?;369370		let total_tokens = token_ids.len();371		for id in token_ids.into_iter() {372			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;373			if id != expected_index {374				return Err("item id should be next".into());375			}376			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;377		}378		let data = (0..total_tokens)379			.map(|_| CreateItemData {380				const_data: BoundedVec::default(),381				variable_data: BoundedVec::default(),382				owner: to.clone(),383			})384			.collect();385386		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;387		Ok(true)388	}389390	#[solidity(rename_selector = "mintBulkWithTokenURI")]391	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]392	fn mint_bulk_with_token_uri(393		&mut self,394		caller: caller,395		to: address,396		tokens: Vec<(uint256, string)>,397	) -> Result<bool> {398		let caller = T::CrossAccountId::from_eth(caller);399		let to = T::CrossAccountId::from_eth(to);400		let mut expected_index = <TokensMinted<T>>::get(self.id)401			.checked_add(1)402			.ok_or("item id overflow")?;403404		let mut data = Vec::with_capacity(tokens.len());405		for (id, token_uri) in tokens {406			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;407			if id != expected_index {408				panic!("item id should be next ({}) but got {}", expected_index, id);409			}410			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;411412			data.push(CreateItemData {413				const_data: Vec::<u8>::from(token_uri)414					.try_into()415					.map_err(|_| "token uri is too long")?,416				variable_data: vec![].try_into().unwrap(),417				owner: to.clone(),418			});419		}420421		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;422		Ok(true)423	}424}425426#[solidity_interface(427	name = "UniqueNFT",428	is(429		ERC721,430		ERC721Metadata,431		ERC721Enumerable,432		ERC721UniqueExtensions,433		ERC721Mintable,434		ERC721Burnable,435	)436)]437impl<T: Config> NonfungibleHandle<T> {}438439// Not a tests, but code generators440generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);441generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);442443impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {444	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");445446	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {447		call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)448	}449}
after · pallets/nonfungible/src/erc.rs
1use core::{2	char::{REPLACEMENT_CHARACTER, decode_utf16},3	convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};6use frame_support::BoundedVec;7use up_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{12	account::CrossAccountId,13	erc::{CommonEvmHandler, PrecompileResult},14};15use pallet_evm_coder_substrate::call;1617use crate::{18	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,19	SelfWeightOf, weights::WeightInfo,20};2122#[derive(ToLog)]23pub enum ERC721Events {24	Transfer {25		#[indexed]26		from: address,27		#[indexed]28		to: address,29		#[indexed]30		token_id: uint256,31	},32	Approval {33		#[indexed]34		owner: address,35		#[indexed]36		approved: address,37		#[indexed]38		token_id: uint256,39	},40	#[allow(dead_code)]41	ApprovalForAll {42		#[indexed]43		owner: address,44		#[indexed]45		operator: address,46		approved: bool,47	},48}4950#[derive(ToLog)]51pub enum ERC721MintableEvents {52	#[allow(dead_code)]53	MintingFinished {},54}5556#[solidity_interface(name = "ERC721Metadata")]57impl<T: Config> NonfungibleHandle<T> {58	fn name(&self) -> Result<string> {59		Ok(decode_utf16(self.name.iter().copied())60			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))61			.collect::<string>())62	}63	fn symbol(&self) -> Result<string> {64		Ok(string::from_utf8_lossy(&self.token_prefix).into())65	}6667	/// Returns token's const_metadata68	#[solidity(rename_selector = "tokenURI")]69	fn token_uri(&self, token_id: uint256) -> Result<string> {70		self.consume_store_reads(1)?;71		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;72		Ok(string::from_utf8_lossy(73			&<TokenData<T>>::get((self.id, token_id))74				.ok_or("token not found")?75				.const_data,76		)77		.into())78	}79}8081#[solidity_interface(name = "ERC721Enumerable")]82impl<T: Config> NonfungibleHandle<T> {83	fn token_by_index(&self, index: uint256) -> Result<uint256> {84		Ok(index)85	}8687	/// Not implemented88	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {89		// TODO: Not implemetable90		Err("not implemented".into())91	}9293	fn total_supply(&self) -> Result<uint256> {94		self.consume_store_reads(1)?;95		Ok(<Pallet<T>>::total_supply(self).into())96	}97}9899#[solidity_interface(name = "ERC721", events(ERC721Events))]100impl<T: Config> NonfungibleHandle<T> {101	fn balance_of(&self, owner: address) -> Result<uint256> {102		self.consume_store_reads(1)?;103		let owner = T::CrossAccountId::from_eth(owner);104		let balance = <AccountBalance<T>>::get((self.id, owner));105		Ok(balance.into())106	}107	fn owner_of(&self, token_id: uint256) -> Result<address> {108		self.consume_store_reads(1)?;109		let token: TokenId = token_id.try_into()?;110		Ok(*<TokenData<T>>::get((self.id, token))111			.ok_or("token not found")?112			.owner113			.as_eth())114	}115	/// Not implemented116	fn safe_transfer_from_with_data(117		&mut self,118		_from: address,119		_to: address,120		_token_id: uint256,121		_data: bytes,122		_value: value,123	) -> Result<void> {124		// TODO: Not implemetable125		Err("not implemented".into())126	}127	/// Not implemented128	fn safe_transfer_from(129		&mut self,130		_from: address,131		_to: address,132		_token_id: uint256,133		_value: value,134	) -> Result<void> {135		// TODO: Not implemetable136		Err("not implemented".into())137	}138139	#[weight(<SelfWeightOf<T>>::transfer_from())]140	fn transfer_from(141		&mut self,142		caller: caller,143		from: address,144		to: address,145		token_id: uint256,146		_value: value,147	) -> Result<void> {148		let caller = T::CrossAccountId::from_eth(caller);149		let from = T::CrossAccountId::from_eth(from);150		let to = T::CrossAccountId::from_eth(to);151		let token = token_id.try_into()?;152153		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token)154			.map_err(dispatch_to_evm::<T>)?;155		Ok(())156	}157158	#[weight(<SelfWeightOf<T>>::approve())]159	fn approve(160		&mut self,161		caller: caller,162		approved: address,163		token_id: uint256,164		_value: value,165	) -> Result<void> {166		let caller = T::CrossAccountId::from_eth(caller);167		let approved = T::CrossAccountId::from_eth(approved);168		let token = token_id.try_into()?;169170		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))171			.map_err(dispatch_to_evm::<T>)?;172		Ok(())173	}174175	/// Not implemented176	fn set_approval_for_all(177		&mut self,178		_caller: caller,179		_operator: address,180		_approved: bool,181	) -> Result<void> {182		// TODO: Not implemetable183		Err("not implemented".into())184	}185186	/// Not implemented187	fn get_approved(&self, _token_id: uint256) -> Result<address> {188		// TODO: Not implemetable189		Err("not implemented".into())190	}191192	/// Not implemented193	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {194		// TODO: Not implemetable195		Err("not implemented".into())196	}197}198199#[solidity_interface(name = "ERC721Burnable")]200impl<T: Config> NonfungibleHandle<T> {201	#[weight(<SelfWeightOf<T>>::burn_item())]202	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {203		let caller = T::CrossAccountId::from_eth(caller);204		let token = token_id.try_into()?;205206		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;207		Ok(())208	}209}210211#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]212impl<T: Config> NonfungibleHandle<T> {213	fn minting_finished(&self) -> Result<bool> {214		Ok(false)215	}216217	/// `token_id` should be obtained with `next_token_id` method,218	/// unlike standard, you can't specify it manually219	#[weight(<SelfWeightOf<T>>::create_item())]220	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {221		let caller = T::CrossAccountId::from_eth(caller);222		let to = T::CrossAccountId::from_eth(to);223		let token_id: u32 = token_id.try_into()?;224		if <TokensMinted<T>>::get(self.id)225			.checked_add(1)226			.ok_or("item id overflow")?227			!= token_id228		{229			return Err("item id should be next".into());230		}231232		<Pallet<T>>::create_item(233			self,234			&caller,235			CreateItemData::<T> {236				const_data: BoundedVec::default(),237				variable_data: BoundedVec::default(),238				owner: to,239			},240		)241		.map_err(dispatch_to_evm::<T>)?;242243		Ok(true)244	}245246	/// `token_id` should be obtained with `next_token_id` method,247	/// unlike standard, you can't specify it manually248	#[solidity(rename_selector = "mintWithTokenURI")]249	#[weight(<SelfWeightOf<T>>::create_item())]250	fn mint_with_token_uri(251		&mut self,252		caller: caller,253		to: address,254		token_id: uint256,255		token_uri: string,256	) -> Result<bool> {257		let caller = T::CrossAccountId::from_eth(caller);258		let to = T::CrossAccountId::from_eth(to);259		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;260		if <TokensMinted<T>>::get(self.id)261			.checked_add(1)262			.ok_or("item id overflow")?263			!= token_id264		{265			return Err("item id should be next".into());266		}267268		<Pallet<T>>::create_item(269			self,270			&caller,271			CreateItemData::<T> {272				const_data: Vec::<u8>::from(token_uri)273					.try_into()274					.map_err(|_| "token uri is too long")?,275				variable_data: BoundedVec::default(),276				owner: to,277			},278		)279		.map_err(dispatch_to_evm::<T>)?;280		Ok(true)281	}282283	/// Not implemented284	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {285		Err("not implementable".into())286	}287}288289#[solidity_interface(name = "ERC721UniqueExtensions")]290impl<T: Config> NonfungibleHandle<T> {291	#[weight(<SelfWeightOf<T>>::transfer())]292	fn transfer(293		&mut self,294		caller: caller,295		to: address,296		token_id: uint256,297		_value: value,298	) -> Result<void> {299		let caller = T::CrossAccountId::from_eth(caller);300		let to = T::CrossAccountId::from_eth(to);301		let token = token_id.try_into()?;302303		<Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;304		Ok(())305	}306307	#[weight(<SelfWeightOf<T>>::burn_from())]308	fn burn_from(309		&mut self,310		caller: caller,311		from: address,312		token_id: uint256,313		_value: value,314	) -> Result<void> {315		let caller = T::CrossAccountId::from_eth(caller);316		let from = T::CrossAccountId::from_eth(from);317		let token = token_id.try_into()?;318319		<Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;320		Ok(())321	}322323	fn next_token_id(&self) -> Result<uint256> {324		self.consume_store_reads(1)?;325		Ok(<TokensMinted<T>>::get(self.id)326			.checked_add(1)327			.ok_or("item id overflow")?328			.into())329	}330331	#[weight(<SelfWeightOf<T>>::set_variable_metadata(data.len() as u32))]332	fn set_variable_metadata(333		&mut self,334		caller: caller,335		token_id: uint256,336		data: bytes,337	) -> Result<void> {338		let caller = T::CrossAccountId::from_eth(caller);339		let token = token_id.try_into()?;340341		<Pallet<T>>::set_variable_metadata(342			self,343			&caller,344			token,345			data.try_into()346				.map_err(|_| "metadata size exceeded limit")?,347		)348		.map_err(dispatch_to_evm::<T>)?;349		Ok(())350	}351352	fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {353		self.consume_store_reads(1)?;354		let token: TokenId = token_id.try_into()?;355356		Ok(<TokenData<T>>::get((self.id, token))357			.ok_or("token not found")?358			.variable_data359			.into_inner())360	}361362	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]363	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {364		let caller = T::CrossAccountId::from_eth(caller);365		let to = T::CrossAccountId::from_eth(to);366		let mut expected_index = <TokensMinted<T>>::get(self.id)367			.checked_add(1)368			.ok_or("item id overflow")?;369370		let total_tokens = token_ids.len();371		for id in token_ids.into_iter() {372			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;373			if id != expected_index {374				return Err("item id should be next".into());375			}376			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;377		}378		let data = (0..total_tokens)379			.map(|_| CreateItemData::<T> {380				const_data: BoundedVec::default(),381				variable_data: BoundedVec::default(),382				owner: to.clone(),383			})384			.collect();385386		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;387		Ok(true)388	}389390	#[solidity(rename_selector = "mintBulkWithTokenURI")]391	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]392	fn mint_bulk_with_token_uri(393		&mut self,394		caller: caller,395		to: address,396		tokens: Vec<(uint256, string)>,397	) -> Result<bool> {398		let caller = T::CrossAccountId::from_eth(caller);399		let to = T::CrossAccountId::from_eth(to);400		let mut expected_index = <TokensMinted<T>>::get(self.id)401			.checked_add(1)402			.ok_or("item id overflow")?;403404		let mut data = Vec::with_capacity(tokens.len());405		for (id, token_uri) in tokens {406			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;407			if id != expected_index {408				panic!("item id should be next ({}) but got {}", expected_index, id);409			}410			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;411412			data.push(CreateItemData::<T> {413				const_data: Vec::<u8>::from(token_uri)414					.try_into()415					.map_err(|_| "token uri is too long")?,416				variable_data: vec![].try_into().unwrap(),417				owner: to.clone(),418			});419		}420421		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;422		Ok(true)423	}424}425426#[solidity_interface(427	name = "UniqueNFT",428	is(429		ERC721,430		ERC721Metadata,431		ERC721Enumerable,432		ERC721UniqueExtensions,433		ERC721Mintable,434		ERC721Burnable,435	)436)]437impl<T: Config> NonfungibleHandle<T> {}438439// Not a tests, but code generators440generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);441generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);442443impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {444	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");445446	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {447		call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)448	}449}
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -2,24 +2,28 @@
 use crate::{Pallet, Config, RefungibleHandle};
 
 use sp_std::prelude::*;
-use pallet_common::benchmarking::{create_collection_raw, create_data};
+use pallet_common::benchmarking::{create_collection_raw, create_data, create_var_data};
 use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH};
+use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT};
 use pallet_common::bench_init;
 use core::convert::TryInto;
 use core::iter::IntoIterator;
 
 const SEED: u32 = 1;
 
-fn create_max_item_data<T: Config>(
-	users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,
-) -> CreateItemData<T> {
-	let const_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	let variable_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	CreateItemData {
+fn create_max_item_data<CrossAccountId: Ord>(
+	users: impl IntoIterator<Item = (CrossAccountId, u128)>,
+) -> CreateRefungibleExData<CrossAccountId> {
+	let const_data = create_data::<CUSTOM_DATA_LIMIT>();
+	let variable_data = create_data::<CUSTOM_DATA_LIMIT>();
+	CreateRefungibleExData {
 		const_data,
 		variable_data,
-		users: users.into_iter().collect(),
+		users: users
+			.into_iter()
+			.collect::<BTreeMap<_, _>>()
+			.try_into()
+			.unwrap(),
 	}
 }
 fn create_max_item<T: Config>(
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -8,8 +8,8 @@
 use sp_std::vec::Vec;
 
 use crate::{
-	AccountBalance, Allowance, Balance, Config, CreateItemData, Error, Owned, Pallet,
-	RefungibleHandle, SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,
+	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,
+	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,
 };
 
 macro_rules! max_weight_of {
@@ -22,7 +22,7 @@
 }
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
-impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
 	fn create_item() -> Weight {
 		<SelfWeightOf<T>>::create_item()
 	}
modifiedpallets/unique/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/unique/src/benchmarking.rs
+++ b/pallets/unique/src/benchmarking.rs
@@ -5,9 +5,8 @@
 use frame_system::RawOrigin;
 use frame_benchmarking::{benchmarks, account};
 use up_data_structs::*;
-use core::convert::TryInto;
 use sp_runtime::DispatchError;
-use pallet_common::benchmarking::{create_data, create_u16_data};
+use pallet_common::benchmarking::{create_data, create_var_data, create_u16_data};
 
 const SEED: u32 = 1;
 
@@ -16,13 +15,9 @@
 	mode: CollectionMode,
 ) -> Result<CollectionId, DispatchError> {
 	T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
-	let col_name = create_u16_data(MAX_COLLECTION_NAME_LENGTH)
-		.try_into()
-		.unwrap();
-	let col_desc = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH)
-		.try_into()
-		.unwrap();
-	let token_prefix = create_data(MAX_TOKEN_PREFIX_LENGTH).try_into().unwrap();
+	let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
+	let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
+	let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
 	<Pallet<T>>::create_collection(
 		RawOrigin::Signed(owner).into(),
 		col_name,
@@ -37,11 +32,10 @@
 }
 
 benchmarks! {
-
 	create_collection {
-		let col_name: Vec<u16> = create_u16_data(MAX_COLLECTION_NAME_LENGTH);
-		let col_desc: Vec<u16> = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH);
-		let token_prefix: Vec<u8> = create_data(MAX_TOKEN_PREFIX_LENGTH);
+		let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
+		let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
+		let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
 		let mode: CollectionMode = CollectionMode::NFT;
 		let caller: T::AccountId = account("caller", 0, SEED);
 		T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
@@ -125,7 +119,7 @@
 
 		let caller: T::AccountId = account("caller", 0, SEED);
 		let collection = create_nft_collection::<T>(caller.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b);
 	}: set_offchain_schema(RawOrigin::Signed(caller.clone()), collection, data)
 
 	set_const_on_chain_schema {
@@ -133,7 +127,7 @@
 
 		let caller: T::AccountId = account("caller", 0, SEED);
 		let collection = create_nft_collection::<T>(caller.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b);
 	}: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)
 
 	set_variable_on_chain_schema {
@@ -141,7 +135,7 @@
 
 		let caller: T::AccountId = account("caller", 0, SEED);
 		let collection = create_nft_collection::<T>(caller.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b);
 	}: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)
 
 	set_schema_version {
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -76,9 +76,7 @@
 /// create_many call
 pub const MAX_ITEMS_PER_BATCH: u32 = 200;
 
-parameter_types! {
-	pub const CustomDataLimit: u32 = CUSTOM_DATA_LIMIT;
-}
+pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;
 
 #[derive(
 	Encode,
@@ -417,15 +415,72 @@
 	}
 }
 
+fn bounded_debug<V, S>(v: &BoundedVec<V, S>, f: &mut fmt::Formatter) -> Result<(), fmt::Error>
+where
+	V: fmt::Debug,
+{
+	use core::fmt::Debug;
+	(&v as &Vec<V>).fmt(f)
+}
+
+#[cfg(feature = "serde1")]
+#[allow(dead_code)]
+mod bounded_map_serde {
+	use core::convert::TryFrom;
+	use sp_std::collections::btree_map::BTreeMap;
+	use frame_support::{traits::Get, storage::bounded_btree_map::BoundedBTreeMap};
+	use serde::{
+		ser::{self, Serialize},
+		de::{self, Deserialize, Error},
+	};
+	pub fn serialize<D, K, V, S>(
+		value: &BoundedBTreeMap<K, V, S>,
+		serializer: D,
+	) -> Result<D::Ok, D::Error>
+	where
+		D: ser::Serializer,
+		K: Serialize + Ord,
+		V: Serialize,
+	{
+		(value as &BTreeMap<_, _>).serialize(serializer)
+	}
+
+	pub fn deserialize<'de, D, K, V, S>(
+		deserializer: D,
+	) -> Result<BoundedBTreeMap<K, V, S>, D::Error>
+	where
+		D: de::Deserializer<'de>,
+		K: de::Deserialize<'de> + Ord,
+		V: de::Deserialize<'de>,
+		S: Get<u32>,
+	{
+		let map = <BTreeMap<K, V>>::deserialize(deserializer)?;
+		let len = map.len();
+		TryFrom::try_from(map).map_err(|_| D::Error::invalid_length(len, &"lesser size"))
+	}
+}
+
+fn bounded_map_debug<K, V, S>(
+	v: &BoundedBTreeMap<K, V, S>,
+	f: &mut fmt::Formatter,
+) -> Result<(), fmt::Error>
+where
+	K: fmt::Debug + Ord,
+	V: fmt::Debug,
+{
+	use core::fmt::Debug;
+	(&v as &BTreeMap<K, V>).fmt(f)
+}
+
 #[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 #[derivative(Debug)]
 pub struct CreateNftData {
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub const_data: BoundedVec<u8, CustomDataLimit>,
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub variable_data: BoundedVec<u8, CustomDataLimit>,
 }
 
@@ -440,10 +495,10 @@
 #[derivative(Debug)]
 pub struct CreateReFungibleData {
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub const_data: BoundedVec<u8, CustomDataLimit>,
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub variable_data: BoundedVec<u8, CustomDataLimit>,
 	pub pieces: u128,
 }