difftreelog
fix add PropertyGuardData
in: master
3 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth373738use crate::{38use crate::{39 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,39 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,40 SelfWeightOf, weights::WeightInfo, TokenProperties, property_guard::PropertyGuard,40 SelfWeightOf, weights::WeightInfo, TokenProperties, property_guard::*,41};41};424243#[solidity_interface(name = "TokenProperties")]43#[solidity_interface(name = "TokenProperties")]83 let value = value.try_into().map_err(|_| "value too long")?;83 let value = value.try_into().map_err(|_| "value too long")?;848485 let is_token_create = false;85 let is_token_create = false;86 let budget = self86 let nesting_budget = self87 .recorder87 .recorder88 .weight_calls_budget(<StructureWeight<T>>::find_parent());88 .weight_calls_budget(<StructureWeight<T>>::find_parent());898990 let mut guard =90 let mut guard =91 PropertyGuard::new(&caller, self, TokenId(token_id), is_token_create, &budget);91 PropertyGuard::new(PropertyGuardData {92 sender: &caller,93 collection: self,94 token_id: TokenId(token_id),95 is_token_create,96 nesting_budget: &nesting_budget97 });929893 <Pallet<T>>::set_token_property(Property { key, value }, &mut guard)99 <Pallet<T>>::set_token_property(Property { key, value }, &mut guard)94 .map_err(dispatch_to_evm::<T>)100 .map_err(dispatch_to_evm::<T>)102 .map_err(|_| "key too long")?;108 .map_err(|_| "key too long")?;103109104 let is_token_create = false;110 let is_token_create = false;105 let budget = self111 let nesting_budget = self106 .recorder112 .recorder107 .weight_calls_budget(<StructureWeight<T>>::find_parent());113 .weight_calls_budget(<StructureWeight<T>>::find_parent());108114109 let mut guard =115 let mut guard =110 PropertyGuard::new(&caller, self, TokenId(token_id), is_token_create, &budget);116 PropertyGuard::new(PropertyGuardData {117 sender: &caller,118 collection: self,119 token_id: TokenId(token_id),120 is_token_create,121 nesting_budget: &nesting_budget122 });111123112 <Pallet<T>>::delete_token_property(key, &mut guard).map_err(dispatch_to_evm::<T>)124 <Pallet<T>>::delete_token_property(key, &mut guard).map_err(dispatch_to_evm::<T>)113 }125 }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.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 {