difftreelog
Add extrinsic: delete collection property
in: master
10 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -292,6 +292,8 @@
CollectionPropertySet(CollectionId, Property),
+ CollectionPropertyDeleted(CollectionId, PropertyKey),
+
TokenPropertySet(CollectionId, TokenId, Property),
TokenPropertyDeleted(CollectionId, TokenId, PropertyKey),
@@ -761,6 +763,34 @@
Ok(())
}
+ pub fn delete_collection_property(
+ collection: &CollectionHandle<T>,
+ sender: &T::CrossAccountId,
+ property_key: PropertyKey,
+ ) -> DispatchResult {
+ collection.check_is_owner_or_admin(sender)?;
+
+ CollectionProperties::<T>::mutate(collection.id, |properties| {
+ properties.remove_property(&property_key);
+ });
+
+ Self::deposit_event(Event::CollectionPropertyDeleted(collection.id, property_key));
+
+ Ok(())
+ }
+
+ pub fn delete_collection_properties(
+ collection: &CollectionHandle<T>,
+ sender: &T::CrossAccountId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResult {
+ for key in property_keys {
+ Self::delete_collection_property(collection, sender, key)?;
+ }
+
+ Ok(())
+ }
+
pub fn set_property_permission(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
@@ -956,6 +986,7 @@
fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
fn burn_item() -> Weight;
fn set_collection_properties(amount: u32) -> Weight;
+ fn delete_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;
@@ -998,6 +1029,11 @@
sender: T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResultWithPostInfo;
+ fn delete_collection_properties(
+ &self,
+ sender: &T::CrossAccountId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo;
fn set_token_properties(
&self,
sender: T::CrossAccountId,
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -54,6 +54,10 @@
<SelfWeightOf<T>>::set_collection_properties(amount)
}
+ fn delete_collection_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::delete_collection_properties(amount)
+ }
+
fn set_token_properties(amount: u32) -> Weight {
<SelfWeightOf<T>>::set_token_properties(amount)
}
@@ -249,6 +253,14 @@
fail!(<Error<T>>::PropertiesNotAllowed)
}
+ fn delete_collection_properties(
+ &self,
+ _sender: &T::CrossAccountId,
+ _property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo {
+ fail!(<Error<T>>::PropertiesNotAllowed)
+ }
+
fn set_token_properties(
&self,
_sender: T::CrossAccountId,
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -36,6 +36,7 @@
fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
fn set_collection_properties(amount: u32) -> Weight;
+ fn delete_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;
@@ -79,6 +80,11 @@
0
}
+ fn delete_collection_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
fn set_token_properties(_amount: u32) -> Weight {
// Error
0
@@ -157,6 +163,11 @@
0
}
+ fn delete_collection_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
fn set_token_properties(_amount: u32) -> Weight {
// Error
0
pallets/nonfungible/src/common.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};20use up_data_structs::{21 TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,22 PropertyKey, PropertyKeyPermission,23};24use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use sp_runtime::DispatchError;26use sp_std::vec::Vec;2728use crate::{29 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,30 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,31};3233pub struct CommonWeights<T: Config>(PhantomData<T>);34impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {35 fn create_item() -> Weight {36 <SelfWeightOf<T>>::create_item()37 }3839 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {40 match data {41 CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),42 _ => 0,43 }44 }4546 fn create_multiple_items(amount: u32) -> Weight {47 <SelfWeightOf<T>>::create_multiple_items(amount)48 }4950 fn burn_item() -> Weight {51 <SelfWeightOf<T>>::burn_item()52 }5354 fn set_collection_properties(amount: u32) -> Weight {55 <SelfWeightOf<T>>::set_collection_properties(amount)56 }5758 fn set_token_properties(amount: u32) -> Weight {59 <SelfWeightOf<T>>::set_token_properties(amount)60 }6162 fn delete_token_properties(amount: u32) -> Weight {63 <SelfWeightOf<T>>::delete_token_properties(amount)64 }6566 fn set_property_permissions(amount: u32) -> Weight {67 <SelfWeightOf<T>>::set_property_permissions(amount)68 }6970 fn transfer() -> Weight {71 <SelfWeightOf<T>>::transfer()72 }7374 fn approve() -> Weight {75 <SelfWeightOf<T>>::approve()76 }7778 fn transfer_from() -> Weight {79 <SelfWeightOf<T>>::transfer_from()80 }8182 fn burn_from() -> Weight {83 <SelfWeightOf<T>>::burn_from()84 }8586 fn set_variable_metadata(bytes: u32) -> Weight {87 <SelfWeightOf<T>>::set_variable_metadata(bytes)88 }89}9091fn map_create_data<T: Config>(92 data: up_data_structs::CreateItemData,93 to: &T::CrossAccountId,94) -> Result<CreateItemData<T>, DispatchError> {95 match data {96 up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {97 const_data: data.const_data,98 variable_data: data.variable_data,99 owner: to.clone(),100 }),101 _ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),102 }103}104105impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {106 fn create_item(107 &self,108 sender: T::CrossAccountId,109 to: T::CrossAccountId,110 data: up_data_structs::CreateItemData,111 nesting_budget: &dyn Budget,112 ) -> DispatchResultWithPostInfo {113 with_weight(114 <Pallet<T>>::create_item(115 self,116 &sender,117 map_create_data::<T>(data, &to)?,118 nesting_budget,119 ),120 <CommonWeights<T>>::create_item(),121 )122 }123124 fn create_multiple_items(125 &self,126 sender: T::CrossAccountId,127 to: T::CrossAccountId,128 data: Vec<up_data_structs::CreateItemData>,129 nesting_budget: &dyn Budget,130 ) -> DispatchResultWithPostInfo {131 let data = data132 .into_iter()133 .map(|d| map_create_data::<T>(d, &to))134 .collect::<Result<Vec<_>, DispatchError>>()?;135136 let amount = data.len();137 with_weight(138 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),139 <CommonWeights<T>>::create_multiple_items(amount as u32),140 )141 }142143 fn create_multiple_items_ex(144 &self,145 sender: <T>::CrossAccountId,146 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,147 nesting_budget: &dyn Budget,148 ) -> DispatchResultWithPostInfo {149 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);150 let data = match data {151 up_data_structs::CreateItemExData::NFT(nft) => nft,152 _ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),153 };154155 with_weight(156 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),157 weight,158 )159 }160161 fn set_collection_properties(162 &self,163 sender: T::CrossAccountId,164 properties: Vec<Property>,165 ) -> DispatchResultWithPostInfo {166 let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);167168 with_weight(169 <Pallet<T>>::set_collection_properties(self, &sender, properties),170 weight,171 )172 }173174 fn set_token_properties(175 &self,176 sender: T::CrossAccountId,177 token_id: TokenId,178 properties: Vec<Property>,179 ) -> DispatchResultWithPostInfo {180 let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);181182 with_weight(183 <Pallet<T>>::set_token_properties(self, &sender, token_id, properties),184 weight,185 )186 }187188 fn delete_token_properties(189 &self,190 sender: T::CrossAccountId,191 token_id: TokenId,192 property_keys: Vec<PropertyKey>,193 ) -> DispatchResultWithPostInfo {194 let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);195196 with_weight(197 <Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),198 weight,199 )200 }201202 fn set_property_permissions(203 &self,204 sender: &T::CrossAccountId,205 property_permissions: Vec<PropertyKeyPermission>,206 ) -> DispatchResultWithPostInfo {207 let weight =208 <CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);209210 with_weight(211 <Pallet<T>>::set_property_permissions(self, sender, property_permissions),212 weight,213 )214 }215216 fn burn_item(217 &self,218 sender: T::CrossAccountId,219 token: TokenId,220 amount: u128,221 ) -> DispatchResultWithPostInfo {222 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);223 if amount == 1 {224 with_weight(225 <Pallet<T>>::burn(self, &sender, token),226 <CommonWeights<T>>::burn_item(),227 )228 } else {229 Ok(().into())230 }231 }232233 fn transfer(234 &self,235 from: T::CrossAccountId,236 to: T::CrossAccountId,237 token: TokenId,238 amount: u128,239 nesting_budget: &dyn Budget,240 ) -> DispatchResultWithPostInfo {241 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);242 if amount == 1 {243 with_weight(244 <Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),245 <CommonWeights<T>>::transfer(),246 )247 } else {248 Ok(().into())249 }250 }251252 fn approve(253 &self,254 sender: T::CrossAccountId,255 spender: T::CrossAccountId,256 token: TokenId,257 amount: u128,258 ) -> DispatchResultWithPostInfo {259 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);260261 with_weight(262 if amount == 1 {263 <Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))264 } else {265 <Pallet<T>>::set_allowance(self, &sender, token, None)266 },267 <CommonWeights<T>>::approve(),268 )269 }270271 fn transfer_from(272 &self,273 sender: T::CrossAccountId,274 from: T::CrossAccountId,275 to: T::CrossAccountId,276 token: TokenId,277 amount: u128,278 nesting_budget: &dyn Budget,279 ) -> DispatchResultWithPostInfo {280 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);281282 if amount == 1 {283 with_weight(284 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),285 <CommonWeights<T>>::transfer_from(),286 )287 } else {288 Ok(().into())289 }290 }291292 fn burn_from(293 &self,294 sender: T::CrossAccountId,295 from: T::CrossAccountId,296 token: TokenId,297 amount: u128,298 nesting_budget: &dyn Budget,299 ) -> DispatchResultWithPostInfo {300 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);301302 if amount == 1 {303 with_weight(304 <Pallet<T>>::burn_from(self, &sender, &from, token, nesting_budget),305 <CommonWeights<T>>::burn_from(),306 )307 } else {308 Ok(().into())309 }310 }311312 fn set_variable_metadata(313 &self,314 sender: T::CrossAccountId,315 token: TokenId,316 data: BoundedVec<u8, CustomDataLimit>,317 ) -> DispatchResultWithPostInfo {318 let len = data.len();319 with_weight(320 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),321 <CommonWeights<T>>::set_variable_metadata(len as u32),322 )323 }324325 fn check_nesting(326 &self,327 sender: T::CrossAccountId,328 from: (CollectionId, TokenId),329 under: TokenId,330 budget: &dyn Budget,331 ) -> sp_runtime::DispatchResult {332 <Pallet<T>>::check_nesting(self, sender, from, under, budget)333 }334335 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {336 <Owned<T>>::iter_prefix((self.id, account))337 .map(|(id, _)| id)338 .collect()339 }340341 fn collection_tokens(&self) -> Vec<TokenId> {342 <TokenData<T>>::iter_prefix((self.id,))343 .map(|(id, _)| id)344 .collect()345 }346347 fn token_exists(&self, token: TokenId) -> bool {348 <Pallet<T>>::token_exists(self, token)349 }350351 fn last_token_id(&self) -> TokenId {352 TokenId(<TokensMinted<T>>::get(self.id))353 }354355 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {356 <TokenData<T>>::get((self.id, token)).map(|t| t.owner)357 }358 fn const_metadata(&self, token: TokenId) -> Vec<u8> {359 <TokenData<T>>::get((self.id, token))360 .map(|t| t.const_data)361 .unwrap_or_default()362 .into_inner()363 }364 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {365 <TokenData<T>>::get((self.id, token))366 .map(|t| t.variable_data)367 .unwrap_or_default()368 .into_inner()369 }370371 fn total_supply(&self) -> u32 {372 <Pallet<T>>::total_supply(self)373 }374375 fn account_balance(&self, account: T::CrossAccountId) -> u32 {376 <AccountBalance<T>>::get((self.id, account))377 }378379 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {380 if <TokenData<T>>::get((self.id, token))381 .map(|a| a.owner == account)382 .unwrap_or(false)383 {384 1385 } else {386 0387 }388 }389390 fn allowance(391 &self,392 sender: T::CrossAccountId,393 spender: T::CrossAccountId,394 token: TokenId,395 ) -> u128 {396 if <TokenData<T>>::get((self.id, token))397 .map(|a| a.owner != sender)398 .unwrap_or(true)399 {400 0401 } else if <Allowance<T>>::get((self.id, token)) == Some(spender) {402 1403 } else {404 0405 }406 }407}pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -366,6 +366,14 @@
<PalletCommon<T>>::set_collection_properties(collection, sender, properties)
}
+ pub fn delete_collection_properties(
+ collection: &CollectionHandle<T>,
+ sender: &T::CrossAccountId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResult {
+ <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
+ }
+
pub fn set_property_permissions(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -37,6 +37,7 @@
fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
fn set_collection_properties(amount: u32) -> Weight;
+ fn delete_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;
@@ -100,6 +101,11 @@
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
+ fn delete_collection_properties(amount: u32) -> Weight {
+ // TODO calculate appropriate weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
+ }
+
fn set_token_properties(amount: u32) -> Weight {
// TODO calculate appropriate weight
(50_000_000 as Weight).saturating_mul(amount as Weight)
@@ -210,6 +216,11 @@
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
+ fn delete_collection_properties(amount: u32) -> Weight {
+ // TODO calculate appropriate weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
+ }
+
fn set_token_properties(amount: u32) -> Weight {
// TODO calculate appropriate weight
(50_000_000 as Weight).saturating_mul(amount as Weight)
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -70,6 +70,10 @@
<SelfWeightOf<T>>::set_collection_properties(amount)
}
+ fn delete_collection_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::delete_collection_properties(amount)
+ }
+
fn set_token_properties(amount: u32) -> Weight {
<SelfWeightOf<T>>::set_token_properties(amount)
}
@@ -268,6 +272,14 @@
fail!(<Error<T>>::PropertiesNotAllowed)
}
+ fn delete_collection_properties(
+ &self,
+ _sender: &T::CrossAccountId,
+ _property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo {
+ fail!(<Error<T>>::PropertiesNotAllowed)
+ }
+
fn set_token_properties(
&self,
_sender: T::CrossAccountId,
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -39,6 +39,7 @@
fn burn_item_partial() -> Weight;
fn burn_item_fully() -> Weight;
fn set_collection_properties(amount: u32) -> Weight;
+ fn delete_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;
@@ -139,6 +140,11 @@
0
}
+ fn delete_collection_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
fn set_token_properties(_amount: u32) -> Weight {
// Error
0
@@ -328,6 +334,11 @@
0
}
+ fn delete_collection_properties(_amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
fn set_token_properties(_amount: u32) -> Weight {
// Error
0
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -708,6 +708,20 @@
dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))
}
+ #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]
+ #[transactional]
+ pub fn delete_collection_properties(
+ origin,
+ collection_id: CollectionId,
+ property_keys: Vec<PropertyKey>,
+ ) -> DispatchResultWithPostInfo {
+ ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);
+
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+ dispatch_call::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))
+ }
+
#[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]
#[transactional]
pub fn set_token_properties(
@@ -723,19 +737,19 @@
dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))
}
- #[weight = T::CommonWeightInfo::delete_token_properties(properties.len() as u32)]
+ #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]
#[transactional]
pub fn delete_token_properties(
origin,
collection_id: CollectionId,
token_id: TokenId,
- properties: Vec<PropertyKey>
+ property_keys: Vec<PropertyKey>
) -> DispatchResultWithPostInfo {
- ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
+ ensure!(!property_keys.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))
+ dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))
}
#[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]
runtime/common/src/weights.rsdiffbeforeafterboth--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -58,6 +58,10 @@
dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))
}
+ fn delete_collection_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))
+ }
+
fn set_token_properties(amount: u32) -> Weight {
dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
}