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
63206320
6321[[package]]6321[[package]]
6322name = "pallet-refungible"6322name = "pallet-refungible"
6323version = "0.1.2"6323version = "0.2.0"
6324dependencies = [6324dependencies = [
6325 "ethereum",6325 "ethereum",
6326 "evm-coder",6326 "evm-coder",
1273712737
12738[[package]]12738[[package]]
12739name = "up-data-structs"12739name = "up-data-structs"
12740version = "0.1.2"12740version = "0.2.0"
12741dependencies = [12741dependencies = [
12742 "derivative",12742 "derivative",
12743 "frame-support",12743 "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
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 {
263 if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {266 let storage_version = StorageVersion::get::<Pallet<T>>();
267 if storage_version < StorageVersion::new(1) {
264 <TokenData<T>>::translate_values::<ItemDataVersion1, _>(|v| {268 <TokenData<T>>::translate_values::<ItemDataVersion1, _>(|v| {
265 Some(<ItemDataVersion2>::from(v))269 Some(<ItemDataVersion2>::from(v))
266 })270 })
267 }271 } else if storage_version < StorageVersion::new(2) {
272 <TokenData<T>>::remove_all(None);
273 }
268274
269 0275 0
270 }276 }
377383
378 <TokensMinted<T>>::remove(id);384 <TokensMinted<T>>::remove(id);
379 <TokensBurnt<T>>::remove(id);385 <TokensBurnt<T>>::remove(id);
380 <TokenData<T>>::remove_prefix((id,), None);
381 <TotalSupply<T>>::remove_prefix((id,), None);386 <TotalSupply<T>>::remove_prefix((id,), None);
382 <Balance<T>>::remove_prefix((id,), None);387 <Balance<T>>::remove_prefix((id,), None);
383 <Allowance<T>>::remove_prefix((id,), None);388 <Allowance<T>>::remove_prefix((id,), None);
387 }392 }
388393
389 fn collection_has_tokens(collection_id: CollectionId) -> bool {394 fn collection_has_tokens(collection_id: CollectionId) -> bool {
390 <TokenData<T>>::iter_prefix((collection_id,))395 <TotalSupply<T>>::iter_prefix((collection_id,))
391 .next()396 .next()
392 .is_some()397 .is_some()
393 }398 }
401 .ok_or(ArithmeticError::Overflow)?;406 .ok_or(ArithmeticError::Overflow)?;
402407
403 <TokensBurnt<T>>::insert(collection.id, burnt);408 <TokensBurnt<T>>::insert(collection.id, burnt);
404 <TokenData<T>>::remove((collection.id, token_id));
405 <TokenProperties<T>>::remove((collection.id, token_id));409 <TokenProperties<T>>::remove((collection.id, token_id));
406 <TotalSupply<T>>::remove((collection.id, token_id));410 <TotalSupply<T>>::remove((collection.id, token_id));
407 <Balance<T>>::remove_prefix((collection.id, token_id), None);411 <Balance<T>>::remove_prefix((collection.id, token_id), None);
883 let token_id = first_token_id + i as u32 + 1;887 let token_id = first_token_id + i as u32 + 1;
884 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);888 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);
885
886 <TokenData<T>>::insert(
887 (collection.id, token_id),
888 ItemData {
889 const_data: data.const_data.clone(),
890 },
891 );
892889
893 for (user, amount) in data.users.iter() {890 for (user, amount) in data.users.iter() {
894 if *amount == 0 {891 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"))]
874impl CreateItemData {864impl CreateItemData {
875 /// Get size of custom data.865 /// Get size of custom data.
876 pub fn data_size(&self) -> usize {866 pub fn data_size(&self) -> usize {
877 match self {
878 CreateItemData::ReFungible(data) => data.const_data.len(),
879 _ => 0,867 0
880 }
881 }868 }
882}869}
883870
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