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

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2021-11-26parent: #d1696cc.patch.diff
in: master

26 files changed

modified.maintain/frame-weight-template.hbsdiffbeforeafterboth
--- a/.maintain/frame-weight-template.hbs
+++ b/.maintain/frame-weight-template.hbs
@@ -14,6 +14,7 @@
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
 
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
modifiedMakefilediffbeforeafterboth
--- a/Makefile
+++ b/Makefile
@@ -57,9 +57,5 @@
 bench-nonfungible:
 	make _bench PALLET=nonfungible
 
-.PHONY: bench-evm-coder-substrate
-bench-evm-coder-substrate:
-	make _bench PALLET=evm-coder-substrate
-
 .PHONY: bench
-bench: bench-evm-migration bench-nft bench-fungible bench-refungible bench-nonfungible bench-evm-coder-substrate
+bench: bench-evm-migration bench-nft bench-fungible bench-refungible bench-nonfungible
modifiedcrates/evm-coder-macros/src/solidity_interface.rsdiffbeforeafterboth
--- a/crates/evm-coder-macros/src/solidity_interface.rs
+++ b/crates/evm-coder-macros/src/solidity_interface.rs
@@ -226,16 +226,10 @@
 		}
 	}
 	fn is_value(&self) -> bool {
-		match self {
-			Self::Plain(v) if v == "value" => true,
-			_ => false,
-		}
+		matches!(self, Self::Plain(v) if v == "value")
 	}
 	fn is_caller(&self) -> bool {
-		match self {
-			Self::Plain(v) if v == "caller" => true,
-			_ => false,
-		}
+		matches!(self, Self::Plain(v) if v == "caller")
 	}
 	fn is_special(&self) -> bool {
 		self.is_caller() || self.is_value()
@@ -599,7 +593,7 @@
 						#args,
 					)*
 				)?;
-				(&result).into_result()
+				(&result).to_result()
 			}
 		}
 	}
