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

difftreelog

Revert "fix zero transfer"

Daniel Shiposha2022-12-06parent: #2f762b2.patch.diff
in: master
This reverts commit 2880b7f76c032798bcf34e0b1b79ca02a267e201.

13 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5901,7 +5901,7 @@
 
 [[package]]
 name = "pallet-common"
-version = "0.1.13"
+version = "0.1.12"
 dependencies = [
  "ethereum",
  "evm-coder",
@@ -6191,7 +6191,7 @@
 
 [[package]]
 name = "pallet-fungible"
-version = "0.1.8"
+version = "0.1.7"
 dependencies = [
  "ethereum",
  "evm-coder",
@@ -6446,7 +6446,7 @@
 
 [[package]]
 name = "pallet-nonfungible"
-version = "0.1.10"
+version = "0.1.9"
 dependencies = [
  "ethereum",
  "evm-coder",
@@ -6568,7 +6568,7 @@
 
 [[package]]
 name = "pallet-refungible"
-version = "0.2.9"
+version = "0.2.8"
 dependencies = [
  "derivative",
  "ethereum",
modifiedpallets/common/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/common/CHANGELOG.md
+++ b/pallets/common/CHANGELOG.md
@@ -4,12 +4,6 @@
 
 <!-- bureaucrate goes here -->
 
-## [0.1.13] - 2022-12-05
-
-### Added
-
-- The error `ZeroTransferNotAllowed` to handling transactions with the transfer of a zero amount of tokens.
-
 ## [0.1.12] - 2022-11-16
 
 ### Changed
modifiedpallets/common/Cargo.tomldiffbeforeafterboth
--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-common"
-version = "0.1.13"
+version = "0.1.12"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -601,9 +601,6 @@
 
 		/// Tried to access an internal collection with an external API
 		CollectionIsInternal,
-
-		/// Transfer operation with zero amount
-		ZeroTransferNotAllowed,
 	}
 
 	/// Storage of the count of created collections. Essentially contains the last collection ID.
modifiedpallets/fungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/fungible/CHANGELOG.md
+++ b/pallets/fungible/CHANGELOG.md
@@ -4,12 +4,6 @@
 
 <!-- bureaucrate goes here -->
 
-## [0.1.9] - 2022-12-05
-
-### Fixed 
-
-- Transfer with zero tokens.
-
 ## [0.1.8] - 2022-11-18
 
 ### Added
modifiedpallets/fungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/fungible/Cargo.toml
+++ b/pallets/fungible/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-fungible"
-version = "0.1.8"
+version = "0.1.7"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -365,8 +365,6 @@
 		amount: u128,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		ensure!(amount > 0, <CommonError<T>>::ZeroTransferNotAllowed);
-
 		ensure!(
 			collection.limits.transfers_enabled(),
 			<CommonError<T>>::TransferNotAllowed,
modifiedpallets/nonfungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/nonfungible/CHANGELOG.md
+++ b/pallets/nonfungible/CHANGELOG.md
@@ -4,12 +4,6 @@
 
 <!-- bureaucrate goes here -->
 
-## [0.1.11] - 2022-12-05
-
-### Fixed
-
-- Transfer with zero tokens.
-
 ## [0.1.10] - 2022-11-18
 
 ### Added
modifiedpallets/nonfungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/nonfungible/Cargo.toml
+++ b/pallets/nonfungible/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-nonfungible"
-version = "0.1.10"
+version = "0.1.9"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
before · pallets/nonfungible/src/common.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};20use up_data_structs::{21	TokenId, CreateItemExData, CollectionId, budget::Budget, Property, PropertyKey,22	PropertyKeyPermission, PropertyValue,23};24use pallet_common::{25	CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,26	weights::WeightInfo as _, Error as CommonError,27};28use sp_runtime::DispatchError;29use sp_std::{vec::Vec, vec};3031use crate::{32	AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,33	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,34};3536pub struct CommonWeights<T: Config>(PhantomData<T>);37impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {38	fn create_item() -> Weight {39		<SelfWeightOf<T>>::create_item()40	}4142	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {43		match data {44			CreateItemExData::NFT(t) => {45				<SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32)46					+ t.iter()47						.filter_map(|t| {48							if t.properties.len() > 0 {49								Some(Self::set_token_properties(t.properties.len() as u32))50							} else {51								None52							}53						})54						.fold(Weight::zero(), |a, b| a.saturating_add(b))55			}56			_ => Weight::zero(),57		}58	}5960	fn create_multiple_items(data: &[up_data_structs::CreateItemData]) -> Weight {61		<SelfWeightOf<T>>::create_multiple_items(data.len() as u32)62			+ data63				.iter()64				.filter_map(|t| match t {65					up_data_structs::CreateItemData::NFT(n) if n.properties.len() > 0 => {66						Some(Self::set_token_properties(n.properties.len() as u32))67					}68					_ => None,69				})70				.fold(Weight::zero(), |a, b| a.saturating_add(b))71	}7273	fn burn_item() -> Weight {74		<SelfWeightOf<T>>::burn_item()75	}7677	fn set_collection_properties(amount: u32) -> Weight {78		<pallet_common::SelfWeightOf<T>>::set_collection_properties(amount)79	}8081	fn delete_collection_properties(amount: u32) -> Weight {82		<pallet_common::SelfWeightOf<T>>::delete_collection_properties(amount)83	}8485	fn set_token_properties(amount: u32) -> Weight {86		<SelfWeightOf<T>>::set_token_properties(amount)87	}8889	fn delete_token_properties(amount: u32) -> Weight {90		<SelfWeightOf<T>>::delete_token_properties(amount)91	}9293	fn set_token_property_permissions(amount: u32) -> Weight {94		<SelfWeightOf<T>>::set_token_property_permissions(amount)95	}9697	fn transfer() -> Weight {98		<SelfWeightOf<T>>::transfer()99	}100101	fn approve() -> Weight {102		<SelfWeightOf<T>>::approve()103	}104105	fn transfer_from() -> Weight {106		<SelfWeightOf<T>>::transfer_from()107	}108109	fn burn_from() -> Weight {110		<SelfWeightOf<T>>::burn_from()111	}112113	fn burn_recursively_self_raw() -> Weight {114		<SelfWeightOf<T>>::burn_recursively_self_raw()115	}116117	fn burn_recursively_breadth_raw(amount: u32) -> Weight {118		<SelfWeightOf<T>>::burn_recursively_breadth_plus_self_plus_self_per_each_raw(amount)119			.saturating_sub(Self::burn_recursively_self_raw().saturating_mul(amount as u64 + 1))120	}121122	fn token_owner() -> Weight {123		<SelfWeightOf<T>>::token_owner()124	}125}126127fn map_create_data<T: Config>(128	data: up_data_structs::CreateItemData,129	to: &T::CrossAccountId,130) -> Result<CreateItemData<T>, DispatchError> {131	match data {132		up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {133			properties: data.properties,134			owner: to.clone(),135		}),136		_ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),137	}138}139140/// Implementation of `CommonCollectionOperations` for `NonfungibleHandle`. It wraps Nonfungible Pallete141/// methods and adds weight info.142impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {143	fn create_item(144		&self,145		sender: T::CrossAccountId,146		to: T::CrossAccountId,147		data: up_data_structs::CreateItemData,148		nesting_budget: &dyn Budget,149	) -> DispatchResultWithPostInfo {150		with_weight(151			<Pallet<T>>::create_item(152				self,153				&sender,154				map_create_data::<T>(data, &to)?,155				nesting_budget,156			),157			<CommonWeights<T>>::create_item(),158		)159	}160161	fn create_multiple_items(162		&self,163		sender: T::CrossAccountId,164		to: T::CrossAccountId,165		data: Vec<up_data_structs::CreateItemData>,166		nesting_budget: &dyn Budget,167	) -> DispatchResultWithPostInfo {168		let weight = <CommonWeights<T>>::create_multiple_items(&data);169		let data = data170			.into_iter()171			.map(|d| map_create_data::<T>(d, &to))172			.collect::<Result<Vec<_>, DispatchError>>()?;173174		with_weight(175			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),176			weight,177		)178	}179180	fn create_multiple_items_ex(181		&self,182		sender: <T>::CrossAccountId,183		data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,184		nesting_budget: &dyn Budget,185	) -> DispatchResultWithPostInfo {186		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);187		let data = match data {188			up_data_structs::CreateItemExData::NFT(nft) => nft,189			_ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),190		};191192		with_weight(193			<Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),194			weight,195		)196	}197198	fn set_collection_properties(199		&self,200		sender: T::CrossAccountId,201		properties: Vec<Property>,202	) -> DispatchResultWithPostInfo {203		let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);204205		with_weight(206			<Pallet<T>>::set_collection_properties(self, &sender, properties),207			weight,208		)209	}210211	fn delete_collection_properties(212		&self,213		sender: &T::CrossAccountId,214		property_keys: Vec<PropertyKey>,215	) -> DispatchResultWithPostInfo {216		let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);217218		with_weight(219			<Pallet<T>>::delete_collection_properties(self, sender, property_keys),220			weight,221		)222	}223224	fn set_token_properties(225		&self,226		sender: T::CrossAccountId,227		token_id: TokenId,228		properties: Vec<Property>,229		nesting_budget: &dyn Budget,230	) -> DispatchResultWithPostInfo {231		let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);232233		with_weight(234			<Pallet<T>>::set_token_properties(235				self,236				&sender,237				token_id,238				properties.into_iter(),239				false,240				nesting_budget,241			),242			weight,243		)244	}245246	fn delete_token_properties(247		&self,248		sender: T::CrossAccountId,249		token_id: TokenId,250		property_keys: Vec<PropertyKey>,251		nesting_budget: &dyn Budget,252	) -> DispatchResultWithPostInfo {253		let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);254255		with_weight(256			<Pallet<T>>::delete_token_properties(257				self,258				&sender,259				token_id,260				property_keys.into_iter(),261				nesting_budget,262			),263			weight,264		)265	}266267	fn set_token_property_permissions(268		&self,269		sender: &T::CrossAccountId,270		property_permissions: Vec<PropertyKeyPermission>,271	) -> DispatchResultWithPostInfo {272		let weight =273			<CommonWeights<T>>::set_token_property_permissions(property_permissions.len() as u32);274275		with_weight(276			<Pallet<T>>::set_token_property_permissions(self, sender, property_permissions),277			weight,278		)279	}280281	fn burn_item(282		&self,283		sender: T::CrossAccountId,284		token: TokenId,285		amount: u128,286	) -> DispatchResultWithPostInfo {287		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);288		if amount == 1 {289			with_weight(290				<Pallet<T>>::burn(self, &sender, token),291				<CommonWeights<T>>::burn_item(),292			)293		} else {294			Ok(().into())295		}296	}297298	fn burn_item_recursively(299		&self,300		sender: T::CrossAccountId,301		token: TokenId,302		self_budget: &dyn Budget,303		breadth_budget: &dyn Budget,304	) -> DispatchResultWithPostInfo {305		<Pallet<T>>::burn_recursively(self, &sender, token, self_budget, breadth_budget)306	}307308	fn transfer(309		&self,310		from: T::CrossAccountId,311		to: T::CrossAccountId,312		token: TokenId,313		amount: u128,314		nesting_budget: &dyn Budget,315	) -> DispatchResultWithPostInfo {316		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);317		ensure!(amount > 0, <CommonError<T>>::ZeroTransferNotAllowed);318319		with_weight(320			<Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),321			<CommonWeights<T>>::transfer(),322		)323	}324325	fn approve(326		&self,327		sender: T::CrossAccountId,328		spender: T::CrossAccountId,329		token: TokenId,330		amount: u128,331	) -> DispatchResultWithPostInfo {332		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);333334		with_weight(335			if amount == 1 {336				<Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))337			} else {338				<Pallet<T>>::set_allowance(self, &sender, token, None)339			},340			<CommonWeights<T>>::approve(),341		)342	}343344	fn transfer_from(345		&self,346		sender: T::CrossAccountId,347		from: T::CrossAccountId,348		to: T::CrossAccountId,349		token: TokenId,350		amount: u128,351		nesting_budget: &dyn Budget,352	) -> DispatchResultWithPostInfo {353		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);354		ensure!(amount > 0, <CommonError<T>>::ZeroTransferNotAllowed);355356		with_weight(357			<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),358			<CommonWeights<T>>::transfer_from(),359		)360	}361362	fn burn_from(363		&self,364		sender: T::CrossAccountId,365		from: T::CrossAccountId,366		token: TokenId,367		amount: u128,368		nesting_budget: &dyn Budget,369	) -> DispatchResultWithPostInfo {370		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);371372		if amount == 1 {373			with_weight(374				<Pallet<T>>::burn_from(self, &sender, &from, token, nesting_budget),375				<CommonWeights<T>>::burn_from(),376			)377		} else {378			Ok(().into())379		}380	}381382	fn check_nesting(383		&self,384		sender: T::CrossAccountId,385		from: (CollectionId, TokenId),386		under: TokenId,387		nesting_budget: &dyn Budget,388	) -> sp_runtime::DispatchResult {389		<Pallet<T>>::check_nesting(self, sender, from, under, nesting_budget)390	}391392	fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId)) {393		<Pallet<T>>::nest((self.id, under), to_nest);394	}395396	fn unnest(&self, under: TokenId, to_unnest: (CollectionId, TokenId)) {397		<Pallet<T>>::unnest((self.id, under), to_unnest);398	}399400	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {401		<Owned<T>>::iter_prefix((self.id, account))402			.map(|(id, _)| id)403			.collect()404	}405406	fn collection_tokens(&self) -> Vec<TokenId> {407		<TokenData<T>>::iter_prefix((self.id,))408			.map(|(id, _)| id)409			.collect()410	}411412	fn token_exists(&self, token: TokenId) -> bool {413		<Pallet<T>>::token_exists(self, token)414	}415416	fn last_token_id(&self) -> TokenId {417		TokenId(<TokensMinted<T>>::get(self.id))418	}419420	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {421		<TokenData<T>>::get((self.id, token)).map(|t| t.owner)422	}423424	/// Returns token owners.425	fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {426		self.token_owner(token).map_or_else(|| vec![], |t| vec![t])427	}428429	fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {430		<Pallet<T>>::token_properties((self.id, token_id))431			.get(key)432			.cloned()433	}434435	fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {436		let properties = <Pallet<T>>::token_properties((self.id, token_id));437438		keys.map(|keys| {439			keys.into_iter()440				.filter_map(|key| {441					properties.get(&key).map(|value| Property {442						key,443						value: value.clone(),444					})445				})446				.collect()447		})448		.unwrap_or_else(|| {449			properties450				.into_iter()451				.map(|(key, value)| Property { key, value })452				.collect()453		})454	}455456	fn total_supply(&self) -> u32 {457		<Pallet<T>>::total_supply(self)458	}459460	fn account_balance(&self, account: T::CrossAccountId) -> u32 {461		<AccountBalance<T>>::get((self.id, account))462	}463464	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {465		if <TokenData<T>>::get((self.id, token))466			.map(|a| a.owner == account)467			.unwrap_or(false)468		{469			1470		} else {471			0472		}473	}474475	fn allowance(476		&self,477		sender: T::CrossAccountId,478		spender: T::CrossAccountId,479		token: TokenId,480	) -> u128 {481		if <TokenData<T>>::get((self.id, token))482			.map(|a| a.owner != sender)483			.unwrap_or(true)484		{485			0486		} else if <Allowance<T>>::get((self.id, token)) == Some(spender) {487			1488		} else {489			0490		}491	}492493	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {494		None495	}496497	fn total_pieces(&self, token: TokenId) -> Option<u128> {498		if <TokenData<T>>::contains_key((self.id, token)) {499			Some(1)500		} else {501			None502		}503	}504}
modifiedpallets/refungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/refungible/CHANGELOG.md
+++ b/pallets/refungible/CHANGELOG.md
@@ -3,11 +3,6 @@
 All notable changes to this project will be documented in this file.
 
 <!-- bureaucrate goes here -->
-## [0.2.10] - 2022-12-05
-
-### Fixed
-
-- Transfer with zero pieces.
 
 ## [0.2.9] - 2022-11-18
 
modifiedpallets/refungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-refungible"
-version = "0.2.9"
+version = "0.2.8"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -727,8 +727,6 @@
 		amount: u128,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		ensure!(amount > 0, <CommonError<T>>::ZeroTransferNotAllowed);
-
 		ensure!(
 			collection.limits.transfers_enabled(),
 			<CommonError<T>>::TransferNotAllowed