git.delta.rocks / unique-network / refs/commits / 27f22a5bc9e8

difftreelog

cargo fmt

Daniel Shiposha2022-06-30parent: #a74fad6.patch.diff
in: master

3 files changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -16,15 +16,13 @@
 
 #![cfg_attr(not(feature = "std"), no_std)]
 
-use frame_support::{
-	pallet_prelude::*,
-	transactional,
-	BoundedVec,
-	dispatch::DispatchResult,
-};
+use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};
 use frame_system::{pallet_prelude::*, ensure_signed};
 use sp_runtime::{DispatchError, Permill, traits::StaticLookup};
-use sp_std::{vec::Vec, collections::{btree_set::BTreeSet, btree_map::BTreeMap}};
+use sp_std::{
+	vec::Vec,
+	collections::{btree_set::BTreeSet, btree_map::BTreeMap},
+};
 use up_data_structs::{*, mapping::TokenAddressMapping};
 use pallet_common::{
 	Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations,
@@ -500,7 +498,8 @@
 					collection_id,
 					nft_id,
 					RmrkProperty::PendingNftAccept
-				)?.is_none(),
+				)?
+				.is_none(),
 				<Error<T>>::NoPermission
 			);
 
@@ -539,7 +538,7 @@
 							PropertyScope::Rmrk,
 							Self::rmrk_property::<Option<PendingTarget>>(
 								PendingNftAccept,
-								&Some((target_collection_id, target_nft_id.into()))
+								&Some((target_collection_id, target_nft_id.into())),
 							)?,
 						)?;
 
@@ -642,7 +641,7 @@
 			let pending_target = Self::get_nft_property_decoded::<Option<PendingTarget>>(
 				collection_id,
 				nft_id,
-				RmrkProperty::PendingNftAccept
+				RmrkProperty::PendingNftAccept,
 			)?;
 
 			if let Some(pending_target) = pending_target {
@@ -694,15 +693,16 @@
 				<Error<T>>::NoAvailableNftId
 			);
 
-
 			let pending_target = Self::get_nft_property_decoded::<Option<PendingTarget>>(
 				collection_id,
 				nft_id,
-				RmrkProperty::PendingNftAccept
+				RmrkProperty::PendingNftAccept,
 			)?;
 
 			match pending_target {
-				Some(pending_target) => Self::remove_pending_child(pending_target, (rmrk_collection_id, rmrk_nft_id))?,
+				Some(pending_target) => {
+					Self::remove_pending_child(pending_target, (rmrk_collection_id, rmrk_nft_id))?
+				}
 				None => return Err(<Error<T>>::CannotRejectNonPendingNft.into()),
 			}
 
@@ -995,14 +995,14 @@
 				|value| -> DispatchResult {
 					let mut bases: BasesMap = match value {
 						Some(value) => Self::decode_property(value)?,
-						None => BasesMap::new()
+						None => BasesMap::new(),
 					};
-	
+
 					*bases.entry(base_id).or_insert(0) += 1;
-	
+
 					*value = Some(Self::encode_property(&bases)?);
 					Ok(())
-				}
+				},
 			)?;
 
 			Self::deposit_event(Event::ResourceAdded {
@@ -1249,12 +1249,15 @@
 		)
 	}
 
-	fn iterate_pending_children(collection_id: CollectionId, nft_id: TokenId) -> Result<impl Iterator<Item=PendingChild>, DispatchError> {
+	fn iterate_pending_children(
+		collection_id: CollectionId,
+		nft_id: TokenId,
+	) -> Result<impl Iterator<Item = PendingChild>, DispatchError> {
 		let property = <PalletNft<T>>::token_aux_property((
 			collection_id,
 			nft_id,
 			PropertyScope::Rmrk,
-			Self::rmrk_property_key(PendingChildren)?
+			Self::rmrk_property_key(PendingChildren)?,
 		));
 
 		let pending_children = match property {
@@ -1345,8 +1348,9 @@
 			collection_id,
 			nft_id,
 			scope,
-			resource_id_key.clone()
-		)).ok_or(<Error<T>>::ResourceDoesntExist)?;
+			resource_id_key.clone(),
+		))
+		.ok_or(<Error<T>>::ResourceDoesntExist)?;
 
 		let resource_info: RmrkResourceInfo = Self::decode_property(&resource)?;
 
