difftreelog
Add change_property_permissions
in: master
10 files changed
pallets/common/src/lib.rsdiffbeforeafterboth36 CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,36 CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,37 CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,37 CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,38 PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,38 PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,39 PropertiesError,39 PropertiesError, PropertyKeyPermission,40};40};41pub use pallet::*;41pub use pallet::*;42use sp_core::H160;42use sp_core::H160;294294295 TokenPropertySet(CollectionId, TokenId, Property),295 TokenPropertySet(CollectionId, TokenId, Property),296297 PropertyPermissionSet(CollectionId, PropertyKeyPermission),296 }298 }297299298 #[pallet::error]300 #[pallet::error]741 |properties| properties.try_change_property(property.clone())743 |properties| properties.try_change_property(property.clone())742 )?;744 )?;743745744 <Pallet<T>>::deposit_event(Event::CollectionPropertySet(collection.id, property));746 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));745747746 Ok(())748 Ok(())747 }749 }761 pub fn change_property_permission(763 pub fn change_property_permission(762 collection: &CollectionHandle<T>,764 collection: &CollectionHandle<T>,763 sender: &T::CrossAccountId,765 sender: &T::CrossAccountId,764 property_key: PropertyKey,766 property_permission: PropertyKeyPermission765 permission: PropertyPermission,766 ) -> DispatchResult {767 ) -> DispatchResult {767 collection.check_is_owner_or_admin(sender)?;768 collection.check_is_owner_or_admin(sender)?;769770 let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);771 let current_permission = all_permissions.get(&property_permission.key);772 if matches![current_permission, Some(PropertyPermission::AdminConst | PropertyPermission::ItemOwnerConst)] {773 return Err(<Error<T>>::NoPermission.into());774 }768775769 CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {776 CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {777 let property_permission = property_permission.clone();770 permissions.try_insert(property_key, permission)778 permissions.try_insert(property_permission.key, property_permission.permission)771 })779 })772 .map_err(|_| PropertiesError::PropertyLimitReached)?;780 .map_err(|_| PropertiesError::PropertyLimitReached)?;781782 Self::deposit_event(Event::PropertyPermissionSet(collection.id, property_permission));773783774 Ok(())784 Ok(())775 }785 }786787 pub fn change_property_permissions(788 collection: &CollectionHandle<T>,789 sender: &T::CrossAccountId,790 property_permissions: Vec<PropertyKeyPermission>791 ) -> DispatchResult {792 for prop_pemission in property_permissions {793 Self::change_property_permission(collection, sender, prop_pemission)?;794 }795796 Ok(())797 }776798777 fn set_field_raw(799 fn set_field_raw(778 collection_id: CollectionId,800 collection_id: CollectionId,928 fn burn_item() -> Weight;950 fn burn_item() -> Weight;929 fn change_collection_properties(amount: u32) -> Weight;951 fn change_collection_properties(amount: u32) -> Weight;930 fn change_token_properties(amount: u32) -> Weight;952 fn change_token_properties(amount: u32) -> Weight;953 fn change_property_permissions(amount: u32) -> Weight;931 fn transfer() -> Weight;954 fn transfer() -> Weight;932 fn approve() -> Weight;955 fn approve() -> Weight;933 fn transfer_from() -> Weight;956 fn transfer_from() -> Weight;975 token_id: TokenId,996 token_id: TokenId,976 property: Vec<Property>,997 property: Vec<Property>,977 ) -> DispatchResultWithPostInfo;998 ) -> DispatchResultWithPostInfo;978999 fn change_property_permissions(1000 &self,1001 sender: &T::CrossAccountId,1002 property_permissions: Vec<PropertyKeyPermission>,1003 ) -> DispatchResultWithPostInfo;979 fn transfer(1004 fn transfer(980 &self,1005 &self,981 sender: T::CrossAccountId,1006 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.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,
+ budget::Budget, Property, PropertyKeyPermission,
};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
@@ -74,6 +74,10 @@
<SelfWeightOf<T>>::change_token_properties(amount)
}
+ fn change_property_permissions(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::change_property_permissions(amount)
+ }
+
fn transfer() -> Weight {
max_weight_of!(
transfer_normal(),
@@ -269,6 +273,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/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())
}