referrerpolicy=no-referrer-when-downgrade

pallet_nfts/
lib.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! # Nfts Module
19//!
20//! A simple, secure module for dealing with non-fungible items.
21//!
22//! ## Related Modules
23//!
24//! * [`System`](../frame_system/index.html)
25//! * [`Support`](../frame_support/index.html)
26
27#![recursion_limit = "256"]
28// Ensure we're `no_std` when compiling for Wasm.
29#![cfg_attr(not(feature = "std"), no_std)]
30
31#[cfg(feature = "runtime-benchmarks")]
32mod benchmarking;
33pub mod migration;
34#[cfg(test)]
35pub mod mock;
36#[cfg(test)]
37mod tests;
38
39mod common_functions;
40/// A library providing the feature set of this pallet. It contains modules with helper methods that
41/// perform storage updates and checks required by this pallet's dispatchables. To use pallet level
42/// features, make sure to set appropriate bitflags for [`Config::Features`] in your runtime
43/// configuration trait.
44mod features;
45mod impl_nonfungibles;
46mod types;
47
48pub mod macros;
49pub mod weights;
50
51extern crate alloc;
52
53use alloc::{boxed::Box, vec, vec::Vec};
54use codec::{Decode, Encode};
55use frame_support::traits::{
56	tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, Incrementable,
57	ReservableCurrency,
58};
59use frame_system::Config as SystemConfig;
60use sp_runtime::{
61	traits::{BlockNumberProvider, IdentifyAccount, Saturating, StaticLookup, Verify, Zero},
62	Debug,
63};
64
65pub use pallet::*;
66pub use types::*;
67pub use weights::WeightInfo;
68
69/// The log target of this pallet.
70pub const LOG_TARGET: &'static str = "runtime::nfts";
71
72/// A type alias for the account ID type used in the dispatchable functions of this pallet.
73type AccountIdLookupOf<T> = <<T as SystemConfig>::Lookup as StaticLookup>::Source;
74
75#[frame_support::pallet]
76pub mod pallet {
77	use super::*;
78	use frame_support::{pallet_prelude::*, traits::ExistenceRequirement};
79	use frame_system::{ensure_signed, pallet_prelude::OriginFor};
80
81	/// The in-code storage version.
82	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
83
84	#[pallet::pallet]
85	#[pallet::storage_version(STORAGE_VERSION)]
86	pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
87
88	#[cfg(feature = "runtime-benchmarks")]
89	pub trait BenchmarkHelper<CollectionId, ItemId, Public, AccountId, Signature> {
90		fn collection(i: u16) -> CollectionId;
91		fn item(i: u16) -> ItemId;
92		fn signer() -> (Public, AccountId);
93		fn sign(signer: &Public, message: &[u8]) -> Signature;
94	}
95	#[cfg(feature = "runtime-benchmarks")]
96	impl<CollectionId, ItemId>
97		BenchmarkHelper<
98			CollectionId,
99			ItemId,
100			sp_runtime::MultiSigner,
101			sp_runtime::AccountId32,
102			sp_runtime::MultiSignature,
103		> for ()
104	where
105		CollectionId: From<u16>,
106		ItemId: From<u16>,
107	{
108		fn collection(i: u16) -> CollectionId {
109			i.into()
110		}
111		fn item(i: u16) -> ItemId {
112			i.into()
113		}
114		fn signer() -> (sp_runtime::MultiSigner, sp_runtime::AccountId32) {
115			let public = sp_io::crypto::sr25519_generate(0.into(), None);
116			let account = sp_runtime::MultiSigner::Sr25519(public).into_account();
117			(public.into(), account)
118		}
119		fn sign(signer: &sp_runtime::MultiSigner, message: &[u8]) -> sp_runtime::MultiSignature {
120			sp_runtime::MultiSignature::Sr25519(
121				sp_io::crypto::sr25519_sign(0.into(), &signer.clone().try_into().unwrap(), message)
122					.unwrap(),
123			)
124		}
125	}
126
127	#[pallet::config]
128	/// The module configuration trait.
129	pub trait Config<I: 'static = ()>: frame_system::Config {
130		/// The overarching event type.
131		#[allow(deprecated)]
132		type RuntimeEvent: From<Event<Self, I>>
133			+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
134
135		/// Identifier for the collection of item.
136		///
137		/// SAFETY: The functions in the `Incrementable` trait are fallible. If the functions
138		/// of the implementation both return `None`, the automatic CollectionId generation
139		/// should not be used. So the `create` and `force_create` extrinsics and the
140		/// `create_collection` function will return an `UnknownCollection` Error. Instead use
141		/// the `create_collection_with_id` function. However, if the `Incrementable` trait
142		/// implementation has an incremental order, the `create_collection_with_id` function
143		/// should not be used as it can claim a value in the ID sequence.
144		type CollectionId: Member + Parameter + MaxEncodedLen + Copy + Incrementable;
145
146		/// The type used to identify a unique item within a collection.
147		type ItemId: Member + Parameter + MaxEncodedLen + Copy;
148
149		/// The currency mechanism, used for paying for reserves.
150		type Currency: ReservableCurrency<Self::AccountId>;
151
152		/// The origin which may forcibly create or destroy an item or otherwise alter privileged
153		/// attributes.
154		type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
155
156		/// Standard collection creation is only allowed if the origin attempting it and the
157		/// collection are in this set.
158		type CreateOrigin: EnsureOriginWithArg<
159			Self::RuntimeOrigin,
160			Self::CollectionId,
161			Success = Self::AccountId,
162		>;
163
164		/// Locker trait to enable Locking mechanism downstream.
165		type Locker: Locker<Self::CollectionId, Self::ItemId>;
166
167		/// The basic amount of funds that must be reserved for collection.
168		#[pallet::constant]
169		type CollectionDeposit: Get<DepositBalanceOf<Self, I>>;
170
171		/// The basic amount of funds that must be reserved for an item.
172		#[pallet::constant]
173		type ItemDeposit: Get<DepositBalanceOf<Self, I>>;
174
175		/// The basic amount of funds that must be reserved when adding metadata to your item.
176		#[pallet::constant]
177		type MetadataDepositBase: Get<DepositBalanceOf<Self, I>>;
178
179		/// The basic amount of funds that must be reserved when adding an attribute to an item.
180		#[pallet::constant]
181		type AttributeDepositBase: Get<DepositBalanceOf<Self, I>>;
182
183		/// The additional funds that must be reserved for the number of bytes store in metadata,
184		/// either "normal" metadata or attribute metadata.
185		#[pallet::constant]
186		type DepositPerByte: Get<DepositBalanceOf<Self, I>>;
187
188		/// The maximum length of data stored on-chain.
189		#[pallet::constant]
190		type StringLimit: Get<u32>;
191
192		/// The maximum length of an attribute key.
193		#[pallet::constant]
194		type KeyLimit: Get<u32>;
195
196		/// The maximum length of an attribute value.
197		#[pallet::constant]
198		type ValueLimit: Get<u32>;
199
200		/// The maximum approvals an item could have.
201		#[pallet::constant]
202		type ApprovalsLimit: Get<u32>;
203
204		/// The maximum attributes approvals an item could have.
205		#[pallet::constant]
206		type ItemAttributesApprovalsLimit: Get<u32>;
207
208		/// The max number of tips a user could send.
209		#[pallet::constant]
210		type MaxTips: Get<u32>;
211
212		/// The max duration in blocks for deadlines.
213		#[pallet::constant]
214		type MaxDeadlineDuration: Get<BlockNumberFor<Self, I>>;
215
216		/// The max number of attributes a user could set per call.
217		#[pallet::constant]
218		type MaxAttributesPerCall: Get<u32>;
219
220		/// Disables some of pallet's features.
221		#[pallet::constant]
222		type Features: Get<PalletFeatures>;
223
224		/// Off-Chain signature type.
225		///
226		/// Can verify whether an `Self::OffchainPublic` created a signature.
227		type OffchainSignature: Verify<Signer = Self::OffchainPublic> + Parameter;
228
229		/// Off-Chain public key.
230		///
231		/// Must identify as an on-chain `Self::AccountId`.
232		type OffchainPublic: IdentifyAccount<AccountId = Self::AccountId>;
233
234		#[cfg(feature = "runtime-benchmarks")]
235		/// A set of helper functions for benchmarking.
236		type Helper: BenchmarkHelper<
237			Self::CollectionId,
238			Self::ItemId,
239			Self::OffchainPublic,
240			Self::AccountId,
241			Self::OffchainSignature,
242		>;
243
244		/// Weight information for extrinsics in this pallet.
245		type WeightInfo: WeightInfo;
246
247		/// Provider for the block number. Normally this is the `frame_system` pallet.
248		type BlockNumberProvider: BlockNumberProvider;
249	}
250
251	/// Details of a collection.
252	#[pallet::storage]
253	pub type Collection<T: Config<I>, I: 'static = ()> = StorageMap<
254		_,
255		Blake2_128Concat,
256		T::CollectionId,
257		CollectionDetails<T::AccountId, DepositBalanceOf<T, I>>,
258	>;
259
260	/// The collection, if any, of which an account is willing to take ownership.
261	#[pallet::storage]
262	pub type OwnershipAcceptance<T: Config<I>, I: 'static = ()> =
263		StorageMap<_, Blake2_128Concat, T::AccountId, T::CollectionId>;
264
265	/// The items held by any given account; set out this way so that items owned by a single
266	/// account can be enumerated.
267	#[pallet::storage]
268	pub type Account<T: Config<I>, I: 'static = ()> = StorageNMap<
269		_,
270		(
271			NMapKey<Blake2_128Concat, T::AccountId>, // owner
272			NMapKey<Blake2_128Concat, T::CollectionId>,
273			NMapKey<Blake2_128Concat, T::ItemId>,
274		),
275		(),
276		OptionQuery,
277	>;
278
279	/// The collections owned by any given account; set out this way so that collections owned by
280	/// a single account can be enumerated.
281	#[pallet::storage]
282	pub type CollectionAccount<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
283		_,
284		Blake2_128Concat,
285		T::AccountId,
286		Blake2_128Concat,
287		T::CollectionId,
288		(),
289		OptionQuery,
290	>;
291
292	/// The items in existence and their ownership details.
293	#[pallet::storage]
294	/// Stores collection roles as per account.
295	pub type CollectionRoleOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
296		_,
297		Blake2_128Concat,
298		T::CollectionId,
299		Blake2_128Concat,
300		T::AccountId,
301		CollectionRoles,
302		OptionQuery,
303	>;
304
305	/// The items in existence and their ownership details.
306	#[pallet::storage]
307	pub type Item<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
308		_,
309		Blake2_128Concat,
310		T::CollectionId,
311		Blake2_128Concat,
312		T::ItemId,
313		ItemDetails<T::AccountId, ItemDepositOf<T, I>, ApprovalsOf<T, I>>,
314		OptionQuery,
315	>;
316
317	/// Metadata of a collection.
318	#[pallet::storage]
319	pub type CollectionMetadataOf<T: Config<I>, I: 'static = ()> = StorageMap<
320		_,
321		Blake2_128Concat,
322		T::CollectionId,
323		CollectionMetadata<DepositBalanceOf<T, I>, T::StringLimit>,
324		OptionQuery,
325	>;
326
327	/// Metadata of an item.
328	#[pallet::storage]
329	pub type ItemMetadataOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
330		_,
331		Blake2_128Concat,
332		T::CollectionId,
333		Blake2_128Concat,
334		T::ItemId,
335		ItemMetadata<ItemMetadataDepositOf<T, I>, T::StringLimit>,
336		OptionQuery,
337	>;
338
339	/// Attributes of a collection.
340	#[pallet::storage]
341	pub type Attribute<T: Config<I>, I: 'static = ()> = StorageNMap<
342		_,
343		(
344			NMapKey<Blake2_128Concat, T::CollectionId>,
345			NMapKey<Blake2_128Concat, Option<T::ItemId>>,
346			NMapKey<Blake2_128Concat, AttributeNamespace<T::AccountId>>,
347			NMapKey<Blake2_128Concat, BoundedVec<u8, T::KeyLimit>>,
348		),
349		(BoundedVec<u8, T::ValueLimit>, AttributeDepositOf<T, I>),
350		OptionQuery,
351	>;
352
353	/// A price of an item.
354	#[pallet::storage]
355	pub type ItemPriceOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
356		_,
357		Blake2_128Concat,
358		T::CollectionId,
359		Blake2_128Concat,
360		T::ItemId,
361		(ItemPrice<T, I>, Option<T::AccountId>),
362		OptionQuery,
363	>;
364
365	/// Item attribute approvals.
366	#[pallet::storage]
367	pub type ItemAttributesApprovalsOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
368		_,
369		Blake2_128Concat,
370		T::CollectionId,
371		Blake2_128Concat,
372		T::ItemId,
373		ItemAttributesApprovals<T, I>,
374		ValueQuery,
375	>;
376
377	/// Stores the `CollectionId` that is going to be used for the next collection.
378	/// This gets incremented whenever a new collection is created.
379	#[pallet::storage]
380	pub type NextCollectionId<T: Config<I>, I: 'static = ()> =
381		StorageValue<_, T::CollectionId, OptionQuery>;
382
383	/// Handles all the pending swaps.
384	#[pallet::storage]
385	pub type PendingSwapOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
386		_,
387		Blake2_128Concat,
388		T::CollectionId,
389		Blake2_128Concat,
390		T::ItemId,
391		PendingSwap<
392			T::CollectionId,
393			T::ItemId,
394			PriceWithDirection<ItemPrice<T, I>>,
395			BlockNumberFor<T, I>,
396		>,
397		OptionQuery,
398	>;
399
400	/// Config of a collection.
401	#[pallet::storage]
402	pub type CollectionConfigOf<T: Config<I>, I: 'static = ()> =
403		StorageMap<_, Blake2_128Concat, T::CollectionId, CollectionConfigFor<T, I>, OptionQuery>;
404
405	/// Config of an item.
406	#[pallet::storage]
407	pub type ItemConfigOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
408		_,
409		Blake2_128Concat,
410		T::CollectionId,
411		Blake2_128Concat,
412		T::ItemId,
413		ItemConfig,
414		OptionQuery,
415	>;
416
417	#[pallet::event]
418	#[pallet::generate_deposit(pub(super) fn deposit_event)]
419	pub enum Event<T: Config<I>, I: 'static = ()> {
420		/// A `collection` was created.
421		Created { collection: T::CollectionId, creator: T::AccountId, owner: T::AccountId },
422		/// A `collection` was force-created.
423		ForceCreated { collection: T::CollectionId, owner: T::AccountId },
424		/// A `collection` was destroyed.
425		Destroyed { collection: T::CollectionId },
426		/// An `item` was issued.
427		Issued { collection: T::CollectionId, item: T::ItemId, owner: T::AccountId },
428		/// An `item` was transferred.
429		Transferred {
430			collection: T::CollectionId,
431			item: T::ItemId,
432			from: T::AccountId,
433			to: T::AccountId,
434		},
435		/// An `item` was destroyed.
436		Burned { collection: T::CollectionId, item: T::ItemId, owner: T::AccountId },
437		/// An `item` became non-transferable.
438		ItemTransferLocked { collection: T::CollectionId, item: T::ItemId },
439		/// An `item` became transferable.
440		ItemTransferUnlocked { collection: T::CollectionId, item: T::ItemId },
441		/// `item` metadata or attributes were locked.
442		ItemPropertiesLocked {
443			collection: T::CollectionId,
444			item: T::ItemId,
445			lock_metadata: bool,
446			lock_attributes: bool,
447		},
448		/// Some `collection` was locked.
449		CollectionLocked { collection: T::CollectionId },
450		/// The owner changed.
451		OwnerChanged { collection: T::CollectionId, new_owner: T::AccountId },
452		/// The management team changed.
453		TeamChanged {
454			collection: T::CollectionId,
455			issuer: Option<T::AccountId>,
456			admin: Option<T::AccountId>,
457			freezer: Option<T::AccountId>,
458		},
459		/// An `item` of a `collection` has been approved by the `owner` for transfer by
460		/// a `delegate`.
461		TransferApproved {
462			collection: T::CollectionId,
463			item: T::ItemId,
464			owner: T::AccountId,
465			delegate: T::AccountId,
466			deadline: Option<BlockNumberFor<T, I>>,
467		},
468		/// An approval for a `delegate` account to transfer the `item` of an item
469		/// `collection` was cancelled by its `owner`.
470		ApprovalCancelled {
471			collection: T::CollectionId,
472			item: T::ItemId,
473			owner: T::AccountId,
474			delegate: T::AccountId,
475		},
476		/// All approvals of an item got cancelled.
477		AllApprovalsCancelled { collection: T::CollectionId, item: T::ItemId, owner: T::AccountId },
478		/// A `collection` has had its config changed by the `Force` origin.
479		CollectionConfigChanged { collection: T::CollectionId },
480		/// New metadata has been set for a `collection`.
481		CollectionMetadataSet { collection: T::CollectionId, data: BoundedVec<u8, T::StringLimit> },
482		/// Metadata has been cleared for a `collection`.
483		CollectionMetadataCleared { collection: T::CollectionId },
484		/// New metadata has been set for an item.
485		ItemMetadataSet {
486			collection: T::CollectionId,
487			item: T::ItemId,
488			data: BoundedVec<u8, T::StringLimit>,
489		},
490		/// Metadata has been cleared for an item.
491		ItemMetadataCleared { collection: T::CollectionId, item: T::ItemId },
492		/// The deposit for a set of `item`s within a `collection` has been updated.
493		Redeposited { collection: T::CollectionId, successful_items: Vec<T::ItemId> },
494		/// New attribute metadata has been set for a `collection` or `item`.
495		AttributeSet {
496			collection: T::CollectionId,
497			maybe_item: Option<T::ItemId>,
498			key: BoundedVec<u8, T::KeyLimit>,
499			value: BoundedVec<u8, T::ValueLimit>,
500			namespace: AttributeNamespace<T::AccountId>,
501		},
502		/// Attribute metadata has been cleared for a `collection` or `item`.
503		AttributeCleared {
504			collection: T::CollectionId,
505			maybe_item: Option<T::ItemId>,
506			key: BoundedVec<u8, T::KeyLimit>,
507			namespace: AttributeNamespace<T::AccountId>,
508		},
509		/// A new approval to modify item attributes was added.
510		ItemAttributesApprovalAdded {
511			collection: T::CollectionId,
512			item: T::ItemId,
513			delegate: T::AccountId,
514		},
515		/// A new approval to modify item attributes was removed.
516		ItemAttributesApprovalRemoved {
517			collection: T::CollectionId,
518			item: T::ItemId,
519			delegate: T::AccountId,
520		},
521		/// Ownership acceptance has changed for an account.
522		OwnershipAcceptanceChanged { who: T::AccountId, maybe_collection: Option<T::CollectionId> },
523		/// Max supply has been set for a collection.
524		CollectionMaxSupplySet { collection: T::CollectionId, max_supply: u32 },
525		/// Mint settings for a collection had changed.
526		CollectionMintSettingsUpdated { collection: T::CollectionId },
527		/// Event gets emitted when the `NextCollectionId` gets incremented.
528		NextCollectionIdIncremented { next_id: Option<T::CollectionId> },
529		/// The price was set for the item.
530		ItemPriceSet {
531			collection: T::CollectionId,
532			item: T::ItemId,
533			price: ItemPrice<T, I>,
534			whitelisted_buyer: Option<T::AccountId>,
535		},
536		/// The price for the item was removed.
537		ItemPriceRemoved { collection: T::CollectionId, item: T::ItemId },
538		/// An item was bought.
539		ItemBought {
540			collection: T::CollectionId,
541			item: T::ItemId,
542			price: ItemPrice<T, I>,
543			seller: T::AccountId,
544			buyer: T::AccountId,
545		},
546		/// A tip was sent.
547		TipSent {
548			collection: T::CollectionId,
549			item: T::ItemId,
550			sender: T::AccountId,
551			receiver: T::AccountId,
552			amount: DepositBalanceOf<T, I>,
553		},
554		/// An `item` swap intent was created.
555		SwapCreated {
556			offered_collection: T::CollectionId,
557			offered_item: T::ItemId,
558			desired_collection: T::CollectionId,
559			desired_item: Option<T::ItemId>,
560			price: Option<PriceWithDirection<ItemPrice<T, I>>>,
561			deadline: BlockNumberFor<T, I>,
562		},
563		/// The swap was cancelled.
564		SwapCancelled {
565			offered_collection: T::CollectionId,
566			offered_item: T::ItemId,
567			desired_collection: T::CollectionId,
568			desired_item: Option<T::ItemId>,
569			price: Option<PriceWithDirection<ItemPrice<T, I>>>,
570			deadline: BlockNumberFor<T, I>,
571		},
572		/// The swap has been claimed.
573		SwapClaimed {
574			sent_collection: T::CollectionId,
575			sent_item: T::ItemId,
576			sent_item_owner: T::AccountId,
577			received_collection: T::CollectionId,
578			received_item: T::ItemId,
579			received_item_owner: T::AccountId,
580			price: Option<PriceWithDirection<ItemPrice<T, I>>>,
581			deadline: BlockNumberFor<T, I>,
582		},
583		/// New attributes have been set for an `item` of the `collection`.
584		PreSignedAttributesSet {
585			collection: T::CollectionId,
586			item: T::ItemId,
587			namespace: AttributeNamespace<T::AccountId>,
588		},
589		/// A new attribute in the `Pallet` namespace was set for the `collection` or an `item`
590		/// within that `collection`.
591		PalletAttributeSet {
592			collection: T::CollectionId,
593			item: Option<T::ItemId>,
594			attribute: PalletAttributes<T::CollectionId>,
595			value: BoundedVec<u8, T::ValueLimit>,
596		},
597	}
598
599	#[pallet::error]
600	pub enum Error<T, I = ()> {
601		/// The signing account has no permission to do the operation.
602		NoPermission,
603		/// The given item ID is unknown.
604		UnknownCollection,
605		/// The item ID has already been used for an item.
606		AlreadyExists,
607		/// The approval had a deadline that expired, so the approval isn't valid anymore.
608		ApprovalExpired,
609		/// The owner turned out to be different to what was expected.
610		WrongOwner,
611		/// The witness data given does not match the current state of the chain.
612		BadWitness,
613		/// Collection ID is already taken.
614		CollectionIdInUse,
615		/// Items within that collection are non-transferable.
616		ItemsNonTransferable,
617		/// The provided account is not a delegate.
618		NotDelegate,
619		/// The delegate turned out to be different to what was expected.
620		WrongDelegate,
621		/// No approval exists that would allow the transfer.
622		Unapproved,
623		/// The named owner has not signed ownership acceptance of the collection.
624		Unaccepted,
625		/// The item is locked (non-transferable).
626		ItemLocked,
627		/// Item's attributes are locked.
628		LockedItemAttributes,
629		/// Collection's attributes are locked.
630		LockedCollectionAttributes,
631		/// Item's metadata is locked.
632		LockedItemMetadata,
633		/// Collection's metadata is locked.
634		LockedCollectionMetadata,
635		/// All items have been minted.
636		MaxSupplyReached,
637		/// The max supply is locked and can't be changed.
638		MaxSupplyLocked,
639		/// The provided max supply is less than the number of items a collection already has.
640		MaxSupplyTooSmall,
641		/// The given item ID is unknown.
642		UnknownItem,
643		/// Swap doesn't exist.
644		UnknownSwap,
645		/// The given item has no metadata set.
646		MetadataNotFound,
647		/// The provided attribute can't be found.
648		AttributeNotFound,
649		/// Item is not for sale.
650		NotForSale,
651		/// The provided bid is too low.
652		BidTooLow,
653		/// The item has reached its approval limit.
654		ReachedApprovalLimit,
655		/// The deadline has already expired.
656		DeadlineExpired,
657		/// The duration provided should be less than or equal to `MaxDeadlineDuration`.
658		WrongDuration,
659		/// The method is disabled by system settings.
660		MethodDisabled,
661		/// The provided setting can't be set.
662		WrongSetting,
663		/// Item's config already exists and should be equal to the provided one.
664		InconsistentItemConfig,
665		/// Config for a collection or an item can't be found.
666		NoConfig,
667		/// Some roles were not cleared.
668		RolesNotCleared,
669		/// Mint has not started yet.
670		MintNotStarted,
671		/// Mint has already ended.
672		MintEnded,
673		/// The provided Item was already used for claiming.
674		AlreadyClaimed,
675		/// The provided data is incorrect.
676		IncorrectData,
677		/// The extrinsic was sent by the wrong origin.
678		WrongOrigin,
679		/// The provided signature is incorrect.
680		WrongSignature,
681		/// The provided metadata might be too long.
682		IncorrectMetadata,
683		/// Can't set more attributes per one call.
684		MaxAttributesLimitReached,
685		/// The provided namespace isn't supported in this call.
686		WrongNamespace,
687		/// Can't delete non-empty collections.
688		CollectionNotEmpty,
689		/// The witness data should be provided.
690		WitnessRequired,
691		/// The collection deposit could not be fully moved due to a lock or freeze on the owner.
692		IncompleteDepositTransfer,
693	}
694
695	#[pallet::call]
696	impl<T: Config<I>, I: 'static> Pallet<T, I> {
697		/// Issue a new collection of non-fungible items from a public origin.
698		///
699		/// This new collection has no items initially and its owner is the origin.
700		///
701		/// The origin must be Signed and the sender must have sufficient funds free.
702		///
703		/// `CollectionDeposit` funds of sender are reserved.
704		///
705		/// Parameters:
706		/// - `admin`: The admin of this collection. The admin is the initial address of each
707		/// member of the collection's admin team.
708		///
709		/// Emits `Created` event when successful.
710		///
711		/// Weight: `O(1)`
712		#[pallet::call_index(0)]
713		#[pallet::weight(T::WeightInfo::create())]
714		pub fn create(
715			origin: OriginFor<T>,
716			admin: AccountIdLookupOf<T>,
717			config: CollectionConfigFor<T, I>,
718		) -> DispatchResult {
719			let collection = NextCollectionId::<T, I>::get()
720				.or(T::CollectionId::initial_value())
721				.ok_or(Error::<T, I>::UnknownCollection)?;
722
723			let owner = T::CreateOrigin::ensure_origin(origin, &collection)?;
724			let admin = T::Lookup::lookup(admin)?;
725
726			// DepositRequired can be disabled by calling the force_create() only
727			ensure!(
728				!config.has_disabled_setting(CollectionSetting::DepositRequired),
729				Error::<T, I>::WrongSetting
730			);
731
732			Self::do_create_collection(
733				collection,
734				owner.clone(),
735				admin.clone(),
736				config,
737				T::CollectionDeposit::get(),
738				Event::Created { collection, creator: owner, owner: admin },
739			)?;
740
741			Self::set_next_collection_id(collection);
742			Ok(())
743		}
744
745		/// Issue a new collection of non-fungible items from a privileged origin.
746		///
747		/// This new collection has no items initially.
748		///
749		/// The origin must conform to `ForceOrigin`.
750		///
751		/// Unlike `create`, no funds are reserved.
752		///
753		/// - `owner`: The owner of this collection of items. The owner has full superuser
754		///   permissions over this item, but may later change and configure the permissions using
755		///   `transfer_ownership` and `set_team`.
756		///
757		/// Emits `ForceCreated` event when successful.
758		///
759		/// Weight: `O(1)`
760		#[pallet::call_index(1)]
761		#[pallet::weight(T::WeightInfo::force_create())]
762		pub fn force_create(
763			origin: OriginFor<T>,
764			owner: AccountIdLookupOf<T>,
765			config: CollectionConfigFor<T, I>,
766		) -> DispatchResult {
767			T::ForceOrigin::ensure_origin(origin)?;
768			let owner = T::Lookup::lookup(owner)?;
769
770			let collection = NextCollectionId::<T, I>::get()
771				.or(T::CollectionId::initial_value())
772				.ok_or(Error::<T, I>::UnknownCollection)?;
773
774			Self::do_create_collection(
775				collection,
776				owner.clone(),
777				owner.clone(),
778				config,
779				Zero::zero(),
780				Event::ForceCreated { collection, owner },
781			)?;
782
783			Self::set_next_collection_id(collection);
784			Ok(())
785		}
786
787		/// Destroy a collection of fungible items.
788		///
789		/// The origin must conform to `ForceOrigin` or must be `Signed` and the sender must be the
790		/// owner of the `collection`.
791		///
792		/// NOTE: The collection must have 0 items to be destroyed.
793		///
794		/// - `collection`: The identifier of the collection to be destroyed.
795		/// - `witness`: Information on the items minted in the collection. This must be
796		/// correct.
797		///
798		/// Emits `Destroyed` event when successful.
799		///
800		/// Weight: `O(m + c + a)` where:
801		/// - `m = witness.item_metadatas`
802		/// - `c = witness.item_configs`
803		/// - `a = witness.attributes`
804		#[pallet::call_index(2)]
805		#[pallet::weight(T::WeightInfo::destroy(
806			witness.item_metadatas,
807			witness.item_configs,
808			witness.attributes,
809 		))]
810		pub fn destroy(
811			origin: OriginFor<T>,
812			collection: T::CollectionId,
813			witness: DestroyWitness,
814		) -> DispatchResultWithPostInfo {
815			let maybe_check_owner = T::ForceOrigin::try_origin(origin)
816				.map(|_| None)
817				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
818			let details = Self::do_destroy_collection(collection, witness, maybe_check_owner)?;
819
820			Ok(Some(T::WeightInfo::destroy(
821				details.item_metadatas,
822				details.item_configs,
823				details.attributes,
824			))
825			.into())
826		}
827
828		/// Mint an item of a particular collection.
829		///
830		/// The origin must be Signed and the sender must comply with the `mint_settings` rules.
831		///
832		/// - `collection`: The collection of the item to be minted.
833		/// - `item`: An identifier of the new item.
834		/// - `mint_to`: Account into which the item will be minted.
835		/// - `witness_data`: When the mint type is `HolderOf(collection_id)`, then the owned
836		///   item_id from that collection needs to be provided within the witness data object. If
837		///   the mint price is set, then it should be additionally confirmed in the `witness_data`.
838		///
839		/// Note: the deposit will be taken from the `origin` and not the `owner` of the `item`.
840		///
841		/// Emits `Issued` event when successful.
842		///
843		/// Weight: `O(1)`
844		#[pallet::call_index(3)]
845		#[pallet::weight(T::WeightInfo::mint())]
846		pub fn mint(
847			origin: OriginFor<T>,
848			collection: T::CollectionId,
849			item: T::ItemId,
850			mint_to: AccountIdLookupOf<T>,
851			witness_data: Option<MintWitness<T::ItemId, DepositBalanceOf<T, I>>>,
852		) -> DispatchResult {
853			let caller = ensure_signed(origin)?;
854			let mint_to = T::Lookup::lookup(mint_to)?;
855			let item_config =
856				ItemConfig { settings: Self::get_default_item_settings(&collection)? };
857
858			Self::do_mint(
859				collection,
860				item,
861				Some(caller.clone()),
862				mint_to.clone(),
863				item_config,
864				|collection_details, collection_config| {
865					let mint_settings = collection_config.mint_settings;
866					let now = T::BlockNumberProvider::current_block_number();
867
868					if let Some(start_block) = mint_settings.start_block {
869						ensure!(start_block <= now, Error::<T, I>::MintNotStarted);
870					}
871					if let Some(end_block) = mint_settings.end_block {
872						ensure!(end_block >= now, Error::<T, I>::MintEnded);
873					}
874
875					match mint_settings.mint_type {
876						MintType::Issuer => {
877							ensure!(
878								Self::has_role(&collection, &caller, CollectionRole::Issuer),
879								Error::<T, I>::NoPermission
880							);
881						},
882						MintType::HolderOf(collection_id) => {
883							let MintWitness { owned_item, .. } =
884								witness_data.clone().ok_or(Error::<T, I>::WitnessRequired)?;
885							let owned_item = owned_item.ok_or(Error::<T, I>::BadWitness)?;
886
887							let owns_item = Account::<T, I>::contains_key((
888								&caller,
889								&collection_id,
890								&owned_item,
891							));
892							ensure!(owns_item, Error::<T, I>::BadWitness);
893
894							let pallet_attribute =
895								PalletAttributes::<T::CollectionId>::UsedToClaim(collection);
896
897							let key = (
898								&collection_id,
899								Some(owned_item),
900								AttributeNamespace::Pallet,
901								&Self::construct_attribute_key(pallet_attribute.encode())?,
902							);
903							let already_claimed = Attribute::<T, I>::contains_key(key.clone());
904							ensure!(!already_claimed, Error::<T, I>::AlreadyClaimed);
905
906							let attribute_value = Self::construct_attribute_value(vec![])?;
907							Attribute::<T, I>::insert(
908								key,
909								(
910									attribute_value.clone(),
911									AttributeDeposit { account: None, amount: Zero::zero() },
912								),
913							);
914							Self::deposit_event(Event::PalletAttributeSet {
915								collection: collection_id,
916								item: Some(owned_item),
917								attribute: pallet_attribute,
918								value: attribute_value,
919							});
920						},
921						_ => {},
922					}
923
924					if let Some(price) = mint_settings.price {
925						let MintWitness { mint_price, .. } =
926							witness_data.clone().ok_or(Error::<T, I>::WitnessRequired)?;
927						let mint_price = mint_price.ok_or(Error::<T, I>::BadWitness)?;
928						ensure!(mint_price >= price, Error::<T, I>::BadWitness);
929						T::Currency::transfer(
930							&caller,
931							&collection_details.owner,
932							price,
933							ExistenceRequirement::KeepAlive,
934						)?;
935					}
936
937					Ok(())
938				},
939			)
940		}
941
942		/// Mint an item of a particular collection from a privileged origin.
943		///
944		/// The origin must conform to `ForceOrigin` or must be `Signed` and the sender must be the
945		/// Issuer of the `collection`.
946		///
947		/// - `collection`: The collection of the item to be minted.
948		/// - `item`: An identifier of the new item.
949		/// - `mint_to`: Account into which the item will be minted.
950		/// - `item_config`: A config of the new item.
951		///
952		/// Emits `Issued` event when successful.
953		///
954		/// Weight: `O(1)`
955		#[pallet::call_index(4)]
956		#[pallet::weight(T::WeightInfo::force_mint())]
957		pub fn force_mint(
958			origin: OriginFor<T>,
959			collection: T::CollectionId,
960			item: T::ItemId,
961			mint_to: AccountIdLookupOf<T>,
962			item_config: ItemConfig,
963		) -> DispatchResult {
964			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
965				.map(|_| None)
966				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
967			let mint_to = T::Lookup::lookup(mint_to)?;
968
969			if let Some(check_origin) = maybe_check_origin {
970				ensure!(
971					Self::has_role(&collection, &check_origin, CollectionRole::Issuer),
972					Error::<T, I>::NoPermission
973				);
974			}
975			Self::do_mint(collection, item, None, mint_to, item_config, |_, _| Ok(()))
976		}
977
978		/// Destroy a single item.
979		///
980		/// The origin must conform to `ForceOrigin` or must be Signed and the signing account must
981		/// be the owner of the `item`.
982		///
983		/// - `collection`: The collection of the item to be burned.
984		/// - `item`: The item to be burned.
985		///
986		/// Emits `Burned`.
987		///
988		/// Weight: `O(1)`
989		#[pallet::call_index(5)]
990		#[pallet::weight(T::WeightInfo::burn())]
991		pub fn burn(
992			origin: OriginFor<T>,
993			collection: T::CollectionId,
994			item: T::ItemId,
995		) -> DispatchResult {
996			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
997				.map(|_| None)
998				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
999
1000			Self::do_burn(collection, item, |details| {
1001				if let Some(check_origin) = maybe_check_origin {
1002					ensure!(details.owner == check_origin, Error::<T, I>::NoPermission);
1003				}
1004				Ok(())
1005			})
1006		}
1007
1008		/// Move an item from the sender account to another.
1009		///
1010		/// Origin must be Signed and the signing account must be either:
1011		/// - the Owner of the `item`;
1012		/// - the approved delegate for the `item` (in this case, the approval is reset).
1013		///
1014		/// Arguments:
1015		/// - `collection`: The collection of the item to be transferred.
1016		/// - `item`: The item to be transferred.
1017		/// - `dest`: The account to receive ownership of the item.
1018		///
1019		/// Emits `Transferred`.
1020		///
1021		/// Weight: `O(1)`
1022		#[pallet::call_index(6)]
1023		#[pallet::weight(T::WeightInfo::transfer())]
1024		pub fn transfer(
1025			origin: OriginFor<T>,
1026			collection: T::CollectionId,
1027			item: T::ItemId,
1028			dest: AccountIdLookupOf<T>,
1029		) -> DispatchResult {
1030			let origin = ensure_signed(origin)?;
1031			let dest = T::Lookup::lookup(dest)?;
1032
1033			Self::do_transfer(collection, item, dest, |_, details| {
1034				if details.owner != origin {
1035					let deadline =
1036						details.approvals.get(&origin).ok_or(Error::<T, I>::NoPermission)?;
1037					if let Some(d) = deadline {
1038						let block_number = T::BlockNumberProvider::current_block_number();
1039						ensure!(block_number <= *d, Error::<T, I>::ApprovalExpired);
1040					}
1041				}
1042				Ok(())
1043			})
1044		}
1045
1046		/// Re-evaluate the deposits on some items.
1047		///
1048		/// Origin must be Signed and the sender should be the Owner of the `collection`.
1049		///
1050		/// - `collection`: The collection of the items to be reevaluated.
1051		/// - `items`: The items of the collection whose deposits will be reevaluated.
1052		///
1053		/// NOTE: This exists as a best-effort function. Any items which are unknown or
1054		/// in the case that the owner account does not have reservable funds to pay for a
1055		/// deposit increase are ignored. Generally the owner isn't going to call this on items
1056		/// whose existing deposit is less than the refreshed deposit as it would only cost them,
1057		/// so it's of little consequence.
1058		///
1059		/// It will still return an error in the case that the collection is unknown or the signer
1060		/// is not permitted to call it.
1061		///
1062		/// Weight: `O(items.len())`
1063		#[pallet::call_index(7)]
1064		#[pallet::weight(T::WeightInfo::redeposit(items.len() as u32))]
1065		pub fn redeposit(
1066			origin: OriginFor<T>,
1067			collection: T::CollectionId,
1068			items: Vec<T::ItemId>,
1069		) -> DispatchResult {
1070			let origin = ensure_signed(origin)?;
1071
1072			let collection_details =
1073				Collection::<T, I>::get(&collection).ok_or(Error::<T, I>::UnknownCollection)?;
1074			ensure!(collection_details.owner == origin, Error::<T, I>::NoPermission);
1075
1076			let config = Self::get_collection_config(&collection)?;
1077			let deposit = match config.is_setting_enabled(CollectionSetting::DepositRequired) {
1078				true => T::ItemDeposit::get(),
1079				false => Zero::zero(),
1080			};
1081
1082			let mut successful = Vec::with_capacity(items.len());
1083			for item in items.into_iter() {
1084				let mut details = match Item::<T, I>::get(&collection, &item) {
1085					Some(x) => x,
1086					None => continue,
1087				};
1088				let old = details.deposit.amount;
1089				if old > deposit {
1090					T::Currency::unreserve(&details.deposit.account, old - deposit);
1091				} else if deposit > old {
1092					if T::Currency::reserve(&details.deposit.account, deposit - old).is_err() {
1093						// NOTE: No alterations made to collection_details in this iteration so far,
1094						// so this is OK to do.
1095						continue;
1096					}
1097				} else {
1098					continue;
1099				}
1100				details.deposit.amount = deposit;
1101				Item::<T, I>::insert(&collection, &item, &details);
1102				successful.push(item);
1103			}
1104
1105			Self::deposit_event(Event::<T, I>::Redeposited {
1106				collection,
1107				successful_items: successful,
1108			});
1109
1110			Ok(())
1111		}
1112
1113		/// Disallow further unprivileged transfer of an item.
1114		///
1115		/// Origin must be Signed and the sender should be the Freezer of the `collection`.
1116		///
1117		/// - `collection`: The collection of the item to be changed.
1118		/// - `item`: The item to become non-transferable.
1119		///
1120		/// Emits `ItemTransferLocked`.
1121		///
1122		/// Weight: `O(1)`
1123		#[pallet::call_index(8)]
1124		#[pallet::weight(T::WeightInfo::lock_item_transfer())]
1125		pub fn lock_item_transfer(
1126			origin: OriginFor<T>,
1127			collection: T::CollectionId,
1128			item: T::ItemId,
1129		) -> DispatchResult {
1130			let origin = ensure_signed(origin)?;
1131			Self::do_lock_item_transfer(origin, collection, item)
1132		}
1133
1134		/// Re-allow unprivileged transfer of an item.
1135		///
1136		/// Origin must be Signed and the sender should be the Freezer of the `collection`.
1137		///
1138		/// - `collection`: The collection of the item to be changed.
1139		/// - `item`: The item to become transferable.
1140		///
1141		/// Emits `ItemTransferUnlocked`.
1142		///
1143		/// Weight: `O(1)`
1144		#[pallet::call_index(9)]
1145		#[pallet::weight(T::WeightInfo::unlock_item_transfer())]
1146		pub fn unlock_item_transfer(
1147			origin: OriginFor<T>,
1148			collection: T::CollectionId,
1149			item: T::ItemId,
1150		) -> DispatchResult {
1151			let origin = ensure_signed(origin)?;
1152			Self::do_unlock_item_transfer(origin, collection, item)
1153		}
1154
1155		/// Disallows specified settings for the whole collection.
1156		///
1157		/// Origin must be Signed and the sender should be the Owner of the `collection`.
1158		///
1159		/// - `collection`: The collection to be locked.
1160		/// - `lock_settings`: The settings to be locked.
1161		///
1162		/// Note: it's possible to only lock(set) the setting, but not to unset it.
1163		///
1164		/// Emits `CollectionLocked`.
1165		///
1166		/// Weight: `O(1)`
1167		#[pallet::call_index(10)]
1168		#[pallet::weight(T::WeightInfo::lock_collection())]
1169		pub fn lock_collection(
1170			origin: OriginFor<T>,
1171			collection: T::CollectionId,
1172			lock_settings: CollectionSettings,
1173		) -> DispatchResult {
1174			let origin = ensure_signed(origin)?;
1175			Self::do_lock_collection(origin, collection, lock_settings)
1176		}
1177
1178		/// Change the Owner of a collection.
1179		///
1180		/// Origin must be Signed and the sender should be the Owner of the `collection`.
1181		///
1182		/// The collection deposit is moved from the current to the new owner. Fails with
1183		/// [`Error::IncompleteDepositTransfer`] if a lock or freeze on the current owner blocks
1184		/// the full transfer; clear it and retry.
1185		///
1186		/// - `collection`: The collection whose owner should be changed.
1187		/// - `owner`: The new Owner of this collection. They must have called
1188		///   `set_accept_ownership` with `collection` in order for this operation to succeed.
1189		///
1190		/// Emits `OwnerChanged`.
1191		///
1192		/// Weight: `O(1)`
1193		#[pallet::call_index(11)]
1194		#[pallet::weight(T::WeightInfo::transfer_ownership())]
1195		pub fn transfer_ownership(
1196			origin: OriginFor<T>,
1197			collection: T::CollectionId,
1198			new_owner: AccountIdLookupOf<T>,
1199		) -> DispatchResult {
1200			let origin = ensure_signed(origin)?;
1201			let new_owner = T::Lookup::lookup(new_owner)?;
1202			Self::do_transfer_ownership(origin, collection, new_owner)
1203		}
1204
1205		/// Change the Issuer, Admin and Freezer of a collection.
1206		///
1207		/// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the
1208		/// `collection`.
1209		///
1210		/// Note: by setting the role to `None` only the `ForceOrigin` will be able to change it
1211		/// after to `Some(account)`.
1212		///
1213		/// - `collection`: The collection whose team should be changed.
1214		/// - `issuer`: The new Issuer of this collection.
1215		/// - `admin`: The new Admin of this collection.
1216		/// - `freezer`: The new Freezer of this collection.
1217		///
1218		/// Emits `TeamChanged`.
1219		///
1220		/// Weight: `O(1)`
1221		#[pallet::call_index(12)]
1222		#[pallet::weight(T::WeightInfo::set_team())]
1223		pub fn set_team(
1224			origin: OriginFor<T>,
1225			collection: T::CollectionId,
1226			issuer: Option<AccountIdLookupOf<T>>,
1227			admin: Option<AccountIdLookupOf<T>>,
1228			freezer: Option<AccountIdLookupOf<T>>,
1229		) -> DispatchResult {
1230			let maybe_check_owner = T::ForceOrigin::try_origin(origin)
1231				.map(|_| None)
1232				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1233			let issuer = issuer.map(T::Lookup::lookup).transpose()?;
1234			let admin = admin.map(T::Lookup::lookup).transpose()?;
1235			let freezer = freezer.map(T::Lookup::lookup).transpose()?;
1236			Self::do_set_team(maybe_check_owner, collection, issuer, admin, freezer)
1237		}
1238
1239		/// Change the Owner of a collection.
1240		///
1241		/// Origin must be `ForceOrigin`.
1242		///
1243		/// The collection deposit is moved from the current to the new owner. Fails with
1244		/// [`Error::IncompleteDepositTransfer`] if a lock or freeze on the current owner blocks
1245		/// the full transfer; clear it and retry.
1246		///
1247		/// - `collection`: The identifier of the collection.
1248		/// - `owner`: The new Owner of this collection.
1249		///
1250		/// Emits `OwnerChanged`.
1251		///
1252		/// Weight: `O(1)`
1253		#[pallet::call_index(13)]
1254		#[pallet::weight(T::WeightInfo::force_collection_owner())]
1255		pub fn force_collection_owner(
1256			origin: OriginFor<T>,
1257			collection: T::CollectionId,
1258			owner: AccountIdLookupOf<T>,
1259		) -> DispatchResult {
1260			T::ForceOrigin::ensure_origin(origin)?;
1261			let new_owner = T::Lookup::lookup(owner)?;
1262			Self::do_force_collection_owner(collection, new_owner)
1263		}
1264
1265		/// Change the config of a collection.
1266		///
1267		/// Origin must be `ForceOrigin`.
1268		///
1269		/// - `collection`: The identifier of the collection.
1270		/// - `config`: The new config of this collection.
1271		///
1272		/// Emits `CollectionConfigChanged`.
1273		///
1274		/// Weight: `O(1)`
1275		#[pallet::call_index(14)]
1276		#[pallet::weight(T::WeightInfo::force_collection_config())]
1277		pub fn force_collection_config(
1278			origin: OriginFor<T>,
1279			collection: T::CollectionId,
1280			config: CollectionConfigFor<T, I>,
1281		) -> DispatchResult {
1282			T::ForceOrigin::ensure_origin(origin)?;
1283			Self::do_force_collection_config(collection, config)
1284		}
1285
1286		/// Approve an item to be transferred by a delegated third-party account.
1287		///
1288		/// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the
1289		/// `item`.
1290		///
1291		/// - `collection`: The collection of the item to be approved for delegated transfer.
1292		/// - `item`: The item to be approved for delegated transfer.
1293		/// - `delegate`: The account to delegate permission to transfer the item.
1294		/// - `maybe_deadline`: Optional deadline for the approval. Specified by providing the
1295		/// 	number of blocks after which the approval will expire
1296		///
1297		/// Emits `TransferApproved` on success.
1298		///
1299		/// Weight: `O(1)`
1300		#[pallet::call_index(15)]
1301		#[pallet::weight(T::WeightInfo::approve_transfer())]
1302		pub fn approve_transfer(
1303			origin: OriginFor<T>,
1304			collection: T::CollectionId,
1305			item: T::ItemId,
1306			delegate: AccountIdLookupOf<T>,
1307			maybe_deadline: Option<BlockNumberFor<T, I>>,
1308		) -> DispatchResult {
1309			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1310				.map(|_| None)
1311				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1312			let delegate = T::Lookup::lookup(delegate)?;
1313			Self::do_approve_transfer(
1314				maybe_check_origin,
1315				collection,
1316				item,
1317				delegate,
1318				maybe_deadline,
1319			)
1320		}
1321
1322		/// Cancel one of the transfer approvals for a specific item.
1323		///
1324		/// Origin must be either:
1325		/// - the `Force` origin;
1326		/// - `Signed` with the signer being the Owner of the `item`;
1327		///
1328		/// Arguments:
1329		/// - `collection`: The collection of the item of whose approval will be cancelled.
1330		/// - `item`: The item of the collection of whose approval will be cancelled.
1331		/// - `delegate`: The account that is going to loose their approval.
1332		///
1333		/// Emits `ApprovalCancelled` on success.
1334		///
1335		/// Weight: `O(1)`
1336		#[pallet::call_index(16)]
1337		#[pallet::weight(T::WeightInfo::cancel_approval())]
1338		pub fn cancel_approval(
1339			origin: OriginFor<T>,
1340			collection: T::CollectionId,
1341			item: T::ItemId,
1342			delegate: AccountIdLookupOf<T>,
1343		) -> DispatchResult {
1344			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1345				.map(|_| None)
1346				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1347			let delegate = T::Lookup::lookup(delegate)?;
1348			Self::do_cancel_approval(maybe_check_origin, collection, item, delegate)
1349		}
1350
1351		/// Cancel all the approvals of a specific item.
1352		///
1353		/// Origin must be either:
1354		/// - the `Force` origin;
1355		/// - `Signed` with the signer being the Owner of the `item`;
1356		///
1357		/// Arguments:
1358		/// - `collection`: The collection of the item of whose approvals will be cleared.
1359		/// - `item`: The item of the collection of whose approvals will be cleared.
1360		///
1361		/// Emits `AllApprovalsCancelled` on success.
1362		///
1363		/// Weight: `O(1)`
1364		#[pallet::call_index(17)]
1365		#[pallet::weight(T::WeightInfo::clear_all_transfer_approvals())]
1366		pub fn clear_all_transfer_approvals(
1367			origin: OriginFor<T>,
1368			collection: T::CollectionId,
1369			item: T::ItemId,
1370		) -> DispatchResult {
1371			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1372				.map(|_| None)
1373				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1374			Self::do_clear_all_transfer_approvals(maybe_check_origin, collection, item)
1375		}
1376
1377		/// Disallows changing the metadata or attributes of the item.
1378		///
1379		/// Origin must be either `ForceOrigin` or Signed and the sender should be the Admin
1380		/// of the `collection`.
1381		///
1382		/// - `collection`: The collection if the `item`.
1383		/// - `item`: An item to be locked.
1384		/// - `lock_metadata`: Specifies whether the metadata should be locked.
1385		/// - `lock_attributes`: Specifies whether the attributes in the `CollectionOwner` namespace
1386		///   should be locked.
1387		///
1388		/// Note: `lock_attributes` affects the attributes in the `CollectionOwner` namespace only.
1389		/// When the metadata or attributes are locked, it won't be possible the unlock them.
1390		///
1391		/// Emits `ItemPropertiesLocked`.
1392		///
1393		/// Weight: `O(1)`
1394		#[pallet::call_index(18)]
1395		#[pallet::weight(T::WeightInfo::lock_item_properties())]
1396		pub fn lock_item_properties(
1397			origin: OriginFor<T>,
1398			collection: T::CollectionId,
1399			item: T::ItemId,
1400			lock_metadata: bool,
1401			lock_attributes: bool,
1402		) -> DispatchResult {
1403			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1404				.map(|_| None)
1405				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1406			Self::do_lock_item_properties(
1407				maybe_check_origin,
1408				collection,
1409				item,
1410				lock_metadata,
1411				lock_attributes,
1412			)
1413		}
1414
1415		/// Set an attribute for a collection or item.
1416		///
1417		/// Origin must be Signed and must conform to the namespace ruleset:
1418		/// - `CollectionOwner` namespace could be modified by the `collection` Admin only;
1419		/// - `ItemOwner` namespace could be modified by the `maybe_item` owner only. `maybe_item`
1420		///   should be set in that case;
1421		/// - `Account(AccountId)` namespace could be modified only when the `origin` was given a
1422		///   permission to do so;
1423		///
1424		/// The funds of `origin` are reserved according to the formula:
1425		/// `AttributeDepositBase + DepositPerByte * (key.len + value.len)` taking into
1426		/// account any already reserved funds.
1427		///
1428		/// - `collection`: The identifier of the collection whose item's metadata to set.
1429		/// - `maybe_item`: The identifier of the item whose metadata to set.
1430		/// - `namespace`: Attribute's namespace.
1431		/// - `key`: The key of the attribute.
1432		/// - `value`: The value to which to set the attribute.
1433		///
1434		/// Emits `AttributeSet`.
1435		///
1436		/// Weight: `O(1)`
1437		#[pallet::call_index(19)]
1438		#[pallet::weight(T::WeightInfo::set_attribute())]
1439		pub fn set_attribute(
1440			origin: OriginFor<T>,
1441			collection: T::CollectionId,
1442			maybe_item: Option<T::ItemId>,
1443			namespace: AttributeNamespace<T::AccountId>,
1444			key: BoundedVec<u8, T::KeyLimit>,
1445			value: BoundedVec<u8, T::ValueLimit>,
1446		) -> DispatchResult {
1447			let origin = ensure_signed(origin)?;
1448			let depositor = match namespace {
1449				AttributeNamespace::CollectionOwner => {
1450					Self::collection_owner(collection).ok_or(Error::<T, I>::UnknownCollection)?
1451				},
1452				_ => origin.clone(),
1453			};
1454			Self::do_set_attribute(origin, collection, maybe_item, namespace, key, value, depositor)
1455		}
1456
1457		/// Force-set an attribute for a collection or item.
1458		///
1459		/// Origin must be `ForceOrigin`.
1460		///
1461		/// If the attribute already exists and it was set by another account, the deposit
1462		/// will be returned to the previous owner.
1463		///
1464		/// - `set_as`: An optional owner of the attribute.
1465		/// - `collection`: The identifier of the collection whose item's metadata to set.
1466		/// - `maybe_item`: The identifier of the item whose metadata to set.
1467		/// - `namespace`: Attribute's namespace.
1468		/// - `key`: The key of the attribute.
1469		/// - `value`: The value to which to set the attribute.
1470		///
1471		/// Emits `AttributeSet`.
1472		///
1473		/// Weight: `O(1)`
1474		#[pallet::call_index(20)]
1475		#[pallet::weight(T::WeightInfo::force_set_attribute())]
1476		pub fn force_set_attribute(
1477			origin: OriginFor<T>,
1478			set_as: Option<T::AccountId>,
1479			collection: T::CollectionId,
1480			maybe_item: Option<T::ItemId>,
1481			namespace: AttributeNamespace<T::AccountId>,
1482			key: BoundedVec<u8, T::KeyLimit>,
1483			value: BoundedVec<u8, T::ValueLimit>,
1484		) -> DispatchResult {
1485			T::ForceOrigin::ensure_origin(origin)?;
1486			Self::do_force_set_attribute(set_as, collection, maybe_item, namespace, key, value)
1487		}
1488
1489		/// Clear an attribute for a collection or item.
1490		///
1491		/// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the
1492		/// attribute.
1493		///
1494		/// Any deposit is freed for the collection's owner.
1495		///
1496		/// - `collection`: The identifier of the collection whose item's metadata to clear.
1497		/// - `maybe_item`: The identifier of the item whose metadata to clear.
1498		/// - `namespace`: Attribute's namespace.
1499		/// - `key`: The key of the attribute.
1500		///
1501		/// Emits `AttributeCleared`.
1502		///
1503		/// Weight: `O(1)`
1504		#[pallet::call_index(21)]
1505		#[pallet::weight(T::WeightInfo::clear_attribute())]
1506		pub fn clear_attribute(
1507			origin: OriginFor<T>,
1508			collection: T::CollectionId,
1509			maybe_item: Option<T::ItemId>,
1510			namespace: AttributeNamespace<T::AccountId>,
1511			key: BoundedVec<u8, T::KeyLimit>,
1512		) -> DispatchResult {
1513			let maybe_check_owner = T::ForceOrigin::try_origin(origin)
1514				.map(|_| None)
1515				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1516			Self::do_clear_attribute(maybe_check_owner, collection, maybe_item, namespace, key)
1517		}
1518
1519		/// Approve item's attributes to be changed by a delegated third-party account.
1520		///
1521		/// Origin must be Signed and must be an owner of the `item`.
1522		///
1523		/// - `collection`: A collection of the item.
1524		/// - `item`: The item that holds attributes.
1525		/// - `delegate`: The account to delegate permission to change attributes of the item.
1526		///
1527		/// Emits `ItemAttributesApprovalAdded` on success.
1528		#[pallet::call_index(22)]
1529		#[pallet::weight(T::WeightInfo::approve_item_attributes())]
1530		pub fn approve_item_attributes(
1531			origin: OriginFor<T>,
1532			collection: T::CollectionId,
1533			item: T::ItemId,
1534			delegate: AccountIdLookupOf<T>,
1535		) -> DispatchResult {
1536			let origin = ensure_signed(origin)?;
1537			let delegate = T::Lookup::lookup(delegate)?;
1538			Self::do_approve_item_attributes(origin, collection, item, delegate)
1539		}
1540
1541		/// Cancel the previously provided approval to change item's attributes.
1542		/// All the previously set attributes by the `delegate` will be removed.
1543		///
1544		/// Origin must be Signed and must be an owner of the `item`.
1545		///
1546		/// - `collection`: Collection that the item is contained within.
1547		/// - `item`: The item that holds attributes.
1548		/// - `delegate`: The previously approved account to remove.
1549		///
1550		/// Emits `ItemAttributesApprovalRemoved` on success.
1551		#[pallet::call_index(23)]
1552		#[pallet::weight(T::WeightInfo::cancel_item_attributes_approval(
1553			witness.account_attributes
1554		))]
1555		pub fn cancel_item_attributes_approval(
1556			origin: OriginFor<T>,
1557			collection: T::CollectionId,
1558			item: T::ItemId,
1559			delegate: AccountIdLookupOf<T>,
1560			witness: CancelAttributesApprovalWitness,
1561		) -> DispatchResult {
1562			let origin = ensure_signed(origin)?;
1563			let delegate = T::Lookup::lookup(delegate)?;
1564			Self::do_cancel_item_attributes_approval(origin, collection, item, delegate, witness)
1565		}
1566
1567		/// Set the metadata for an item.
1568		///
1569		/// Origin must be either `ForceOrigin` or Signed and the sender should be the Admin of the
1570		/// `collection`.
1571		///
1572		/// If the origin is Signed, then funds of signer are reserved according to the formula:
1573		/// `MetadataDepositBase + DepositPerByte * data.len` taking into
1574		/// account any already reserved funds.
1575		///
1576		/// - `collection`: The identifier of the collection whose item's metadata to set.
1577		/// - `item`: The identifier of the item whose metadata to set.
1578		/// - `data`: The general information of this item. Limited in length by `StringLimit`.
1579		///
1580		/// Emits `ItemMetadataSet`.
1581		///
1582		/// Weight: `O(1)`
1583		#[pallet::call_index(24)]
1584		#[pallet::weight(T::WeightInfo::set_metadata())]
1585		pub fn set_metadata(
1586			origin: OriginFor<T>,
1587			collection: T::CollectionId,
1588			item: T::ItemId,
1589			data: BoundedVec<u8, T::StringLimit>,
1590		) -> DispatchResult {
1591			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1592				.map(|_| None)
1593				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1594			Self::do_set_item_metadata(maybe_check_origin, collection, item, data, None)
1595		}
1596
1597		/// Clear the metadata for an item.
1598		///
1599		/// Origin must be either `ForceOrigin` or Signed and the sender should be the Admin of the
1600		/// `collection`.
1601		///
1602		/// Any deposit is freed for the collection's owner.
1603		///
1604		/// - `collection`: The identifier of the collection whose item's metadata to clear.
1605		/// - `item`: The identifier of the item whose metadata to clear.
1606		///
1607		/// Emits `ItemMetadataCleared`.
1608		///
1609		/// Weight: `O(1)`
1610		#[pallet::call_index(25)]
1611		#[pallet::weight(T::WeightInfo::clear_metadata())]
1612		pub fn clear_metadata(
1613			origin: OriginFor<T>,
1614			collection: T::CollectionId,
1615			item: T::ItemId,
1616		) -> DispatchResult {
1617			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1618				.map(|_| None)
1619				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1620			Self::do_clear_item_metadata(maybe_check_origin, collection, item)
1621		}
1622
1623		/// Set the metadata for a collection.
1624		///
1625		/// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Admin of
1626		/// the `collection`.
1627		///
1628		/// If the origin is `Signed`, then funds of signer are reserved according to the formula:
1629		/// `MetadataDepositBase + DepositPerByte * data.len` taking into
1630		/// account any already reserved funds.
1631		///
1632		/// - `collection`: The identifier of the item whose metadata to update.
1633		/// - `data`: The general information of this item. Limited in length by `StringLimit`.
1634		///
1635		/// Emits `CollectionMetadataSet`.
1636		///
1637		/// Weight: `O(1)`
1638		#[pallet::call_index(26)]
1639		#[pallet::weight(T::WeightInfo::set_collection_metadata())]
1640		pub fn set_collection_metadata(
1641			origin: OriginFor<T>,
1642			collection: T::CollectionId,
1643			data: BoundedVec<u8, T::StringLimit>,
1644		) -> DispatchResult {
1645			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1646				.map(|_| None)
1647				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1648			Self::do_set_collection_metadata(maybe_check_origin, collection, data)
1649		}
1650
1651		/// Clear the metadata for a collection.
1652		///
1653		/// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Admin of
1654		/// the `collection`.
1655		///
1656		/// Any deposit is freed for the collection's owner.
1657		///
1658		/// - `collection`: The identifier of the collection whose metadata to clear.
1659		///
1660		/// Emits `CollectionMetadataCleared`.
1661		///
1662		/// Weight: `O(1)`
1663		#[pallet::call_index(27)]
1664		#[pallet::weight(T::WeightInfo::clear_collection_metadata())]
1665		pub fn clear_collection_metadata(
1666			origin: OriginFor<T>,
1667			collection: T::CollectionId,
1668		) -> DispatchResult {
1669			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1670				.map(|_| None)
1671				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1672			Self::do_clear_collection_metadata(maybe_check_origin, collection)
1673		}
1674
1675		/// Set (or reset) the acceptance of ownership for a particular account.
1676		///
1677		/// Origin must be `Signed` and if `maybe_collection` is `Some`, then the signer must have a
1678		/// provider reference.
1679		///
1680		/// - `maybe_collection`: The identifier of the collection whose ownership the signer is
1681		///   willing to accept, or if `None`, an indication that the signer is willing to accept no
1682		///   ownership transferal.
1683		///
1684		/// Emits `OwnershipAcceptanceChanged`.
1685		#[pallet::call_index(28)]
1686		#[pallet::weight(T::WeightInfo::set_accept_ownership())]
1687		pub fn set_accept_ownership(
1688			origin: OriginFor<T>,
1689			maybe_collection: Option<T::CollectionId>,
1690		) -> DispatchResult {
1691			let who = ensure_signed(origin)?;
1692			Self::do_set_accept_ownership(who, maybe_collection)
1693		}
1694
1695		/// Set the maximum number of items a collection could have.
1696		///
1697		/// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of
1698		/// the `collection`.
1699		///
1700		/// - `collection`: The identifier of the collection to change.
1701		/// - `max_supply`: The maximum number of items a collection could have.
1702		///
1703		/// Emits `CollectionMaxSupplySet` event when successful.
1704		#[pallet::call_index(29)]
1705		#[pallet::weight(T::WeightInfo::set_collection_max_supply())]
1706		pub fn set_collection_max_supply(
1707			origin: OriginFor<T>,
1708			collection: T::CollectionId,
1709			max_supply: u32,
1710		) -> DispatchResult {
1711			let maybe_check_owner = T::ForceOrigin::try_origin(origin)
1712				.map(|_| None)
1713				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1714			Self::do_set_collection_max_supply(maybe_check_owner, collection, max_supply)
1715		}
1716
1717		/// Update mint settings.
1718		///
1719		/// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Issuer
1720		/// of the `collection`.
1721		///
1722		/// - `collection`: The identifier of the collection to change.
1723		/// - `mint_settings`: The new mint settings.
1724		///
1725		/// Emits `CollectionMintSettingsUpdated` event when successful.
1726		#[pallet::call_index(30)]
1727		#[pallet::weight(T::WeightInfo::update_mint_settings())]
1728		pub fn update_mint_settings(
1729			origin: OriginFor<T>,
1730			collection: T::CollectionId,
1731			mint_settings: MintSettings<BalanceOf<T, I>, BlockNumberFor<T, I>, T::CollectionId>,
1732		) -> DispatchResult {
1733			let maybe_check_origin = T::ForceOrigin::try_origin(origin)
1734				.map(|_| None)
1735				.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
1736			Self::do_update_mint_settings(maybe_check_origin, collection, mint_settings)
1737		}
1738
1739		/// Set (or reset) the price for an item.
1740		///
1741		/// Origin must be Signed and must be the owner of the `item`.
1742		///
1743		/// - `collection`: The collection of the item.
1744		/// - `item`: The item to set the price for.
1745		/// - `price`: The price for the item. Pass `None`, to reset the price.
1746		/// - `buyer`: Restricts the buy operation to a specific account.
1747		///
1748		/// Emits `ItemPriceSet` on success if the price is not `None`.
1749		/// Emits `ItemPriceRemoved` on success if the price is `None`.
1750		#[pallet::call_index(31)]
1751		#[pallet::weight(T::WeightInfo::set_price())]
1752		pub fn set_price(
1753			origin: OriginFor<T>,
1754			collection: T::CollectionId,
1755			item: T::ItemId,
1756			price: Option<ItemPrice<T, I>>,
1757			whitelisted_buyer: Option<AccountIdLookupOf<T>>,
1758		) -> DispatchResult {
1759			let origin = ensure_signed(origin)?;
1760			let whitelisted_buyer = whitelisted_buyer.map(T::Lookup::lookup).transpose()?;
1761			Self::do_set_price(collection, item, origin, price, whitelisted_buyer)
1762		}
1763
1764		/// Allows to buy an item if it's up for sale.
1765		///
1766		/// Origin must be Signed and must not be the owner of the `item`.
1767		///
1768		/// - `collection`: The collection of the item.
1769		/// - `item`: The item the sender wants to buy.
1770		/// - `bid_price`: The price the sender is willing to pay.
1771		///
1772		/// Emits `ItemBought` on success.
1773		#[pallet::call_index(32)]
1774		#[pallet::weight(T::WeightInfo::buy_item())]
1775		pub fn buy_item(
1776			origin: OriginFor<T>,
1777			collection: T::CollectionId,
1778			item: T::ItemId,
1779			bid_price: ItemPrice<T, I>,
1780		) -> DispatchResult {
1781			let origin = ensure_signed(origin)?;
1782			Self::do_buy_item(collection, item, origin, bid_price)
1783		}
1784
1785		/// Allows to pay the tips.
1786		///
1787		/// Origin must be Signed.
1788		///
1789		/// - `tips`: Tips array.
1790		///
1791		/// Emits `TipSent` on every tip transfer.
1792		#[pallet::call_index(33)]
1793		#[pallet::weight(T::WeightInfo::pay_tips(tips.len() as u32))]
1794		pub fn pay_tips(
1795			origin: OriginFor<T>,
1796			tips: BoundedVec<ItemTipOf<T, I>, T::MaxTips>,
1797		) -> DispatchResult {
1798			let origin = ensure_signed(origin)?;
1799			Self::do_pay_tips(origin, tips)
1800		}
1801
1802		/// Register a new atomic swap, declaring an intention to send an `item` in exchange for
1803		/// `desired_item` from origin to target on the current blockchain.
1804		/// The target can execute the swap during the specified `duration` of blocks (if set).
1805		/// Additionally, the price could be set for the desired `item`.
1806		///
1807		/// Origin must be Signed and must be an owner of the `item`.
1808		///
1809		/// - `collection`: The collection of the item.
1810		/// - `item`: The item an owner wants to give.
1811		/// - `desired_collection`: The collection of the desired item.
1812		/// - `desired_item`: The desired item an owner wants to receive.
1813		/// - `maybe_price`: The price an owner is willing to pay or receive for the desired `item`.
1814		/// - `duration`: A deadline for the swap. Specified by providing the number of blocks
1815		/// 	after which the swap will expire.
1816		///
1817		/// Emits `SwapCreated` on success.
1818		#[pallet::call_index(34)]
1819		#[pallet::weight(T::WeightInfo::create_swap())]
1820		pub fn create_swap(
1821			origin: OriginFor<T>,
1822			offered_collection: T::CollectionId,
1823			offered_item: T::ItemId,
1824			desired_collection: T::CollectionId,
1825			maybe_desired_item: Option<T::ItemId>,
1826			maybe_price: Option<PriceWithDirection<ItemPrice<T, I>>>,
1827			duration: BlockNumberFor<T, I>,
1828		) -> DispatchResult {
1829			let origin = ensure_signed(origin)?;
1830			Self::do_create_swap(
1831				origin,
1832				offered_collection,
1833				offered_item,
1834				desired_collection,
1835				maybe_desired_item,
1836				maybe_price,
1837				duration,
1838			)
1839		}
1840
1841		/// Cancel an atomic swap.
1842		///
1843		/// Origin must be Signed.
1844		/// Origin must be an owner of the `item` if the deadline hasn't expired.
1845		///
1846		/// - `collection`: The collection of the item.
1847		/// - `item`: The item an owner wants to give.
1848		///
1849		/// Emits `SwapCancelled` on success.
1850		#[pallet::call_index(35)]
1851		#[pallet::weight(T::WeightInfo::cancel_swap())]
1852		pub fn cancel_swap(
1853			origin: OriginFor<T>,
1854			offered_collection: T::CollectionId,
1855			offered_item: T::ItemId,
1856		) -> DispatchResult {
1857			let origin = ensure_signed(origin)?;
1858			Self::do_cancel_swap(origin, offered_collection, offered_item)
1859		}
1860
1861		/// Claim an atomic swap.
1862		/// This method executes a pending swap, that was created by a counterpart before.
1863		///
1864		/// Origin must be Signed and must be an owner of the `item`.
1865		///
1866		/// - `send_collection`: The collection of the item to be sent.
1867		/// - `send_item`: The item to be sent.
1868		/// - `receive_collection`: The collection of the item to be received.
1869		/// - `receive_item`: The item to be received.
1870		/// - `witness_price`: A price that was previously agreed on.
1871		///
1872		/// Emits `SwapClaimed` on success.
1873		#[pallet::call_index(36)]
1874		#[pallet::weight(T::WeightInfo::claim_swap())]
1875		pub fn claim_swap(
1876			origin: OriginFor<T>,
1877			send_collection: T::CollectionId,
1878			send_item: T::ItemId,
1879			receive_collection: T::CollectionId,
1880			receive_item: T::ItemId,
1881			witness_price: Option<PriceWithDirection<ItemPrice<T, I>>>,
1882		) -> DispatchResult {
1883			let origin = ensure_signed(origin)?;
1884			Self::do_claim_swap(
1885				origin,
1886				send_collection,
1887				send_item,
1888				receive_collection,
1889				receive_item,
1890				witness_price,
1891			)
1892		}
1893
1894		/// Mint an item by providing the pre-signed approval.
1895		///
1896		/// Origin must be Signed.
1897		///
1898		/// - `mint_data`: The pre-signed approval that consists of the information about the item,
1899		///   its metadata, attributes, who can mint it (`None` for anyone) and until what block
1900		///   number.
1901		/// - `signature`: The signature of the `data` object.
1902		/// - `signer`: The `data` object's signer. Should be an Issuer of the collection.
1903		///
1904		/// Emits `Issued` on success.
1905		/// Emits `AttributeSet` if the attributes were provided.
1906		/// Emits `ItemMetadataSet` if the metadata was not empty.
1907		#[pallet::call_index(37)]
1908		#[pallet::weight(T::WeightInfo::mint_pre_signed(mint_data.attributes.len() as u32))]
1909		pub fn mint_pre_signed(
1910			origin: OriginFor<T>,
1911			mint_data: Box<PreSignedMintOf<T, I>>,
1912			signature: T::OffchainSignature,
1913			signer: T::AccountId,
1914		) -> DispatchResult {
1915			let origin = ensure_signed(origin)?;
1916			Self::validate_signature(&Encode::encode(&mint_data), &signature, &signer)?;
1917			Self::do_mint_pre_signed(origin, *mint_data, signer)
1918		}
1919
1920		/// Set attributes for an item by providing the pre-signed approval.
1921		///
1922		/// Origin must be Signed and must be an owner of the `data.item`.
1923		///
1924		/// - `data`: The pre-signed approval that consists of the information about the item,
1925		///   attributes to update and until what block number.
1926		/// - `signature`: The signature of the `data` object.
1927		/// - `signer`: The `data` object's signer. Should be an Admin of the collection for the
1928		///   `CollectionOwner` namespace.
1929		///
1930		/// Emits `AttributeSet` for each provided attribute.
1931		/// Emits `ItemAttributesApprovalAdded` if the approval wasn't set before.
1932		/// Emits `PreSignedAttributesSet` on success.
1933		#[pallet::call_index(38)]
1934		#[pallet::weight(T::WeightInfo::set_attributes_pre_signed(data.attributes.len() as u32))]
1935		pub fn set_attributes_pre_signed(
1936			origin: OriginFor<T>,
1937			data: PreSignedAttributesOf<T, I>,
1938			signature: T::OffchainSignature,
1939			signer: T::AccountId,
1940		) -> DispatchResult {
1941			let origin = ensure_signed(origin)?;
1942			Self::validate_signature(&Encode::encode(&data), &signature, &signer)?;
1943			Self::do_set_attributes_pre_signed(origin, data, signer)
1944		}
1945	}
1946}
1947
1948sp_core::generate_feature_enabled_macro!(runtime_benchmarks_enabled, feature = "runtime-benchmarks", $);