difftreelog
Add extrinsic: delete token property
in: master
12 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -294,6 +294,8 @@
TokenPropertySet(CollectionId, TokenId, Property),
+ TokenPropertyDeleted(CollectionId, TokenId, PropertyKey),
+
PropertyPermissionSet(CollectionId, PropertyKeyPermission),
}
@@ -738,10 +740,9 @@
) -> DispatchResult {
collection.check_is_owner_or_admin(sender)?;
- CollectionProperties::<T>::try_mutate(
- collection.id,
- |properties| properties.try_set_property(property.clone())
- )?;
+ CollectionProperties::<T>::try_mutate(collection.id, |properties| {
+ properties.try_set_property(property.clone())
+ })?;
Self::deposit_event(Event::CollectionPropertySet(collection.id, property));
@@ -763,13 +764,16 @@
pub fn set_property_permission(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
- property_permission: PropertyKeyPermission
+ property_permission: PropertyKeyPermission,
) -> DispatchResult {
collection.check_is_owner_or_admin(sender)?;
let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);
let current_permission = all_permissions.get(&property_permission.key);
- if matches![current_permission, Some(PropertyPermission::AdminConst | PropertyPermission::ItemOwnerConst)] {
+ if matches![
+ current_permission,
+ Some(PropertyPermission::AdminConst | PropertyPermission::ItemOwnerConst)
+ ] {
return Err(<Error<T>>::NoPermission.into());
}
@@ -779,7 +783,10 @@
})
.map_err(|_| PropertiesError::PropertyLimitReached)?;
- Self::deposit_event(Event::PropertyPermissionSet(collection.id, property_permission));
+ Self::deposit_event(Event::PropertyPermissionSet(
+ collection.id,
+ property_permission,
+ ));
Ok(())
}
@@ -787,7 +794,7 @@
pub fn set_property_permissions(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
- property_permissions: Vec<PropertyKeyPermission>
+ property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResult {
for prop_pemission in property_permissions {
Self::set_property_permission(collection, sender, prop_pemission)?;
@@ -950,6 +957,7 @@
fn burn_item() -> Weight;
fn set_collection_properties(amount: u32) -> Weight;
fn set_token_properties(amount: u32) -> Weight;
+ fn delete_token_properties(amount: u32) -> Weight;
fn set_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
@@ -996,6 +1004,12 @@
token_id: TokenId,
property: Vec<Property>,
) -> DispatchResultWithPostInfo;
+ fn delete_token_properties(
+ &self,
+ sender: T::CrossAccountId,
+ token_id: TokenId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo;
fn set_property_permissions(
&self,
sender: &T::CrossAccountId,
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -21,7 +21,7 @@
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::ArithmeticError;
use sp_std::{vec::Vec, vec};
-use up_data_structs::{CustomDataLimit, Property, PropertyKeyPermission,};
+use up_data_structs::{CustomDataLimit, Property, PropertyKey, PropertyKeyPermission};
use crate::{
Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
@@ -58,6 +58,10 @@
<SelfWeightOf<T>>::set_token_properties(amount)
}
+ fn delete_token_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::delete_token_properties(amount)
+ }
+
fn set_property_permissions(amount: u32) -> Weight {
<SelfWeightOf<T>>::set_property_permissions(amount)
}
@@ -262,6 +266,15 @@
fail!(<Error<T>>::PropertiesNotAllowed)
}
+ fn delete_token_properties(
+ &self,
+ _sender: T::CrossAccountId,
+ _token_id: TokenId,
+ _property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo {
+ fail!(<Error<T>>::PropertiesNotAllowed)
+ }
+
fn set_variable_metadata(
&self,
_sender: T::CrossAccountId,
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -37,6 +37,7 @@
fn burn_item() -> Weight;
fn set_collection_properties(amount: u32) -> Weight;
fn set_token_properties(amount: u32) -> Weight;
+ fn delete_token_properties(amount: u32) -> Weight;
fn set_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
@@ -73,17 +74,22 @@
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
- fn set_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
+ fn set_token_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_token_properties(amount: u32) -> Weight {
+ fn delete_token_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(_amount: u32) -> Weight {
// Error
0
}
@@ -146,17 +152,22 @@
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
- fn set_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_token_properties(amount: u32) -> Weight {
+ fn set_token_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_property_permissions(amount: u32) -> Weight {
+ fn delete_token_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
+ fn set_property_permissions(_amount: u32) -> Weight {
// Error
0
}
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -18,7 +18,8 @@
use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
use up_data_structs::{
- TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property, PropertyKeyPermission,
+ TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,
+ PropertyKey, PropertyKeyPermission,
};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
@@ -58,6 +59,10 @@
<SelfWeightOf<T>>::set_token_properties(amount)
}
+ fn delete_token_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::delete_token_properties(amount)
+ }
+
fn set_property_permissions(amount: u32) -> Weight {
<SelfWeightOf<T>>::set_property_permissions(amount)
}
@@ -162,7 +167,7 @@
with_weight(
<Pallet<T>>::set_collection_properties(self, &sender, properties),
- weight
+ weight,
)
}
@@ -176,7 +181,21 @@
with_weight(
<Pallet<T>>::set_token_properties(self, &sender, token_id, properties),
- weight
+ weight,
+ )
+ }
+
+ fn delete_token_properties(
+ &self,
+ sender: T::CrossAccountId,
+ token_id: TokenId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo {
+ let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),
+ weight,
)
}
@@ -185,11 +204,12 @@
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResultWithPostInfo {
- let weight = <CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);
+ let weight =
+ <CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);
with_weight(
<Pallet<T>>::set_property_permissions(self, sender, property_permissions),
- weight
+ weight,
)
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -21,7 +21,7 @@
use up_data_structs::{
AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
- PropertyKeyPermission,
+ PropertyKey, PropertyKeyPermission,
};
use pallet_evm::account::CrossAccountId;
use pallet_common::{
@@ -261,8 +261,63 @@
token_id: TokenId,
property: Property,
) -> DispatchResult {
+ Self::check_token_change_permission(collection, sender, token_id, &property.key)?;
+
+ <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
+ properties.try_set_property(property.clone())
+ })?;
+
+ <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
+ collection.id,
+ token_id,
+ property,
+ ));
+
+ Ok(())
+ }
+
+ pub fn set_token_properties(
+ collection: &NonfungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ token_id: TokenId,
+ properties: Vec<Property>,
+ ) -> DispatchResult {
+ for property in properties {
+ Self::set_token_property(collection, sender, token_id, property)?;
+ }
+
+ Ok(())
+ }
+
+ pub fn delete_token_property(
+ collection: &NonfungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ token_id: TokenId,
+ property_key: PropertyKey,
+ ) -> DispatchResult {
+ Self::check_token_change_permission(collection, sender, token_id, &property_key)?;
+
+ <TokenProperties<T>>::mutate((collection.id, token_id), |properties| {
+ properties.remove_property(&property_key);
+ });
+
+ <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
+ collection.id,
+ token_id,
+ property_key,
+ ));
+
+ Ok(())
+ }
+
+ fn check_token_change_permission(
+ collection: &NonfungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ token_id: TokenId,
+ property_key: &PropertyKey,
+ ) -> DispatchResult {
let permission = <PalletCommon<T>>::property_permission(collection.id)
- .get(&property.key)
+ .get(property_key)
.map(|p| p.clone())
.unwrap_or(PropertyPermission::None);
@@ -275,43 +330,29 @@
};
let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))
- .get_property(&property.key)
+ .get_property(property_key)
.is_some();
match (permission, is_property_exists) {
- (PropertyPermission::AdminConst, false) => {
- collection.check_is_owner_or_admin(sender)?
- }
- (PropertyPermission::Admin, _) => collection.check_is_owner_or_admin(sender)?,
- (PropertyPermission::ItemOwnerConst, false) => check_token_owner()?,
- (PropertyPermission::ItemOwner, _) => check_token_owner()?,
+ (PropertyPermission::AdminConst, false) => collection.check_is_owner_or_admin(sender),
+ (PropertyPermission::Admin, _) => collection.check_is_owner_or_admin(sender),
+ (PropertyPermission::ItemOwnerConst, false) => check_token_owner(),
+ (PropertyPermission::ItemOwner, _) => check_token_owner(),
(PropertyPermission::ItemOwnerOrAdmin, _) => {
- check_token_owner().or(collection.check_is_owner_or_admin(sender))?;
+ check_token_owner().or(collection.check_is_owner_or_admin(sender))
}
- _ => return Err(<CommonError<T>>::NoPermission.into()),
+ _ => Err(<CommonError<T>>::NoPermission.into()),
}
-
- <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
- properties.try_set_property(property.clone())
- })?;
-
- <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
- collection.id,
- token_id,
- property,
- ));
-
- Ok(())
}
- pub fn set_token_properties(
+ pub fn delete_token_properties(
collection: &NonfungibleHandle<T>,
sender: &T::CrossAccountId,
token_id: TokenId,
- properties: Vec<Property>,
+ property_keys: Vec<PropertyKey>,
) -> DispatchResult {
- for property in properties {
- Self::set_token_property(collection, sender, token_id, property)?;
+ for key in property_keys {
+ Self::delete_token_property(collection, sender, token_id, key)?;
}
Ok(())
@@ -328,13 +369,9 @@
pub fn set_property_permissions(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
- property_permissions: Vec<PropertyKeyPermission>
+ property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResult {
- <PalletCommon<T>>::set_property_permissions(
- collection,
- sender,
- property_permissions,
- )
+ <PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)
}
pub fn transfer(
pallets/nonfungible/src/weights.rsdiffbeforeafterboth1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_nonfungible4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-03-01, STEPS: `50`, REPEAT: 200, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// --pallet13// pallet-nonfungible14// --wasm-execution15// compiled16// --extrinsic17// *18// --template19// .maintain/frame-weight-template.hbs20// --steps=5021// --repeat=20022// --heap-pages=409623// --output=./pallets/nonfungible/src/weights.rs2425#![cfg_attr(rustfmt, rustfmt_skip)]26#![allow(unused_parens)]27#![allow(unused_imports)]28#![allow(clippy::unnecessary_cast)]2930use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};31use sp_std::marker::PhantomData;3233/// Weight functions needed for pallet_nonfungible.34pub trait WeightInfo {35 fn create_item() -> Weight;36 fn create_multiple_items(b: u32, ) -> Weight;37 fn create_multiple_items_ex(b: u32, ) -> Weight;38 fn burn_item() -> Weight;39 fn set_collection_properties(amount: u32) -> Weight;40 fn set_token_properties(amount: u32) -> Weight;41 fn set_property_permissions(amount: u32) -> Weight;42 fn transfer() -> Weight;43 fn approve() -> Weight;44 fn transfer_from() -> Weight;45 fn burn_from() -> Weight;46 fn set_variable_metadata(b: u32, ) -> Weight;47}4849/// Weights for pallet_nonfungible using the Substrate node and recommended hardware.50pub struct SubstrateWeight<T>(PhantomData<T>);51impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {52 // Storage: Nonfungible TokensMinted (r:1 w:1)53 // Storage: Nonfungible AccountBalance (r:1 w:1)54 // Storage: Nonfungible TokenData (r:0 w:1)55 // Storage: Nonfungible Owned (r:0 w:1)56 fn create_item() -> Weight {57 (18_450_000 as Weight)58 .saturating_add(T::DbWeight::get().reads(2 as Weight))59 .saturating_add(T::DbWeight::get().writes(4 as Weight))60 }61 // Storage: Nonfungible TokensMinted (r:1 w:1)62 // Storage: Nonfungible AccountBalance (r:1 w:1)63 // Storage: Nonfungible TokenData (r:0 w:4)64 // Storage: Nonfungible Owned (r:0 w:4)65 fn create_multiple_items(b: u32, ) -> Weight {66 (10_228_000 as Weight)67 // Standard Error: 1_00068 .saturating_add((4_392_000 as Weight).saturating_mul(b as Weight))69 .saturating_add(T::DbWeight::get().reads(2 as Weight))70 .saturating_add(T::DbWeight::get().writes(2 as Weight))71 .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))72 }73 // Storage: Nonfungible TokensMinted (r:1 w:1)74 // Storage: Nonfungible AccountBalance (r:4 w:4)75 // Storage: Nonfungible TokenData (r:0 w:4)76 // Storage: Nonfungible Owned (r:0 w:4)77 fn create_multiple_items_ex(b: u32, ) -> Weight {78 (6_543_000 as Weight)79 // Standard Error: 2_00080 .saturating_add((7_175_000 as Weight).saturating_mul(b as Weight))81 .saturating_add(T::DbWeight::get().reads(1 as Weight))82 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))83 .saturating_add(T::DbWeight::get().writes(1 as Weight))84 .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))85 }86 // Storage: Nonfungible TokenData (r:1 w:1)87 // Storage: Nonfungible TokensBurnt (r:1 w:1)88 // Storage: Nonfungible AccountBalance (r:1 w:1)89 // Storage: Nonfungible Allowance (r:1 w:0)90 // Storage: Nonfungible Owned (r:0 w:1)91 fn burn_item() -> Weight {92 (24_554_000 as Weight)93 .saturating_add(T::DbWeight::get().reads(4 as Weight))94 .saturating_add(T::DbWeight::get().writes(4 as Weight))95 }9697 fn set_collection_properties(amount: u32) -> Weight {98 // TODO calculate appropriate weight99 (50_000_000 as Weight).saturating_mul(amount as Weight)100 }101102 fn set_token_properties(amount: u32) -> Weight {103 // TODO calculate appropriate weight104 (50_000_000 as Weight).saturating_mul(amount as Weight)105 }106107 fn set_property_permissions(amount: u32) -> Weight {108 // TODO calculate appropriate weight109 (50_000_000 as Weight).saturating_mul(amount as Weight)110 }111112 // Storage: Nonfungible TokenData (r:1 w:1)113 // Storage: Nonfungible AccountBalance (r:2 w:2)114 // Storage: Nonfungible Allowance (r:1 w:0)115 // Storage: Nonfungible Owned (r:0 w:2)116 fn transfer() -> Weight {117 (28_339_000 as Weight)118 .saturating_add(T::DbWeight::get().reads(4 as Weight))119 .saturating_add(T::DbWeight::get().writes(5 as Weight))120 }121 // Storage: Nonfungible TokenData (r:1 w:0)122 // Storage: Nonfungible Allowance (r:1 w:1)123 fn approve() -> Weight {124 (17_616_000 as Weight)125 .saturating_add(T::DbWeight::get().reads(2 as Weight))126 .saturating_add(T::DbWeight::get().writes(1 as Weight))127 }128 // Storage: Nonfungible Allowance (r:1 w:1)129 // Storage: Nonfungible TokenData (r:1 w:1)130 // Storage: Nonfungible AccountBalance (r:2 w:2)131 // Storage: Nonfungible Owned (r:0 w:2)132 fn transfer_from() -> Weight {133 (32_196_000 as Weight)134 .saturating_add(T::DbWeight::get().reads(4 as Weight))135 .saturating_add(T::DbWeight::get().writes(6 as Weight))136 }137 // Storage: Nonfungible Allowance (r:1 w:1)138 // Storage: Nonfungible TokenData (r:1 w:1)139 // Storage: Nonfungible TokensBurnt (r:1 w:1)140 // Storage: Nonfungible AccountBalance (r:1 w:1)141 // Storage: Nonfungible Owned (r:0 w:1)142 fn burn_from() -> Weight {143 (27_580_000 as Weight)144 .saturating_add(T::DbWeight::get().reads(4 as Weight))145 .saturating_add(T::DbWeight::get().writes(5 as Weight))146 }147 // Storage: Nonfungible TokenData (r:1 w:1)148 fn set_variable_metadata(_b: u32, ) -> Weight {149 (7_700_000 as Weight)150 .saturating_add(T::DbWeight::get().reads(1 as Weight))151 .saturating_add(T::DbWeight::get().writes(1 as Weight))152 }153}154155// For backwards compatibility and tests156impl WeightInfo for () {157 // Storage: Nonfungible TokensMinted (r:1 w:1)158 // Storage: Nonfungible AccountBalance (r:1 w:1)159 // Storage: Nonfungible TokenData (r:0 w:1)160 // Storage: Nonfungible Owned (r:0 w:1)161 fn create_item() -> Weight {162 (18_450_000 as Weight)163 .saturating_add(RocksDbWeight::get().reads(2 as Weight))164 .saturating_add(RocksDbWeight::get().writes(4 as Weight))165 }166 // Storage: Nonfungible TokensMinted (r:1 w:1)167 // Storage: Nonfungible AccountBalance (r:1 w:1)168 // Storage: Nonfungible TokenData (r:0 w:4)169 // Storage: Nonfungible Owned (r:0 w:4)170 fn create_multiple_items(b: u32, ) -> Weight {171 (10_228_000 as Weight)172 // Standard Error: 1_000173 .saturating_add((4_392_000 as Weight).saturating_mul(b as Weight))174 .saturating_add(RocksDbWeight::get().reads(2 as Weight))175 .saturating_add(RocksDbWeight::get().writes(2 as Weight))176 .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))177 }178 // Storage: Nonfungible TokensMinted (r:1 w:1)179 // Storage: Nonfungible AccountBalance (r:4 w:4)180 // Storage: Nonfungible TokenData (r:0 w:4)181 // Storage: Nonfungible Owned (r:0 w:4)182 fn create_multiple_items_ex(b: u32, ) -> Weight {183 (6_543_000 as Weight)184 // Standard Error: 2_000185 .saturating_add((7_175_000 as Weight).saturating_mul(b as Weight))186 .saturating_add(RocksDbWeight::get().reads(1 as Weight))187 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))188 .saturating_add(RocksDbWeight::get().writes(1 as Weight))189 .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))190 }191 // Storage: Nonfungible TokenData (r:1 w:1)192 // Storage: Nonfungible TokensBurnt (r:1 w:1)193 // Storage: Nonfungible AccountBalance (r:1 w:1)194 // Storage: Nonfungible Allowance (r:1 w:0)195 // Storage: Nonfungible Owned (r:0 w:1)196 fn burn_item() -> Weight {197 (24_554_000 as Weight)198 .saturating_add(RocksDbWeight::get().reads(4 as Weight))199 .saturating_add(RocksDbWeight::get().writes(4 as Weight))200 }201202 fn set_collection_properties(amount: u32) -> Weight {203 // TODO calculate appropriate weight204 (50_000_000 as Weight).saturating_mul(amount as Weight)205 }206207 fn set_token_properties(amount: u32) -> Weight {208 // TODO calculate appropriate weight209 (50_000_000 as Weight).saturating_mul(amount as Weight)210 }211212 fn set_property_permissions(amount: u32) -> Weight {213 // TODO calculate appropriate weight214 (50_000_000 as Weight).saturating_mul(amount as Weight)215 }216217 // Storage: Nonfungible TokenData (r:1 w:1)218 // Storage: Nonfungible AccountBalance (r:2 w:2)219 // Storage: Nonfungible Allowance (r:1 w:0)220 // Storage: Nonfungible Owned (r:0 w:2)221 fn transfer() -> Weight {222 (28_339_000 as Weight)223 .saturating_add(RocksDbWeight::get().reads(4 as Weight))224 .saturating_add(RocksDbWeight::get().writes(5 as Weight))225 }226 // Storage: Nonfungible TokenData (r:1 w:0)227 // Storage: Nonfungible Allowance (r:1 w:1)228 fn approve() -> Weight {229 (17_616_000 as Weight)230 .saturating_add(RocksDbWeight::get().reads(2 as Weight))231 .saturating_add(RocksDbWeight::get().writes(1 as Weight))232 }233 // Storage: Nonfungible Allowance (r:1 w:1)234 // Storage: Nonfungible TokenData (r:1 w:1)235 // Storage: Nonfungible AccountBalance (r:2 w:2)236 // Storage: Nonfungible Owned (r:0 w:2)237 fn transfer_from() -> Weight {238 (32_196_000 as Weight)239 .saturating_add(RocksDbWeight::get().reads(4 as Weight))240 .saturating_add(RocksDbWeight::get().writes(6 as Weight))241 }242 // Storage: Nonfungible Allowance (r:1 w:1)243 // Storage: Nonfungible TokenData (r:1 w:1)244 // Storage: Nonfungible TokensBurnt (r:1 w:1)245 // Storage: Nonfungible AccountBalance (r:1 w:1)246 // Storage: Nonfungible Owned (r:0 w:1)247 fn burn_from() -> Weight {248 (27_580_000 as Weight)249 .saturating_add(RocksDbWeight::get().reads(4 as Weight))250 .saturating_add(RocksDbWeight::get().writes(5 as Weight))251 }252 // Storage: Nonfungible TokenData (r:1 w:1)253 fn set_variable_metadata(_b: u32, ) -> Weight {254 (7_700_000 as Weight)255 .saturating_add(RocksDbWeight::get().reads(1 as Weight))256 .saturating_add(RocksDbWeight::get().writes(1 as Weight))257 }258}1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_nonfungible4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-03-01, STEPS: `50`, REPEAT: 200, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// --pallet13// pallet-nonfungible14// --wasm-execution15// compiled16// --extrinsic17// *18// --template19// .maintain/frame-weight-template.hbs20// --steps=5021// --repeat=20022// --heap-pages=409623// --output=./pallets/nonfungible/src/weights.rs2425#![cfg_attr(rustfmt, rustfmt_skip)]26#![allow(unused_parens)]27#![allow(unused_imports)]28#![allow(clippy::unnecessary_cast)]2930use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};31use sp_std::marker::PhantomData;3233/// Weight functions needed for pallet_nonfungible.34pub trait WeightInfo {35 fn create_item() -> Weight;36 fn create_multiple_items(b: u32, ) -> Weight;37 fn create_multiple_items_ex(b: u32, ) -> Weight;38 fn burn_item() -> Weight;39 fn set_collection_properties(amount: u32) -> Weight;40 fn set_token_properties(amount: u32) -> Weight;41 fn delete_token_properties(amount: u32) -> Weight;42 fn set_property_permissions(amount: u32) -> Weight;43 fn transfer() -> Weight;44 fn approve() -> Weight;45 fn transfer_from() -> Weight;46 fn burn_from() -> Weight;47 fn set_variable_metadata(b: u32, ) -> Weight;48}4950/// Weights for pallet_nonfungible using the Substrate node and recommended hardware.51pub struct SubstrateWeight<T>(PhantomData<T>);52impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {53 // Storage: Nonfungible TokensMinted (r:1 w:1)54 // Storage: Nonfungible AccountBalance (r:1 w:1)55 // Storage: Nonfungible TokenData (r:0 w:1)56 // Storage: Nonfungible Owned (r:0 w:1)57 fn create_item() -> Weight {58 (18_450_000 as Weight)59 .saturating_add(T::DbWeight::get().reads(2 as Weight))60 .saturating_add(T::DbWeight::get().writes(4 as Weight))61 }62 // Storage: Nonfungible TokensMinted (r:1 w:1)63 // Storage: Nonfungible AccountBalance (r:1 w:1)64 // Storage: Nonfungible TokenData (r:0 w:4)65 // Storage: Nonfungible Owned (r:0 w:4)66 fn create_multiple_items(b: u32, ) -> Weight {67 (10_228_000 as Weight)68 // Standard Error: 1_00069 .saturating_add((4_392_000 as Weight).saturating_mul(b as Weight))70 .saturating_add(T::DbWeight::get().reads(2 as Weight))71 .saturating_add(T::DbWeight::get().writes(2 as Weight))72 .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))73 }74 // Storage: Nonfungible TokensMinted (r:1 w:1)75 // Storage: Nonfungible AccountBalance (r:4 w:4)76 // Storage: Nonfungible TokenData (r:0 w:4)77 // Storage: Nonfungible Owned (r:0 w:4)78 fn create_multiple_items_ex(b: u32, ) -> Weight {79 (6_543_000 as Weight)80 // Standard Error: 2_00081 .saturating_add((7_175_000 as Weight).saturating_mul(b as Weight))82 .saturating_add(T::DbWeight::get().reads(1 as Weight))83 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))84 .saturating_add(T::DbWeight::get().writes(1 as Weight))85 .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))86 }87 // Storage: Nonfungible TokenData (r:1 w:1)88 // Storage: Nonfungible TokensBurnt (r:1 w:1)89 // Storage: Nonfungible AccountBalance (r:1 w:1)90 // Storage: Nonfungible Allowance (r:1 w:0)91 // Storage: Nonfungible Owned (r:0 w:1)92 fn burn_item() -> Weight {93 (24_554_000 as Weight)94 .saturating_add(T::DbWeight::get().reads(4 as Weight))95 .saturating_add(T::DbWeight::get().writes(4 as Weight))96 }9798 fn set_collection_properties(amount: u32) -> Weight {99 // TODO calculate appropriate weight100 (50_000_000 as Weight).saturating_mul(amount as Weight)101 }102103 fn set_token_properties(amount: u32) -> Weight {104 // TODO calculate appropriate weight105 (50_000_000 as Weight).saturating_mul(amount as Weight)106 }107108 fn delete_token_properties(amount: u32) -> Weight {109 // TODO calculate appropriate weight110 (50_000_000 as Weight).saturating_mul(amount as Weight)111 }112113 fn set_property_permissions(amount: u32) -> Weight {114 // TODO calculate appropriate weight115 (50_000_000 as Weight).saturating_mul(amount as Weight)116 }117118 // Storage: Nonfungible TokenData (r:1 w:1)119 // Storage: Nonfungible AccountBalance (r:2 w:2)120 // Storage: Nonfungible Allowance (r:1 w:0)121 // Storage: Nonfungible Owned (r:0 w:2)122 fn transfer() -> Weight {123 (28_339_000 as Weight)124 .saturating_add(T::DbWeight::get().reads(4 as Weight))125 .saturating_add(T::DbWeight::get().writes(5 as Weight))126 }127 // Storage: Nonfungible TokenData (r:1 w:0)128 // Storage: Nonfungible Allowance (r:1 w:1)129 fn approve() -> Weight {130 (17_616_000 as Weight)131 .saturating_add(T::DbWeight::get().reads(2 as Weight))132 .saturating_add(T::DbWeight::get().writes(1 as Weight))133 }134 // Storage: Nonfungible Allowance (r:1 w:1)135 // Storage: Nonfungible TokenData (r:1 w:1)136 // Storage: Nonfungible AccountBalance (r:2 w:2)137 // Storage: Nonfungible Owned (r:0 w:2)138 fn transfer_from() -> Weight {139 (32_196_000 as Weight)140 .saturating_add(T::DbWeight::get().reads(4 as Weight))141 .saturating_add(T::DbWeight::get().writes(6 as Weight))142 }143 // Storage: Nonfungible Allowance (r:1 w:1)144 // Storage: Nonfungible TokenData (r:1 w:1)145 // Storage: Nonfungible TokensBurnt (r:1 w:1)146 // Storage: Nonfungible AccountBalance (r:1 w:1)147 // Storage: Nonfungible Owned (r:0 w:1)148 fn burn_from() -> Weight {149 (27_580_000 as Weight)150 .saturating_add(T::DbWeight::get().reads(4 as Weight))151 .saturating_add(T::DbWeight::get().writes(5 as Weight))152 }153 // Storage: Nonfungible TokenData (r:1 w:1)154 fn set_variable_metadata(_b: u32, ) -> Weight {155 (7_700_000 as Weight)156 .saturating_add(T::DbWeight::get().reads(1 as Weight))157 .saturating_add(T::DbWeight::get().writes(1 as Weight))158 }159}160161// For backwards compatibility and tests162impl WeightInfo for () {163 // Storage: Nonfungible TokensMinted (r:1 w:1)164 // Storage: Nonfungible AccountBalance (r:1 w:1)165 // Storage: Nonfungible TokenData (r:0 w:1)166 // Storage: Nonfungible Owned (r:0 w:1)167 fn create_item() -> Weight {168 (18_450_000 as Weight)169 .saturating_add(RocksDbWeight::get().reads(2 as Weight))170 .saturating_add(RocksDbWeight::get().writes(4 as Weight))171 }172 // Storage: Nonfungible TokensMinted (r:1 w:1)173 // Storage: Nonfungible AccountBalance (r:1 w:1)174 // Storage: Nonfungible TokenData (r:0 w:4)175 // Storage: Nonfungible Owned (r:0 w:4)176 fn create_multiple_items(b: u32, ) -> Weight {177 (10_228_000 as Weight)178 // Standard Error: 1_000179 .saturating_add((4_392_000 as Weight).saturating_mul(b as Weight))180 .saturating_add(RocksDbWeight::get().reads(2 as Weight))181 .saturating_add(RocksDbWeight::get().writes(2 as Weight))182 .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))183 }184 // Storage: Nonfungible TokensMinted (r:1 w:1)185 // Storage: Nonfungible AccountBalance (r:4 w:4)186 // Storage: Nonfungible TokenData (r:0 w:4)187 // Storage: Nonfungible Owned (r:0 w:4)188 fn create_multiple_items_ex(b: u32, ) -> Weight {189 (6_543_000 as Weight)190 // Standard Error: 2_000191 .saturating_add((7_175_000 as Weight).saturating_mul(b as Weight))192 .saturating_add(RocksDbWeight::get().reads(1 as Weight))193 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))194 .saturating_add(RocksDbWeight::get().writes(1 as Weight))195 .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))196 }197 // Storage: Nonfungible TokenData (r:1 w:1)198 // Storage: Nonfungible TokensBurnt (r:1 w:1)199 // Storage: Nonfungible AccountBalance (r:1 w:1)200 // Storage: Nonfungible Allowance (r:1 w:0)201 // Storage: Nonfungible Owned (r:0 w:1)202 fn burn_item() -> Weight {203 (24_554_000 as Weight)204 .saturating_add(RocksDbWeight::get().reads(4 as Weight))205 .saturating_add(RocksDbWeight::get().writes(4 as Weight))206 }207208 fn set_collection_properties(amount: u32) -> Weight {209 // TODO calculate appropriate weight210 (50_000_000 as Weight).saturating_mul(amount as Weight)211 }212213 fn set_token_properties(amount: u32) -> Weight {214 // TODO calculate appropriate weight215 (50_000_000 as Weight).saturating_mul(amount as Weight)216 }217218 fn delete_token_properties(amount: u32) -> Weight {219 // TODO calculate appropriate weight220 (50_000_000 as Weight).saturating_mul(amount as Weight)221 }222223 fn set_property_permissions(amount: u32) -> Weight {224 // TODO calculate appropriate weight225 (50_000_000 as Weight).saturating_mul(amount as Weight)226 }227228 // Storage: Nonfungible TokenData (r:1 w:1)229 // Storage: Nonfungible AccountBalance (r:2 w:2)230 // Storage: Nonfungible Allowance (r:1 w:0)231 // Storage: Nonfungible Owned (r:0 w:2)232 fn transfer() -> Weight {233 (28_339_000 as Weight)234 .saturating_add(RocksDbWeight::get().reads(4 as Weight))235 .saturating_add(RocksDbWeight::get().writes(5 as Weight))236 }237 // Storage: Nonfungible TokenData (r:1 w:0)238 // Storage: Nonfungible Allowance (r:1 w:1)239 fn approve() -> Weight {240 (17_616_000 as Weight)241 .saturating_add(RocksDbWeight::get().reads(2 as Weight))242 .saturating_add(RocksDbWeight::get().writes(1 as Weight))243 }244 // Storage: Nonfungible Allowance (r:1 w:1)245 // Storage: Nonfungible TokenData (r:1 w:1)246 // Storage: Nonfungible AccountBalance (r:2 w:2)247 // Storage: Nonfungible Owned (r:0 w:2)248 fn transfer_from() -> Weight {249 (32_196_000 as Weight)250 .saturating_add(RocksDbWeight::get().reads(4 as Weight))251 .saturating_add(RocksDbWeight::get().writes(6 as Weight))252 }253 // Storage: Nonfungible Allowance (r:1 w:1)254 // Storage: Nonfungible TokenData (r:1 w:1)255 // Storage: Nonfungible TokensBurnt (r:1 w:1)256 // Storage: Nonfungible AccountBalance (r:1 w:1)257 // Storage: Nonfungible Owned (r:0 w:1)258 fn burn_from() -> Weight {259 (27_580_000 as Weight)260 .saturating_add(RocksDbWeight::get().reads(4 as Weight))261 .saturating_add(RocksDbWeight::get().writes(5 as Weight))262 }263 // Storage: Nonfungible TokenData (r:1 w:1)264 fn set_variable_metadata(_b: u32, ) -> Weight {265 (7_700_000 as Weight)266 .saturating_add(RocksDbWeight::get().reads(1 as Weight))267 .saturating_add(RocksDbWeight::get().writes(1 as Weight))268 }269}pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -20,7 +20,7 @@
use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};
use up_data_structs::{
CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,
- budget::Budget, Property, PropertyKeyPermission,
+ budget::Budget, Property, PropertyKey, PropertyKeyPermission,
};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
@@ -74,6 +74,10 @@
<SelfWeightOf<T>>::set_token_properties(amount)
}
+ fn delete_token_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::delete_token_properties(amount)
+ }
+
fn set_property_permissions(amount: u32) -> Weight {
<SelfWeightOf<T>>::set_property_permissions(amount)
}
@@ -281,6 +285,15 @@
fail!(<Error<T>>::PropertiesNotAllowed)
}
+ fn delete_token_properties(
+ &self,
+ _sender: T::CrossAccountId,
+ _token_id: TokenId,
+ _property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo {
+ fail!(<Error<T>>::PropertiesNotAllowed)
+ }
+
fn set_variable_metadata(
&self,
sender: T::CrossAccountId,
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -40,6 +40,7 @@
fn burn_item_fully() -> Weight;
fn set_collection_properties(amount: u32) -> Weight;
fn set_token_properties(amount: u32) -> Weight;
+ fn delete_token_properties(amount: u32) -> Weight;
fn set_property_permissions(amount: u32) -> Weight;
fn transfer_normal() -> Weight;
fn transfer_creating() -> Weight;
@@ -133,17 +134,22 @@
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
- fn set_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
+ fn set_token_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_token_properties(amount: u32) -> Weight {
+ fn delete_token_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(_amount: u32) -> Weight {
// Error
0
}
@@ -317,17 +323,22 @@
.saturating_add(RocksDbWeight::get().writes(6 as Weight))
}
- fn set_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_token_properties(amount: u32) -> Weight {
+ fn set_token_properties(_amount: u32) -> Weight {
// Error
0
}
- fn set_property_permissions(amount: u32) -> Weight {
+ fn delete_token_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
+ fn set_property_permissions(_amount: u32) -> Weight {
// Error
0
}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -39,7 +39,7 @@
MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,
SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,
- CreateItemExData, budget, CollectionField, Property, PropertyKeyPermission,
+ CreateItemExData, budget, CollectionField, Property, PropertyKey, PropertyKeyPermission,
};
use pallet_evm::account::CrossAccountId;
use pallet_common::{
@@ -723,6 +723,21 @@
dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))
}
+ #[weight = T::CommonWeightInfo::delete_token_properties(properties.len() as u32)]
+ #[transactional]
+ pub fn delete_token_properties(
+ origin,
+ collection_id: CollectionId,
+ token_id: TokenId,
+ properties: Vec<PropertyKey>
+ ) -> DispatchResultWithPostInfo {
+ ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
+
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+ dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, properties))
+ }
+
#[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]
#[transactional]
pub fn set_property_permissions(
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -720,6 +720,17 @@
Ok(())
}
+ pub fn remove_property(&mut self, key: &PropertyKey) {
+ let property = self.map.get(key);
+
+ if let Some(value) = property {
+ let value_len = value.len() as u32;
+
+ self.map.remove(key);
+ self.consumed_space -= value_len;
+ }
+ }
+
pub fn get_property(&self, key: &PropertyKey) -> Option<&PropertyValue> {
self.map.get(key)
}
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -16,9 +16,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use up_data_structs::{
- CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,
-};
+use up_data_structs::{CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits};
use sp_std::vec::Vec;
use codec::Decode;
use sp_runtime::DispatchError;
runtime/common/src/weights.rsdiffbeforeafterboth--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -62,6 +62,10 @@
dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
}
+ fn delete_token_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))
+ }
+
fn set_property_permissions(amount: u32) -> Weight {
dispatch_weight::<T>() + max_weight_of!(set_property_permissions(amount))
}