git.delta.rocks / unique-network / refs/commits / de884669db7a

difftreelog

source

pallets/unique/src/lib.rs41.5 KiBsourcehistory
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//! # Unique Pallet18//!19//! A pallet governing Unique transactions.20//!21//! - [`Config`]22//! - [`Call`]23//! - [`Pallet`]24//!25//! ## Overview26//!27//! The Unique pallet's purpose is to be the primary interface between28//! external users and the inner structure of the Unique chains.29//!30//! It also contains an implementation of [`CollectionHelpers`][`eth`],31//! an Ethereum contract dealing with collection operations.32//!33//! ## Interface34//!35//! ### Dispatchables36//!37//! - `create_collection` - Create a collection of tokens. **Deprecated**, use `create_collection_ex`.38//! - `create_collection_ex` - Create a collection of tokens with explicit parameters.39//! - `destroy_collection` - Destroy a collection if no tokens exist within.40//! - `add_to_allow_list` - Add an address to allow list.41//! - `remove_from_allow_list` - Remove an address from allow list.42//! - `change_collection_owner` - Change the owner of the collection.43//! - `add_collection_admin` - Add an admin to a collection.44//! - `remove_collection_admin` - Remove admin of a collection.45//! - `set_collection_sponsor` - Invite a new collection sponsor.46//! - `confirm_sponsorship` - Confirm own sponsorship of a collection, becoming the sponsor.47//! - `remove_collection_sponsor` - Remove a sponsor from a collection.48//! - `create_item` - Create an item within a collection.49//! - `create_multiple_items` - Create multiple items within a collection.50//! - `set_collection_properties` - Add or change collection properties.51//! - `delete_collection_properties` - Delete specified collection properties.52//! - `set_token_properties` - Add or change token properties.53//! - `delete_token_properties` - Delete token properties.54//! - `set_token_property_permissions` - Add or change token property permissions of a collection.55//! - `create_multiple_items_ex` - Create multiple items within a collection with explicitly specified initial parameters.56//! - `set_transfers_enabled_flag` - Completely allow or disallow transfers for a particular collection.57//! - `burn_item` - Destroy an item.58//! - `burn_from` - Destroy an item on behalf of the owner as a non-owner account.59//! - `transfer` - Change ownership of the token.60//! - `transfer_from` - Change ownership of the token on behalf of the owner as a non-owner account.61//! - `approve` - Allow a non-permissioned address to transfer or burn an item.62//! - `set_collection_limits` - Set specific limits of a collection.63//! - `set_collection_permissions` - Set specific permissions of a collection.64//! - `repartition` - Re-partition a refungible token, while owning all of its parts.6566#![recursion_limit = "1024"]67#![cfg_attr(not(feature = "std"), no_std)]68#![allow(69	clippy::too_many_arguments,70	clippy::unnecessary_mut_passed,71	clippy::unused_unit72)]7374extern crate alloc;7576use frame_support::{77	decl_module, decl_storage, decl_error,78	dispatch::DispatchResult,79	ensure, fail,80	weights::{Weight},81	pallet_prelude::{DispatchResultWithPostInfo, ConstU32},82	BoundedVec,83};84use scale_info::TypeInfo;85use frame_system::{self as system, ensure_signed, ensure_root};86use sp_std::{vec, vec::Vec};87use up_data_structs::{88	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,89	MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,90	MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,91	CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,92	CreateCollectionData, CreateItemExData, budget, Property, PropertyKey, PropertyKeyPermission,93};94use pallet_evm::account::CrossAccountId;95use pallet_common::{96	CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,97	dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,98};99pub mod eth;100101#[cfg(feature = "runtime-benchmarks")]102pub mod benchmarking;103pub mod weights;104use weights::WeightInfo;105106/// A maximum number of levels of depth in the token nesting tree.107pub const NESTING_BUDGET: u32 = 5;108109decl_error! {110	/// Errors for the common Unique transactions.111	pub enum Error for Module<T: Config> {112		/// Decimal_points parameter must be lower than [`up_data_structs::MAX_DECIMAL_POINTS`].113		CollectionDecimalPointLimitExceeded,114		/// Length of items properties must be greater than 0.115		EmptyArgument,116		/// Repertition is only supported by refungible collection.117		RepartitionCalledOnNonRefungibleCollection,118	}119}120121/// Configuration trait of this pallet.122pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {123	/// Weight information for extrinsics in this pallet.124	type WeightInfo: WeightInfo;125126	/// Weight information for common pallet operations.127	type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;128129	/// Weight info information for extra refungible pallet operations.130	type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;131}132133type SelfWeightOf<T> = <T as Config>::WeightInfo;134135// # Used definitions136//137// ## User control levels138//139// chain-controlled - key is uncontrolled by user140//                    i.e autoincrementing index141//                    can use non-cryptographic hash142// real - key is controlled by user143//        but it is hard to generate enough colliding values, i.e owner of signed txs144//        can use non-cryptographic hash145// controlled - key is completly controlled by users146//              i.e maps with mutable keys147//              should use cryptographic hash148//149// ## User control level downgrade reasons150//151// ?1 - chain-controlled -> controlled152//      collections/tokens can be destroyed, resulting in massive holes153// ?2 - chain-controlled -> controlled154//      same as ?1, but can be only added, resulting in easier exploitation155// ?3 - real -> controlled156//      no confirmation required, so addresses can be easily generated157decl_storage! {158	trait Store for Module<T: Config> as Unique {159160		//#region Private members161		/// Used for migrations162		ChainVersion: u64;163		//#endregion164165		//#region Tokens transfer sponosoring rate limit baskets166		/// (Collection id (controlled?2), who created (real))167		/// TODO: Off chain worker should remove from this map when collection gets removed168		pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;169		/// Collection id (controlled?2), token id (controlled?2)170		pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;171		/// Collection id (controlled?2), owning user (real)172		pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;173		/// Collection id (controlled?2), token id (controlled?2)174		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>;175		//#endregion176177		/// Variable metadata sponsoring178		/// Collection id (controlled?2), token id (controlled?2)179		#[deprecated]180		pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;181		/// Last sponsoring of token property setting // todo:doc rephrase this and the following182		pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;183184		/// Last sponsoring of NFT approval in a collection185		pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;186		/// Last sponsoring of fungible tokens approval in a collection187		pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;188		/// Last sponsoring of RFT approval in a collection189		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>;190	}191}192193decl_module! {194	/// Type alias to Pallet, to be used by construct_runtime.195	pub struct Module<T: Config> for enum Call196	where197		origin: T::RuntimeOrigin198	{199		type Error = Error<T>;200201		#[doc = "A maximum number of levels of depth in the token nesting tree."]202		const NESTING_BUDGET: u32 = NESTING_BUDGET;203204		#[doc = "Maximal length of a collection name."]205		const MAX_COLLECTION_NAME_LENGTH: u32 = MAX_COLLECTION_NAME_LENGTH;206207		#[doc = "Maximal length of a collection description."]208		const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = MAX_COLLECTION_DESCRIPTION_LENGTH;209210		#[doc = "Maximal length of a token prefix."]211		const MAX_TOKEN_PREFIX_LENGTH: u32 = MAX_TOKEN_PREFIX_LENGTH;212213		#[doc = "Maximum admins per collection."]214		const COLLECTION_ADMINS_LIMIT: u32 = COLLECTION_ADMINS_LIMIT;215216		#[doc = "Maximal length of a property key."]217		const MAX_PROPERTY_KEY_LENGTH: u32 = MAX_PROPERTY_KEY_LENGTH;218219		#[doc = "Maximal length of a property value."]220		const MAX_PROPERTY_VALUE_LENGTH: u32 = MAX_PROPERTY_VALUE_LENGTH;221222		#[doc = "A maximum number of token properties."]223		const MAX_PROPERTIES_PER_ITEM: u32 = MAX_PROPERTIES_PER_ITEM;224225		#[doc = "Maximum size for all collection properties."]226		const MAX_COLLECTION_PROPERTIES_SIZE: u32 = MAX_COLLECTION_PROPERTIES_SIZE;227228		#[doc = "Maximum size of all token properties."]229		const MAX_TOKEN_PROPERTIES_SIZE: u32 = MAX_TOKEN_PROPERTIES_SIZE;230231		#[doc = "Default NFT collection limit."]232		const NFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::NFT);233234		#[doc = "Default RFT collection limit."]235		const RFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::ReFungible);236237		#[doc = "Default FT collection limit."]238		const FT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::Fungible(0));239240		fn on_initialize(_now: T::BlockNumber) -> Weight {241			Weight::zero()242		}243244		fn on_runtime_upgrade() -> Weight {245			Weight::zero()246		}247248		/// Create a collection of tokens.249		///250		/// Each Token may have multiple properties encoded as an array of bytes251		/// of certain length. The initial owner of the collection is set252		/// to the address that signed the transaction and can be changed later.253		///254		/// Prefer the more advanced [`create_collection_ex`][`Pallet::create_collection_ex`] instead.255		///256		/// # Permissions257		///258		/// * Anyone - becomes the owner of the new collection.259		///260		/// # Arguments261		///262		/// * `collection_name`: Wide-character string with collection name263		/// (limit [`MAX_COLLECTION_NAME_LENGTH`]).264		/// * `collection_description`: Wide-character string with collection description265		/// (limit [`MAX_COLLECTION_DESCRIPTION_LENGTH`]).266		/// * `token_prefix`: Byte string containing the token prefix to mark a collection267		/// to which a token belongs (limit [`MAX_TOKEN_PREFIX_LENGTH`]).268		/// * `mode`: Type of items stored in the collection and type dependent data.269		///270		/// returns collection ID271		///272		/// Deprecated: `create_collection_ex` is more up-to-date and advanced, prefer it instead.273		#[weight = <SelfWeightOf<T>>::create_collection()]274		fn create_collection(275			origin,276			collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,277			collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,278			token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,279			mode: CollectionMode280		) -> DispatchResult {281			let data: CreateCollectionData<T::AccountId> = CreateCollectionData {282				name: collection_name,283				description: collection_description,284				token_prefix,285				mode,286				..Default::default()287			};288			Self::create_collection_ex(origin, data)289		}290291		/// Create a collection with explicit parameters.292		///293		/// Prefer it to the deprecated [`create_collection`][`Pallet::create_collection`] method.294		///295		/// # Permissions296		///297		/// * Anyone - becomes the owner of the new collection.298		///299		/// # Arguments300		///301		/// * `data`: Explicit data of a collection used for its creation.302		#[weight = <SelfWeightOf<T>>::create_collection()]303		pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {304			let sender = ensure_signed(origin)?;305306			// =========307			let sender = T::CrossAccountId::from_sub(sender);308			let _id = T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;309310			Ok(())311		}312313		/// Destroy a collection if no tokens exist within.314		///315		/// # Permissions316		///317		/// * Collection owner318		///319		/// # Arguments320		///321		/// * `collection_id`: Collection to destroy.322		#[weight = <SelfWeightOf<T>>::destroy_collection()]323		pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {324			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);325326			Self::destroy_collection_internal(sender, collection_id)327		}328329		/// Add an address to allow list.330		///331		/// # Permissions332		///333		/// * Collection owner334		/// * Collection admin335		///336		/// # Arguments337		///338		/// * `collection_id`: ID of the modified collection.339		/// * `address`: ID of the address to be added to the allowlist.340		#[weight = <SelfWeightOf<T>>::add_to_allow_list()]341		pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{342343			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);344			let collection = <CollectionHandle<T>>::try_get(collection_id)?;345			collection.check_is_internal()?;346347			<PalletCommon<T>>::toggle_allowlist(348				&collection,349				&sender,350				&address,351				true,352			)?;353354			Ok(())355		}356357		/// Remove an address from allow list.358		///359		/// # Permissions360		///361		/// * Collection owner362		/// * Collection admin363		///364		/// # Arguments365		///366		/// * `collection_id`: ID of the modified collection.367		/// * `address`: ID of the address to be removed from the allowlist.368		#[weight = <SelfWeightOf<T>>::remove_from_allow_list()]369		pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{370371			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);372			let collection = <CollectionHandle<T>>::try_get(collection_id)?;373			collection.check_is_internal()?;374375			<PalletCommon<T>>::toggle_allowlist(376				&collection,377				&sender,378				&address,379				false,380			)?;381382			Ok(())383		}384385		/// Change the owner of the collection.386		///387		/// # Permissions388		///389		/// * Collection owner390		///391		/// # Arguments392		///393		/// * `collection_id`: ID of the modified collection.394		/// * `new_owner`: ID of the account that will become the owner.395		#[weight = <SelfWeightOf<T>>::change_collection_owner()]396		pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {397			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);398			let new_owner = T::CrossAccountId::from_sub(new_owner);399			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;400			target_collection.change_owner(sender, new_owner.clone())401		}402403		/// Add an admin to a collection.404		///405		/// NFT Collection can be controlled by multiple admin addresses406		/// (some which can also be servers, for example). Admins can issue407		/// and burn NFTs, as well as add and remove other admins,408		/// but cannot change NFT or Collection ownership.409		///410		/// # Permissions411		///412		/// * Collection owner413		/// * Collection admin414		///415		/// # Arguments416		///417		/// * `collection_id`: ID of the Collection to add an admin for.418		/// * `new_admin`: Address of new admin to add.419		#[weight = <SelfWeightOf<T>>::add_collection_admin()]420		pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {421			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);422			let collection = <CollectionHandle<T>>::try_get(collection_id)?;423			<PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)424		}425426		/// Remove admin of a collection.427		///428		/// An admin address can remove itself. List of admins may become empty,429		/// in which case only Collection Owner will be able to add an Admin.430		///431		/// # Permissions432		///433		/// * Collection owner434		/// * Collection admin435		///436		/// # Arguments437		///438		/// * `collection_id`: ID of the collection to remove the admin for.439		/// * `account_id`: Address of the admin to remove.440		#[weight = <SelfWeightOf<T>>::remove_collection_admin()]441		pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {442			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);443			let collection = <CollectionHandle<T>>::try_get(collection_id)?;444			<PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)445		}446447		/// Set (invite) a new collection sponsor.448		///449		/// If successful, confirmation from the sponsor-to-be will be pending.450		///451		/// # Permissions452		///453		/// * Collection owner454		/// * Collection admin455		///456		/// # Arguments457		///458		/// * `collection_id`: ID of the modified collection.459		/// * `new_sponsor`: ID of the account of the sponsor-to-be.460		#[weight = <SelfWeightOf<T>>::set_collection_sponsor()]461		pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {462			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);463			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;464			target_collection.set_sponsor(&sender, new_sponsor.clone())465		}466467		/// Confirm own sponsorship of a collection, becoming the sponsor.468		///469		/// An invitation must be pending, see [`set_collection_sponsor`][`Pallet::set_collection_sponsor`].470		/// Sponsor can pay the fees of a transaction instead of the sender,471		/// but only within specified limits.472		///473		/// # Permissions474		///475		/// * Sponsor-to-be476		///477		/// # Arguments478		///479		/// * `collection_id`: ID of the collection with the pending sponsor.480		#[weight = <SelfWeightOf<T>>::confirm_sponsorship()]481		pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {482			let sender = ensure_signed(origin)?;483			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;484			target_collection.confirm_sponsorship(&sender)485		}486487		/// Remove a collection's a sponsor, making everyone pay for their own transactions.488		///489		/// # Permissions490		///491		/// * Collection owner492		///493		/// # Arguments494		///495		/// * `collection_id`: ID of the collection with the sponsor to remove.496		#[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]497		pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {498			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);499			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;500			target_collection.remove_sponsor(&sender)501		}502503		/// Mint an item within a collection.504		///505		/// A collection must exist first, see [`create_collection_ex`][`Pallet::create_collection_ex`].506		///507		/// # Permissions508		///509		/// * Collection owner510		/// * Collection admin511		/// * Anyone if512		///     * Allow List is enabled, and513		///     * Address is added to allow list, and514		///     * MintPermission is enabled (see [`set_collection_permissions`][`Pallet::set_collection_permissions`])515		///516		/// # Arguments517		///518		/// * `collection_id`: ID of the collection to which an item would belong.519		/// * `owner`: Address of the initial owner of the item.520		/// * `data`: Token data describing the item to store on chain.521		#[weight = T::CommonWeightInfo::create_item(&data)]522		pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {523			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);524			let budget = budget::Value::new(NESTING_BUDGET);525526			dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))527		}528529		/// Create multiple items within a collection.530		///531		/// A collection must exist first, see [`create_collection_ex`][`Pallet::create_collection_ex`].532		///533		/// # Permissions534		///535		/// * Collection owner536		/// * Collection admin537		/// * Anyone if538		///     * Allow List is enabled, and539		///     * Address is added to the allow list, and540		///     * MintPermission is enabled (see [`set_collection_permissions`][`Pallet::set_collection_permissions`])541		///542		/// # Arguments543		///544		/// * `collection_id`: ID of the collection to which the tokens would belong.545		/// * `owner`: Address of the initial owner of the tokens.546		/// * `items_data`: Vector of data describing each item to be created.547		#[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]548		pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {549			ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);550			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);551			let budget = budget::Value::new(NESTING_BUDGET);552553			dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))554		}555556		/// Add or change collection properties.557		///558		/// # Permissions559		///560		/// * Collection owner561		/// * Collection admin562		///563		/// # Arguments564		///565		/// * `collection_id`: ID of the modified collection.566		/// * `properties`: Vector of key-value pairs stored as the collection's metadata.567		/// Keys support Latin letters, `-`, `_`, and `.` as symbols.568		#[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]569		pub fn set_collection_properties(570			origin,571			collection_id: CollectionId,572			properties: Vec<Property>573		) -> DispatchResultWithPostInfo {574			ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);575576			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);577578			dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))579		}580581		/// Delete specified collection properties.582		///583		/// # Permissions584		///585		/// * Collection Owner586		/// * Collection Admin587		///588		/// # Arguments589		///590		/// * `collection_id`: ID of the modified collection.591		/// * `property_keys`: Vector of keys of the properties to be deleted.592		/// Keys support Latin letters, `-`, `_`, and `.` as symbols.593		#[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]594		pub fn delete_collection_properties(595			origin,596			collection_id: CollectionId,597			property_keys: Vec<PropertyKey>,598		) -> DispatchResultWithPostInfo {599			ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);600601			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);602603			dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))604		}605606		/// Add or change token properties according to collection's permissions.607		/// Currently properties only work with NFTs.608		///609		/// # Permissions610		///611		/// * Depends on collection's token property permissions and specified property mutability:612		/// 	* Collection owner613		/// 	* Collection admin614		/// 	* Token owner615		///616		/// See [`set_token_property_permissions`][`Pallet::set_token_property_permissions`].617		///618		/// # Arguments619		///620		/// * `collection_id: ID of the collection to which the token belongs.621		/// * `token_id`: ID of the modified token.622		/// * `properties`: Vector of key-value pairs stored as the token's metadata.623		/// Keys support Latin letters, `-`, `_`, and `.` as symbols.624		#[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]625		pub fn set_token_properties(626			origin,627			collection_id: CollectionId,628			token_id: TokenId,629			properties: Vec<Property>630		) -> DispatchResultWithPostInfo {631			ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);632633			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);634			let budget = budget::Value::new(NESTING_BUDGET);635636			dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties, &budget))637		}638639		/// Delete specified token properties. Currently properties only work with NFTs.640		///641		/// # Permissions642		///643		/// * Depends on collection's token property permissions and specified property mutability:644		/// 	* Collection owner645		/// 	* Collection admin646		/// 	* Token owner647		///648		/// # Arguments649		///650		/// * `collection_id`: ID of the collection to which the token belongs.651		/// * `token_id`: ID of the modified token.652		/// * `property_keys`: Vector of keys of the properties to be deleted.653		/// Keys support Latin letters, `-`, `_`, and `.` as symbols.654		#[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]655		pub fn delete_token_properties(656			origin,657			collection_id: CollectionId,658			token_id: TokenId,659			property_keys: Vec<PropertyKey>660		) -> DispatchResultWithPostInfo {661			ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);662663			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);664			let budget = budget::Value::new(NESTING_BUDGET);665666			dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys, &budget))667		}668669		/// Add or change token property permissions of a collection.670		///671		/// Without a permission for a particular key, a property with that key672		/// cannot be created in a token.673		///674		/// # Permissions675		///676		/// * Collection owner677		/// * Collection admin678		///679		/// # Arguments680		///681		/// * `collection_id`: ID of the modified collection.682		/// * `property_permissions`: Vector of permissions for property keys.683		/// Keys support Latin letters, `-`, `_`, and `.` as symbols.684		#[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]685		pub fn set_token_property_permissions(686			origin,687			collection_id: CollectionId,688			property_permissions: Vec<PropertyKeyPermission>,689		) -> DispatchResultWithPostInfo {690			ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);691692			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);693694			dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))695		}696697		/// Create multiple items within a collection with explicitly specified initial parameters.698		///699		/// # Permissions700		///701		/// * Collection owner702		/// * Collection admin703		/// * Anyone if704		///     * Allow List is enabled, and705		///     * Address is added to allow list, and706		///     * MintPermission is enabled (see [`set_collection_permissions`][`Pallet::set_collection_permissions`])707		///708		/// # Arguments709		///710		/// * `collection_id`: ID of the collection to which the tokens would belong.711		/// * `data`: Explicit item creation data.712		#[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]713		pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {714			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);715			let budget = budget::Value::new(NESTING_BUDGET);716717			dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))718		}719720		/// Completely allow or disallow transfers for a particular collection.721		///722		/// # Permissions723		///724		/// * Collection owner725		///726		/// # Arguments727		///728		/// * `collection_id`: ID of the collection.729		/// * `value`: New value of the flag, are transfers allowed?730		#[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]731		pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {732			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);733			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;734			target_collection.check_is_internal()?;735			target_collection.check_is_owner(&sender)?;736737			// =========738739			target_collection.limits.transfers_enabled = Some(value);740			target_collection.save()741		}742743		/// Destroy an item.744		///745		/// # Permissions746		///747		/// * Collection owner748		/// * Collection admin749		/// * Current item owner750		///751		/// # Arguments752		///753		/// * `collection_id`: ID of the collection to which the item belongs.754		/// * `item_id`: ID of item to burn.755		/// * `value`: Number of pieces of the item to destroy.756		/// 	* Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.757		///     * Fungible Mode: The desired number of pieces to burn.758		///     * Re-Fungible Mode: The desired number of pieces to burn.759		#[weight = T::CommonWeightInfo::burn_item()]760		pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {761			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);762763			let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;764			if value == 1 {765				<NftTransferBasket<T>>::remove(collection_id, item_id);766				<NftApproveBasket<T>>::remove(collection_id, item_id);767			}768			// Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?769			// <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());770			// <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));771			Ok(post_info)772		}773774		/// Destroy a token on behalf of the owner as a non-owner account.775		///776		/// See also: [`approve`][`Pallet::approve`].777		///778		/// After this method executes, one approval is removed from the total so that779		/// the approved address will not be able to transfer this item again from this owner.780		///781		/// # Permissions782		///783		/// * Collection owner784		/// * Collection admin785		/// * Current token owner786		/// * Address approved by current item owner787		///788		/// # Arguments789		///790		/// * `from`: The owner of the burning item.791		/// * `collection_id`: ID of the collection to which the item belongs.792		/// * `item_id`: ID of item to burn.793		/// * `value`: Number of pieces to burn.794		/// 	* Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.795		///     * Fungible Mode: The desired number of pieces to burn.796		///     * Re-Fungible Mode: The desired number of pieces to burn.797		#[weight = T::CommonWeightInfo::burn_from()]798		pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {799			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);800			let budget = budget::Value::new(NESTING_BUDGET);801802			dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))803		}804805		/// Change ownership of the token.806		///807		/// # Permissions808		///809		/// * Collection owner810		/// * Collection admin811		/// * Current token owner812		///813		/// # Arguments814		///815		/// * `recipient`: Address of token recipient.816		/// * `collection_id`: ID of the collection the item belongs to.817		/// * `item_id`: ID of the item.818		///     * Non-Fungible Mode: Required.819		///     * Fungible Mode: Ignored.820		///     * Re-Fungible Mode: Required.821		///822		/// * `value`: Amount to transfer.823		/// 	* Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.824		///     * Fungible Mode: The desired number of pieces to transfer.825		///     * Re-Fungible Mode: The desired number of pieces to transfer.826		#[weight = T::CommonWeightInfo::transfer()]827		pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {828			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);829			let budget = budget::Value::new(NESTING_BUDGET);830831			dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))832		}833834		/// Allow a non-permissioned address to transfer or burn an item.835		///836		/// # Permissions837		///838		/// * Collection owner839		/// * Collection admin840		/// * Current item owner841		///842		/// # Arguments843		///844		/// * `spender`: Account to be approved to make specific transactions on non-owned tokens.845		/// * `collection_id`: ID of the collection the item belongs to.846		/// * `item_id`: ID of the item transactions on which are now approved.847		/// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).848		/// Set to 0 to revoke the approval.849		#[weight = T::CommonWeightInfo::approve()]850		pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {851			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);852853			dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))854		}855856		/// Allow a non-permissioned address to transfer or burn an item from owner's eth mirror.857		///858		/// # Permissions859		///860		/// * Collection owner861		/// * Collection admin862		/// * Current item owner863		///864		/// # Arguments865		///866		/// * `from`: Owner's account eth mirror867		/// * `to`: Account to be approved to make specific transactions on non-owned tokens.868		/// * `collection_id`: ID of the collection the item belongs to.869		/// * `item_id`: ID of the item transactions on which are now approved.870		/// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).871		/// Set to 0 to revoke the approval.872		#[weight = T::CommonWeightInfo::approve_from()]873		pub fn approve_from(origin, from:T::CrossAccountId, to: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {874			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);875876			dispatch_tx::<T, _>(collection_id, |d| d.approve_from(sender, from, to, item_id, amount))877		}878879		/// Change ownership of an item on behalf of the owner as a non-owner account.880		///881		/// See the [`approve`][`Pallet::approve`] method for additional information.882		///883		/// After this method executes, one approval is removed from the total so that884		/// the approved address will not be able to transfer this item again from this owner.885		///886		/// # Permissions887		///888		/// * Collection owner889		/// * Collection admin890		/// * Current item owner891		/// * Address approved by current item owner892		///893		/// # Arguments894		///895		/// * `from`: Address that currently owns the token.896		/// * `recipient`: Address of the new token-owner-to-be.897		/// * `collection_id`: ID of the collection the item.898		/// * `item_id`: ID of the item to be transferred.899		/// * `value`: Amount to transfer.900		/// 	* Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.901		///     * Fungible Mode: The desired number of pieces to transfer.902		///     * Re-Fungible Mode: The desired number of pieces to transfer.903		#[weight = T::CommonWeightInfo::transfer_from()]904		pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {905			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);906			let budget = budget::Value::new(NESTING_BUDGET);907908			dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))909		}910911		/// Set specific limits of a collection. Empty, or None fields mean chain default.912		///913		/// # Permissions914		///915		/// * Collection owner916		/// * Collection admin917		///918		/// # Arguments919		///920		/// * `collection_id`: ID of the modified collection.921		/// * `new_limit`: New limits of the collection. Fields that are not set (None)922		/// will not overwrite the old ones.923		#[weight = <SelfWeightOf<T>>::set_collection_limits()]924		pub fn set_collection_limits(925			origin,926			collection_id: CollectionId,927			new_limit: CollectionLimits,928		) -> DispatchResult {929			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);930			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;931			<PalletCommon<T>>::update_limits(&sender, &mut target_collection, new_limit)932		}933934		/// Set specific permissions of a collection. Empty, or None fields mean chain default.935		///936		/// # Permissions937		///938		/// * Collection owner939		/// * Collection admin940		///941		/// # Arguments942		///943		/// * `collection_id`: ID of the modified collection.944		/// * `new_permission`: New permissions of the collection. Fields that are not set (None)945		/// will not overwrite the old ones.946		#[weight = <SelfWeightOf<T>>::set_collection_limits()]947		pub fn set_collection_permissions(948			origin,949			collection_id: CollectionId,950			new_permission: CollectionPermissions,951		) -> DispatchResult {952			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);953			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;954			<PalletCommon<T>>::update_permissions(955				&sender,956				&mut target_collection,957				new_permission958			)959		}960961		/// Re-partition a refungible token, while owning all of its parts/pieces.962		///963		/// # Permissions964		///965		/// * Token owner (must own every part)966		///967		/// # Arguments968		///969		/// * `collection_id`: ID of the collection the RFT belongs to.970		/// * `token_id`: ID of the RFT.971		/// * `amount`: New number of parts/pieces into which the token shall be partitioned.972		#[weight = T::RefungibleExtensionsWeightInfo::repartition()]973		pub fn repartition(974			origin,975			collection_id: CollectionId,976			token_id: TokenId,977			amount: u128,978		) -> DispatchResultWithPostInfo {979			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);980			dispatch_tx::<T, _>(collection_id, |d| {981				if let Some(refungible_extensions) = d.refungible_extensions() {982					refungible_extensions.repartition(&sender, token_id, amount)983				} else {984					fail!(<Error<T>>::RepartitionCalledOnNonRefungibleCollection)985				}986			})987		}988989		/// Sets or unsets the approval of a given operator.990		///991		/// The `operator` is allowed to transfer all tokens of the `owner` on their behalf.992		///993		/// # Arguments994		///995		/// * `owner`: Token owner996		/// * `operator`: Operator997		/// * `approve`: Should operator status be granted or revoked?998		#[weight = T::CommonWeightInfo::set_allowance_for_all()]999		pub fn set_allowance_for_all(1000			origin,1001			collection_id: CollectionId,1002			operator: T::CrossAccountId,1003			approve: bool,1004		) -> DispatchResultWithPostInfo {1005			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1006			dispatch_tx::<T, _>(collection_id, |d| {1007				d.set_allowance_for_all(sender, operator, approve)1008			})1009		}10101011		/// Repairs a collection if the data was somehow corrupted.1012		///1013		/// # Arguments1014		///1015		/// * `collection_id`: ID of the collection to repair.1016		#[weight = <SelfWeightOf<T>>::force_repair_collection()]1017		pub fn force_repair_collection(1018			origin,1019			collection_id: CollectionId,1020		) -> DispatchResult {1021			ensure_root(origin)?;1022			<PalletCommon<T>>::repair_collection(collection_id)1023		}10241025		/// Repairs a token if the data was somehow corrupted.1026		///1027		/// # Arguments1028		///1029		/// * `collection_id`: ID of the collection the item belongs to.1030		/// * `item_id`: ID of the item.1031		#[weight = T::CommonWeightInfo::force_repair_item()]1032		pub fn force_repair_item(1033			origin,1034			collection_id: CollectionId,1035			item_id: TokenId,1036		) -> DispatchResultWithPostInfo {1037			ensure_root(origin)?;1038			dispatch_tx::<T, _>(collection_id, |d| {1039				d.repair_item(item_id)1040			})1041		}1042	}1043}10441045impl<T: Config> Pallet<T> {1046	/// Force set `sponsor` for `collection`.1047	///1048	/// Differs from [`set_collection_sponsor`][`Pallet::set_collection_sponsor`] in that confirmation1049	/// from the `sponsor` is not required.1050	///1051	/// # Arguments1052	///1053	/// * `sponsor`: ID of the account of the sponsor-to-be.1054	/// * `collection_id`: ID of the modified collection.1055	pub fn force_set_sponsor(sponsor: T::AccountId, collection_id: CollectionId) -> DispatchResult {1056		let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1057		target_collection.force_set_sponsor(sponsor.clone())1058	}10591060	/// Force remove `sponsor` for `collection`.1061	///1062	/// Differs from `remove_sponsor` in that1063	/// it doesn't require consent from the `owner` of the collection.1064	///1065	/// # Arguments1066	///1067	/// * `collection_id`: ID of the modified collection.1068	pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {1069		let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1070		target_collection.force_remove_sponsor()1071	}10721073	#[inline(always)]1074	pub(crate) fn destroy_collection_internal(1075		sender: T::CrossAccountId,1076		collection_id: CollectionId,1077	) -> DispatchResult {1078		let collection = <CollectionHandle<T>>::try_get(collection_id)?;1079		collection.check_is_internal()?;10801081		T::CollectionDispatch::destroy(sender, collection)?;10821083		// TODO: basket cleanup should be moved elsewhere1084		// Maybe runtime dispatch.rs should perform it?10851086		let _ = <NftTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1087		let _ = <FungibleTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1088		let _ = <ReFungibleTransferBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);10891090		let _ = <NftApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1091		let _ = <FungibleApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1092		let _ = <RefungibleApproveBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);10931094		Ok(())1095	}1096}