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.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.rsdiffbeforeafterboth39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,41 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,41 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,42 CreateItemExData, budget, CollectionField, Property,42 CreateItemExData, budget, CollectionField, Property, PropertyKeyPermission,43};43};44use pallet_evm::account::CrossAccountId;44use pallet_evm::account::CrossAccountId;45use pallet_common::{45use pallet_common::{723 dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))723 dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))724 }724 }725726 #[weight = T::CommonWeightInfo::change_property_permissions(property_permissions.len() as u32)]727 #[transactional]728 pub fn change_property_permissions(729 origin,730 collection_id: CollectionId,731 property_permissions: Vec<PropertyKeyPermission>,732 ) -> DispatchResultWithPostInfo {733 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);734735 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);736737 dispatch_call::<T, _>(collection_id, |d| d.change_property_permissions(&sender, property_permissions))738 }725739726 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]740 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]727 #[transactional]741 #[transactional]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())
}