@@ -1392,7 +1396,7 @@
 			|value| -> DispatchResult {
 				let mut bases: BasesMap = match value {
 					Some(value) => Self::decode_property(value)?,
-					None => BasesMap::new()
+					None => BasesMap::new(),
 				};
 
 				let remaining = bases.get(&base_id);
@@ -1405,7 +1409,7 @@
 
 				*value = Some(Self::encode_property(&bases)?);
 				Ok(())
-			}
+			},
 		)
 	}
 
modifiedpallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth
before · pallets/proxy-rmrk-core/src/property.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 super::*;18use up_data_structs::PropertyScope;19use core::convert::AsRef;2021pub const RESOURCE_ID_PREFIX: &str = "rsid-";22pub const USER_PROPERTY_PREFIX: &str = "userprop-";2324pub enum RmrkProperty<'r> {25	Metadata,26	CollectionType,27	RmrkInternalCollectionId,28	TokenType,29	Transferable,30	RoyaltyInfo,31	Equipped,32	ResourcePriorities,33	NextResourceId,34	ResourceId(RmrkResourceId),35	PendingNftAccept,36	PendingChildren,37	AssociatedBases,38	Parts,39	Base,40	Src,41	EquippedNft,42	BaseType,43	ExternalPartId,44	EquippableList,45	ZIndex,46	ThemeName,47	ThemeInherit,48	UserProperty(&'r [u8]),49}5051impl<'r> RmrkProperty<'r> {52	pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {53		fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {54			container.as_ref()55		}5657		macro_rules! key {58            ($($component:expr),+) => {59                PropertyKey::try_from([$(key!(@ &$component)),+].concat())60                    .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)61            };6263            (@ $key:expr) => {64                get_bytes($key)65            };66        }6768		match self {69			Self::Metadata => key!("metadata"),70			Self::CollectionType => key!("collection-type"),71			Self::RmrkInternalCollectionId => key!("internal-id"),72			Self::TokenType => key!("token-type"),73			Self::Transferable => key!("transferable"),74			Self::RoyaltyInfo => key!("royalty-info"),75			Self::Equipped => key!("equipped"),76			Self::ResourcePriorities => key!("resource-priorities"),77			Self::NextResourceId => key!("next-resource-id"),78			Self::ResourceId(id) => key!(RESOURCE_ID_PREFIX, id.to_le_bytes()),79			Self::PendingNftAccept => key!("pending-nft-accept"),80			Self::PendingChildren => key!("pending-children"),81			Self::AssociatedBases => key!("assoc-bases"),82			Self::Parts => key!("parts"),83			Self::Base => key!("base"),84			Self::Src => key!("src"),85			Self::EquippedNft => key!("equipped-nft"),86			Self::BaseType => key!("base-type"),87			Self::ExternalPartId => key!("ext-part-id"),88			Self::EquippableList => key!("equippable-list"),89			Self::ZIndex => key!("z-index"),90			Self::ThemeName => key!("theme-name"),91			Self::ThemeInherit => key!("theme-inherit"),92			Self::UserProperty(name) => key!(USER_PROPERTY_PREFIX, name),93		}94	}95}9697pub fn strip_key_prefix(key: &PropertyKey, prefix: &str) -> Option<PropertyKey> {98	let key_prefix = PropertyKey::try_from(prefix.as_bytes().to_vec()).ok()?;99	let key_prefix = PropertyScope::Rmrk.apply(key_prefix).ok()?;100101	key.as_slice().strip_prefix(key_prefix.as_slice())?102		.to_vec().try_into().ok()103}104105pub fn is_valid_key_prefix(key: &PropertyKey, prefix: &str) -> bool {106	strip_key_prefix(key, prefix).is_some()107}
after · pallets/proxy-rmrk-core/src/property.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 super::*;18use up_data_structs::PropertyScope;19use core::convert::AsRef;2021pub const RESOURCE_ID_PREFIX: &str = "rsid-";22pub const USER_PROPERTY_PREFIX: &str = "userprop-";2324pub enum RmrkProperty<'r> {25	Metadata,26	CollectionType,27	RmrkInternalCollectionId,28	TokenType,29	Transferable,30	RoyaltyInfo,31	Equipped,32	ResourcePriorities,33	NextResourceId,34	ResourceId(RmrkResourceId),35	PendingNftAccept,36	PendingChildren,37	AssociatedBases,38	Parts,39	Base,40	Src,41	EquippedNft,42	BaseType,43	ExternalPartId,44	EquippableList,45	ZIndex,46	ThemeName,47	ThemeInherit,48	UserProperty(&'r [u8]),49}5051impl<'r> RmrkProperty<'r> {52	pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {53		fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {54			container.as_ref()55		}5657		macro_rules! key {58            ($($component:expr),+) => {59                PropertyKey::try_from([$(key!(@ &$component)),+].concat())60                    .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)61            };6263            (@ $key:expr) => {64                get_bytes($key)65            };66        }6768		match self {69			Self::Metadata => key!("metadata"),70			Self::CollectionType => key!("collection-type"),71			Self::RmrkInternalCollectionId => key!("internal-id"),72			Self::TokenType => key!("token-type"),73			Self::Transferable => key!("transferable"),74			Self::RoyaltyInfo => key!("royalty-info"),75			Self::Equipped => key!("equipped"),76			Self::ResourcePriorities => key!("resource-priorities"),77			Self::NextResourceId => key!("next-resource-id"),78			Self::ResourceId(id) => key!(RESOURCE_ID_PREFIX, id.to_le_bytes()),79			Self::PendingNftAccept => key!("pending-nft-accept"),80			Self::PendingChildren => key!("pending-children"),81			Self::AssociatedBases => key!("assoc-bases"),82			Self::Parts => key!("parts"),83			Self::Base => key!("base"),84			Self::Src => key!("src"),85			Self::EquippedNft => key!("equipped-nft"),86			Self::BaseType => key!("base-type"),87			Self::ExternalPartId => key!("ext-part-id"),88			Self::EquippableList => key!("equippable-list"),89			Self::ZIndex => key!("z-index"),90			Self::ThemeName => key!("theme-name"),91			Self::ThemeInherit => key!("theme-inherit"),92			Self::UserProperty(name) => key!(USER_PROPERTY_PREFIX, name),93		}94	}95}9697pub fn strip_key_prefix(key: &PropertyKey, prefix: &str) -> Option<PropertyKey> {98	let key_prefix = PropertyKey::try_from(prefix.as_bytes().to_vec()).ok()?;99	let key_prefix = PropertyScope::Rmrk.apply(key_prefix).ok()?;100101	key.as_slice()102		.strip_prefix(key_prefix.as_slice())?103		.to_vec()104		.try_into()105		.ok()106}107108pub fn is_valid_key_prefix(key: &PropertyKey, prefix: &str) -> bool {109	strip_key_prefix(key, prefix).is_some()110}
modifiedpallets/proxy-rmrk-core/src/rpc.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/rpc.rs
+++ b/pallets/proxy-rmrk-core/src/rpc.rs
@@ -141,11 +141,12 @@
 				})
 			})
 			.chain(
-				<Pallet<T>>::iterate_pending_children(collection_id, nft_id)?
-					.map(|(child_collection, child_nft_id)| RmrkNftChild {
+				<Pallet<T>>::iterate_pending_children(collection_id, nft_id)?.map(
+					|(child_collection, child_nft_id)| RmrkNftChild {
 						collection_id: child_collection,
 						nft_id: child_nft_id,
-					})
+					},
+				),
 			)
 			.collect(),
 	)