git.delta.rocks / unique-network / refs/commits / 3a3be8f24ac9

difftreelog

major: move RFT const data to depricated.

Trubnikov Sergey2022-08-01parent: #4247b84.patch.diff
in: master

9 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6320,7 +6320,7 @@
 
 [[package]]
 name = "pallet-refungible"
-version = "0.1.2"
+version = "0.2.0"
 dependencies = [
  "ethereum",
  "evm-coder",
@@ -12737,7 +12737,7 @@
 
 [[package]]
 name = "up-data-structs"
-version = "0.1.2"
+version = "0.2.0"
 dependencies = [
  "derivative",
  "frame-support",
modifiedpallets/refungible/CHANGELOG.mddiffbeforeafterboth
22
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
44
5## [v0.2.0] - 2022-08-01
6### Deprecated
7- `ItemData`
8- `TokenData`
9
5## [v0.1.2] - 2022-07-1410## [v0.1.2] - 2022-07-14
611
7### Other changes12### Other changes
modifiedpallets/refungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-refungible"
-version = "0.1.2"
+version = "0.2.0"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -32,7 +32,7 @@
 
 use crate::{
 	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,
-	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,
+	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted, TotalSupply,
 };
 
 macro_rules! max_weight_of {
@@ -155,7 +155,6 @@
 ) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {
 	match data {
 		up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {
-			const_data: data.const_data,
 			users: {
 				let mut out = BTreeMap::new();
 				out.insert(to.clone(), data.pieces);
@@ -421,7 +420,7 @@
 	}
 
 	fn collection_tokens(&self) -> Vec<TokenId> {
-		<TokenData<T>>::iter_prefix((self.id,))
+		<TotalSupply<T>>::iter_prefix((self.id,))
 			.map(|(id, _)| id)
 			.collect()
 	}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -123,6 +123,7 @@
 /// for the convenience of database access. Notably contains the token metadata.
 #[struct_versioning::versioned(version = 2, upper)]
 #[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]
+#[deprecated(since = "0.2.0", note = "ItemData is no more contains usefull data")]
 pub struct ItemData {
 	pub const_data: BoundedVec<u8, CustomDataLimit>,
 
@@ -180,7 +181,9 @@
 		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
 
 	/// Token data, used to partially describe a token.
+	// TODO: remove
 	#[pallet::storage]
+	#[deprecated(since = "0.2.0", note = "ItemData is no more contains usefull data")]
 	pub type TokenData<T: Config> = StorageNMap<
 		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
 		Value = ItemData,
@@ -260,10 +263,13 @@
 	#[pallet::hooks]
 	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
 		fn on_runtime_upgrade() -> Weight {
-			if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
+			let storage_version = StorageVersion::get::<Pallet<T>>();
+			if storage_version < StorageVersion::new(1) {
 				<TokenData<T>>::translate_values::<ItemDataVersion1, _>(|v| {
 					Some(<ItemDataVersion2>::from(v))
 				})
+			} else if storage_version < StorageVersion::new(2) {
+				<TokenData<T>>::remove_all(None);
 			}
 
 			0
@@ -377,7 +383,6 @@
 
 		<TokensMinted<T>>::remove(id);
 		<TokensBurnt<T>>::remove(id);
-		<TokenData<T>>::remove_prefix((id,), None);
 		<TotalSupply<T>>::remove_prefix((id,), None);
 		<Balance<T>>::remove_prefix((id,), None);
 		<Allowance<T>>::remove_prefix((id,), None);
@@ -387,7 +392,7 @@
 	}
 
 	fn collection_has_tokens(collection_id: CollectionId) -> bool {
-		<TokenData<T>>::iter_prefix((collection_id,))
+		<TotalSupply<T>>::iter_prefix((collection_id,))
 			.next()
 			.is_some()
 	}
@@ -401,7 +406,6 @@
 			.ok_or(ArithmeticError::Overflow)?;
 
 		<TokensBurnt<T>>::insert(collection.id, burnt);
-		<TokenData<T>>::remove((collection.id, token_id));
 		<TokenProperties<T>>::remove((collection.id, token_id));
 		<TotalSupply<T>>::remove((collection.id, token_id));
 		<Balance<T>>::remove_prefix((collection.id, token_id), None);
@@ -882,13 +886,6 @@
 			for (i, data) in data.iter().enumerate() {
 				let token_id = first_token_id + i as u32 + 1;
 				<TotalSupply<T>>::insert((collection.id, token_id), totals[i]);
-
-				<TokenData<T>>::insert(
-					(collection.id, token_id),
-					ItemData {
-						const_data: data.const_data.clone(),
-					},
-				);
 
 				for (user, amount) in data.users.iter() {
 					if *amount == 0 {
modifiedprimitives/data-structs/CHANGELOG.mddiffbeforeafterboth
--- a/primitives/data-structs/CHANGELOG.md
+++ b/primitives/data-structs/CHANGELOG.md
@@ -2,6 +2,9 @@
 
 All notable changes to this project will be documented in this file.
 
+## [v0.2.0] - 2022-08-01
+### Deprecated
+- `CreateReFungibleData::const_data`
 
 ## [v0.1.2] - 2022-07-25
 ### Added
modifiedprimitives/data-structs/Cargo.tomldiffbeforeafterboth
--- a/primitives/data-structs/Cargo.toml
+++ b/primitives/data-structs/Cargo.toml
@@ -6,7 +6,7 @@
 license = 'GPLv3'
 homepage = "https://unique.network"
 repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = '0.1.2'
+version = '0.2.0'
 
 [dependencies]
 scale-info = { version = "2.0.1", default-features = false, features = [
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -780,12 +780,7 @@
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 #[derivative(Debug)]
 pub struct CreateReFungibleData {
-	/// Immutable metadata of the token
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
-	#[derivative(Debug(format_with = "bounded::vec_debug"))]
-	pub const_data: BoundedVec<u8, CustomDataLimit>,
-
-	/// Pieces of created token.
+	/// Number of pieces the RFT is split into
 	pub pieces: u128,
 
 	/// Key-value pairs used to describe the token as metadata
@@ -832,11 +827,6 @@
 #[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
 #[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
 pub struct CreateRefungibleExData<CrossAccountId> {
-	/// Custom data stored in token.
-	#[derivative(Debug(format_with = "bounded::vec_debug"))]
-	pub const_data: BoundedVec<u8, CustomDataLimit>,
-
-	/// Users who will be assigned the specified number of token parts.
 	#[derivative(Debug(format_with = "bounded::map_debug"))]
 	pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,
 	#[derivative(Debug(format_with = "bounded::vec_debug"))]
@@ -874,10 +864,7 @@
 impl CreateItemData {
 	/// Get size of custom data.
 	pub fn data_size(&self) -> usize {
-		match self {
-			CreateItemData::ReFungible(data) => data.const_data.len(),
-			_ => 0,
-		}
+		0
 	}
 }
 
modifiedruntime/tests/src/tests.rsdiffbeforeafterboth
--- a/runtime/tests/src/tests.rs
+++ b/runtime/tests/src/tests.rs
@@ -62,7 +62,6 @@
 
 fn default_re_fungible_data() -> CreateReFungibleData {
 	CreateReFungibleData {
-		const_data: vec![1, 2, 3].try_into().unwrap(),
 		pieces: 1023,
 		properties: vec![Property {
 			key: b"test-prop".to_vec().try_into().unwrap(),
@@ -298,7 +297,6 @@
 		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
 		let balance =
 			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
-		assert_eq!(item.const_data, data.const_data.into_inner());
 		assert_eq!(balance, 1023);
 	});
 }
@@ -333,7 +331,6 @@
 			));
 			let balance =
 				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));
-			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
 			assert_eq!(balance, 1023);
 		}
 	});
@@ -446,7 +443,6 @@
 		let data = default_re_fungible_data();
 		create_test_item(collection_id, &data.clone().into());
 		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
-		assert_eq!(item.const_data, data.const_data.into_inner());
 		assert_eq!(
 			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
 			1