difftreelog
refactor set_token_property_permissions
in: master
15 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1019,7 +1019,7 @@
}
#[transactional]
- pub fn set_property_permissions(
+ pub fn set_token_property_permissions(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
@@ -1239,7 +1239,7 @@
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;
+ fn set_token_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -1318,7 +1318,7 @@
token_id: TokenId,
property_keys: Vec<PropertyKey>,
) -> DispatchResultWithPostInfo;
- fn set_property_permissions(
+ fn set_token_property_permissions(
&self,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -72,7 +72,7 @@
0
}
- fn set_property_permissions(_amount: u32) -> Weight {
+ fn set_token_property_permissions(_amount: u32) -> Weight {
// Error
0
}
@@ -302,7 +302,7 @@
fail!(<Error<T>>::SettingPropertiesNotAllowed)
}
- fn set_property_permissions(
+ fn set_token_property_permissions(
&self,
_sender: &T::CrossAccountId,
_property_permissions: Vec<PropertyKeyPermission>,
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -147,7 +147,7 @@
<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&burner))?;
}: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, &Unlimited)?}
- set_property_permissions {
+ set_token_property_permissions {
let b in 0..MAX_PROPERTIES_PER_ITEM;
bench_init!{
owner: sub; collection: collection(owner);
@@ -161,7 +161,7 @@
token_owner: false,
},
}).collect::<Vec<_>>();
- }: {<Pallet<T>>::set_property_permissions(&collection, &owner, perms)?}
+ }: {<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?}
set_token_properties {
let b in 0..MAX_PROPERTIES_PER_ITEM;
@@ -177,7 +177,7 @@
token_owner: true,
},
}).collect::<Vec<_>>();
- <Pallet<T>>::set_property_permissions(&collection, &owner, perms)?;
+ <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
let props = (0..b).map(|k| Property {
key: property_key(k as usize),
value: property_value(),
@@ -199,7 +199,7 @@
token_owner: true,
},
}).collect::<Vec<_>>();
- <Pallet<T>>::set_property_permissions(&collection, &owner, perms)?;
+ <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
let props = (0..b).map(|k| Property {
key: property_key(k as usize),
value: property_value(),
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -89,8 +89,8 @@
<SelfWeightOf<T>>::delete_token_properties(amount)
}
- fn set_property_permissions(amount: u32) -> Weight {
- <SelfWeightOf<T>>::set_property_permissions(amount)
+ fn set_token_property_permissions(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_token_property_permissions(amount)
}
fn transfer() -> Weight {
@@ -242,16 +242,16 @@
)
}
- fn set_property_permissions(
+ fn set_token_property_permissions(
&self,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResultWithPostInfo {
let weight =
- <CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);
+ <CommonWeights<T>>::set_token_property_permissions(property_permissions.len() as u32);
with_weight(
- <Pallet<T>>::set_property_permissions(self, sender, property_permissions),
+ <Pallet<T>>::set_token_property_permissions(self, sender, property_permissions),
weight,
)
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -594,12 +594,12 @@
<PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
}
- pub fn set_property_permissions(
+ pub fn set_token_property_permissions(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResult {
- <PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)
+ <PalletCommon<T>>::set_token_property_permissions(collection, sender, property_permissions)
}
pub fn set_property_permission(
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -42,7 +42,7 @@
fn approve() -> Weight;
fn transfer_from() -> Weight;
fn burn_from() -> Weight;
- fn set_property_permissions(b: u32) -> Weight;
+ fn set_token_property_permissions(b: u32) -> Weight;
fn set_token_properties(b: u32) -> Weight;
fn delete_token_properties(b: u32) -> Weight;
}
@@ -159,7 +159,7 @@
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
// Storage: Common CollectionPropertyPermissions (r:1 w:1)
- fn set_property_permissions(b: u32, ) -> Weight {
+ fn set_token_property_permissions(b: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 3_432_000
.saturating_add((126_888_000 as Weight).saturating_mul(b as Weight))
@@ -299,7 +299,7 @@
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
}
// Storage: Common CollectionPropertyPermissions (r:1 w:1)
- fn set_property_permissions(b: u32, ) -> Weight {
+ fn set_token_property_permissions(b: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 3_432_000
.saturating_add((126_888_000 as Weight).saturating_mul(b as Weight))
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -85,8 +85,8 @@
<SelfWeightOf<T>>::delete_token_properties(amount)
}
- fn set_property_permissions(amount: u32) -> Weight {
- <SelfWeightOf<T>>::set_property_permissions(amount)
+ fn set_token_property_permissions(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_token_property_permissions(amount)
}
fn transfer() -> Weight {
@@ -315,7 +315,7 @@
fail!(<Error<T>>::SettingPropertiesNotAllowed)
}
- fn set_property_permissions(
+ fn set_token_property_permissions(
&self,
_sender: &T::CrossAccountId,
_property_permissions: Vec<PropertyKeyPermission>,
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -40,7 +40,7 @@
fn burn_item_fully() -> Weight;
fn set_token_properties(amount: u32) -> Weight;
fn delete_token_properties(amount: u32) -> Weight;
- fn set_property_permissions(amount: u32) -> Weight;
+ fn set_token_property_permissions(amount: u32) -> Weight;
fn transfer_normal() -> Weight;
fn transfer_creating() -> Weight;
fn transfer_removing() -> Weight;
@@ -142,7 +142,7 @@
0
}
- fn set_property_permissions(_amount: u32) -> Weight {
+ fn set_token_property_permissions(_amount: u32) -> Weight {
// Error
0
}
@@ -320,7 +320,7 @@
0
}
- fn set_property_permissions(_amount: u32) -> Weight {
+ fn set_token_property_permissions(_amount: u32) -> Weight {
// Error
0
}
pallets/unique/src/lib.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/>.1617#![recursion_limit = "1024"]18#![cfg_attr(not(feature = "std"), no_std)]19#![allow(20 clippy::too_many_arguments,21 clippy::unnecessary_mut_passed,22 clippy::unused_unit23)]2425extern crate alloc;2627use frame_support::{28 decl_module, decl_storage, decl_error, decl_event,29 dispatch::DispatchResult,30 ensure,31 weights::{Weight},32 transactional,33 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},34 BoundedVec,35};36use scale_info::TypeInfo;37use frame_system::{self as system, ensure_signed};38use sp_runtime::{sp_std::prelude::Vec};39use up_data_structs::{40 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,41 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,42 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,43 PropertyKeyPermission,44};45use pallet_evm::account::CrossAccountId;46use pallet_common::{47 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,48 dispatch::CollectionDispatch,49};50pub mod eth;5152#[cfg(feature = "runtime-benchmarks")]53mod benchmarking;54pub mod weights;55use weights::WeightInfo;5657const NESTING_BUDGET: u32 = 5;5859decl_error! {60 /// Error for non-fungible-token module.61 pub enum Error for Module<T: Config> {62 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.63 CollectionDecimalPointLimitExceeded,64 /// This address is not set as sponsor, use setCollectionSponsor first.65 ConfirmUnsetSponsorFail,66 /// Length of items properties must be greater than 0.67 EmptyArgument,68 }69}7071pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {72 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;7374 /// Weight information for extrinsics in this pallet.75 type WeightInfo: WeightInfo;76 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;77}7879decl_event! {80 pub enum Event<T>81 where82 <T as frame_system::Config>::AccountId,83 <T as pallet_evm::account::Config>::CrossAccountId,84 {85 /// Collection sponsor was removed86 ///87 /// # Arguments88 ///89 /// * collection_id: Globally unique collection identifier.90 CollectionSponsorRemoved(CollectionId),9192 /// Collection admin was added93 ///94 /// # Arguments95 ///96 /// * collection_id: Globally unique collection identifier.97 ///98 /// * admin: Admin address.99 CollectionAdminAdded(CollectionId, CrossAccountId),100101 /// Collection owned was change102 ///103 /// # Arguments104 ///105 /// * collection_id: Globally unique collection identifier.106 ///107 /// * owner: New owner address.108 CollectionOwnedChanged(CollectionId, AccountId),109110 /// Collection sponsor was set111 ///112 /// # Arguments113 ///114 /// * collection_id: Globally unique collection identifier.115 ///116 /// * owner: New sponsor address.117 CollectionSponsorSet(CollectionId, AccountId),118119 /// New sponsor was confirm120 ///121 /// # Arguments122 ///123 /// * collection_id: Globally unique collection identifier.124 ///125 /// * sponsor: New sponsor address.126 SponsorshipConfirmed(CollectionId, AccountId),127128 /// Collection admin was removed129 ///130 /// # Arguments131 ///132 /// * collection_id: Globally unique collection identifier.133 ///134 /// * admin: Admin address.135 CollectionAdminRemoved(CollectionId, CrossAccountId),136137 /// Address was remove from allow list138 ///139 /// # Arguments140 ///141 /// * collection_id: Globally unique collection identifier.142 ///143 /// * user: Address.144 AllowListAddressRemoved(CollectionId, CrossAccountId),145146 /// Address was add to allow list147 ///148 /// # Arguments149 ///150 /// * collection_id: Globally unique collection identifier.151 ///152 /// * user: Address.153 AllowListAddressAdded(CollectionId, CrossAccountId),154155 /// Collection limits was set156 ///157 /// # Arguments158 ///159 /// * collection_id: Globally unique collection identifier.160 CollectionLimitSet(CollectionId),161162 CollectionPermissionSet(CollectionId),163 }164}165166type SelfWeightOf<T> = <T as Config>::WeightInfo;167168// # Used definitions169//170// ## User control levels171//172// chain-controlled - key is uncontrolled by user173// i.e autoincrementing index174// can use non-cryptographic hash175// real - key is controlled by user176// but it is hard to generate enough colliding values, i.e owner of signed txs177// can use non-cryptographic hash178// controlled - key is completly controlled by users179// i.e maps with mutable keys180// should use cryptographic hash181//182// ## User control level downgrade reasons183//184// ?1 - chain-controlled -> controlled185// collections/tokens can be destroyed, resulting in massive holes186// ?2 - chain-controlled -> controlled187// same as ?1, but can be only added, resulting in easier exploitation188// ?3 - real -> controlled189// no confirmation required, so addresses can be easily generated190decl_storage! {191 trait Store for Module<T: Config> as Unique {192193 //#region Private members194 /// Used for migrations195 ChainVersion: u64;196 //#endregion197198 //#region Tokens transfer rate limit baskets199 /// (Collection id (controlled?2), who created (real))200 /// TODO: Off chain worker should remove from this map when collection gets removed201 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;202 /// Collection id (controlled?2), token id (controlled?2)203 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;204 /// Collection id (controlled?2), owning user (real)205 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;206 /// Collection id (controlled?2), token id (controlled?2)207 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;208 //#endregion209210 /// Variable metadata sponsoring211 /// Collection id (controlled?2), token id (controlled?2)212 #[deprecated]213 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;214 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;215216 /// Approval sponsoring217 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;218 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;219 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;220 }221}222223decl_module! {224 pub struct Module<T: Config> for enum Call225 where226 origin: T::Origin227 {228 type Error = Error<T>;229230 fn deposit_event() = default;231232 fn on_initialize(_now: T::BlockNumber) -> Weight {233 0234 }235236 fn on_runtime_upgrade() -> Weight {237 let limit = None;238239 <VariableMetaDataBasket<T>>::remove_all(limit);240241 0242 }243244 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner of the collection is set to the address that signed the transaction and can be changed later.245 ///246 /// # Permissions247 ///248 /// * Anyone.249 ///250 /// # Arguments251 ///252 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.253 ///254 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.255 ///256 /// * token_prefix: UTF-8 string with token prefix.257 ///258 /// * mode: [CollectionMode] collection type and type dependent data.259 // returns collection ID260 #[weight = <SelfWeightOf<T>>::create_collection()]261 #[transactional]262 #[deprecated]263 pub fn create_collection(origin,264 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,265 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,266 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,267 mode: CollectionMode) -> DispatchResult {268 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {269 name: collection_name,270 description: collection_description,271 token_prefix,272 mode,273 ..Default::default()274 };275 Self::create_collection_ex(origin, data)276 }277278 /// This method creates a collection279 ///280 /// Prefer it to deprecated [`created_collection`] method281 #[weight = <SelfWeightOf<T>>::create_collection()]282 #[transactional]283 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {284 let sender = ensure_signed(origin)?;285286 // =========287288 T::CollectionDispatch::create(T::CrossAccountId::from_sub(sender), data)?;289290 Ok(())291 }292293 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.294 ///295 /// # Permissions296 ///297 /// * Collection Owner.298 ///299 /// # Arguments300 ///301 /// * collection_id: collection to destroy.302 #[weight = <SelfWeightOf<T>>::destroy_collection()]303 #[transactional]304 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {305 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);306 let collection = <CollectionHandle<T>>::try_get(collection_id)?;307 collection.check_is_internal()?;308309 // =========310311 T::CollectionDispatch::destroy(sender, collection)?;312313 <NftTransferBasket<T>>::remove_prefix(collection_id, None);314 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);315 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);316317 <NftApproveBasket<T>>::remove_prefix(collection_id, None);318 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);319 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);320321 Ok(())322 }323324 /// Add an address to allow list.325 ///326 /// # Permissions327 ///328 /// * Collection Owner329 /// * Collection Admin330 ///331 /// # Arguments332 ///333 /// * collection_id.334 ///335 /// * address.336 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]337 #[transactional]338 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{339340 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);341 let collection = <CollectionHandle<T>>::try_get(collection_id)?;342 collection.check_is_internal()?;343344 <PalletCommon<T>>::toggle_allowlist(345 &collection,346 &sender,347 &address,348 true,349 )?;350351 Self::deposit_event(Event::<T>::AllowListAddressAdded(352 collection_id,353 address354 ));355356 Ok(())357 }358359 /// Remove an address from allow list.360 ///361 /// # Permissions362 ///363 /// * Collection Owner364 /// * Collection Admin365 ///366 /// # Arguments367 ///368 /// * collection_id.369 ///370 /// * address.371 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]372 #[transactional]373 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{374375 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);376 let collection = <CollectionHandle<T>>::try_get(collection_id)?;377 collection.check_is_internal()?;378379 <PalletCommon<T>>::toggle_allowlist(380 &collection,381 &sender,382 &address,383 false,384 )?;385386 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(387 collection_id,388 address389 ));390391 Ok(())392 }393394 /// Change the owner of the collection.395 ///396 /// # Permissions397 ///398 /// * Collection Owner.399 ///400 /// # Arguments401 ///402 /// * collection_id.403 ///404 /// * new_owner.405 #[weight = <SelfWeightOf<T>>::change_collection_owner()]406 #[transactional]407 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {408409 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);410411 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;412 target_collection.check_is_internal()?;413 target_collection.check_is_owner(&sender)?;414415 target_collection.owner = new_owner.clone();416 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(417 collection_id,418 new_owner419 ));420421 target_collection.save()422 }423424 /// Adds an admin of the Collection.425 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.426 ///427 /// # Permissions428 ///429 /// * Collection Owner.430 /// * Collection Admin.431 ///432 /// # Arguments433 ///434 /// * collection_id: ID of the Collection to add admin for.435 ///436 /// * new_admin_id: Address of new admin to add.437 #[weight = <SelfWeightOf<T>>::add_collection_admin()]438 #[transactional]439 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {440 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);441 let collection = <CollectionHandle<T>>::try_get(collection_id)?;442 collection.check_is_internal()?;443444 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(445 collection_id,446 new_admin_id.clone()447 ));448449 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)450 }451452 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.453 ///454 /// # Permissions455 ///456 /// * Collection Owner.457 /// * Collection Admin.458 ///459 /// # Arguments460 ///461 /// * collection_id: ID of the Collection to remove admin for.462 ///463 /// * account_id: Address of admin to remove.464 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]465 #[transactional]466 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {467 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);468 let collection = <CollectionHandle<T>>::try_get(collection_id)?;469 collection.check_is_internal()?;470471 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(472 collection_id,473 account_id.clone()474 ));475476 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)477 }478479 /// # Permissions480 ///481 /// * Collection Owner482 ///483 /// # Arguments484 ///485 /// * collection_id.486 ///487 /// * new_sponsor.488 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]489 #[transactional]490 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {491 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);492493 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;494 target_collection.check_is_owner_or_admin(&sender)?;495 target_collection.check_is_internal()?;496497 target_collection.set_sponsor(new_sponsor.clone())?;498499 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(500 collection_id,501 new_sponsor502 ));503504 target_collection.save()505 }506507 /// # Permissions508 ///509 /// * Sponsor.510 ///511 /// # Arguments512 ///513 /// * collection_id.514 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]515 #[transactional]516 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {517 let sender = ensure_signed(origin)?;518519 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;520 target_collection.check_is_internal()?;521 ensure!(522 target_collection.confirm_sponsorship(&sender)?,523 Error::<T>::ConfirmUnsetSponsorFail524 );525526 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(527 collection_id,528 sender529 ));530531 target_collection.save()532 }533534 /// Switch back to pay-per-own-transaction model.535 ///536 /// # Permissions537 ///538 /// * Collection owner.539 ///540 /// # Arguments541 ///542 /// * collection_id.543 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]544 #[transactional]545 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {546 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);547548 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;549 target_collection.check_is_internal()?;550 target_collection.check_is_owner(&sender)?;551552 target_collection.sponsorship = SponsorshipState::Disabled;553554 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(555 collection_id556 ));557 target_collection.save()558 }559560 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.561 ///562 /// # Permissions563 ///564 /// * Collection Owner.565 /// * Collection Admin.566 /// * Anyone if567 /// * Allow List is enabled, and568 /// * Address is added to allow list, and569 /// * MintPermission is enabled (see SetMintPermission method)570 ///571 /// # Arguments572 ///573 /// * collection_id: ID of the collection.574 ///575 /// * owner: Address, initial owner of the NFT.576 ///577 /// * data: Token data to store on chain.578 #[weight = T::CommonWeightInfo::create_item()]579 #[transactional]580 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {581 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);582 let budget = budget::Value::new(NESTING_BUDGET);583584 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))585 }586587 /// This method creates multiple items in a collection created with CreateCollection method.588 ///589 /// # Permissions590 ///591 /// * Collection Owner.592 /// * Collection Admin.593 /// * Anyone if594 /// * Allow List is enabled, and595 /// * Address is added to allow list, and596 /// * MintPermission is enabled (see SetMintPermission method)597 ///598 /// # Arguments599 ///600 /// * collection_id: ID of the collection.601 ///602 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].603 ///604 /// * owner: Address, initial owner of the NFT.605 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]606 #[transactional]607 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {608 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);609 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);610 let budget = budget::Value::new(NESTING_BUDGET);611612 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))613 }614615 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]616 #[transactional]617 pub fn set_collection_properties(618 origin,619 collection_id: CollectionId,620 properties: Vec<Property>621 ) -> DispatchResultWithPostInfo {622 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);623624 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);625626 dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))627 }628629 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]630 #[transactional]631 pub fn delete_collection_properties(632 origin,633 collection_id: CollectionId,634 property_keys: Vec<PropertyKey>,635 ) -> DispatchResultWithPostInfo {636 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);637638 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);639640 dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))641 }642643 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]644 #[transactional]645 pub fn set_token_properties(646 origin,647 collection_id: CollectionId,648 token_id: TokenId,649 properties: Vec<Property>650 ) -> DispatchResultWithPostInfo {651 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);652653 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);654655 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))656 }657658 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]659 #[transactional]660 pub fn delete_token_properties(661 origin,662 collection_id: CollectionId,663 token_id: TokenId,664 property_keys: Vec<PropertyKey>665 ) -> DispatchResultWithPostInfo {666 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);667668 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);669670 dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))671 }672673 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]674 #[transactional]675 pub fn set_property_permissions(676 origin,677 collection_id: CollectionId,678 property_permissions: Vec<PropertyKeyPermission>,679 ) -> DispatchResultWithPostInfo {680 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);681682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);683684 dispatch_tx::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))685 }686687 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]688 #[transactional]689 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {690 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);691 let budget = budget::Value::new(NESTING_BUDGET);692693 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))694 }695696 // TODO! transaction weight697698 /// Set transfers_enabled value for particular collection699 ///700 /// # Permissions701 ///702 /// * Collection Owner.703 ///704 /// # Arguments705 ///706 /// * collection_id: ID of the collection.707 ///708 /// * value: New flag value.709 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]710 #[transactional]711 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {712 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);713 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;714 target_collection.check_is_internal()?;715 target_collection.check_is_owner(&sender)?;716717 // =========718719 target_collection.limits.transfers_enabled = Some(value);720 target_collection.save()721 }722723 /// Destroys a concrete instance of NFT.724 ///725 /// # Permissions726 ///727 /// * Collection Owner.728 /// * Collection Admin.729 /// * Current NFT Owner.730 ///731 /// # Arguments732 ///733 /// * collection_id: ID of the collection.734 ///735 /// * item_id: ID of NFT to burn.736 #[weight = T::CommonWeightInfo::burn_item()]737 #[transactional]738 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {739 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);740741 let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;742 if value == 1 {743 <NftTransferBasket<T>>::remove(collection_id, item_id);744 <NftApproveBasket<T>>::remove(collection_id, item_id);745 }746 // Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?747 // <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());748 // <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));749 Ok(post_info)750 }751752 /// Destroys a concrete instance of NFT on behalf of the owner753 /// See also: [`approve`]754 ///755 /// # Permissions756 ///757 /// * Collection Owner.758 /// * Collection Admin.759 /// * Current NFT Owner.760 ///761 /// # Arguments762 ///763 /// * collection_id: ID of the collection.764 ///765 /// * item_id: ID of NFT to burn.766 ///767 /// * from: owner of item768 #[weight = T::CommonWeightInfo::burn_from()]769 #[transactional]770 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {771 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);772 let budget = budget::Value::new(NESTING_BUDGET);773774 dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))775 }776777 /// Change ownership of the token.778 ///779 /// # Permissions780 ///781 /// * Collection Owner782 /// * Collection Admin783 /// * Current NFT owner784 ///785 /// # Arguments786 ///787 /// * recipient: Address of token recipient.788 ///789 /// * collection_id.790 ///791 /// * item_id: ID of the item792 /// * Non-Fungible Mode: Required.793 /// * Fungible Mode: Ignored.794 /// * Re-Fungible Mode: Required.795 ///796 /// * value: Amount to transfer.797 /// * Non-Fungible Mode: Ignored798 /// * Fungible Mode: Must specify transferred amount799 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)800 #[weight = T::CommonWeightInfo::transfer()]801 #[transactional]802 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {803 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);804 let budget = budget::Value::new(NESTING_BUDGET);805806 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))807 }808809 /// Set, change, or remove approved address to transfer the ownership of the NFT.810 ///811 /// # Permissions812 ///813 /// * Collection Owner814 /// * Collection Admin815 /// * Current NFT owner816 ///817 /// # Arguments818 ///819 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).820 ///821 /// * collection_id.822 ///823 /// * item_id: ID of the item.824 #[weight = T::CommonWeightInfo::approve()]825 #[transactional]826 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {827 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);828829 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))830 }831832 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.833 ///834 /// # Permissions835 /// * Collection Owner836 /// * Collection Admin837 /// * Current NFT owner838 /// * Address approved by current NFT owner839 ///840 /// # Arguments841 ///842 /// * from: Address that owns token.843 ///844 /// * recipient: Address of token recipient.845 ///846 /// * collection_id.847 ///848 /// * item_id: ID of the item.849 ///850 /// * value: Amount to transfer.851 #[weight = T::CommonWeightInfo::transfer_from()]852 #[transactional]853 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {854 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);855 let budget = budget::Value::new(NESTING_BUDGET);856857 dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))858 }859860 #[weight = <SelfWeightOf<T>>::set_collection_limits()]861 #[transactional]862 pub fn set_collection_limits(863 origin,864 collection_id: CollectionId,865 new_limit: CollectionLimits,866 ) -> DispatchResult {867 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);868 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;869 target_collection.check_is_internal()?;870 target_collection.check_is_owner_or_admin(&sender)?;871 let old_limit = &target_collection.limits;872873 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;874875 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(876 collection_id877 ));878879 target_collection.save()880 }881882 #[weight = <SelfWeightOf<T>>::set_collection_limits()]883 #[transactional]884 pub fn set_collection_permissions(885 origin,886 collection_id: CollectionId,887 new_limit: CollectionPermissions,888 ) -> DispatchResult {889 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);890 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;891 target_collection.check_is_internal()?;892 target_collection.check_is_owner_or_admin(&sender)?;893 let old_limit = &target_collection.permissions;894895 target_collection.permissions = <PalletCommon<T>>::clamp_permissions(target_collection.mode.clone(), &old_limit, new_limit)?;896897 <Pallet<T>>::deposit_event(Event::<T>::CollectionPermissionSet(898 collection_id899 ));900901 target_collection.save()902 }903 }904}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/>.1617#![recursion_limit = "1024"]18#![cfg_attr(not(feature = "std"), no_std)]19#![allow(20 clippy::too_many_arguments,21 clippy::unnecessary_mut_passed,22 clippy::unused_unit23)]2425extern crate alloc;2627use frame_support::{28 decl_module, decl_storage, decl_error, decl_event,29 dispatch::DispatchResult,30 ensure,31 weights::{Weight},32 transactional,33 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},34 BoundedVec,35};36use scale_info::TypeInfo;37use frame_system::{self as system, ensure_signed};38use sp_runtime::{sp_std::prelude::Vec};39use up_data_structs::{40 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,41 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,42 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,43 PropertyKeyPermission,44};45use pallet_evm::account::CrossAccountId;46use pallet_common::{47 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,48 dispatch::CollectionDispatch,49};50pub mod eth;5152#[cfg(feature = "runtime-benchmarks")]53mod benchmarking;54pub mod weights;55use weights::WeightInfo;5657const NESTING_BUDGET: u32 = 5;5859decl_error! {60 /// Error for non-fungible-token module.61 pub enum Error for Module<T: Config> {62 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.63 CollectionDecimalPointLimitExceeded,64 /// This address is not set as sponsor, use setCollectionSponsor first.65 ConfirmUnsetSponsorFail,66 /// Length of items properties must be greater than 0.67 EmptyArgument,68 }69}7071pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {72 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;7374 /// Weight information for extrinsics in this pallet.75 type WeightInfo: WeightInfo;76 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;77}7879decl_event! {80 pub enum Event<T>81 where82 <T as frame_system::Config>::AccountId,83 <T as pallet_evm::account::Config>::CrossAccountId,84 {85 /// Collection sponsor was removed86 ///87 /// # Arguments88 ///89 /// * collection_id: Globally unique collection identifier.90 CollectionSponsorRemoved(CollectionId),9192 /// Collection admin was added93 ///94 /// # Arguments95 ///96 /// * collection_id: Globally unique collection identifier.97 ///98 /// * admin: Admin address.99 CollectionAdminAdded(CollectionId, CrossAccountId),100101 /// Collection owned was change102 ///103 /// # Arguments104 ///105 /// * collection_id: Globally unique collection identifier.106 ///107 /// * owner: New owner address.108 CollectionOwnedChanged(CollectionId, AccountId),109110 /// Collection sponsor was set111 ///112 /// # Arguments113 ///114 /// * collection_id: Globally unique collection identifier.115 ///116 /// * owner: New sponsor address.117 CollectionSponsorSet(CollectionId, AccountId),118119 /// New sponsor was confirm120 ///121 /// # Arguments122 ///123 /// * collection_id: Globally unique collection identifier.124 ///125 /// * sponsor: New sponsor address.126 SponsorshipConfirmed(CollectionId, AccountId),127128 /// Collection admin was removed129 ///130 /// # Arguments131 ///132 /// * collection_id: Globally unique collection identifier.133 ///134 /// * admin: Admin address.135 CollectionAdminRemoved(CollectionId, CrossAccountId),136137 /// Address was remove from allow list138 ///139 /// # Arguments140 ///141 /// * collection_id: Globally unique collection identifier.142 ///143 /// * user: Address.144 AllowListAddressRemoved(CollectionId, CrossAccountId),145146 /// Address was add to allow list147 ///148 /// # Arguments149 ///150 /// * collection_id: Globally unique collection identifier.151 ///152 /// * user: Address.153 AllowListAddressAdded(CollectionId, CrossAccountId),154155 /// Collection limits was set156 ///157 /// # Arguments158 ///159 /// * collection_id: Globally unique collection identifier.160 CollectionLimitSet(CollectionId),161162 CollectionPermissionSet(CollectionId),163 }164}165166type SelfWeightOf<T> = <T as Config>::WeightInfo;167168// # Used definitions169//170// ## User control levels171//172// chain-controlled - key is uncontrolled by user173// i.e autoincrementing index174// can use non-cryptographic hash175// real - key is controlled by user176// but it is hard to generate enough colliding values, i.e owner of signed txs177// can use non-cryptographic hash178// controlled - key is completly controlled by users179// i.e maps with mutable keys180// should use cryptographic hash181//182// ## User control level downgrade reasons183//184// ?1 - chain-controlled -> controlled185// collections/tokens can be destroyed, resulting in massive holes186// ?2 - chain-controlled -> controlled187// same as ?1, but can be only added, resulting in easier exploitation188// ?3 - real -> controlled189// no confirmation required, so addresses can be easily generated190decl_storage! {191 trait Store for Module<T: Config> as Unique {192193 //#region Private members194 /// Used for migrations195 ChainVersion: u64;196 //#endregion197198 //#region Tokens transfer rate limit baskets199 /// (Collection id (controlled?2), who created (real))200 /// TODO: Off chain worker should remove from this map when collection gets removed201 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;202 /// Collection id (controlled?2), token id (controlled?2)203 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;204 /// Collection id (controlled?2), owning user (real)205 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;206 /// Collection id (controlled?2), token id (controlled?2)207 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;208 //#endregion209210 /// Variable metadata sponsoring211 /// Collection id (controlled?2), token id (controlled?2)212 #[deprecated]213 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;214 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;215216 /// Approval sponsoring217 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;218 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;219 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;220 }221}222223decl_module! {224 pub struct Module<T: Config> for enum Call225 where226 origin: T::Origin227 {228 type Error = Error<T>;229230 fn deposit_event() = default;231232 fn on_initialize(_now: T::BlockNumber) -> Weight {233 0234 }235236 fn on_runtime_upgrade() -> Weight {237 let limit = None;238239 <VariableMetaDataBasket<T>>::remove_all(limit);240241 0242 }243244 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner of the collection is set to the address that signed the transaction and can be changed later.245 ///246 /// # Permissions247 ///248 /// * Anyone.249 ///250 /// # Arguments251 ///252 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.253 ///254 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.255 ///256 /// * token_prefix: UTF-8 string with token prefix.257 ///258 /// * mode: [CollectionMode] collection type and type dependent data.259 // returns collection ID260 #[weight = <SelfWeightOf<T>>::create_collection()]261 #[transactional]262 #[deprecated]263 pub fn create_collection(origin,264 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,265 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,266 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,267 mode: CollectionMode) -> DispatchResult {268 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {269 name: collection_name,270 description: collection_description,271 token_prefix,272 mode,273 ..Default::default()274 };275 Self::create_collection_ex(origin, data)276 }277278 /// This method creates a collection279 ///280 /// Prefer it to deprecated [`created_collection`] method281 #[weight = <SelfWeightOf<T>>::create_collection()]282 #[transactional]283 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {284 let sender = ensure_signed(origin)?;285286 // =========287288 T::CollectionDispatch::create(T::CrossAccountId::from_sub(sender), data)?;289290 Ok(())291 }292293 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.294 ///295 /// # Permissions296 ///297 /// * Collection Owner.298 ///299 /// # Arguments300 ///301 /// * collection_id: collection to destroy.302 #[weight = <SelfWeightOf<T>>::destroy_collection()]303 #[transactional]304 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {305 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);306 let collection = <CollectionHandle<T>>::try_get(collection_id)?;307 collection.check_is_internal()?;308309 // =========310311 T::CollectionDispatch::destroy(sender, collection)?;312313 <NftTransferBasket<T>>::remove_prefix(collection_id, None);314 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);315 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);316317 <NftApproveBasket<T>>::remove_prefix(collection_id, None);318 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);319 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);320321 Ok(())322 }323324 /// Add an address to allow list.325 ///326 /// # Permissions327 ///328 /// * Collection Owner329 /// * Collection Admin330 ///331 /// # Arguments332 ///333 /// * collection_id.334 ///335 /// * address.336 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]337 #[transactional]338 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{339340 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);341 let collection = <CollectionHandle<T>>::try_get(collection_id)?;342 collection.check_is_internal()?;343344 <PalletCommon<T>>::toggle_allowlist(345 &collection,346 &sender,347 &address,348 true,349 )?;350351 Self::deposit_event(Event::<T>::AllowListAddressAdded(352 collection_id,353 address354 ));355356 Ok(())357 }358359 /// Remove an address from allow list.360 ///361 /// # Permissions362 ///363 /// * Collection Owner364 /// * Collection Admin365 ///366 /// # Arguments367 ///368 /// * collection_id.369 ///370 /// * address.371 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]372 #[transactional]373 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{374375 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);376 let collection = <CollectionHandle<T>>::try_get(collection_id)?;377 collection.check_is_internal()?;378379 <PalletCommon<T>>::toggle_allowlist(380 &collection,381 &sender,382 &address,383 false,384 )?;385386 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(387 collection_id,388 address389 ));390391 Ok(())392 }393394 /// Change the owner of the collection.395 ///396 /// # Permissions397 ///398 /// * Collection Owner.399 ///400 /// # Arguments401 ///402 /// * collection_id.403 ///404 /// * new_owner.405 #[weight = <SelfWeightOf<T>>::change_collection_owner()]406 #[transactional]407 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {408409 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);410411 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;412 target_collection.check_is_internal()?;413 target_collection.check_is_owner(&sender)?;414415 target_collection.owner = new_owner.clone();416 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(417 collection_id,418 new_owner419 ));420421 target_collection.save()422 }423424 /// Adds an admin of the Collection.425 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.426 ///427 /// # Permissions428 ///429 /// * Collection Owner.430 /// * Collection Admin.431 ///432 /// # Arguments433 ///434 /// * collection_id: ID of the Collection to add admin for.435 ///436 /// * new_admin_id: Address of new admin to add.437 #[weight = <SelfWeightOf<T>>::add_collection_admin()]438 #[transactional]439 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {440 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);441 let collection = <CollectionHandle<T>>::try_get(collection_id)?;442 collection.check_is_internal()?;443444 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(445 collection_id,446 new_admin_id.clone()447 ));448449 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)450 }451452 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.453 ///454 /// # Permissions455 ///456 /// * Collection Owner.457 /// * Collection Admin.458 ///459 /// # Arguments460 ///461 /// * collection_id: ID of the Collection to remove admin for.462 ///463 /// * account_id: Address of admin to remove.464 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]465 #[transactional]466 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {467 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);468 let collection = <CollectionHandle<T>>::try_get(collection_id)?;469 collection.check_is_internal()?;470471 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(472 collection_id,473 account_id.clone()474 ));475476 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)477 }478479 /// # Permissions480 ///481 /// * Collection Owner482 ///483 /// # Arguments484 ///485 /// * collection_id.486 ///487 /// * new_sponsor.488 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]489 #[transactional]490 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {491 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);492493 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;494 target_collection.check_is_owner_or_admin(&sender)?;495 target_collection.check_is_internal()?;496497 target_collection.set_sponsor(new_sponsor.clone())?;498499 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(500 collection_id,501 new_sponsor502 ));503504 target_collection.save()505 }506507 /// # Permissions508 ///509 /// * Sponsor.510 ///511 /// # Arguments512 ///513 /// * collection_id.514 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]515 #[transactional]516 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {517 let sender = ensure_signed(origin)?;518519 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;520 target_collection.check_is_internal()?;521 ensure!(522 target_collection.confirm_sponsorship(&sender)?,523 Error::<T>::ConfirmUnsetSponsorFail524 );525526 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(527 collection_id,528 sender529 ));530531 target_collection.save()532 }533534 /// Switch back to pay-per-own-transaction model.535 ///536 /// # Permissions537 ///538 /// * Collection owner.539 ///540 /// # Arguments541 ///542 /// * collection_id.543 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]544 #[transactional]545 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {546 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);547548 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;549 target_collection.check_is_internal()?;550 target_collection.check_is_owner(&sender)?;551552 target_collection.sponsorship = SponsorshipState::Disabled;553554 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(555 collection_id556 ));557 target_collection.save()558 }559560 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.561 ///562 /// # Permissions563 ///564 /// * Collection Owner.565 /// * Collection Admin.566 /// * Anyone if567 /// * Allow List is enabled, and568 /// * Address is added to allow list, and569 /// * MintPermission is enabled (see SetMintPermission method)570 ///571 /// # Arguments572 ///573 /// * collection_id: ID of the collection.574 ///575 /// * owner: Address, initial owner of the NFT.576 ///577 /// * data: Token data to store on chain.578 #[weight = T::CommonWeightInfo::create_item()]579 #[transactional]580 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {581 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);582 let budget = budget::Value::new(NESTING_BUDGET);583584 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))585 }586587 /// This method creates multiple items in a collection created with CreateCollection method.588 ///589 /// # Permissions590 ///591 /// * Collection Owner.592 /// * Collection Admin.593 /// * Anyone if594 /// * Allow List is enabled, and595 /// * Address is added to allow list, and596 /// * MintPermission is enabled (see SetMintPermission method)597 ///598 /// # Arguments599 ///600 /// * collection_id: ID of the collection.601 ///602 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].603 ///604 /// * owner: Address, initial owner of the NFT.605 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]606 #[transactional]607 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {608 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);609 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);610 let budget = budget::Value::new(NESTING_BUDGET);611612 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))613 }614615 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]616 #[transactional]617 pub fn set_collection_properties(618 origin,619 collection_id: CollectionId,620 properties: Vec<Property>621 ) -> DispatchResultWithPostInfo {622 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);623624 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);625626 dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))627 }628629 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]630 #[transactional]631 pub fn delete_collection_properties(632 origin,633 collection_id: CollectionId,634 property_keys: Vec<PropertyKey>,635 ) -> DispatchResultWithPostInfo {636 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);637638 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);639640 dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))641 }642643 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]644 #[transactional]645 pub fn set_token_properties(646 origin,647 collection_id: CollectionId,648 token_id: TokenId,649 properties: Vec<Property>650 ) -> DispatchResultWithPostInfo {651 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);652653 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);654655 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))656 }657658 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]659 #[transactional]660 pub fn delete_token_properties(661 origin,662 collection_id: CollectionId,663 token_id: TokenId,664 property_keys: Vec<PropertyKey>665 ) -> DispatchResultWithPostInfo {666 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);667668 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);669670 dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))671 }672673 #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]674 #[transactional]675 pub fn set_token_property_permissions(676 origin,677 collection_id: CollectionId,678 property_permissions: Vec<PropertyKeyPermission>,679 ) -> DispatchResultWithPostInfo {680 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);681682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);683684 dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))685 }686687 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]688 #[transactional]689 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {690 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);691 let budget = budget::Value::new(NESTING_BUDGET);692693 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))694 }695696 // TODO! transaction weight697698 /// Set transfers_enabled value for particular collection699 ///700 /// # Permissions701 ///702 /// * Collection Owner.703 ///704 /// # Arguments705 ///706 /// * collection_id: ID of the collection.707 ///708 /// * value: New flag value.709 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]710 #[transactional]711 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {712 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);713 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;714 target_collection.check_is_internal()?;715 target_collection.check_is_owner(&sender)?;716717 // =========718719 target_collection.limits.transfers_enabled = Some(value);720 target_collection.save()721 }722723 /// Destroys a concrete instance of NFT.724 ///725 /// # Permissions726 ///727 /// * Collection Owner.728 /// * Collection Admin.729 /// * Current NFT Owner.730 ///731 /// # Arguments732 ///733 /// * collection_id: ID of the collection.734 ///735 /// * item_id: ID of NFT to burn.736 #[weight = T::CommonWeightInfo::burn_item()]737 #[transactional]738 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {739 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);740741 let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;742 if value == 1 {743 <NftTransferBasket<T>>::remove(collection_id, item_id);744 <NftApproveBasket<T>>::remove(collection_id, item_id);745 }746 // Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?747 // <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());748 // <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));749 Ok(post_info)750 }751752 /// Destroys a concrete instance of NFT on behalf of the owner753 /// See also: [`approve`]754 ///755 /// # Permissions756 ///757 /// * Collection Owner.758 /// * Collection Admin.759 /// * Current NFT Owner.760 ///761 /// # Arguments762 ///763 /// * collection_id: ID of the collection.764 ///765 /// * item_id: ID of NFT to burn.766 ///767 /// * from: owner of item768 #[weight = T::CommonWeightInfo::burn_from()]769 #[transactional]770 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {771 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);772 let budget = budget::Value::new(NESTING_BUDGET);773774 dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))775 }776777 /// Change ownership of the token.778 ///779 /// # Permissions780 ///781 /// * Collection Owner782 /// * Collection Admin783 /// * Current NFT owner784 ///785 /// # Arguments786 ///787 /// * recipient: Address of token recipient.788 ///789 /// * collection_id.790 ///791 /// * item_id: ID of the item792 /// * Non-Fungible Mode: Required.793 /// * Fungible Mode: Ignored.794 /// * Re-Fungible Mode: Required.795 ///796 /// * value: Amount to transfer.797 /// * Non-Fungible Mode: Ignored798 /// * Fungible Mode: Must specify transferred amount799 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)800 #[weight = T::CommonWeightInfo::transfer()]801 #[transactional]802 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {803 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);804 let budget = budget::Value::new(NESTING_BUDGET);805806 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))807 }808809 /// Set, change, or remove approved address to transfer the ownership of the NFT.810 ///811 /// # Permissions812 ///813 /// * Collection Owner814 /// * Collection Admin815 /// * Current NFT owner816 ///817 /// # Arguments818 ///819 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).820 ///821 /// * collection_id.822 ///823 /// * item_id: ID of the item.824 #[weight = T::CommonWeightInfo::approve()]825 #[transactional]826 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {827 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);828829 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))830 }831832 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.833 ///834 /// # Permissions835 /// * Collection Owner836 /// * Collection Admin837 /// * Current NFT owner838 /// * Address approved by current NFT owner839 ///840 /// # Arguments841 ///842 /// * from: Address that owns token.843 ///844 /// * recipient: Address of token recipient.845 ///846 /// * collection_id.847 ///848 /// * item_id: ID of the item.849 ///850 /// * value: Amount to transfer.851 #[weight = T::CommonWeightInfo::transfer_from()]852 #[transactional]853 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {854 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);855 let budget = budget::Value::new(NESTING_BUDGET);856857 dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))858 }859860 #[weight = <SelfWeightOf<T>>::set_collection_limits()]861 #[transactional]862 pub fn set_collection_limits(863 origin,864 collection_id: CollectionId,865 new_limit: CollectionLimits,866 ) -> DispatchResult {867 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);868 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;869 target_collection.check_is_internal()?;870 target_collection.check_is_owner_or_admin(&sender)?;871 let old_limit = &target_collection.limits;872873 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;874875 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(876 collection_id877 ));878879 target_collection.save()880 }881882 #[weight = <SelfWeightOf<T>>::set_collection_limits()]883 #[transactional]884 pub fn set_collection_permissions(885 origin,886 collection_id: CollectionId,887 new_limit: CollectionPermissions,888 ) -> DispatchResult {889 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);890 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;891 target_collection.check_is_internal()?;892 target_collection.check_is_owner_or_admin(&sender)?;893 let old_limit = &target_collection.permissions;894895 target_collection.permissions = <PalletCommon<T>>::clamp_permissions(target_collection.mode.clone(), &old_limit, new_limit)?;896897 <Pallet<T>>::deposit_event(Event::<T>::CollectionPermissionSet(898 collection_id899 ));900901 target_collection.save()902 }903 }904}runtime/common/src/weights.rsdiffbeforeafterboth--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -70,8 +70,8 @@
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))
+ fn set_token_property_permissions(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))
}
fn transfer() -> Weight {
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -48,7 +48,7 @@
const alice = privateKeyWrapper('//Alice');
await submitTransactionAsync(
alice,
- api.tx.unique.setPropertyPermissions(collectionId, [{key: 'data', permission: {tokenOwner: true}}]),
+ api.tx.unique.setTokenPropertyPermissions(collectionId, [{key: 'data', permission: {tokenOwner: true}}]),
);
const args = [
@@ -470,7 +470,7 @@
const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const tx1 = api.tx.unique.setPropertyPermissions(collectionId, propPerms);
+ const tx1 = api.tx.unique.setTokenPropertyPermissions(collectionId, propPerms);
await expect(executeTransaction(api, alice, tx1)).to.be.rejectedWith(/common\.PropertyLimitReached/);
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -222,7 +222,7 @@
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await usingApi(async (api, privateKeyWrapper) => {
const alice = privateKeyWrapper('//Alice');
- await expect(executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);
+ await expect(executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);
});
});
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -29,7 +29,7 @@
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
const token = await createItemExpectSuccess(alice, collection, 'NFT');
- await executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, [{
+ await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{
key: 'testKey',
permission: {
collectionAdmin: true,
@@ -52,7 +52,7 @@
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
const token = await createItemExpectSuccess(alice, collection, 'NFT');
- await executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, [{
+ await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{
key: 'testKey',
permission: {
mutable: true,
@@ -77,7 +77,7 @@
const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});
const token = await createItemExpectSuccess(alice, collection, 'NFT');
- await executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, [{
+ await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{
key: 'testKey',
permission: {
collectionAdmin: true,
tests/src/nesting/properties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/properties.test.ts
+++ b/tests/src/nesting/properties.test.ts
@@ -38,7 +38,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collectionId, propertyPermissions),
+ api.tx.unique.setTokenPropertyPermissions(collectionId, propertyPermissions),
)).to.not.be.rejected;
const collectionProperties = [
@@ -362,7 +362,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true}}]),
)).to.not.be.rejected;
await addCollectionAdminExpectSuccess(alice, collection, bob.address);
@@ -370,7 +370,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]),
)).to.not.be.rejected;
const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery', 'mindgame'])).toHuman();
@@ -388,13 +388,13 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, collectionAdmin: true}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, collectionAdmin: true}}]),
)).to.not.be.rejected;
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]),
)).to.not.be.rejected;
const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();
@@ -420,7 +420,7 @@
await expect(executeTransaction(
api,
bob,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, tokenOwner: true}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, tokenOwner: true}}]),
)).to.be.rejectedWith(/common\.NoPermission/);
const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();
@@ -443,7 +443,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, constitution),
+ api.tx.unique.setTokenPropertyPermissions(collection, constitution),
)).to.be.rejectedWith(/common\.PropertyLimitReached/);
const propertyRights = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();
@@ -458,13 +458,13 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]),
)).to.not.be.rejected;
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'skullduggery', permission: {}}]),
)).to.be.rejectedWith(/common\.NoPermission/);
const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();
@@ -488,21 +488,21 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, invalidProperties[i]),
+ api.tx.unique.setTokenPropertyPermissions(collection, invalidProperties[i]),
), `on setting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
}
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: '', permission: {}}]),
), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);
const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [
+ api.tx.unique.setTokenPropertyPermissions(collection, [
{key: correctKey, permission: {collectionAdmin: true}},
]),
), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;
@@ -576,7 +576,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]),
), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;
await expect(executeTransaction(
@@ -612,7 +612,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]),
), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;
await expect(executeTransaction(
@@ -655,7 +655,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]),
), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;
await expect(executeTransaction(
@@ -721,7 +721,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: `${i}`, permission: passage.permission}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: `${i}`, permission: passage.permission}]),
), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;
await expect(executeTransaction(
@@ -798,7 +798,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [{key: 'now-existent', permission: {}}]),
+ api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'now-existent', permission: {}}]),
), 'on setting a new non-permitted property').to.not.be.rejected;
await expect(executeTransaction(
@@ -818,7 +818,7 @@
await expect(executeTransaction(
api,
alice,
- api.tx.unique.setPropertyPermissions(collection, [
+ api.tx.unique.setTokenPropertyPermissions(collection, [
{key: 'a_holy_book', permission: {collectionAdmin: true, tokenOwner: true}},
{key: 'young_years', permission: {collectionAdmin: true, tokenOwner: true}},
]),
tests/src/rmrk/rmrk.test.tsdiffbeforeafterboth--- a/tests/src/rmrk/rmrk.test.ts
+++ b/tests/src/rmrk/rmrk.test.ts
@@ -129,8 +129,8 @@
await expect(executeTransaction(api, alice, txDeleteCollectionProperties), 'deleting collection properties')
.to.be.rejectedWith(/common\.CollectionIsExternal/);
- const txSetPropertyPermissions = api.tx.unique.setPropertyPermissions(uniqueCollectionId, [{key: 'a', permission: {mutable: true}}]);
- await expect(executeTransaction(api, alice, txSetPropertyPermissions), 'setting property permissions')
+ const txsetTokenPropertyPermissions = api.tx.unique.setTokenPropertyPermissions(uniqueCollectionId, [{key: 'a', permission: {mutable: true}}]);
+ await expect(executeTransaction(api, alice, txsetTokenPropertyPermissions), 'setting property permissions')
.to.be.rejectedWith(/common\.CollectionIsExternal/);
// NFT