git.delta.rocks / unique-network / refs/commits / 8065c75e5568

difftreelog

Merge pull request #463 from UniqueNetwork/feature/remove_const_data_rft

Yaroslav Bolyukin2022-08-03parents: #b21ac36 #a7dc6fb.patch.diff
in: master

10 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6311,7 +6311,7 @@
 
 [[package]]
 name = "pallet-refungible"
-version = "0.1.2"
+version = "0.2.0"
 dependencies = [
  "ethereum",
  "evm-coder",
@@ -12732,7 +12732,7 @@
 
 [[package]]
 name = "up-data-structs"
-version = "0.1.2"
+version = "0.2.0"
 dependencies = [
  "derivative",
  "frame-support",
modifiedpallets/refungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/refungible/CHANGELOG.md
+++ b/pallets/refungible/CHANGELOG.md
@@ -2,6 +2,11 @@
 
 All notable changes to this project will be documented in this file.
 
+## [v0.2.0] - 2022-08-01
+### Deprecated
+- `ItemData`
+- `TokenData`
+
 ## [v0.1.2] - 2022-07-14
 
 ### 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
123/// for the convenience of database access. Notably contains the token metadata.123/// for the convenience of database access. Notably contains the token metadata.
124#[struct_versioning::versioned(version = 2, upper)]124#[struct_versioning::versioned(version = 2, upper)]
125#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]125#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]
126#[deprecated(since = "0.2.0", note = "ItemData is no more contains usefull data")]
126pub struct ItemData {127pub struct ItemData {
127 pub const_data: BoundedVec<u8, CustomDataLimit>,128 pub const_data: BoundedVec<u8, CustomDataLimit>,
128129
162 type WeightInfo: WeightInfo;163 type WeightInfo: WeightInfo;
163 }164 }
164165
165 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);166 const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
166167
167 #[pallet::pallet]168 #[pallet::pallet]
168 #[pallet::storage_version(STORAGE_VERSION)]169 #[pallet::storage_version(STORAGE_VERSION)]
180 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;181 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
181182
182 /// Token data, used to partially describe a token.183 /// Token data, used to partially describe a token.
184 // TODO: remove
183 #[pallet::storage]185 #[pallet::storage]
186 #[deprecated(since = "0.2.0", note = "ItemData is no more contains usefull data")]
184 pub type TokenData<T: Config> = StorageNMap<187 pub type TokenData<T: Config> = StorageNMap<
185 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),188 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
186 Value = ItemData,189 Value = ItemData,
260 #[pallet::hooks]263 #[pallet::hooks]
261 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {264 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
262 fn on_runtime_upgrade() -> Weight {265 fn on_runtime_upgrade() -> Weight {
266 let storage_version = StorageVersion::get::<Pallet<T>>();
267 if storage_version < StorageVersion::new(2) {
268 <TokenData<T>>::remove_all(None);
269 }
263 StorageVersion::new(1).put::<Pallet<T>>();270 StorageVersion::new(2).put::<Pallet<T>>();
264271
265 0272 0
266 }273 }
373380
374 <TokensMinted<T>>::remove(id);381 <TokensMinted<T>>::remove(id);
375 <TokensBurnt<T>>::remove(id);382 <TokensBurnt<T>>::remove(id);
376 <TokenData<T>>::remove_prefix((id,), None);
377 <TotalSupply<T>>::remove_prefix((id,), None);383 <TotalSupply<T>>::remove_prefix((id,), None);
378 <Balance<T>>::remove_prefix((id,), None);384 <Balance<T>>::remove_prefix((id,), None);
379 <Allowance<T>>::remove_prefix((id,), None);385 <Allowance<T>>::remove_prefix((id,), None);
383 }389 }
384390
385 fn collection_has_tokens(collection_id: CollectionId) -> bool {391 fn collection_has_tokens(collection_id: CollectionId) -> bool {
386 <TokenData<T>>::iter_prefix((collection_id,))392 <TotalSupply<T>>::iter_prefix((collection_id,))
387 .next()393 .next()
388 .is_some()394 .is_some()
389 }395 }
397 .ok_or(ArithmeticError::Overflow)?;403 .ok_or(ArithmeticError::Overflow)?;
398404
399 <TokensBurnt<T>>::insert(collection.id, burnt);405 <TokensBurnt<T>>::insert(collection.id, burnt);
400 <TokenData<T>>::remove((collection.id, token_id));
401 <TokenProperties<T>>::remove((collection.id, token_id));406 <TokenProperties<T>>::remove((collection.id, token_id));
402 <TotalSupply<T>>::remove((collection.id, token_id));407 <TotalSupply<T>>::remove((collection.id, token_id));
403 <Balance<T>>::remove_prefix((collection.id, token_id), None);408 <Balance<T>>::remove_prefix((collection.id, token_id), None);
879 let token_id = first_token_id + i as u32 + 1;884 let token_id = first_token_id + i as u32 + 1;
880 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);885 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);
881
882 <TokenData<T>>::insert(
883 (collection.id, token_id),
884 ItemData {
885 const_data: data.const_data.clone(),
886 },
887 );
888886
889 for (user, amount) in data.users.iter() {887 for (user, amount) in data.users.iter() {
890 if *amount == 0 {888 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"))]
@@ -869,16 +859,6 @@
 	/// Extended data for create ReFungible item in case of
 	/// single token, which may have many owners
 	RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),
-}
-
-impl CreateItemData {
-	/// Get size of custom data.
-	pub fn data_size(&self) -> usize {
-		match self {
-			CreateItemData::ReFungible(data) => data.const_data.len(),
-			_ => 0,
-		}
-	}
 }
 
 impl From<CreateNftData> for CreateItemData {
modifiedruntime/common/src/sponsoring.rsdiffbeforeafterboth
--- a/runtime/common/src/sponsoring.rs
+++ b/runtime/common/src/sponsoring.rs
@@ -156,17 +156,13 @@
 pub fn withdraw_create_item<T: Config>(
 	collection: &CollectionHandle<T>,
 	who: &T::CrossAccountId,
-	_properties: &CreateItemData,
+	properties: &CreateItemData,
 ) -> Option<()> {
-	if _properties.data_size() as u32 > collection.limits.sponsored_data_size() {
-		return None;
-	}
-
 	// sponsor timeout
 	let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
 	let limit = collection
 		.limits
-		.sponsor_transfer_timeout(match _properties {
+		.sponsor_transfer_timeout(match properties {
 			CreateItemData::NFT(_) => NFT_SPONSOR_TRANSFER_TIMEOUT,
 			CreateItemData::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
 			CreateItemData::ReFungible(_) => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
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