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.rsdiffbeforeafterboth494 ) -> DispatchResult {494 ) -> DispatchResult {495 Self::check_token_change_permission(&property.key, guard)?;495 Self::check_token_change_permission(&property.key, guard)?;496496497 <TokenProperties<T>>::try_mutate((guard.collection.id, guard.token), |properties| {497 <TokenProperties<T>>::try_mutate((guard.collection.id, guard.token_id), |properties| {498 let property = property.clone();498 let property = property.clone();499 properties.try_set(property.key, property.value)499 properties.try_set(property.key, property.value)500 })500 })501 .map_err(<CommonError<T>>::from)?;501 .map_err(<CommonError<T>>::from)?;502502503 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(503 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(504 guard.collection.id,504 guard.collection.id,505 guard.token,505 guard.token_id,506 property.key,506 property.key,507 ));507 ));508508518 is_token_create: bool,518 is_token_create: bool,519 nesting_budget: &dyn Budget,519 nesting_budget: &dyn Budget,520 ) -> DispatchResult {520 ) -> DispatchResult {521 let mut guard = PropertyGuard::new(521 let mut guard = PropertyGuard::new(PropertyGuardData {522 sender,522 sender,523 collection,523 collection,524 token_id,524 token_id,525 is_token_create,525 is_token_create,526 nesting_budget,526 nesting_budget,527 );527 });528528529 for property in properties {529 for property in properties {530 Self::set_token_property(property, &mut guard)?;530 Self::set_token_property(property, &mut guard)?;539 ) -> DispatchResult {539 ) -> DispatchResult {540 Self::check_token_change_permission(&property_key, guard)?;540 Self::check_token_change_permission(&property_key, guard)?;541541542 <TokenProperties<T>>::try_mutate((guard.collection.id, guard.token), |properties| {542 <TokenProperties<T>>::try_mutate((guard.collection.id, guard.token_id), |properties| {543 properties.remove(&property_key)543 properties.remove(&property_key)544 })544 })545 .map_err(<CommonError<T>>::from)?;545 .map_err(<CommonError<T>>::from)?;546546547 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(547 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(548 guard.collection.id,548 guard.collection.id,549 guard.token,549 guard.token_id,550 property_key,550 property_key,551 ));551 ));552552562 .cloned()562 .cloned()563 .unwrap_or_else(PropertyPermission::none);563 .unwrap_or_else(PropertyPermission::none);564564565 let is_property_exists = TokenProperties::<T>::get((guard.collection.id, guard.token))565 let is_property_exists = TokenProperties::<T>::get((guard.collection.id, guard.token_id))566 .get(property_key)566 .get(property_key)567 .is_some();567 .is_some();568568606 ) -> DispatchResult {606 ) -> DispatchResult {607 let is_token_create = false;607 let is_token_create = false;608608609 let mut guard = PropertyGuard::new(609 let mut guard = PropertyGuard::new(PropertyGuardData {610 sender,610 sender,611 collection,611 collection,612 token_id,612 token_id,613 is_token_create,613 is_token_create,614 nesting_budget,614 nesting_budget,615 );615 });616616617 for key in property_keys {617 for key in property_keys {618 Self::delete_token_property(key, &mut guard)?;618 Self::delete_token_property(key, &mut guard)?;pallets/nonfungible/src/property_guard.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/property_guard.rs
+++ b/pallets/nonfungible/src/property_guard.rs
@@ -3,28 +3,30 @@
pub struct PropertyGuard<'a, T: Config> {
pub sender: &'a T::CrossAccountId,
pub collection: &'a NonfungibleHandle<T>,
- pub token: TokenId,
+ pub token_id: TokenId,
pub is_token_create: bool,
- budget: &'a dyn Budget,
+ nesting_budget: &'a dyn Budget,
collection_admin_result: Option<DispatchResult>,
token_owner_result: Option<DispatchResult>,
}
+pub struct PropertyGuardData<'a, T: Config> {
+ pub sender: &'a T::CrossAccountId,
+ pub collection: &'a NonfungibleHandle<T>,
+ pub token_id: TokenId,
+ pub is_token_create: bool,
+ pub nesting_budget: &'a dyn Budget,
+}
+
impl<'a, T: Config> PropertyGuard<'a, T> {
- pub fn new(
- sender: &'a T::CrossAccountId,
- collection: &'a NonfungibleHandle<T>,
- token: TokenId,
- is_token_create: bool,
- budget: &'a dyn Budget,
- ) -> Self {
+ pub fn new(data: PropertyGuardData<'a, T>) -> Self {
Self {
- sender,
- collection,
- token,
- is_token_create,
- budget,
+ sender: data.sender,
+ collection: data.collection,
+ token_id: data.token_id,
+ is_token_create: data.is_token_create,
+ nesting_budget: data.nesting_budget,
collection_admin_result: None,
token_owner_result: None,
@@ -42,9 +44,9 @@
let is_owned = <PalletStructure<T>>::check_indirectly_owned(
self.sender.clone(),
self.collection.id,
- self.token,
+ self.token_id,
None,
- self.budget,
+ self.nesting_budget,
)?;
if is_owned {