modifiedcrates/evm-coder/src/abi.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -310,7 +310,7 @@
 
 pub trait AbiWrite {
 	fn abi_write(&self, writer: &mut AbiWriter);
-	fn into_result(&self) -> ResultWithPostInfo<AbiWriter> {
+	fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {
 		let mut writer = AbiWriter::new();
 		self.abi_write(&mut writer);
 		Ok(writer.into())
@@ -319,7 +319,7 @@
 
 impl<T: AbiWrite> AbiWrite for ResultWithPostInfo<T> {
 	// this particular AbiWrite implementation should be split to another trait,
-	// which only implements [`into_result`]
+	// which only implements [`to_result`]
 	//
 	// But due to lack of specialization feature in stable Rust, we can't have
 	// blanket impl of this trait `for T where T: AbiWrite`, so here we abusing
@@ -327,7 +327,7 @@
 	fn abi_write(&self, _writer: &mut AbiWriter) {
 		debug_assert!(false, "shouldn't be called, see comment")
 	}
-	fn into_result(&self) -> ResultWithPostInfo<AbiWriter> {
+	fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {
 		match self {
 			Ok(v) => Ok(WithPostDispatchInfo {
 				post_info: v.post_info.clone(),
modifiednode/rpc/src/lib.rsdiffbeforeafterboth
--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -214,7 +214,7 @@
 			500_usize, // max stored filters
 			overrides.clone(),
 			max_past_logs,
-			block_data_cache.clone(),
+			block_data_cache,
 		)));
 	}
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -51,7 +51,7 @@
 		Self::new_with_gas_limit(id, u64::MAX)
 	}
 	pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {
-		Ok(Self::new(id).ok_or_else(|| <Error<T>>::CollectionNotFound)?)
+		Ok(Self::new(id).ok_or(<Error<T>>::CollectionNotFound)?)
 	}
 	pub fn log(&self, log: impl evm_coder::ToLog) {
 		self.recorder.log(log)
@@ -453,7 +453,7 @@
 			collection.limits.owner_can_destroy(),
 			<Error<T>>::NoPermission,
 		);
-		collection.check_is_owner(&sender)?;
+		collection.check_is_owner(sender)?;
 
 		let destroyed_collections = <DestroyedCollectionCount<T>>::get()
 			.0
@@ -476,7 +476,7 @@
 		user: &T::CrossAccountId,
 		allowed: bool,
 	) -> DispatchResult {
-		collection.check_is_owner_or_admin(&sender)?;
+		collection.check_is_owner_or_admin(sender)?;
 
 		// =========
 
@@ -495,7 +495,7 @@
 		user: &T::CrossAccountId,
 		admin: bool,
 	) -> DispatchResult {
-		collection.check_is_owner_or_admin(&sender)?;
+		collection.check_is_owner_or_admin(sender)?;
 
 		let was_admin = <IsAdmin<T>>::get((collection.id, user));
 		if was_admin == admin {
modifiedpallets/evm-contract-helpers/exp.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/exp.rs
+++ b/pallets/evm-contract-helpers/exp.rs
@@ -532,11 +532,11 @@
             match c.call {
                 InternalCall::ContractOwner { contract_address } => {
                     let result = self.contract_owner(contract_address)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::SponsoringEnabled { contract_address } => {
                     let result = self.sponsoring_enabled(contract_address)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::ToggleSponsoring {
                     contract_address,
@@ -544,7 +544,7 @@
                 } => {
                     let result =
                         self.toggle_sponsoring(c.caller.clone(), contract_address, enabled)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::SetSponsoringRateLimit {
                     contract_address,
@@ -555,22 +555,22 @@
                         contract_address,
                         rate_limit,
                     )?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::GetSponsoringRateLimit { contract_address } => {
                     let result = self.get_sponsoring_rate_limit(contract_address)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::Allowed {
                     contract_address,
                     user,
                 } => {
                     let result = self.allowed(contract_address, user)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::AllowlistEnabled { contract_address } => {
                     let result = self.allowlist_enabled(contract_address)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::ToggleAllowlist {
                     contract_address,
@@ -578,7 +578,7 @@
                 } => {
                     let result =
                         self.toggle_allowlist(c.caller.clone(), contract_address, enabled)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 InternalCall::ToggleAllowed {
                     contract_address,
@@ -587,7 +587,7 @@
                 } => {
                     let result =
                         self.toggle_allowed(c.caller.clone(), contract_address, user, allowed)?;
-                    (&result).into_result()
+                    (&result).to_result()
                 }
                 _ => ::core::panicking::panic("internal error: entered unreachable code"),
             }
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -1,10 +1,7 @@
 use core::marker::PhantomData;
 use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use pallet_evm::{
-	ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput, PrecompileResult,
-	PrecompileFailure,
-};
+use pallet_evm::{ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure};
 use sp_core::H160;
 use crate::{
 	AllowlistEnabled, Config, Owner, Pallet, SelfSponsoring, SponsorBasket, SponsoringRateLimit,
@@ -161,7 +158,7 @@
 		if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {
 			let limit = <SponsoringRateLimit<T>>::get(&call.0);
 
-			let timeout = last_tx_block + limit.into();
+			let timeout = last_tx_block + limit;
 			if block_number < timeout {
 				return None;
 			}
modifiedpallets/evm-migration/src/weights.rsdiffbeforeafterboth
--- a/pallets/evm-migration/src/weights.rs
+++ b/pallets/evm-migration/src/weights.rs
@@ -25,6 +25,7 @@
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
 
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
modifiedpallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-transaction-payment/src/lib.rs
+++ b/pallets/evm-transaction-payment/src/lib.rs
@@ -128,7 +128,7 @@
 				let sponsor = frame_support::storage::with_transaction(|| {
 					TransactionOutcome::Rollback(T::EvmSponsorshipHandler::get_sponsor(
 						&who,
-						&(target.clone(), input.clone()),
+						&(*target, input.clone()),
 					))
 				})?;
 				let sponsor = T::EvmAddressMapping::into_account_id(sponsor);
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -116,7 +116,7 @@
 		);
 
 		with_weight(
-			<Pallet<T>>::transfer(&self, &from, &to, amount),
+			<Pallet<T>>::transfer(self, &from, &to, amount),
 			<CommonWeights<T>>::transfer(),
 		)
 	}
@@ -134,7 +134,7 @@
 		);
 
 		with_weight(
-			<Pallet<T>>::set_allowance(&self, &sender, &spender, amount),
+			<Pallet<T>>::set_allowance(self, &sender, &spender, amount),
 			<CommonWeights<T>>::approve(),
 		)
 	}
@@ -153,7 +153,7 @@
 		);
 
 		with_weight(
-			<Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),
+			<Pallet<T>>::transfer_from(self, &sender, &from, &to, amount),
 			<CommonWeights<T>>::transfer_from(),
 		)
 	}
@@ -171,7 +171,7 @@
 		);
 
 		with_weight(
-			<Pallet<T>>::burn_from(&self, &sender, &from, amount),
+			<Pallet<T>>::burn_from(self, &sender, &from, amount),
 			<CommonWeights<T>>::burn_from(),
 		)
 	}
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -6,7 +6,6 @@
 use sp_core::{H160, U256};
 use sp_std::vec::Vec;
 use pallet_common::account::CrossAccountId;
-use pallet_common::erc::PrecompileOutput;
 use pallet_evm_coder_substrate::{call, dispatch_to_evm};
 
 use crate::{
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -303,8 +303,8 @@
 		amount: u128,
 	) -> DispatchResult {
 		if collection.access == AccessMode::AllowList {
-			collection.check_allowlist(&owner)?;
-			collection.check_allowlist(&spender)?;
+			collection.check_allowlist(owner)?;
+			collection.check_allowlist(spender)?;
 		}
 
 		if <Balance<T>>::get((collection.id, owner)) < amount {
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -25,6 +25,7 @@
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
 
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
@@ -32,11 +33,11 @@
 /// Weight functions needed for pallet_fungible.
 pub trait WeightInfo {
 	fn create_item() -> Weight;
-	fn burn_from() -> Weight;
 	fn burn_item() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
+	fn burn_from() -> Weight;
 }
 
 /// Weights for pallet_fungible using the Substrate node and recommended hardware.
modifiedpallets/nft/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nft/src/benchmarking.rs
+++ b/pallets/nft/src/benchmarking.rs
@@ -158,6 +158,7 @@
 			sponsored_data_size: Some(0),
 			token_limit: Some(1),
 			sponsor_transfer_timeout: Some(0),
+			sponsor_approve_timeout: None,
 			owner_can_destroy: Some(true),
 			owner_can_transfer: Some(true),
 			sponsored_data_rate_limit: None,
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -195,7 +195,7 @@
 
 			// Create new collection
 			let new_collection = Collection {
-				owner: who.clone(),
+				owner: who,
 				name: collection_name,
 				mode: mode.clone(),
 				mint_mode: false,
modifiedpallets/nft/src/weights.rsdiffbeforeafterboth
--- a/pallets/nft/src/weights.rs
+++ b/pallets/nft/src/weights.rs
@@ -25,6 +25,7 @@
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
 
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -100,7 +100,7 @@
 		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
 		if amount == 1 {
 			with_weight(
-				<Pallet<T>>::burn(&self, &sender, token),
+				<Pallet<T>>::burn(self, &sender, token),
 				<CommonWeights<T>>::burn_item(),
 			)
 		} else {
@@ -118,7 +118,7 @@
 		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
 		if amount == 1 {
 			with_weight(
-				<Pallet<T>>::transfer(&self, &from, &to, token),
+				<Pallet<T>>::transfer(self, &from, &to, token),
 				<CommonWeights<T>>::transfer(),
 			)
 		} else {
@@ -137,9 +137,9 @@
 
 		with_weight(
 			if amount == 1 {
-				<Pallet<T>>::set_allowance(&self, &sender, token, Some(&spender))
+				<Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))
 			} else {
-				<Pallet<T>>::set_allowance(&self, &sender, token, None)
+				<Pallet<T>>::set_allowance(self, &sender, token, None)
 			},
 			<CommonWeights<T>>::approve(),
 		)
@@ -157,7 +157,7 @@
 
 		if amount == 1 {
 			with_weight(
-				<Pallet<T>>::transfer_from(&self, &sender, &from, &to, token),
+				<Pallet<T>>::transfer_from(self, &sender, &from, &to, token),
 				<CommonWeights<T>>::transfer_from(),
 			)
 		} else {
@@ -176,7 +176,7 @@
 
 		if amount == 1 {
 			with_weight(
-				<Pallet<T>>::burn_from(&self, &sender, &from, token),
+				<Pallet<T>>::burn_from(self, &sender, &from, token),
 				<CommonWeights<T>>::burn_from(),
 			)
 		} else {
@@ -192,7 +192,7 @@
 	) -> DispatchResultWithPostInfo {
 		let len = data.len();
 		with_weight(
-			<Pallet<T>>::set_variable_metadata(&self, &sender, token, data),
+			<Pallet<T>>::set_variable_metadata(self, &sender, token, data),
 			<CommonWeights<T>>::set_variable_metadata(len as u32),
 		)
 	}
@@ -218,12 +218,12 @@
 	}
 	fn const_metadata(&self, token: TokenId) -> Vec<u8> {
 		<TokenData<T>>::get((self.id, token))
-			.map(|t| t.const_data.clone())
+			.map(|t| t.const_data)
 			.unwrap_or_default()
 	}
 	fn variable_metadata(&self, token: TokenId) -> Vec<u8> {
 		<TokenData<T>>::get((self.id, token))
-			.map(|t| t.variable_data.clone())
+			.map(|t| t.variable_data)
 			.unwrap_or_default()
 	}
 
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -13,7 +13,6 @@
 	erc::{CommonEvmHandler, PrecompileResult},
 };
 use pallet_evm_coder_substrate::call;
-use pallet_common::erc::PrecompileOutput;
 
 use crate::{
 	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -169,8 +169,8 @@
 		sender: &T::CrossAccountId,
 		token: TokenId,
 	) -> DispatchResult {
-		let token_data = <TokenData<T>>::get((collection.id, token))
-			.ok_or_else(|| <CommonError<T>>::TokenNotFound)?;
+		let token_data =
+			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
 		ensure!(
 			&token_data.owner == sender
 				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),
@@ -197,7 +197,7 @@
 				collection.id,
 				token,
 				sender.clone(),
-				old_spender.clone(),
+				old_spender,
 				0,
 			));
 		}
@@ -213,7 +213,7 @@
 			token_data.owner,
 			1,
 		));
-		return Ok(());
+		Ok(())
 	}
 
 	pub fn transfer(
@@ -227,8 +227,8 @@
 			<CommonError<T>>::TransferNotAllowed
 		);
 
-		let token_data = <TokenData<T>>::get((collection.id, token))
-			.ok_or_else(|| <CommonError<T>>::TokenNotFound)?;
+		let token_data =
+			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
 		ensure!(
 			&token_data.owner == from
 				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),
@@ -399,7 +399,7 @@
 						collection.id,
 						token,
 						sender.clone(),
-						old_owner.clone(),
+						old_owner,
 						0,
 					));
 				}
