git.delta.rocks / unique-network / refs/commits / 64965b2ec466

difftreelog

fix add PropertyGuardData

Daniel Shiposha2022-07-04parent: #7871a15.patch.diff
in: master

3 files changed

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -37,7 +37,7 @@
 
 use crate::{
 	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
-	SelfWeightOf, weights::WeightInfo, TokenProperties, property_guard::PropertyGuard,
+	SelfWeightOf, weights::WeightInfo, TokenProperties, property_guard::*,
 };
 
 #[solidity_interface(name = "TokenProperties")]
@@ -83,12 +83,18 @@
 		let value = value.try_into().map_err(|_| "value too long")?;
 
 		let is_token_create = false;
-		let budget = self
+		let nesting_budget = self
 			.recorder
 			.weight_calls_budget(<StructureWeight<T>>::find_parent());
 
 		let mut guard =
-			PropertyGuard::new(&caller, self, TokenId(token_id), is_token_create, &budget);
+			PropertyGuard::new(PropertyGuardData {
+				sender: &caller,
+				collection: self,
+				token_id: TokenId(token_id),
+				is_token_create,
+				nesting_budget: &nesting_budget
+			});
 
 		<Pallet<T>>::set_token_property(Property { key, value }, &mut guard)
 			.map_err(dispatch_to_evm::<T>)
@@ -102,12 +108,18 @@
 			.map_err(|_| "key too long")?;
 
 		let is_token_create = false;
-		let budget = self
+		let nesting_budget = self
 			.recorder
 			.weight_calls_budget(<StructureWeight<T>>::find_parent());
 
 		let mut guard =
-			PropertyGuard::new(&caller, self, TokenId(token_id), is_token_create, &budget);
+			PropertyGuard::new(PropertyGuardData {
+				sender: &caller,
+				collection: self,
+				token_id: TokenId(token_id),
+				is_token_create,
+				nesting_budget: &nesting_budget
+			});
 
 		<Pallet<T>>::delete_token_property(key, &mut guard).map_err(dispatch_to_evm::<T>)
 	}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -494,7 +494,7 @@
 	) -> DispatchResult {
 		Self::check_token_change_permission(&property.key, guard)?;
 
-		<TokenProperties<T>>::try_mutate((guard.collection.id, guard.token), |properties| {
+		<TokenProperties<T>>::try_mutate((guard.collection.id, guard.token_id), |properties| {
 			let property = property.clone();
 			properties.try_set(property.key, property.value)
 		})
@@ -502,7 +502,7 @@
 
 		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
 			guard.collection.id,
-			guard.token,
+			guard.token_id,
 			property.key,
 		));
 
@@ -518,13 +518,13 @@
 		is_token_create: bool,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		let mut guard = PropertyGuard::new(
+		let mut guard = PropertyGuard::new(PropertyGuardData {
 			sender,
 			collection,
 			token_id,
 			is_token_create,
 			nesting_budget,
-		);
+		});
 
 		for property in properties {
 			Self::set_token_property(property, &mut guard)?;
@@ -539,14 +539,14 @@
 	) -> DispatchResult {
 		Self::check_token_change_permission(&property_key, guard)?;
 
-		<TokenProperties<T>>::try_mutate((guard.collection.id, guard.token), |properties| {
+		<TokenProperties<T>>::try_mutate((guard.collection.id, guard.token_id), |properties| {
 			properties.remove(&property_key)
 		})
 		.map_err(<CommonError<T>>::from)?;
 
 		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
 			guard.collection.id,
-			guard.token,
+			guard.token_id,
 			property_key,
 		));
 
@@ -562,7 +562,7 @@
 			.cloned()
 			.unwrap_or_else(PropertyPermission::none);
 
-		let is_property_exists = TokenProperties::<T>::get((guard.collection.id, guard.token))
+		let is_property_exists = TokenProperties::<T>::get((guard.collection.id, guard.token_id))
 			.get(property_key)
 			.is_some();
 
@@ -606,13 +606,13 @@
 	) -> DispatchResult {
 		let is_token_create = false;
 
-		let mut guard = PropertyGuard::new(
+		let mut guard = PropertyGuard::new(PropertyGuardData {
 			sender,
 			collection,
 			token_id,
 			is_token_create,
 			nesting_budget,
-		);
+		});
 
 		for key in property_keys {
 			Self::delete_token_property(key, &mut guard)?;
modifiedpallets/nonfungible/src/property_guard.rsdiffbeforeafterboth
3pub struct PropertyGuard<'a, T: Config> {3pub struct PropertyGuard<'a, T: Config> {
4 pub sender: &'a T::CrossAccountId,4 pub sender: &'a T::CrossAccountId,
5 pub collection: &'a NonfungibleHandle<T>,5 pub collection: &'a NonfungibleHandle<T>,
6 pub token: TokenId,6 pub token_id: TokenId,
7 pub is_token_create: bool,7 pub is_token_create: bool,
8 budget: &'a dyn Budget,8 nesting_budget: &'a dyn Budget,
99
10 collection_admin_result: Option<DispatchResult>,10 collection_admin_result: Option<DispatchResult>,
11 token_owner_result: Option<DispatchResult>,11 token_owner_result: Option<DispatchResult>,
12}12}
13
14pub struct PropertyGuardData<'a, T: Config> {
15 pub sender: &'a T::CrossAccountId,
16 pub collection: &'a NonfungibleHandle<T>,
17 pub token_id: TokenId,
18 pub is_token_create: bool,
19 pub nesting_budget: &'a dyn Budget,
20}
1321
14impl<'a, T: Config> PropertyGuard<'a, T> {22impl<'a, T: Config> PropertyGuard<'a, T> {
15 pub fn new(23 pub fn new(data: PropertyGuardData<'a, T>) -> Self {
16 sender: &'a T::CrossAccountId,
17 collection: &'a NonfungibleHandle<T>,
18 token: TokenId,
19 is_token_create: bool,
20 budget: &'a dyn Budget,
21 ) -> Self {
22 Self {24 Self {
23 sender,25 sender: data.sender,
24 collection,26 collection: data.collection,
25 token,27 token_id: data.token_id,
26 is_token_create,28 is_token_create: data.is_token_create,
27 budget,29 nesting_budget: data.nesting_budget,
2830
29 collection_admin_result: None,31 collection_admin_result: None,
30 token_owner_result: None,32 token_owner_result: None,
42 let is_owned = <PalletStructure<T>>::check_indirectly_owned(44 let is_owned = <PalletStructure<T>>::check_indirectly_owned(
43 self.sender.clone(),45 self.sender.clone(),
44 self.collection.id,46 self.collection.id,
45 self.token,47 self.token_id,
46 None,48 None,
47 self.budget,49 self.nesting_budget,
48 )?;50 )?;
4951
50 if is_owned {52 if is_owned {