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
63116311
6312[[package]]6312[[package]]
6313name = "pallet-refungible"6313name = "pallet-refungible"
6314version = "0.1.2"6314version = "0.2.0"
6315dependencies = [6315dependencies = [
6316 "ethereum",6316 "ethereum",
6317 "evm-coder",6317 "evm-coder",
1273212732
12733[[package]]12733[[package]]
12734name = "up-data-structs"12734name = "up-data-structs"
12735version = "0.1.2"12735version = "0.2.0"
12736dependencies = [12736dependencies = [
12737 "derivative",12737 "derivative",
12738 "frame-support",12738 "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
1[package]1[package]
2name = "pallet-refungible"2name = "pallet-refungible"
3version = "0.1.2"3version = "0.2.0"
4license = "GPLv3"4license = "GPLv3"
5edition = "2021"5edition = "2021"
66
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
3232
33use crate::{33use crate::{
34 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,34 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,
35 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,35 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted, TotalSupply,
36};36};
3737
38macro_rules! max_weight_of {38macro_rules! max_weight_of {
155) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {155) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {
156 match data {156 match data {
157 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {157 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {
158 const_data: data.const_data,
159 users: {158 users: {
160 let mut out = BTreeMap::new();159 let mut out = BTreeMap::new();
161 out.insert(to.clone(), data.pieces);160 out.insert(to.clone(), data.pieces);
421 }420 }
422421
423 fn collection_tokens(&self) -> Vec<TokenId> {422 fn collection_tokens(&self) -> Vec<TokenId> {
424 <TokenData<T>>::iter_prefix((self.id,))423 <TotalSupply<T>>::iter_prefix((self.id,))
425 .map(|(id, _)| id)424 .map(|(id, _)| id)
426 .collect()425 .collect()
427 }426 }
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
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- `CreateReFungibleData::const_data`
58
6## [v0.1.2] - 2022-07-259## [v0.1.2] - 2022-07-25
7### Added10### Added
modifiedprimitives/data-structs/Cargo.tomldiffbeforeafterboth
6license = 'GPLv3'6license = 'GPLv3'
7homepage = "https://unique.network"7homepage = "https://unique.network"
8repository = 'https://github.com/UniqueNetwork/unique-chain'8repository = 'https://github.com/UniqueNetwork/unique-chain'
9version = '0.1.2'9version = '0.2.0'
1010
11[dependencies]11[dependencies]
12scale-info = { version = "2.0.1", default-features = false, features = [12scale-info = { version = "2.0.1", default-features = false, features = [
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
780#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]780#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
781#[derivative(Debug)]781#[derivative(Debug)]
782pub struct CreateReFungibleData {782pub struct CreateReFungibleData {
783 /// Immutable metadata of the token783 /// Number of pieces the RFT is split into
784 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
785 #[derivative(Debug(format_with = "bounded::vec_debug"))]
786 pub const_data: BoundedVec<u8, CustomDataLimit>,
787
788 /// Pieces of created token.
789 pub pieces: u128,784 pub pieces: u128,
790785
791 /// Key-value pairs used to describe the token as metadata786 /// Key-value pairs used to describe the token as metadata
832#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]827#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
833#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]828#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
834pub struct CreateRefungibleExData<CrossAccountId> {829pub struct CreateRefungibleExData<CrossAccountId> {
835 /// Custom data stored in token.
836 #[derivative(Debug(format_with = "bounded::vec_debug"))]
837 pub const_data: BoundedVec<u8, CustomDataLimit>,
838
839 /// Users who will be assigned the specified number of token parts.
840 #[derivative(Debug(format_with = "bounded::map_debug"))]830 #[derivative(Debug(format_with = "bounded::map_debug"))]
841 pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,831 pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,
842 #[derivative(Debug(format_with = "bounded::vec_debug"))]832 #[derivative(Debug(format_with = "bounded::vec_debug"))]
871 RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),861 RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),
872}862}
873
874impl CreateItemData {
875 /// Get size of custom data.
876 pub fn data_size(&self) -> usize {
877 match self {
878 CreateItemData::ReFungible(data) => data.const_data.len(),
879 _ => 0,
880 }
881 }
882}
883863
884impl From<CreateNftData> for CreateItemData {864impl From<CreateNftData> for CreateItemData {
885 fn from(item: CreateNftData) -> Self {865 fn from(item: CreateNftData) -> Self {
modifiedruntime/common/src/sponsoring.rsdiffbeforeafterboth
156pub fn withdraw_create_item<T: Config>(156pub fn withdraw_create_item<T: Config>(
157 collection: &CollectionHandle<T>,157 collection: &CollectionHandle<T>,
158 who: &T::CrossAccountId,158 who: &T::CrossAccountId,
159 _properties: &CreateItemData,159 properties: &CreateItemData,
160) -> Option<()> {160) -> Option<()> {
161 if _properties.data_size() as u32 > collection.limits.sponsored_data_size() {
162 return None;
163 }
164
165 // sponsor timeout161 // sponsor timeout
166 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;162 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
167 let limit = collection163 let limit = collection
168 .limits164 .limits
169 .sponsor_transfer_timeout(match _properties {165 .sponsor_transfer_timeout(match properties {
170 CreateItemData::NFT(_) => NFT_SPONSOR_TRANSFER_TIMEOUT,166 CreateItemData::NFT(_) => NFT_SPONSOR_TRANSFER_TIMEOUT,
171 CreateItemData::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,167 CreateItemData::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
172 CreateItemData::ReFungible(_) => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,168 CreateItemData::ReFungible(_) => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
modifiedruntime/tests/src/tests.rsdiffbeforeafterboth
6262
63fn default_re_fungible_data() -> CreateReFungibleData {63fn default_re_fungible_data() -> CreateReFungibleData {
64 CreateReFungibleData {64 CreateReFungibleData {
65 const_data: vec![1, 2, 3].try_into().unwrap(),
66 pieces: 1023,65 pieces: 1023,
67 properties: vec![Property {66 properties: vec![Property {
68 key: b"test-prop".to_vec().try_into().unwrap(),67 key: b"test-prop".to_vec().try_into().unwrap(),
298 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));297 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
299 let balance =298 let balance =
300 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));299 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
301 assert_eq!(item.const_data, data.const_data.into_inner());
302 assert_eq!(balance, 1023);300 assert_eq!(balance, 1023);
303 });301 });
304}302}
333 ));331 ));
334 let balance =332 let balance =
335 <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));333 <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));
336 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
337 assert_eq!(balance, 1023);334 assert_eq!(balance, 1023);
338 }335 }
339 });336 });
446 let data = default_re_fungible_data();443 let data = default_re_fungible_data();
447 create_test_item(collection_id, &data.clone().into());444 create_test_item(collection_id, &data.clone().into());
448 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));445 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
449 assert_eq!(item.const_data, data.const_data.into_inner());
450 assert_eq!(446 assert_eq!(
451 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),447 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),
452 1448 1