@@ -429,7 +429,7 @@
 					collection.id,
 					token,
 					sender.clone(),
-					old_spender.clone(),
+					old_spender,
 					0,
 				));
 			}
@@ -443,9 +443,9 @@
 		spender: Option<&T::CrossAccountId>,
 	) -> DispatchResult {
 		if collection.access == AccessMode::AllowList {
-			collection.check_allowlist(&sender)?;
+			collection.check_allowlist(sender)?;
 			if let Some(spender) = spender {
-				collection.check_allowlist(&spender)?;
+				collection.check_allowlist(spender)?;
 			}
 		}
 
@@ -491,7 +491,7 @@
 
 		// =========
 
-		Self::transfer(collection, &from, to, token)?;
+		Self::transfer(collection, from, to, token)?;
 		// Allowance is reset in [`transfer`]
 		Ok(())
 	}
@@ -519,7 +519,7 @@
 
 		// =========
 
-		Self::burn(collection, &from, token)
+		Self::burn(collection, from, token)
 	}
 
 	pub fn set_variable_metadata(
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -25,6 +25,7 @@
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
 
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
@@ -33,11 +34,11 @@
 pub trait WeightInfo {
 	fn create_item() -> Weight;
 	fn create_multiple_items(b: u32, ) -> Weight;
-	fn burn_from() -> Weight;
 	fn burn_item() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
+	fn burn_from() -> Weight;
 	fn set_variable_metadata(b: u32, ) -> Weight;
 }
 
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -135,7 +135,7 @@
 		amount: u128,
 	) -> DispatchResultWithPostInfo {
 		with_weight(
-			<Pallet<T>>::transfer(&self, &from, &to, token, amount),
+			<Pallet<T>>::transfer(self, &from, &to, token, amount),
 			<CommonWeights<T>>::transfer(),
 		)
 	}
