difftreelog
fix add PropertyGuardData
in: master
3 files changed
pallets/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>)
}
pallets/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)?;
pallets/nonfungible/src/property_guard.rsdiffbeforeafterboth1use super::*;23pub struct PropertyGuard<'a, T: Config> {4 pub sender: &'a T::CrossAccountId,5 pub collection: &'a NonfungibleHandle<T>,6 pub token: TokenId,7 pub is_token_create: bool,8 budget: &'a dyn Budget,910 collection_admin_result: Option<DispatchResult>,11 token_owner_result: Option<DispatchResult>,12}1314impl<'a, T: Config> PropertyGuard<'a, T> {15 pub fn new(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 {23 sender,24 collection,25 token,26 is_token_create,27 budget,2829 collection_admin_result: None,30 token_owner_result: None,31 }32 }3334 pub fn check_collection_admin(&mut self) -> DispatchResult {35 *self36 .collection_admin_result37 .get_or_insert_with(|| self.collection.check_is_owner_or_admin(self.sender))38 }3940 pub fn check_token_owner(&mut self) -> DispatchResult {41 *self.token_owner_result.get_or_insert_with(|| {42 let is_owned = <PalletStructure<T>>::check_indirectly_owned(43 self.sender.clone(),44 self.collection.id,45 self.token,46 None,47 self.budget,48 )?;4950 if is_owned {51 Ok(())52 } else {53 Err(<CommonError<T>>::NoPermission.into())54 }55 })56 }57}