difftreelog
Add change_property_permissions
in: master
10 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -36,7 +36,7 @@
CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,
CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,
PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
- PropertiesError,
+ PropertiesError, PropertyKeyPermission,
};
pub use pallet::*;
use sp_core::H160;
@@ -293,6 +293,8 @@
CollectionPropertySet(CollectionId, Property),
TokenPropertySet(CollectionId, TokenId, Property),
+
+ PropertyPermissionSet(CollectionId, PropertyKeyPermission),
}
#[pallet::error]
@@ -741,7 +743,7 @@
|properties| properties.try_change_property(property.clone())
)?;
- <Pallet<T>>::deposit_event(Event::CollectionPropertySet(collection.id, property));
+ Self::deposit_event(Event::CollectionPropertySet(collection.id, property));
Ok(())
}
@@ -761,19 +763,39 @@
pub fn change_property_permission(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
- property_key: PropertyKey,
- permission: PropertyPermission,
+ 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)] {
+ return Err(<Error<T>>::NoPermission.into());
+ }
+
CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {
- permissions.try_insert(property_key, permission)
+ let property_permission = property_permission.clone();
+ permissions.try_insert(property_permission.key, property_permission.permission)
})
.map_err(|_| PropertiesError::PropertyLimitReached)?;
+ Self::deposit_event(Event::PropertyPermissionSet(collection.id, property_permission));
+
Ok(())
}
+ pub fn change_property_permissions(
+ collection: &CollectionHandle<T>,
+ sender: &T::CrossAccountId,
+ property_permissions: Vec<PropertyKeyPermission>
+ ) -> DispatchResult {
+ for prop_pemission in property_permissions {
+ Self::change_property_permission(collection, sender, prop_pemission)?;
+ }
+
+ Ok(())
+ }
+
fn set_field_raw(
collection_id: CollectionId,
field: CollectionField,
@@ -928,6 +950,7 @@
fn burn_item() -> Weight;
fn change_collection_properties(amount: u32) -> Weight;
fn change_token_properties(amount: u32) -> Weight;
+ fn change_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -962,20 +985,22 @@
token: TokenId,
amount: u128,
) -> DispatchResultWithPostInfo;
-
fn change_collection_properties(
&self,
sender: T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResultWithPostInfo;
-
fn change_token_properties(
&self,
sender: T::CrossAccountId,
token_id: TokenId,
property: Vec<Property>,
) -> DispatchResultWithPostInfo;
-
+ fn change_property_permissions(
+ &self,
+ sender: &T::CrossAccountId,
+ property_permissions: Vec<PropertyKeyPermission>,
+ ) -> DispatchResultWithPostInfo;
fn transfer(
&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};
+use up_data_structs::{CustomDataLimit, Property, PropertyKeyPermission,};
use crate::{
Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
@@ -58,6 +58,10 @@
<SelfWeightOf<T>>::change_token_properties(amount)
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::change_property_permissions(amount)
+ }
+
fn transfer() -> Weight {
<SelfWeightOf<T>>::transfer()
}
@@ -250,6 +254,14 @@
fail!(<Error<T>>::PropertiesNotAllowed)
}
+ fn change_property_permissions(
+ &self,
+ _sender: &T::CrossAccountId,
+ _property_permissions: Vec<PropertyKeyPermission>,
+ ) -> 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 change_collection_properties(amount: u32) -> Weight;
fn change_token_properties(amount: u32) -> Weight;
+ fn change_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -82,6 +83,11 @@
0
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
// Storage: Fungible Balance (r:2 w:2)
fn transfer() -> Weight {
(17_713_000 as Weight)
@@ -150,6 +156,11 @@
0
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
// Storage: Fungible Balance (r:2 w:2)
fn transfer() -> Weight {
(17_713_000 as Weight)
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -18,7 +18,7 @@
use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
use up_data_structs::{
- TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,
+ TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property, PropertyKeyPermission,
};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
@@ -58,6 +58,10 @@
<SelfWeightOf<T>>::change_token_properties(amount)
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::change_property_permissions(amount)
+ }
+
fn transfer() -> Weight {
<SelfWeightOf<T>>::transfer()
}
@@ -176,6 +180,19 @@
)
}
+ fn change_property_permissions(
+ &self,
+ sender: &T::CrossAccountId,
+ property_permissions: Vec<PropertyKeyPermission>,
+ ) -> DispatchResultWithPostInfo {
+ let weight = <CommonWeights<T>>::change_property_permissions(property_permissions.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::change_property_permissions(self, sender, property_permissions),
+ weight
+ )
+ }
+
fn burn_item(
&self,
sender: T::CrossAccountId,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -21,6 +21,7 @@
use up_data_structs::{
AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
+ PropertyKeyPermission,
};
use pallet_evm::account::CrossAccountId;
use pallet_common::{
@@ -324,6 +325,18 @@
<PalletCommon<T>>::change_collection_properties(collection, sender, properties)
}
+ pub fn change_property_permissions(
+ collection: &CollectionHandle<T>,
+ sender: &T::CrossAccountId,
+ property_permissions: Vec<PropertyKeyPermission>
+ ) -> DispatchResult {
+ <PalletCommon<T>>::change_property_permissions(
+ collection,
+ sender,
+ property_permissions,
+ )
+ }
+
pub fn transfer(
collection: &NonfungibleHandle<T>,
from: &T::CrossAccountId,
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -38,6 +38,7 @@
fn burn_item() -> Weight;
fn change_collection_properties(amount: u32) -> Weight;
fn change_token_properties(amount: u32) -> Weight;
+ fn change_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -103,6 +104,11 @@
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ // TODO calculate appropriate weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
+ }
+
// Storage: Nonfungible TokenData (r:1 w:1)
// Storage: Nonfungible AccountBalance (r:2 w:2)
// Storage: Nonfungible Allowance (r:1 w:0)
@@ -203,6 +209,11 @@
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ // TODO calculate appropriate weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
+ }
+
// Storage: Nonfungible TokenData (r:1 w:1)
// Storage: Nonfungible AccountBalance (r:2 w:2)
// Storage: Nonfungible Allowance (r:1 w:0)
pallets/refungible/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 sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};21use up_data_structs::{22 CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,23 budget::Budget, Property,24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;27use sp_std::{vec::Vec, vec};2829use crate::{30 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,31 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,32};3334macro_rules! max_weight_of {35 ($($method:ident ($($args:tt)*)),*) => {36 037 $(38 .max(<SelfWeightOf<T>>::$method($($args)*))39 )*40 };41}4243pub struct CommonWeights<T: Config>(PhantomData<T>);44impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {45 fn create_item() -> Weight {46 <SelfWeightOf<T>>::create_item()47 }4849 fn create_multiple_items(amount: u32) -> Weight {50 <SelfWeightOf<T>>::create_multiple_items(amount)51 }5253 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {54 match call {55 CreateItemExData::RefungibleMultipleOwners(i) => {56 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)57 }58 CreateItemExData::RefungibleMultipleItems(i) => {59 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)60 }61 _ => 0,62 }63 }6465 fn burn_item() -> Weight {66 max_weight_of!(burn_item_partial(), burn_item_fully())67 }6869 fn change_collection_properties(amount: u32) -> Weight {70 <SelfWeightOf<T>>::change_collection_properties(amount)71 }7273 fn change_token_properties(amount: u32) -> Weight {74 <SelfWeightOf<T>>::change_token_properties(amount)75 }7677 fn transfer() -> Weight {78 max_weight_of!(79 transfer_normal(),80 transfer_creating(),81 transfer_removing(),82 transfer_creating_removing()83 )84 }8586 fn approve() -> Weight {87 <SelfWeightOf<T>>::approve()88 }8990 fn transfer_from() -> Weight {91 max_weight_of!(92 transfer_from_normal(),93 transfer_from_creating(),94 transfer_from_removing(),95 transfer_from_creating_removing()96 )97 }9899 fn burn_from() -> Weight {100 <SelfWeightOf<T>>::burn_from()101 }102103 fn set_variable_metadata(bytes: u32) -> Weight {104 <SelfWeightOf<T>>::set_variable_metadata(bytes)105 }106}107108fn map_create_data<T: Config>(109 data: up_data_structs::CreateItemData,110 to: &T::CrossAccountId,111) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {112 match data {113 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {114 const_data: data.const_data,115 variable_data: data.variable_data,116 users: {117 let mut out = BTreeMap::new();118 out.insert(to.clone(), data.pieces);119 out.try_into().expect("limit > 0")120 },121 }),122 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),123 }124}125126impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {127 fn create_item(128 &self,129 sender: T::CrossAccountId,130 to: T::CrossAccountId,131 data: up_data_structs::CreateItemData,132 nesting_budget: &dyn Budget,133 ) -> DispatchResultWithPostInfo {134 with_weight(135 <Pallet<T>>::create_item(136 self,137 &sender,138 map_create_data::<T>(data, &to)?,139 nesting_budget,140 ),141 <CommonWeights<T>>::create_item(),142 )143 }144145 fn create_multiple_items(146 &self,147 sender: T::CrossAccountId,148 to: T::CrossAccountId,149 data: Vec<up_data_structs::CreateItemData>,150 nesting_budget: &dyn Budget,151 ) -> DispatchResultWithPostInfo {152 let data = data153 .into_iter()154 .map(|d| map_create_data::<T>(d, &to))155 .collect::<Result<Vec<_>, DispatchError>>()?;156157 let amount = data.len();158 with_weight(159 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),160 <CommonWeights<T>>::create_multiple_items(amount as u32),161 )162 }163164 fn create_multiple_items_ex(165 &self,166 sender: <T>::CrossAccountId,167 data: CreateItemExData<T::CrossAccountId>,168 nesting_budget: &dyn Budget,169 ) -> DispatchResultWithPostInfo {170 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);171 let data = match data {172 CreateItemExData::RefungibleMultipleOwners(r) => vec![r],173 CreateItemExData::RefungibleMultipleItems(r)174 if r.iter().all(|i| i.users.len() == 1) =>175 {176 r.into_inner()177 }178 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),179 };180181 with_weight(182 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),183 weight,184 )185 }186187 fn burn_item(188 &self,189 sender: T::CrossAccountId,190 token: TokenId,191 amount: u128,192 ) -> DispatchResultWithPostInfo {193 with_weight(194 <Pallet<T>>::burn(self, &sender, token, amount),195 <CommonWeights<T>>::burn_item(),196 )197 }198199 fn transfer(200 &self,201 from: T::CrossAccountId,202 to: T::CrossAccountId,203 token: TokenId,204 amount: u128,205 nesting_budget: &dyn Budget,206 ) -> DispatchResultWithPostInfo {207 with_weight(208 <Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),209 <CommonWeights<T>>::transfer(),210 )211 }212213 fn approve(214 &self,215 sender: T::CrossAccountId,216 spender: T::CrossAccountId,217 token: TokenId,218 amount: u128,219 ) -> DispatchResultWithPostInfo {220 with_weight(221 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),222 <CommonWeights<T>>::approve(),223 )224 }225226 fn transfer_from(227 &self,228 sender: T::CrossAccountId,229 from: T::CrossAccountId,230 to: T::CrossAccountId,231 token: TokenId,232 amount: u128,233 nesting_budget: &dyn Budget,234 ) -> DispatchResultWithPostInfo {235 with_weight(236 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),237 <CommonWeights<T>>::transfer_from(),238 )239 }240241 fn burn_from(242 &self,243 sender: T::CrossAccountId,244 from: T::CrossAccountId,245 token: TokenId,246 amount: u128,247 nesting_budget: &dyn Budget,248 ) -> DispatchResultWithPostInfo {249 with_weight(250 <Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),251 <CommonWeights<T>>::burn_from(),252 )253 }254255 fn change_collection_properties(256 &self,257 _sender: T::CrossAccountId,258 _property: Vec<Property>,259 ) -> DispatchResultWithPostInfo {260 fail!(<Error<T>>::PropertiesNotAllowed)261 }262263 fn change_token_properties(264 &self,265 _sender: T::CrossAccountId,266 _token_id: TokenId,267 _property: Vec<Property>,268 ) -> DispatchResultWithPostInfo {269 fail!(<Error<T>>::PropertiesNotAllowed)270 }271272 fn set_variable_metadata(273 &self,274 sender: T::CrossAccountId,275 token: TokenId,276 data: BoundedVec<u8, CustomDataLimit>,277 ) -> DispatchResultWithPostInfo {278 let len = data.len();279 with_weight(280 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),281 <CommonWeights<T>>::set_variable_metadata(len as u32),282 )283 }284285 fn check_nesting(286 &self,287 _sender: <T>::CrossAccountId,288 _from: (CollectionId, TokenId),289 _under: TokenId,290 _budget: &dyn Budget,291 ) -> sp_runtime::DispatchResult {292 fail!(<Error<T>>::RefungibleDisallowsNesting)293 }294295 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {296 <Owned<T>>::iter_prefix((self.id, account))297 .map(|(id, _)| id)298 .collect()299 }300301 fn collection_tokens(&self) -> Vec<TokenId> {302 <TokenData<T>>::iter_prefix((self.id,))303 .map(|(id, _)| id)304 .collect()305 }306307 fn token_exists(&self, token: TokenId) -> bool {308 <Pallet<T>>::token_exists(self, token)309 }310311 fn last_token_id(&self) -> TokenId {312 TokenId(<TokensMinted<T>>::get(self.id))313 }314315 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {316 None317 }318 fn const_metadata(&self, token: TokenId) -> Vec<u8> {319 <TokenData<T>>::get((self.id, token))320 .const_data321 .into_inner()322 }323 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {324 <TokenData<T>>::get((self.id, token))325 .variable_data326 .into_inner()327 }328329 fn total_supply(&self) -> u32 {330 <Pallet<T>>::total_supply(self)331 }332333 fn account_balance(&self, account: T::CrossAccountId) -> u32 {334 <AccountBalance<T>>::get((self.id, account))335 }336337 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {338 <Balance<T>>::get((self.id, token, account))339 }340341 fn allowance(342 &self,343 sender: T::CrossAccountId,344 spender: T::CrossAccountId,345 token: TokenId,346 ) -> u128 {347 <Allowance<T>>::get((self.id, token, sender, spender))348 }349}1// 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 sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};21use up_data_structs::{22 CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,23 budget::Budget, Property, PropertyKeyPermission,24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;27use sp_std::{vec::Vec, vec};2829use crate::{30 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,31 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,32};3334macro_rules! max_weight_of {35 ($($method:ident ($($args:tt)*)),*) => {36 037 $(38 .max(<SelfWeightOf<T>>::$method($($args)*))39 )*40 };41}4243pub struct CommonWeights<T: Config>(PhantomData<T>);44impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {45 fn create_item() -> Weight {46 <SelfWeightOf<T>>::create_item()47 }4849 fn create_multiple_items(amount: u32) -> Weight {50 <SelfWeightOf<T>>::create_multiple_items(amount)51 }5253 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {54 match call {55 CreateItemExData::RefungibleMultipleOwners(i) => {56 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)57 }58 CreateItemExData::RefungibleMultipleItems(i) => {59 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)60 }61 _ => 0,62 }63 }6465 fn burn_item() -> Weight {66 max_weight_of!(burn_item_partial(), burn_item_fully())67 }6869 fn change_collection_properties(amount: u32) -> Weight {70 <SelfWeightOf<T>>::change_collection_properties(amount)71 }7273 fn change_token_properties(amount: u32) -> Weight {74 <SelfWeightOf<T>>::change_token_properties(amount)75 }7677 fn change_property_permissions(amount: u32) -> Weight {78 <SelfWeightOf<T>>::change_property_permissions(amount)79 }8081 fn transfer() -> Weight {82 max_weight_of!(83 transfer_normal(),84 transfer_creating(),85 transfer_removing(),86 transfer_creating_removing()87 )88 }8990 fn approve() -> Weight {91 <SelfWeightOf<T>>::approve()92 }9394 fn transfer_from() -> Weight {95 max_weight_of!(96 transfer_from_normal(),97 transfer_from_creating(),98 transfer_from_removing(),99 transfer_from_creating_removing()100 )101 }102103 fn burn_from() -> Weight {104 <SelfWeightOf<T>>::burn_from()105 }106107 fn set_variable_metadata(bytes: u32) -> Weight {108 <SelfWeightOf<T>>::set_variable_metadata(bytes)109 }110}111112fn map_create_data<T: Config>(113 data: up_data_structs::CreateItemData,114 to: &T::CrossAccountId,115) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {116 match data {117 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {118 const_data: data.const_data,119 variable_data: data.variable_data,120 users: {121 let mut out = BTreeMap::new();122 out.insert(to.clone(), data.pieces);123 out.try_into().expect("limit > 0")124 },125 }),126 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),127 }128}129130impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {131 fn create_item(132 &self,133 sender: T::CrossAccountId,134 to: T::CrossAccountId,135 data: up_data_structs::CreateItemData,136 nesting_budget: &dyn Budget,137 ) -> DispatchResultWithPostInfo {138 with_weight(139 <Pallet<T>>::create_item(140 self,141 &sender,142 map_create_data::<T>(data, &to)?,143 nesting_budget,144 ),145 <CommonWeights<T>>::create_item(),146 )147 }148149 fn create_multiple_items(150 &self,151 sender: T::CrossAccountId,152 to: T::CrossAccountId,153 data: Vec<up_data_structs::CreateItemData>,154 nesting_budget: &dyn Budget,155 ) -> DispatchResultWithPostInfo {156 let data = data157 .into_iter()158 .map(|d| map_create_data::<T>(d, &to))159 .collect::<Result<Vec<_>, DispatchError>>()?;160161 let amount = data.len();162 with_weight(163 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),164 <CommonWeights<T>>::create_multiple_items(amount as u32),165 )166 }167168 fn create_multiple_items_ex(169 &self,170 sender: <T>::CrossAccountId,171 data: CreateItemExData<T::CrossAccountId>,172 nesting_budget: &dyn Budget,173 ) -> DispatchResultWithPostInfo {174 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);175 let data = match data {176 CreateItemExData::RefungibleMultipleOwners(r) => vec![r],177 CreateItemExData::RefungibleMultipleItems(r)178 if r.iter().all(|i| i.users.len() == 1) =>179 {180 r.into_inner()181 }182 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),183 };184185 with_weight(186 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),187 weight,188 )189 }190191 fn burn_item(192 &self,193 sender: T::CrossAccountId,194 token: TokenId,195 amount: u128,196 ) -> DispatchResultWithPostInfo {197 with_weight(198 <Pallet<T>>::burn(self, &sender, token, amount),199 <CommonWeights<T>>::burn_item(),200 )201 }202203 fn transfer(204 &self,205 from: T::CrossAccountId,206 to: T::CrossAccountId,207 token: TokenId,208 amount: u128,209 nesting_budget: &dyn Budget,210 ) -> DispatchResultWithPostInfo {211 with_weight(212 <Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),213 <CommonWeights<T>>::transfer(),214 )215 }216217 fn approve(218 &self,219 sender: T::CrossAccountId,220 spender: T::CrossAccountId,221 token: TokenId,222 amount: u128,223 ) -> DispatchResultWithPostInfo {224 with_weight(225 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),226 <CommonWeights<T>>::approve(),227 )228 }229230 fn transfer_from(231 &self,232 sender: T::CrossAccountId,233 from: T::CrossAccountId,234 to: T::CrossAccountId,235 token: TokenId,236 amount: u128,237 nesting_budget: &dyn Budget,238 ) -> DispatchResultWithPostInfo {239 with_weight(240 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),241 <CommonWeights<T>>::transfer_from(),242 )243 }244245 fn burn_from(246 &self,247 sender: T::CrossAccountId,248 from: T::CrossAccountId,249 token: TokenId,250 amount: u128,251 nesting_budget: &dyn Budget,252 ) -> DispatchResultWithPostInfo {253 with_weight(254 <Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),255 <CommonWeights<T>>::burn_from(),256 )257 }258259 fn change_collection_properties(260 &self,261 _sender: T::CrossAccountId,262 _property: Vec<Property>,263 ) -> DispatchResultWithPostInfo {264 fail!(<Error<T>>::PropertiesNotAllowed)265 }266267 fn change_token_properties(268 &self,269 _sender: T::CrossAccountId,270 _token_id: TokenId,271 _property: Vec<Property>,272 ) -> DispatchResultWithPostInfo {273 fail!(<Error<T>>::PropertiesNotAllowed)274 }275276 fn change_property_permissions(277 &self,278 _sender: &T::CrossAccountId,279 _property_permissions: Vec<PropertyKeyPermission>,280 ) -> DispatchResultWithPostInfo {281 fail!(<Error<T>>::PropertiesNotAllowed)282 }283284 fn set_variable_metadata(285 &self,286 sender: T::CrossAccountId,287 token: TokenId,288 data: BoundedVec<u8, CustomDataLimit>,289 ) -> DispatchResultWithPostInfo {290 let len = data.len();291 with_weight(292 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),293 <CommonWeights<T>>::set_variable_metadata(len as u32),294 )295 }296297 fn check_nesting(298 &self,299 _sender: <T>::CrossAccountId,300 _from: (CollectionId, TokenId),301 _under: TokenId,302 _budget: &dyn Budget,303 ) -> sp_runtime::DispatchResult {304 fail!(<Error<T>>::RefungibleDisallowsNesting)305 }306307 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {308 <Owned<T>>::iter_prefix((self.id, account))309 .map(|(id, _)| id)310 .collect()311 }312313 fn collection_tokens(&self) -> Vec<TokenId> {314 <TokenData<T>>::iter_prefix((self.id,))315 .map(|(id, _)| id)316 .collect()317 }318319 fn token_exists(&self, token: TokenId) -> bool {320 <Pallet<T>>::token_exists(self, token)321 }322323 fn last_token_id(&self) -> TokenId {324 TokenId(<TokensMinted<T>>::get(self.id))325 }326327 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {328 None329 }330 fn const_metadata(&self, token: TokenId) -> Vec<u8> {331 <TokenData<T>>::get((self.id, token))332 .const_data333 .into_inner()334 }335 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {336 <TokenData<T>>::get((self.id, token))337 .variable_data338 .into_inner()339 }340341 fn total_supply(&self) -> u32 {342 <Pallet<T>>::total_supply(self)343 }344345 fn account_balance(&self, account: T::CrossAccountId) -> u32 {346 <AccountBalance<T>>::get((self.id, account))347 }348349 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {350 <Balance<T>>::get((self.id, token, account))351 }352353 fn allowance(354 &self,355 sender: T::CrossAccountId,356 spender: T::CrossAccountId,357 token: TokenId,358 ) -> u128 {359 <Allowance<T>>::get((self.id, token, sender, spender))360 }361}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 change_collection_properties(amount: u32) -> Weight;
fn change_token_properties(amount: u32) -> Weight;
+ fn change_property_permissions(amount: u32) -> Weight;
fn transfer_normal() -> Weight;
fn transfer_creating() -> Weight;
fn transfer_removing() -> Weight;
@@ -142,6 +143,11 @@
0
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
// Storage: Refungible Balance (r:2 w:2)
fn transfer_normal() -> Weight {
(19_766_000 as Weight)
@@ -321,6 +327,11 @@
0
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
// Storage: Refungible Balance (r:2 w:2)
fn transfer_normal() -> Weight {
(19_766_000 as Weight)
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,
+ CreateItemExData, budget, CollectionField, Property, PropertyKeyPermission,
};
use pallet_evm::account::CrossAccountId;
use pallet_common::{
@@ -723,6 +723,20 @@
dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))
}
+ #[weight = T::CommonWeightInfo::change_property_permissions(property_permissions.len() as u32)]
+ #[transactional]
+ pub fn change_property_permissions(
+ origin,
+ collection_id: CollectionId,
+ property_permissions: Vec<PropertyKeyPermission>,
+ ) -> DispatchResultWithPostInfo {
+ ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);
+
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+ dispatch_call::<T, _>(collection_id, |d| d.change_property_permissions(&sender, property_permissions))
+ }
+
#[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]
#[transactional]
pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {
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!(change_token_properties(amount))
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(change_property_permissions(amount))
+ }
+
fn transfer() -> Weight {
dispatch_weight::<T>() + max_weight_of!(transfer())
}