@@ -148,7 +148,7 @@
 		amount: u128,
 	) -> DispatchResultWithPostInfo {
 		with_weight(
-			<Pallet<T>>::set_allowance(&self, &sender, &spender, token, amount),
+			<Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),
 			<CommonWeights<T>>::approve(),
 		)
 	}
@@ -162,7 +162,7 @@
 		amount: u128,
 	) -> DispatchResultWithPostInfo {
 		with_weight(
-			<Pallet<T>>::transfer_from(&self, &sender, &from, &to, token, amount),
+			<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount),
 			<CommonWeights<T>>::transfer_from(),
 		)
 	}
@@ -175,7 +175,7 @@
 		amount: u128,
 	) -> DispatchResultWithPostInfo {
 		with_weight(
-			<Pallet<T>>::burn_from(&self, &sender, &from, token, amount),
+			<Pallet<T>>::burn_from(self, &sender, &from, token, amount),
 			<CommonWeights<T>>::burn_from(),
 		)
 	}
@@ -188,7 +188,7 @@
 	) -> DispatchResultWithPostInfo {
 		let len = data.len();
 		with_weight(
-			<Pallet<T>>::set_variable_metadata(&self, &sender, token, data),
+			<Pallet<T>>::set_variable_metadata(self, &sender, token, data),
 			<CommonWeights<T>>::set_variable_metadata(len as u32),
 		)
 	}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -189,7 +189,7 @@
 		<Balance<T>>::remove_prefix((collection.id, token_id), None);
 		<Allowance<T>>::remove_prefix((collection.id, token_id), None);
 		// TODO: ERC721 transfer event
