git.delta.rocks / unique-network / refs/commits / 07a6969a6bf5

difftreelog

source

pallets/unique/src/lib.rs33.2 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#![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)]2425use frame_support::{26	decl_module, decl_storage, decl_error, decl_event,27	dispatch::DispatchResult,28	ensure,29	weights::{Weight},30	transactional,31	pallet_prelude::{DispatchResultWithPostInfo, ConstU32},32	BoundedVec,33};34use scale_info::TypeInfo;35use frame_system::{self as system, ensure_signed};36use sp_runtime::{sp_std::prelude::Vec};37use up_data_structs::{38	VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, OFFCHAIN_SCHEMA_LIMIT,39	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,40	AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,41	SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,42	CreateItemExData, budget, CollectionField,43};44use pallet_evm::account::CrossAccountId;45use pallet_common::{46	CollectionHandle, Pallet as PalletCommon, Error as CommonError, CommonWeightInfo,47	dispatch::dispatch_call, dispatch::CollectionDispatch,48};4950#[cfg(feature = "runtime-benchmarks")]51mod benchmarking;52pub mod weights;53use weights::WeightInfo;5455pub trait SponsorshipPredict<T: Config> {56	fn predict(collection: CollectionId, account: T::CrossAccountId, token: TokenId) -> Option<u64>57	where58		u64: From<<T as frame_system::Config>::BlockNumber>;59}6061decl_error! {62	/// Error for non-fungible-token module.63	pub enum Error for Module<T: Config> {64		/// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.65		CollectionDecimalPointLimitExceeded,66		/// This address is not set as sponsor, use setCollectionSponsor first.67		ConfirmUnsetSponsorFail,68		/// Length of items properties must be greater than 0.69		EmptyArgument,70	}71}7273pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {74	type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;7576	/// Weight information for extrinsics in this pallet.77	type WeightInfo: WeightInfo;78	type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;79}8081decl_event! {82	pub enum Event<T>83	where84		<T as frame_system::Config>::AccountId,85		<T as pallet_evm::account::Config>::CrossAccountId,86	{87		/// Collection sponsor was removed88		///89		/// # Arguments90		///91		/// * collection_id: Globally unique collection identifier.92		CollectionSponsorRemoved(CollectionId),9394		/// Collection admin was added95		///96		/// # Arguments97		///98		/// * collection_id: Globally unique collection identifier.99		///100		/// * admin:  Admin address.101		CollectionAdminAdded(CollectionId, CrossAccountId),102103		/// Collection owned was change104		///105		/// # Arguments106		///107		/// * collection_id: Globally unique collection identifier.108		///109		/// * owner:  New owner address.110		CollectionOwnedChanged(CollectionId, AccountId),111112		/// Collection sponsor was set113		///114		/// # Arguments115		///116		/// * collection_id: Globally unique collection identifier.117		///118		/// * owner:  New sponsor address.119		CollectionSponsorSet(CollectionId, AccountId),120121		/// const on chain schema was set122		///123		/// # Arguments124		///125		/// * collection_id: Globally unique collection identifier.126		ConstOnChainSchemaSet(CollectionId),127128		/// New sponsor was confirm129		///130		/// # Arguments131		///132		/// * collection_id: Globally unique collection identifier.133		///134		/// * sponsor:  New sponsor address.135		SponsorshipConfirmed(CollectionId, AccountId),136137		/// Collection admin was removed138		///139		/// # Arguments140		///141		/// * collection_id: Globally unique collection identifier.142		///143		/// * admin:  Admin address.144		CollectionAdminRemoved(CollectionId, CrossAccountId),145146		/// Address was remove from allow list147		///148		/// # Arguments149		///150		/// * collection_id: Globally unique collection identifier.151		///152		/// * user:  Address.153		AllowListAddressRemoved(CollectionId, CrossAccountId),154155		/// Address was add to allow list156		///157		/// # Arguments158		///159		/// * collection_id: Globally unique collection identifier.160		///161		/// * user:  Address.162		AllowListAddressAdded(CollectionId, CrossAccountId),163164		/// Collection limits was set165		///166		/// # Arguments167		///168		/// * collection_id: Globally unique collection identifier.169		CollectionLimitSet(CollectionId),170171		/// Mint permission	was set172		///173		/// # Arguments174		///175		/// * collection_id: Globally unique collection identifier.176		MintPermissionSet(CollectionId),177178		/// Offchain schema was set179		///180		/// # Arguments181		///182		/// * collection_id: Globally unique collection identifier.183		OffchainSchemaSet(CollectionId),184185		/// Public access mode was set186		///187		/// # Arguments188		///189		/// * collection_id: Globally unique collection identifier.190		///191		/// * mode: New access state.192		PublicAccessModeSet(CollectionId, AccessMode),193194		/// Schema version was set195		///196		/// # Arguments197		///198		/// * collection_id: Globally unique collection identifier.199		SchemaVersionSet(CollectionId),200201		/// Variable on chain schema was set202		///203		/// # Arguments204		///205		/// * collection_id: Globally unique collection identifier.206		VariableOnChainSchemaSet(CollectionId),207	}208}209210type SelfWeightOf<T> = <T as Config>::WeightInfo;211212// # Used definitions213//214// ## User control levels215//216// chain-controlled - key is uncontrolled by user217//                    i.e autoincrementing index218//                    can use non-cryptographic hash219// real - key is controlled by user220//        but it is hard to generate enough colliding values, i.e owner of signed txs221//        can use non-cryptographic hash222// controlled - key is completly controlled by users223//              i.e maps with mutable keys224//              should use cryptographic hash225//226// ## User control level downgrade reasons227//228// ?1 - chain-controlled -> controlled229//      collections/tokens can be destroyed, resulting in massive holes230// ?2 - chain-controlled -> controlled231//      same as ?1, but can be only added, resulting in easier exploitation232// ?3 - real -> controlled233//      no confirmation required, so addresses can be easily generated234decl_storage! {235	trait Store for Module<T: Config> as Unique {236237		//#region Private members238		/// Used for migrations239		ChainVersion: u64;240		//#endregion241242		//#region Tokens transfer rate limit baskets243		/// (Collection id (controlled?2), who created (real))244		/// TODO: Off chain worker should remove from this map when collection gets removed245		pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;246		/// Collection id (controlled?2), token id (controlled?2)247		pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;248		/// Collection id (controlled?2), owning user (real)249		pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;250		/// Collection id (controlled?2), token id (controlled?2)251		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>;252		//#endregion253254		/// Variable metadata sponsoring255		/// Collection id (controlled?2), token id (controlled?2)256		pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;257		/// Approval sponsoring258		pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;259		pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;260		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>;261	}262}263264decl_module! {265	pub struct Module<T: Config> for enum Call266	where267		origin: T::Origin268	{269		type Error = Error<T>;270271		fn deposit_event() = default;272273		fn on_initialize(_now: T::BlockNumber) -> Weight {274			0275		}276277		/// 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.278		///279		/// # Permissions280		///281		/// * Anyone.282		///283		/// # Arguments284		///285		/// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.286		///287		/// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.288		///289		/// * token_prefix: UTF-8 string with token prefix.290		///291		/// * mode: [CollectionMode] collection type and type dependent data.292		// returns collection ID293		#[weight = <SelfWeightOf<T>>::create_collection()]294		#[transactional]295		#[deprecated]296		pub fn create_collection(origin,297								 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,298								 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,299								 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,300								 mode: CollectionMode) -> DispatchResult  {301			let data: CreateCollectionData<T::AccountId> = CreateCollectionData {302				name: collection_name,303				description: collection_description,304				token_prefix,305				mode,306				..Default::default()307			};308			Self::create_collection_ex(origin, data)309		}310311		/// This method creates a collection312		///313		/// Prefer it to deprecated [`created_collection`] method314		#[weight = <SelfWeightOf<T>>::create_collection()]315		#[transactional]316		pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {317			let sender = ensure_signed(origin)?;318319			// =========320321			T::CollectionDispatch::create(sender, data)?;322323			Ok(())324		}325326		/// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.327		///328		/// # Permissions329		///330		/// * Collection Owner.331		///332		/// # Arguments333		///334		/// * collection_id: collection to destroy.335		#[weight = <SelfWeightOf<T>>::destroy_collection()]336		#[transactional]337		pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {338			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);339			let collection = <CollectionHandle<T>>::try_get(collection_id)?;340341			// =========342343			T::CollectionDispatch::destroy(sender, collection)?;344345			<NftTransferBasket<T>>::remove_prefix(collection_id, None);346			<FungibleTransferBasket<T>>::remove_prefix(collection_id, None);347			<ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);348349			<VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);350			<NftApproveBasket<T>>::remove_prefix(collection_id, None);351			<FungibleApproveBasket<T>>::remove_prefix(collection_id, None);352			<RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);353354			Ok(())355		}356357		/// Add an address to allow list.358		///359		/// # Permissions360		///361		/// * Collection Owner362		/// * Collection Admin363		///364		/// # Arguments365		///366		/// * collection_id.367		///368		/// * address.369		#[weight = <SelfWeightOf<T>>::add_to_allow_list()]370		#[transactional]371		pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{372373			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);374			let collection = <CollectionHandle<T>>::try_get(collection_id)?;375376			<PalletCommon<T>>::toggle_allowlist(377				&collection,378				&sender,379				&address,380				true,381			)?;382383			Self::deposit_event(Event::<T>::AllowListAddressAdded(384				collection_id,385				address386			));387388			Ok(())389		}390391		/// Remove an address from allow list.392		///393		/// # Permissions394		///395		/// * Collection Owner396		/// * Collection Admin397		///398		/// # Arguments399		///400		/// * collection_id.401		///402		/// * address.403		#[weight = <SelfWeightOf<T>>::remove_from_allow_list()]404		#[transactional]405		pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{406407			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);408			let collection = <CollectionHandle<T>>::try_get(collection_id)?;409410			<PalletCommon<T>>::toggle_allowlist(411				&collection,412				&sender,413				&address,414				false,415			)?;416417			<Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(418				collection_id,419				address420			));421422			Ok(())423		}424425		/// Toggle between normal and allow list access for the methods with access for `Anyone`.426		///427		/// # Permissions428		///429		/// * Collection Owner.430		///431		/// # Arguments432		///433		/// * collection_id.434		///435		/// * mode: [AccessMode]436		#[weight = <SelfWeightOf<T>>::set_public_access_mode()]437		#[transactional]438		pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult439		{440			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);441442			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;443			target_collection.check_is_owner(&sender)?;444445			target_collection.access = mode.clone();446447			<Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(448				collection_id,449				mode450			));451452			target_collection.save()453		}454455		/// Allows Anyone to create tokens if:456		/// * Allow List is enabled, and457		/// * Address is added to allow list, and458		/// * This method was called with True parameter459		///460		/// # Permissions461		/// * Collection Owner462		///463		/// # Arguments464		///465		/// * collection_id.466		///467		/// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.468		#[weight = <SelfWeightOf<T>>::set_mint_permission()]469		#[transactional]470		pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult471		{472			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);473474			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;475			target_collection.check_is_owner(&sender)?;476477			target_collection.mint_mode = mint_permission;478479			<Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(480				collection_id481			));482483			target_collection.save()484		}485486		/// Change the owner of the collection.487		///488		/// # Permissions489		///490		/// * Collection Owner.491		///492		/// # Arguments493		///494		/// * collection_id.495		///496		/// * new_owner.497		#[weight = <SelfWeightOf<T>>::change_collection_owner()]498		#[transactional]499		pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {500501			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);502503			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;504			target_collection.check_is_owner(&sender)?;505506			target_collection.owner = new_owner.clone();507			<Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(508				collection_id,509				new_owner510			));511512			target_collection.save()513		}514515		/// Adds an admin of the Collection.516		/// 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.517		///518		/// # Permissions519		///520		/// * Collection Owner.521		/// * Collection Admin.522		///523		/// # Arguments524		///525		/// * collection_id: ID of the Collection to add admin for.526		///527		/// * new_admin_id: Address of new admin to add.528		#[weight = <SelfWeightOf<T>>::add_collection_admin()]529		#[transactional]530		pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {531			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);532			let collection = <CollectionHandle<T>>::try_get(collection_id)?;533534			<Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(535				collection_id,536				new_admin_id.clone()537			));538539			<PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)540		}541542		/// 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.543		///544		/// # Permissions545		///546		/// * Collection Owner.547		/// * Collection Admin.548		///549		/// # Arguments550		///551		/// * collection_id: ID of the Collection to remove admin for.552		///553		/// * account_id: Address of admin to remove.554		#[weight = <SelfWeightOf<T>>::remove_collection_admin()]555		#[transactional]556		pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {557			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);558			let collection = <CollectionHandle<T>>::try_get(collection_id)?;559560			<Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(561				collection_id,562				account_id.clone()563			));564565			<PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)566		}567568		/// # Permissions569		///570		/// * Collection Owner571		///572		/// # Arguments573		///574		/// * collection_id.575		///576		/// * new_sponsor.577		#[weight = <SelfWeightOf<T>>::set_collection_sponsor()]578		#[transactional]579		pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {580			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);581582			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;583			target_collection.check_is_owner(&sender)?;584585			target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());586587			<Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(588				collection_id,589				new_sponsor590			));591592			target_collection.save()593		}594595		/// # Permissions596		///597		/// * Sponsor.598		///599		/// # Arguments600		///601		/// * collection_id.602		#[weight = <SelfWeightOf<T>>::confirm_sponsorship()]603		#[transactional]604		pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {605			let sender = ensure_signed(origin)?;606607			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;608			ensure!(609				target_collection.sponsorship.pending_sponsor() == Some(&sender),610				Error::<T>::ConfirmUnsetSponsorFail611			);612613			target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());614615			<Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(616				collection_id,617				sender618			));619620			target_collection.save()621		}622623		/// Switch back to pay-per-own-transaction model.624		///625		/// # Permissions626		///627		/// * Collection owner.628		///629		/// # Arguments630		///631		/// * collection_id.632		#[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]633		#[transactional]634		pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {635			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);636637			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;638			target_collection.check_is_owner(&sender)?;639640			target_collection.sponsorship = SponsorshipState::Disabled;641642			<Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(643				collection_id644			));645			target_collection.save()646		}647648		/// This method creates a concrete instance of NFT Collection created with CreateCollection method.649		///650		/// # Permissions651		///652		/// * Collection Owner.653		/// * Collection Admin.654		/// * Anyone if655		///     * Allow List is enabled, and656		///     * Address is added to allow list, and657		///     * MintPermission is enabled (see SetMintPermission method)658		///659		/// # Arguments660		///661		/// * collection_id: ID of the collection.662		///663		/// * owner: Address, initial owner of the NFT.664		///665		/// * data: Token data to store on chain.666		#[weight = T::CommonWeightInfo::create_item()]667		#[transactional]668		pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {669			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);670			let budget = budget::Value::new(2);671672			dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))673		}674675		/// This method creates multiple items in a collection created with CreateCollection method.676		///677		/// # Permissions678		///679		/// * Collection Owner.680		/// * Collection Admin.681		/// * Anyone if682		///     * Allow List is enabled, and683		///     * Address is added to allow list, and684		///     * MintPermission is enabled (see SetMintPermission method)685		///686		/// # Arguments687		///688		/// * collection_id: ID of the collection.689		///690		/// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].691		///692		/// * owner: Address, initial owner of the NFT.693		#[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]694		#[transactional]695		pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {696			ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);697			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);698			let budget = budget::Value::new(2);699700			dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))701		}702703		#[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]704		#[transactional]705		pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {706			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);707			let budget = budget::Value::new(2);708709			dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))710		}711712		// TODO! transaction weight713714		/// Set transfers_enabled value for particular collection715		///716		/// # Permissions717		///718		/// * Collection Owner.719		///720		/// # Arguments721		///722		/// * collection_id: ID of the collection.723		///724		/// * value: New flag value.725		#[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]726		#[transactional]727		pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {728			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);729			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;730			target_collection.check_is_owner(&sender)?;731732			// =========733734			target_collection.limits.transfers_enabled = Some(value);735			target_collection.save()736		}737738		/// Destroys a concrete instance of NFT.739		///740		/// # Permissions741		///742		/// * Collection Owner.743		/// * Collection Admin.744		/// * Current NFT Owner.745		///746		/// # Arguments747		///748		/// * collection_id: ID of the collection.749		///750		/// * item_id: ID of NFT to burn.751		#[weight = T::CommonWeightInfo::burn_item()]752		#[transactional]753		pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {754			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);755756			let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;757			if value == 1 {758				<NftTransferBasket<T>>::remove(collection_id, item_id);759				<NftApproveBasket<T>>::remove(collection_id, item_id);760			}761			// Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?762			// <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());763			// <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));764			Ok(post_info)765		}766767		/// Destroys a concrete instance of NFT on behalf of the owner768		/// See also: [`approve`]769		///770		/// # Permissions771		///772		/// * Collection Owner.773		/// * Collection Admin.774		/// * Current NFT Owner.775		///776		/// # Arguments777		///778		/// * collection_id: ID of the collection.779		///780		/// * item_id: ID of NFT to burn.781		///782		/// * from: owner of item783		#[weight = T::CommonWeightInfo::burn_from()]784		#[transactional]785		pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {786			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);787			let budget = budget::Value::new(2);788789			dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))790		}791792		/// Change ownership of the token.793		///794		/// # Permissions795		///796		/// * Collection Owner797		/// * Collection Admin798		/// * Current NFT owner799		///800		/// # Arguments801		///802		/// * recipient: Address of token recipient.803		///804		/// * collection_id.805		///806		/// * item_id: ID of the item807		///     * Non-Fungible Mode: Required.808		///     * Fungible Mode: Ignored.809		///     * Re-Fungible Mode: Required.810		///811		/// * value: Amount to transfer.812		///     * Non-Fungible Mode: Ignored813		///     * Fungible Mode: Must specify transferred amount814		///     * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)815		#[weight = T::CommonWeightInfo::transfer()]816		#[transactional]817		pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {818			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);819			let budget = budget::Value::new(2);820821			dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))822		}823824		/// Set, change, or remove approved address to transfer the ownership of the NFT.825		///826		/// # Permissions827		///828		/// * Collection Owner829		/// * Collection Admin830		/// * Current NFT owner831		///832		/// # Arguments833		///834		/// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).835		///836		/// * collection_id.837		///838		/// * item_id: ID of the item.839		#[weight = T::CommonWeightInfo::approve()]840		#[transactional]841		pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {842			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);843844			dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))845		}846847		/// 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.848		///849		/// # Permissions850		/// * Collection Owner851		/// * Collection Admin852		/// * Current NFT owner853		/// * Address approved by current NFT owner854		///855		/// # Arguments856		///857		/// * from: Address that owns token.858		///859		/// * recipient: Address of token recipient.860		///861		/// * collection_id.862		///863		/// * item_id: ID of the item.864		///865		/// * value: Amount to transfer.866		#[weight = T::CommonWeightInfo::transfer_from()]867		#[transactional]868		pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {869			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);870			let budget = budget::Value::new(2);871872			dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))873		}874875		/// Set off-chain data schema.876		///877		/// # Permissions878		///879		/// * Collection Owner880		/// * Collection Admin881		///882		/// # Arguments883		///884		/// * collection_id.885		///886		/// * schema: String representing the offchain data schema.887		#[weight = T::CommonWeightInfo::set_variable_metadata(data.len() as u32)]888		#[transactional]889		pub fn set_variable_meta_data (890			origin,891			collection_id: CollectionId,892			item_id: TokenId,893			data: BoundedVec<u8, CustomDataLimit>,894		) -> DispatchResultWithPostInfo {895			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);896897			dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))898		}899900		/// Set meta_update_permission value for particular collection901		///902		/// # Permissions903		///904		/// * Collection Owner.905		///906		/// # Arguments907		///908		/// * collection_id: ID of the collection.909		///910		/// * value: New flag value.911		#[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]912		#[transactional]913		pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {914			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);915			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;916917			ensure!(918				target_collection.meta_update_permission != MetaUpdatePermission::None,919				<CommonError<T>>::MetadataFlagFrozen,920			);921			target_collection.check_is_owner(&sender)?;922923			target_collection.meta_update_permission = value;924925			target_collection.save()926		}927928		/// Set schema standard929		/// ImageURL930		/// Unique931		///932		/// # Permissions933		///934		/// * Collection Owner935		/// * Collection Admin936		///937		/// # Arguments938		///939		/// * collection_id.940		///941		/// * schema: SchemaVersion: enum942		#[weight = <SelfWeightOf<T>>::set_schema_version()]943		#[transactional]944		pub fn set_schema_version(945			origin,946			collection_id: CollectionId,947			version: SchemaVersion948		) -> DispatchResult {949			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);950			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;951			target_collection.check_is_owner_or_admin(&sender)?;952			target_collection.schema_version = version;953954			<Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(955				collection_id956			));957958			target_collection.save()959		}960961		/// Set off-chain data schema.962		///963		/// # Permissions964		///965		/// * Collection Owner966		/// * Collection Admin967		///968		/// # Arguments969		///970		/// * collection_id.971		///972		/// * schema: String representing the offchain data schema.973		#[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]974		#[transactional]975		pub fn set_offchain_schema(976			origin,977			collection_id: CollectionId,978			schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,979		) -> DispatchResult {980			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);981			let collection = <CollectionHandle<T>>::try_get(collection_id)?;982983			// =========984985			<PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;986987			<Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(988				collection_id989			));990			Ok(())991		}992993		/// Set const on-chain data schema.994		///995		/// # Permissions996		///997		/// * Collection Owner998		/// * Collection Admin999		///1000		/// # Arguments1001		///1002		/// * collection_id.1003		///1004		/// * schema: String representing the const on-chain data schema.1005		#[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1006		#[transactional]1007		pub fn set_const_on_chain_schema (1008			origin,1009			collection_id: CollectionId,1010			schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1011		) -> DispatchResult {1012			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1013			let collection = <CollectionHandle<T>>::try_get(collection_id)?;10141015			// =========10161017			<PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10181019			<Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1020				collection_id1021			));1022			Ok(())1023		}10241025		/// Set variable on-chain data schema.1026		///1027		/// # Permissions1028		///1029		/// * Collection Owner1030		/// * Collection Admin1031		///1032		/// # Arguments1033		///1034		/// * collection_id.1035		///1036		/// * schema: String representing the variable on-chain data schema.1037		#[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1038		#[transactional]1039		pub fn set_variable_on_chain_schema (1040			origin,1041			collection_id: CollectionId,1042			schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1043		) -> DispatchResult {1044			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1045			let collection = <CollectionHandle<T>>::try_get(collection_id)?;10461047			// =========10481049			<PalletCommon<T>>::set_field(&collection, &sender, CollectionField::VariableOnChainSchema, schema.into_inner())?;10501051			<Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1052				collection_id1053			));1054			Ok(())1055		}10561057		#[weight = <SelfWeightOf<T>>::set_collection_limits()]1058		#[transactional]1059		pub fn set_collection_limits(1060			origin,1061			collection_id: CollectionId,1062			new_limit: CollectionLimits,1063		) -> DispatchResult {1064			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1065			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1066			target_collection.check_is_owner(&sender)?;1067			let old_limit = &target_collection.limits;10681069			target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10701071			<Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1072				collection_id1073			));10741075			target_collection.save()1076		}1077	}1078}