-		return Ok(());
+		Ok(())
 	}
 
 	pub fn burn(
@@ -367,8 +367,8 @@
 			collection.check_allowlist(sender)?;
 
 			for item in data.iter() {
-				for (user, _) in &item.users {
-					collection.check_allowlist(&user)?;
+				for user in item.users.keys() {
+					collection.check_allowlist(user)?;
 				}
 			}
 		}
@@ -409,7 +409,7 @@
 
 		let mut balances = BTreeMap::new();
 		for data in &data {
-			for (owner, _) in &data.users {
+			for owner in data.users.keys() {
 				let balance = balances
 					.entry(owner)
 					.or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));
@@ -483,8 +483,8 @@
 		amount: u128,
 	) -> DispatchResult {
 		if collection.access == AccessMode::AllowList {
-			collection.check_allowlist(&sender)?;
-			collection.check_allowlist(&spender)?;
+			collection.check_allowlist(sender)?;
+			collection.check_allowlist(spender)?;
 		}
 
 		<PalletCommon<T>>::ensure_correct_receiver(spender)?;
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -25,6 +25,7 @@
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
 
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
@@ -33,7 +34,6 @@
 pub trait WeightInfo {
 	fn create_item() -> Weight;
 	fn create_multiple_items(b: u32, ) -> Weight;
-	fn burn_from() -> Weight;
 	fn burn_item_partial() -> Weight;
 	fn burn_item_fully() -> Weight;
 	fn transfer_normal() -> Weight;
@@ -45,6 +45,7 @@
 	fn transfer_from_creating() -> Weight;
 	fn transfer_from_removing() -> Weight;
 	fn transfer_from_creating_removing() -> Weight;
+	fn burn_from() -> Weight;
 	fn set_variable_metadata(b: u32, ) -> Weight;
 }
 
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
before · primitives/nft/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23use core::convert::{TryFrom, TryInto};45#[cfg(feature = "serde")]6pub use serde::{Serialize, Deserialize};78use sp_core::U256;9use sp_runtime::{ArithmeticError, sp_std::prelude::Vec};10use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};11pub use frame_support::{12	BoundedVec, construct_runtime, decl_event, decl_module, decl_storage, decl_error,13	dispatch::DispatchResult,14	ensure, fail, parameter_types,15	traits::{16		Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,17		Randomness, IsSubType, WithdrawReasons,18	},19	weights::{20		constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},21		DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,22		WeightToFeePolynomial, DispatchClass,23	},24	StorageValue, transactional,25};26use derivative::Derivative;27use scale_info::TypeInfo;2829pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;30pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;31pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;32pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;3334pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {35	10000036} else {37	1038};39pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {40	204841} else {42	1043};44pub const COLLECTION_ADMINS_LIMIT: u32 = 5;45pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;46pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {47	100000048} else {49	1050};5152// Timeouts for item types in passed blocks53pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;54pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;55pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;5657pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;5859// Schema limits60pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 1024;61pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;62pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;6364pub const MAX_COLLECTION_NAME_LENGTH: usize = 64;65pub const MAX_COLLECTION_DESCRIPTION_LENGTH: usize = 256;66pub const MAX_TOKEN_PREFIX_LENGTH: usize = 16;6768/// How much items can be created per single69/// create_many call70pub const MAX_ITEMS_PER_BATCH: u32 = 200;7172parameter_types! {73	pub const CustomDataLimit: u32 = CUSTOM_DATA_LIMIT;74}7576#[derive(Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default, TypeInfo)]77#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]78pub struct CollectionId(pub u32);79impl EncodeLike<u32> for CollectionId {}80impl EncodeLike<CollectionId> for u32 {}8182#[derive(Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default, TypeInfo)]83#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]84pub struct TokenId(pub u32);85impl EncodeLike<u32> for TokenId {}86impl EncodeLike<TokenId> for u32 {}8788impl TokenId {89	pub fn try_next(self) -> Result<TokenId, ArithmeticError> {90		self.091			.checked_add(1)92			.ok_or(ArithmeticError::Overflow)93			.map(Self)94	}95}9697impl From<TokenId> for U256 {98	fn from(t: TokenId) -> Self {99		t.0.into()100	}101}102103impl TryFrom<U256> for TokenId {104	type Error = &'static str;105106	fn try_from(value: U256) -> Result<Self, Self::Error> {107		Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))108	}109}110111pub struct OverflowError;112impl From<OverflowError> for &'static str {113	fn from(_: OverflowError) -> Self {114		"overflow occured"115	}116}117118pub type DecimalPoints = u8;119120#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo)]121#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]122pub enum CollectionMode {123	NFT,124	// decimal points125	Fungible(DecimalPoints),126	ReFungible,127}128129impl CollectionMode {130	pub fn id(&self) -> u8 {131		match self {132			CollectionMode::NFT => 1,133			CollectionMode::Fungible(_) => 2,134			CollectionMode::ReFungible => 3,135		}136	}137}138139pub trait SponsoringResolve<AccountId, Call> {140	fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;141}142143#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo)]144#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]145pub enum AccessMode {146	Normal,147	AllowList,148}149impl Default for AccessMode {150	fn default() -> Self {151		Self::Normal152	}153}154155#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo)]156#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]157pub enum SchemaVersion {158	ImageURL,159	Unique,160}161impl Default for SchemaVersion {162	fn default() -> Self {163		Self::ImageURL164	}165}166167#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]168#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]169pub struct Ownership<AccountId> {170	pub owner: AccountId,171	pub fraction: u128,172}173174#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]175#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]176pub enum SponsorshipState<AccountId> {177	/// The fees are applied to the transaction sender178	Disabled,179	Unconfirmed(AccountId),180	/// Transactions are sponsored by specified account181	Confirmed(AccountId),182}183184impl<AccountId> SponsorshipState<AccountId> {185	pub fn sponsor(&self) -> Option<&AccountId> {186		match self {187			Self::Confirmed(sponsor) => Some(sponsor),188			_ => None,189		}190	}191192	pub fn pending_sponsor(&self) -> Option<&AccountId> {193		match self {194			Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),195			_ => None,196		}197	}198199	pub fn confirmed(&self) -> bool {200		matches!(self, Self::Confirmed(_))201	}202}203204impl<T> Default for SponsorshipState<T> {205	fn default() -> Self {206		Self::Disabled207	}208}209210#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]211#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]212pub struct Collection<AccountId> {213	pub owner: AccountId,214	pub mode: CollectionMode,215	pub access: AccessMode,216	pub name: Vec<u16>,        // 64 include null escape char217	pub description: Vec<u16>, // 256 include null escape char218	pub token_prefix: Vec<u8>, // 16 include null escape char219	pub mint_mode: bool,220	pub offchain_schema: Vec<u8>,221	pub schema_version: SchemaVersion,222	pub sponsorship: SponsorshipState<AccountId>,223	pub limits: CollectionLimits,          // Collection private restrictions224	pub variable_on_chain_schema: Vec<u8>, //225	pub const_on_chain_schema: Vec<u8>,    //226	pub meta_update_permission: MetaUpdatePermission,227}228229#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]230#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]231pub struct NftItemType<AccountId> {232	pub owner: AccountId,233	pub const_data: Vec<u8>,234	pub variable_data: Vec<u8>,235}236237#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]238#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]239pub struct FungibleItemType {240	pub value: u128,241}242243#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]244#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]245pub struct ReFungibleItemType<AccountId> {246	pub owner: Vec<Ownership<AccountId>>,247	pub const_data: Vec<u8>,248	pub variable_data: Vec<u8>,249}250251/// All fields are wrapped in `Option`s, where None means chain default252#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo)]253#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]254pub struct CollectionLimits {255	pub account_token_ownership_limit: Option<u32>,256	pub sponsored_data_size: Option<u32>,257	/// None - setVariableMetadata is not sponsored258	/// Some(v) - setVariableMetadata is sponsored259	///           if there is v block between txs260	pub sponsored_data_rate_limit: Option<(Option<u32>,)>,261	pub token_limit: Option<u32>,262263	// Timeouts for item types in passed blocks264	pub sponsor_transfer_timeout: Option<u32>,265	pub sponsor_approve_timeout: Option<u32>,266	pub owner_can_transfer: Option<bool>,267	pub owner_can_destroy: Option<bool>,268	pub transfers_enabled: Option<bool>,269}270271impl CollectionLimits {272	pub fn account_token_ownership_limit(&self) -> u32 {273		self.account_token_ownership_limit274			.unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)275			.min(MAX_TOKEN_OWNERSHIP)276	}277	pub fn sponsored_data_size(&self) -> u32 {278		self.sponsored_data_size279			.unwrap_or(CUSTOM_DATA_LIMIT)280			.min(CUSTOM_DATA_LIMIT)281	}282	pub fn token_limit(&self) -> u32 {283		self.token_limit284			.unwrap_or(COLLECTION_TOKEN_LIMIT)285			.min(COLLECTION_TOKEN_LIMIT)286	}287	pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {288		self.sponsor_transfer_timeout289			.unwrap_or(default)290			.min(MAX_SPONSOR_TIMEOUT)291	}292	pub fn sponsor_approve_timeout(&self) -> u32 {293		self.sponsor_approve_timeout294			.unwrap_or(SPONSOR_APPROVE_TIMEOUT)295			.min(MAX_SPONSOR_TIMEOUT)296	}297	pub fn owner_can_transfer(&self) -> bool {298		self.owner_can_transfer.unwrap_or(true)299	}300	pub fn owner_can_destroy(&self) -> bool {301		self.owner_can_destroy.unwrap_or(true)302	}303	pub fn transfers_enabled(&self) -> bool {304		self.transfers_enabled.unwrap_or(true)305	}306	pub fn sponsored_data_rate_limit(&self) -> Option<u32> {307		self.sponsored_data_rate_limit308			.unwrap_or((None,))309			.0310			.map(|v| v.min(MAX_SPONSOR_TIMEOUT))311	}312}313314/// BoundedVec doesn't supports serde315#[cfg(feature = "serde1")]316mod bounded_serde {317	use core::convert::TryFrom;318	use frame_support::{BoundedVec, traits::Get};319	use serde::{320		ser::{self, Serialize},321		de::{self, Deserialize, Error},322	};323	use sp_std::vec::Vec;324325	pub fn serialize<D, V, S>(value: &BoundedVec<V, S>, serializer: D) -> Result<D::Ok, D::Error>326	where327		D: ser::Serializer,328		V: Serialize,329	{330		let vec: &Vec<_> = &value;331		vec.serialize(serializer)332	}333334	pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>335	where336		D: de::Deserializer<'de>,337		V: de::Deserialize<'de>,338		S: Get<u32>,339	{340		// TODO: Implement custom visitor, which will limit vec size at parse time? Will serde only be used by chainspec?341		let vec = <Vec<V>>::deserialize(deserializer)?;342		let len = vec.len();343		TryFrom::try_from(vec).map_err(|_| D::Error::invalid_length(len, &"lesser size"))344	}345}346347#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]348#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]349#[derivative(Debug)]350pub struct CreateNftData {351	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]352	#[derivative(Debug = "ignore")]353	pub const_data: BoundedVec<u8, CustomDataLimit>,354	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]355	#[derivative(Debug = "ignore")]356	pub variable_data: BoundedVec<u8, CustomDataLimit>,357}358359#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]360#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]361pub struct CreateFungibleData {362	pub value: u128,363}364365#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]366#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]367#[derivative(Debug)]368pub struct CreateReFungibleData {369	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]370	#[derivative(Debug = "ignore")]371	pub const_data: BoundedVec<u8, CustomDataLimit>,372	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]373	#[derivative(Debug = "ignore")]374	pub variable_data: BoundedVec<u8, CustomDataLimit>,375	pub pieces: u128,376}377378#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]379#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]380pub enum MetaUpdatePermission {381	ItemOwner,382	Admin,383	None,384}385386impl Default for MetaUpdatePermission {387	fn default() -> Self {388		Self::ItemOwner389	}390}391392#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]393#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]394pub enum CreateItemData {395	NFT(CreateNftData),396	Fungible(CreateFungibleData),397	ReFungible(CreateReFungibleData),398}399400impl CreateItemData {401	pub fn data_size(&self) -> usize {402		match self {403			CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),404			CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),405			_ => 0,406		}407	}408}409410impl From<CreateNftData> for CreateItemData {411	fn from(item: CreateNftData) -> Self {412		CreateItemData::NFT(item)413	}414}415416impl From<CreateReFungibleData> for CreateItemData {417	fn from(item: CreateReFungibleData) -> Self {418		CreateItemData::ReFungible(item)419	}420}421422impl From<CreateFungibleData> for CreateItemData {423	fn from(item: CreateFungibleData) -> Self {424		CreateItemData::Fungible(item)425	}426}427428#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]429#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]430pub struct CollectionStats {431	pub created: u32,432	pub destroyed: u32,433	pub alive: u32,434}
after · primitives/nft/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23use core::convert::{TryFrom, TryInto};45#[cfg(feature = "serde")]6pub use serde::{Serialize, Deserialize};78use sp_core::U256;9use sp_runtime::{ArithmeticError, sp_std::prelude::Vec};10use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};11pub use frame_support::{12	BoundedVec, construct_runtime, decl_event, decl_module, decl_storage, decl_error,13	dispatch::DispatchResult,14	ensure, fail, parameter_types,15	traits::{16		Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,17		Randomness, IsSubType, WithdrawReasons,18	},19	weights::{20		constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},21		DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,22		WeightToFeePolynomial, DispatchClass,23	},24	StorageValue, transactional,25};26use derivative::Derivative;27use scale_info::TypeInfo;2829pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;30pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;31pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;32pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;3334pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {35	10000036} else {37	1038};39pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {40	204841} else {42	1043};44pub const COLLECTION_ADMINS_LIMIT: u32 = 5;45pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;46pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {47	100000048} else {49	1050};5152// Timeouts for item types in passed blocks53pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;54pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;55pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;5657pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;5859// Schema limits60pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 1024;61pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;62pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;6364pub const MAX_COLLECTION_NAME_LENGTH: usize = 64;65pub const MAX_COLLECTION_DESCRIPTION_LENGTH: usize = 256;66pub const MAX_TOKEN_PREFIX_LENGTH: usize = 16;6768/// How much items can be created per single69/// create_many call70pub const MAX_ITEMS_PER_BATCH: u32 = 200;7172parameter_types! {73	pub const CustomDataLimit: u32 = CUSTOM_DATA_LIMIT;74}7576#[derive(Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default, TypeInfo)]77#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]78pub struct CollectionId(pub u32);79impl EncodeLike<u32> for CollectionId {}80impl EncodeLike<CollectionId> for u32 {}8182#[derive(Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default, TypeInfo)]83#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]84pub struct TokenId(pub u32);85impl EncodeLike<u32> for TokenId {}86impl EncodeLike<TokenId> for u32 {}8788impl TokenId {89	pub fn try_next(self) -> Result<TokenId, ArithmeticError> {90		self.091			.checked_add(1)92			.ok_or(ArithmeticError::Overflow)93			.map(Self)94	}95}9697impl From<TokenId> for U256 {98	fn from(t: TokenId) -> Self {99		t.0.into()100	}101}102103impl TryFrom<U256> for TokenId {104	type Error = &'static str;105106	fn try_from(value: U256) -> Result<Self, Self::Error> {107		Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))108	}109}110111pub struct OverflowError;112impl From<OverflowError> for &'static str {113	fn from(_: OverflowError) -> Self {114		"overflow occured"115	}116}117118pub type DecimalPoints = u8;119120#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo)]121#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]122pub enum CollectionMode {123	NFT,124	// decimal points125	Fungible(DecimalPoints),126	ReFungible,127}128129impl CollectionMode {130	pub fn id(&self) -> u8 {131		match self {132			CollectionMode::NFT => 1,133			CollectionMode::Fungible(_) => 2,134			CollectionMode::ReFungible => 3,135		}136	}137}138139pub trait SponsoringResolve<AccountId, Call> {140	fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;141}142143#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo)]144#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]145pub enum AccessMode {146	Normal,147	AllowList,148}149impl Default for AccessMode {150	fn default() -> Self {151		Self::Normal152	}153}154155#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo)]156#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]157pub enum SchemaVersion {158	ImageURL,159	Unique,160}161impl Default for SchemaVersion {162	fn default() -> Self {163		Self::ImageURL164	}165}166167#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]168#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]169pub struct Ownership<AccountId> {170	pub owner: AccountId,171	pub fraction: u128,172}173174#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]175#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]176pub enum SponsorshipState<AccountId> {177	/// The fees are applied to the transaction sender178	Disabled,179	Unconfirmed(AccountId),180	/// Transactions are sponsored by specified account181	Confirmed(AccountId),182}183184impl<AccountId> SponsorshipState<AccountId> {185	pub fn sponsor(&self) -> Option<&AccountId> {186		match self {187			Self::Confirmed(sponsor) => Some(sponsor),188			_ => None,189		}190	}191192	pub fn pending_sponsor(&self) -> Option<&AccountId> {193		match self {194			Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),195			_ => None,196		}197	}198199	pub fn confirmed(&self) -> bool {200		matches!(self, Self::Confirmed(_))201	}202}203204impl<T> Default for SponsorshipState<T> {205	fn default() -> Self {206		Self::Disabled207	}208}209210#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]211#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]212pub struct Collection<AccountId> {213	pub owner: AccountId,214	pub mode: CollectionMode,215	pub access: AccessMode,216	pub name: Vec<u16>,        // 64 include null escape char217	pub description: Vec<u16>, // 256 include null escape char218	pub token_prefix: Vec<u8>, // 16 include null escape char219	pub mint_mode: bool,220	pub offchain_schema: Vec<u8>,221	pub schema_version: SchemaVersion,222	pub sponsorship: SponsorshipState<AccountId>,223	pub limits: CollectionLimits,          // Collection private restrictions224	pub variable_on_chain_schema: Vec<u8>, //225	pub const_on_chain_schema: Vec<u8>,    //226	pub meta_update_permission: MetaUpdatePermission,227}228229#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]230#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]231pub struct NftItemType<AccountId> {232	pub owner: AccountId,233	pub const_data: Vec<u8>,234	pub variable_data: Vec<u8>,235}236237#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]238#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]239pub struct FungibleItemType {240	pub value: u128,241}242243#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]244#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]245pub struct ReFungibleItemType<AccountId> {246	pub owner: Vec<Ownership<AccountId>>,247	pub const_data: Vec<u8>,248	pub variable_data: Vec<u8>,249}250251/// All fields are wrapped in `Option`s, where None means chain default252#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo)]253#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]254pub struct CollectionLimits {255	pub account_token_ownership_limit: Option<u32>,256	pub sponsored_data_size: Option<u32>,257	/// None - setVariableMetadata is not sponsored258	/// Some(v) - setVariableMetadata is sponsored259	///           if there is v block between txs260	pub sponsored_data_rate_limit: Option<(Option<u32>,)>,261	pub token_limit: Option<u32>,262263	// Timeouts for item types in passed blocks264	pub sponsor_transfer_timeout: Option<u32>,265	pub sponsor_approve_timeout: Option<u32>,266	pub owner_can_transfer: Option<bool>,267	pub owner_can_destroy: Option<bool>,268	pub transfers_enabled: Option<bool>,269}270271impl CollectionLimits {272	pub fn account_token_ownership_limit(&self) -> u32 {273		self.account_token_ownership_limit274			.unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)275			.min(MAX_TOKEN_OWNERSHIP)276	}277	pub fn sponsored_data_size(&self) -> u32 {278		self.sponsored_data_size279			.unwrap_or(CUSTOM_DATA_LIMIT)280			.min(CUSTOM_DATA_LIMIT)281	}282	pub fn token_limit(&self) -> u32 {283		self.token_limit284			.unwrap_or(COLLECTION_TOKEN_LIMIT)285			.min(COLLECTION_TOKEN_LIMIT)286	}287	pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {288		self.sponsor_transfer_timeout289			.unwrap_or(default)290			.min(MAX_SPONSOR_TIMEOUT)291	}292	pub fn sponsor_approve_timeout(&self) -> u32 {293		self.sponsor_approve_timeout294			.unwrap_or(SPONSOR_APPROVE_TIMEOUT)295			.min(MAX_SPONSOR_TIMEOUT)296	}297	pub fn owner_can_transfer(&self) -> bool {298		self.owner_can_transfer.unwrap_or(true)299	}300	pub fn owner_can_destroy(&self) -> bool {301		self.owner_can_destroy.unwrap_or(true)302	}303	pub fn transfers_enabled(&self) -> bool {304		self.transfers_enabled.unwrap_or(true)305	}306	pub fn sponsored_data_rate_limit(&self) -> Option<u32> {307		self.sponsored_data_rate_limit308			.unwrap_or((None,))309			.0310			.map(|v| v.min(MAX_SPONSOR_TIMEOUT))311	}312}313314/// BoundedVec doesn't supports serde315#[cfg(feature = "serde1")]316mod bounded_serde {317	use core::convert::TryFrom;318	use frame_support::{BoundedVec, traits::Get};319	use serde::{320		ser::{self, Serialize},321		de::{self, Deserialize, Error},322	};323	use sp_std::vec::Vec;324325	pub fn serialize<D, V, S>(value: &BoundedVec<V, S>, serializer: D) -> Result<D::Ok, D::Error>326	where327		D: ser::Serializer,328		V: Serialize,329	{330		(value as &Vec<_>).serialize(serializer)331	}332333	pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>334	where335		D: de::Deserializer<'de>,336		V: de::Deserialize<'de>,337		S: Get<u32>,338	{339		// TODO: Implement custom visitor, which will limit vec size at parse time? Will serde only be used by chainspec?340		let vec = <Vec<V>>::deserialize(deserializer)?;341		let len = vec.len();342		TryFrom::try_from(vec).map_err(|_| D::Error::invalid_length(len, &"lesser size"))343	}344}345346#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]347#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]348#[derivative(Debug)]349pub struct CreateNftData {350	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]351	#[derivative(Debug = "ignore")]352	pub const_data: BoundedVec<u8, CustomDataLimit>,353	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]354	#[derivative(Debug = "ignore")]355	pub variable_data: BoundedVec<u8, CustomDataLimit>,356}357358#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]359#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]360pub struct CreateFungibleData {361	pub value: u128,362}363364#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]365#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]366#[derivative(Debug)]367pub struct CreateReFungibleData {368	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]369	#[derivative(Debug = "ignore")]370	pub const_data: BoundedVec<u8, CustomDataLimit>,371	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]372	#[derivative(Debug = "ignore")]373	pub variable_data: BoundedVec<u8, CustomDataLimit>,374	pub pieces: u128,375}376377#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]378#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]379pub enum MetaUpdatePermission {380	ItemOwner,381	Admin,382	None,383}384385impl Default for MetaUpdatePermission {386	fn default() -> Self {387		Self::ItemOwner388	}389}390391#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]392#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]393pub enum CreateItemData {394	NFT(CreateNftData),395	Fungible(CreateFungibleData),396	ReFungible(CreateReFungibleData),397}398399impl CreateItemData {400	pub fn data_size(&self) -> usize {401		match self {402			CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),403			CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),404			_ => 0,405		}406	}407}408409impl From<CreateNftData> for CreateItemData {410	fn from(item: CreateNftData) -> Self {411		CreateItemData::NFT(item)412	}413}414415impl From<CreateReFungibleData> for CreateItemData {416	fn from(item: CreateReFungibleData) -> Self {417		CreateItemData::ReFungible(item)418	}419}420421impl From<CreateFungibleData> for CreateItemData {422	fn from(item: CreateFungibleData) -> Self {423		CreateItemData::Fungible(item)424	}425}426427#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]428#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]429pub struct CollectionStats {430	pub created: u32,431	pub destroyed: u32,432	pub alive: u32,433}
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -1177,6 +1177,7 @@
 			EVM::account_storages(address, H256::from_slice(&tmp[..]))
 		}
 
+		#[allow(clippy::redundant_closure)]
 		fn call(
 			from: H160,
 			to: H160,
@@ -1207,6 +1208,7 @@
 			).map_err(|err| err.into())
 		}
 
+		#[allow(clippy::redundant_closure)]
 		fn create(
 			from: H160,
 			data: Vec<u8>,