git.delta.rocks / unique-network / refs/commits / 9d5e6bdc297d

difftreelog

fix forward collection flags

Yaroslav Bolyukin2022-10-13parent: #f27580f.patch.diff
in: master

10 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -9,7 +9,7 @@
 	traits::Get,
 };
 use sp_runtime::DispatchError;
-use up_data_structs::{CollectionId, CreateCollectionData};
+use up_data_structs::{CollectionId, CreateCollectionData, CollectionFlags};
 
 use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};
 
@@ -80,6 +80,7 @@
 		sender: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError>;
 
 	/// Delete the collection.
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -212,8 +212,9 @@
 		owner: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError> {
-		<PalletCommon<T>>::init_collection(owner, payer, data, CollectionFlags::default())
+		<PalletCommon<T>>::init_collection(owner, payer, data, flags)
 	}
 
 	/// Initializes the collection with ForeignCollection flag. Returns [CollectionId] on success, [DispatchError] otherwise.
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -55,7 +55,7 @@
 		owner,
 		CollectionMode::NFT,
 		|owner: T::CrossAccountId, data| {
-			<Pallet<T>>::init_collection(owner.clone(), owner, data, true)
+			<Pallet<T>>::init_collection(owner.clone(), owner, data, Default::default())
 		},
 		NonfungibleHandle::cast,
 	)
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -408,17 +408,9 @@
 		owner: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
-		is_external: bool,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError> {
-		<PalletCommon<T>>::init_collection(
-			owner,
-			payer,
-			data,
-			CollectionFlags {
-				external: is_external,
-				..Default::default()
-			},
-		)
+		<PalletCommon<T>>::init_collection(owner, payer, data, flags)
 	}
 
 	/// Destroy NFT collection
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -1448,7 +1448,15 @@
 		data: CreateCollectionData<T::AccountId>,
 		properties: impl Iterator<Item = Property>,
 	) -> Result<CollectionId, DispatchError> {
-		let collection_id = <PalletNft<T>>::init_collection(sender.clone(), sender, data, true);
+		let collection_id = <PalletNft<T>>::init_collection(
+			sender.clone(),
+			sender,
+			data,
+			up_data_structs::CollectionFlags {
+				external: true,
+				..Default::default()
+			},
+		);
 
 		if let Err(DispatchError::Arithmetic(_)) = &collection_id {
 			return Err(<Error<T>>::NoAvailableCollectionId.into());
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
before · pallets/proxy-rmrk-equip/src/lib.rs
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//! # RMRK Core Proxy Pallet18//!19//! A pallet used as proxy for RMRK Core (<https://rmrk-team.github.io/rmrk-substrate/#/pallets/rmrk-core>).20//!21//! - [`Config`]22//! - [`Call`]23//! - [`Pallet`]24//!25//! ## Overview26//!27//! The RMRK Equip Proxy pallet mirrors the functionality of RMRK Equip,28//! binding its externalities to Unique's own underlying structure.29//! It is purposed to mimic RMRK Equip exactly, allowing seamless integrations30//! of solutions based on RMRK.31//!32//! RMRK Equip itself contains functionality to equip NFTs, and work with Bases,33//! Parts, and Themes. See [Proxy Implementation](#proxy-implementation) for details.34//!35//! Equip Proxy is responsible for a more specific area of RMRK, and heavily relies on the Core.36//! For a more foundational description of proxy implementation, please refer to [`pallet_rmrk_core`].37//!38//! *Note*, that while RMRK itself is subject to active development and restructuring,39//! the proxy may be caught temporarily out of date.40//!41//! ### What is RMRK?42//!43//! RMRK is a set of NFT standards which compose several "NFT 2.0 lego" primitives.44//! Putting these legos together allows a user to create NFT systems of arbitrary complexity.45//!46//! Meaning, RMRK NFTs are dynamic, able to nest into each other and form a hierarchy,47//! make use of specific changeable and partially shared metadata in the form of resources,48//! and more.49//!50//! Visit RMRK documentation and repositories to learn more:51//! - Docs: <https://docs.rmrk.app/getting-started/>52//! - FAQ: <https://coda.io/@rmrk/faq>53//! - Substrate code repository: <https://github.com/rmrk-team/rmrk-substrate>54//! - RMRK spec repository: <https://github.com/rmrk-team/rmrk-spec>55//!56//! ## Terminology57//!58//! For more information on RMRK, see RMRK's own documentation.59//!60//! ### Intro to RMRK61//!62//! - **Resource:** Additional piece of metadata of an NFT usually serving to add63//! a piece of media on top of the root metadata (NFT's own), be it a different wing64//! on the root template bird or something entirely unrelated.65//!66//! - **Base:** A list of possible "components" - Parts, a combination of which can67//! be appended/equipped to/on an NFT.68//!69//! - **Part:** Something that, together with other Parts, can constitute an NFT.70//! Parts are defined in the Base to which they belong. Parts can be either71//! of the `slot` type or `fixed` type. Slots are intended for equippables.72//! Note that "part of something" and "Part of a Base" can be easily confused,73//! and so in this documentation these words are distinguished by the capital letter.74//!75//! - **Theme:** Named objects of variable => value pairs which get interpolated into76//! the Base's `themable` Parts. Themes can hold any value, but are often represented77//! in RMRK's examples as colors applied to visible Parts.78//!79//! ### Peculiarities in Unique80//!81//! - **Scoped properties:** Properties that are normally obscured from users.82//! Their purpose is to contain structured metadata that was not included in the Unique standard83//! for collections and tokens, meant to be operated on by proxies and other outliers.84//! Scoped property keys are prefixed with `some-scope:`, where `some-scope` is85//! an arbitrary keyword, like "rmrk". `:` is considered an unacceptable symbol in user-defined86//! properties, which, along with other safeguards, makes scoped ones impossible to tamper with.87//!88//! - **Auxiliary properties:** A slightly different structure of properties,89//! trading universality of use for more convenient storage, writes and access.90//! Meant to be inaccessible to end users.91//!92//! ## Proxy Implementation93//!94//! An external user is supposed to be able to utilize this proxy as they would95//! utilize RMRK, and get exactly the same results. Normally, Unique transactions96//! are off-limits to RMRK collections and tokens, and vice versa. However,97//! the information stored on chain can be freely interpreted by storage reads and Unique RPCs.98//!99//! ### ID Mapping100//!101//! RMRK's collections' IDs are counted independently of Unique's and start at 0.102//! Note that tokens' IDs still start at 1.103//! The collections themselves, as well as tokens, are stored as Unique collections,104//! and thus RMRK IDs are mapped to Unique IDs (but not vice versa).105//!106//! ### External/Internal Collection Insulation107//!108//! A Unique transaction cannot target collections purposed for RMRK,109//! and they are flagged as `external` to specify that. On the other hand,110//! due to the mapping, RMRK transactions and RPCs simply cannot reach Unique collections.111//!112//! ### Native Properties113//!114//! Many of RMRK's native parameters are stored as scoped properties of a collection115//! or an NFT on the chain. Scoped properties are prefixed with `rmrk:`, where `:`116//! is an unacceptable symbol in user-defined properties, which, along with other safeguards,117//! makes them impossible to tamper with.118//!119//! ### Collection and NFT Types, or Base, Parts and Themes Handling120//!121//! RMRK introduces the concept of a Base, which is a catalogue of Parts,122//! possible components of an NFT. Due to its similarity with the functionality123//! of a token collection, a Base is stored and handled as one, and the Base's Parts and Themes124//! are this collection's NFTs. See [`CollectionType`] and [`NftType`].125//!126//! ## Interface127//!128//! ### Dispatchables129//!130//! - `create_base` - Create a new Base.131//! - `theme_add` - Add a Theme to a Base.132//! - `equippable` - Update the array of Collections allowed to be equipped to a Base's specified Slot Part.133134#![cfg_attr(not(feature = "std"), no_std)]135136use frame_support::{pallet_prelude::*, BoundedVec, dispatch::DispatchResult};137use frame_system::{pallet_prelude::*, ensure_signed};138use sp_runtime::DispatchError;139use up_data_structs::*;140use pallet_common::{Pallet as PalletCommon, Error as CommonError};141use pallet_rmrk_core::{142	Pallet as PalletCore, Error as CoreError,143	misc::{self, *},144	property::RmrkProperty::*,145};146use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};147use pallet_evm::account::CrossAccountId;148use weights::WeightInfo;149150pub use pallet::*;151152#[cfg(feature = "runtime-benchmarks")]153pub mod benchmarking;154pub mod rpc;155pub mod weights;156157pub type SelfWeightOf<T> = <T as Config>::WeightInfo;158159#[frame_support::pallet]160pub mod pallet {161	use super::*;162163	#[pallet::config]164	pub trait Config: frame_system::Config + pallet_rmrk_core::Config {165		/// Overarching event type.166		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;167168		/// The weight information of this pallet.169		type WeightInfo: WeightInfo;170	}171172	/// Map of a Base ID and a Part ID to an NFT in the Base collection serving as the Part.173	#[pallet::storage]174	#[pallet::getter(fn internal_part_id)]175	pub type InernalPartId<T: Config> =176		StorageDoubleMap<_, Twox64Concat, CollectionId, Twox64Concat, RmrkPartId, TokenId>;177178	/// Checkmark that a Base has a Theme NFT named "default".179	#[pallet::storage]180	#[pallet::getter(fn base_has_default_theme)]181	pub type BaseHasDefaultTheme<T: Config> =182		StorageMap<_, Twox64Concat, CollectionId, bool, ValueQuery>;183184	#[pallet::pallet]185	#[pallet::generate_store(pub(super) trait Store)]186	pub struct Pallet<T>(_);187188	#[pallet::event]189	#[pallet::generate_deposit(pub(super) fn deposit_event)]190	pub enum Event<T: Config> {191		BaseCreated {192			issuer: T::AccountId,193			base_id: RmrkBaseId,194		},195		EquippablesUpdated {196			base_id: RmrkBaseId,197			slot_id: RmrkSlotId,198		},199	}200201	#[pallet::error]202	pub enum Error<T> {203		/// No permission to perform action.204		PermissionError,205		/// Could not find an ID for a Base collection. It is likely there were too many collections created on the chain, causing an overflow.206		NoAvailableBaseId,207		/// Could not find a suitable ID for a Part, likely too many Part tokens were created in the Base, causing an overflow208		NoAvailablePartId,209		/// Base collection linked to this ID does not exist.210		BaseDoesntExist,211		/// No Theme named "default" is associated with the Base.212		NeedsDefaultThemeFirst,213		/// Part linked to this ID does not exist.214		PartDoesntExist,215		/// Cannot assign equippables to a fixed Part.216		NoEquippableOnFixedPart,217	}218219	#[pallet::call]220	impl<T: Config> Pallet<T> {221		/// Create a new Base.222		///223		/// Modeled after the [Base interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/base.md)224		///225		/// # Permissions226		/// - Anyone - will be assigned as the issuer of the Base.227		///228		/// # Arguments:229		/// - `origin`: Caller, will be assigned as the issuer of the Base230		/// - `base_type`: Arbitrary media type, e.g. "svg".231		/// - `symbol`: Arbitrary client-chosen symbol.232		/// - `parts`: Array of Fixed and Slot Parts composing the Base,233		/// confined in length by [`RmrkPartsLimit`](up_data_structs::RmrkPartsLimit).234		#[pallet::weight(<SelfWeightOf<T>>::create_base(parts.len() as u32))]235		pub fn create_base(236			origin: OriginFor<T>,237			base_type: RmrkString,238			symbol: RmrkBaseSymbol,239			parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,240		) -> DispatchResult {241			let sender = ensure_signed(origin)?;242			let cross_sender = T::CrossAccountId::from_sub(sender.clone());243244			let data = CreateCollectionData {245				limits: None,246				token_prefix: symbol247					.into_inner()248					.try_into()249					.map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,250				..Default::default()251			};252253			let collection_id_res = <PalletNft<T>>::init_collection(254				cross_sender.clone(),255				cross_sender.clone(),256				data,257				true,258			);259260			if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {261				return Err(<Error<T>>::NoAvailableBaseId.into());262			}263264			let collection_id = collection_id_res?;265266			<PalletCommon<T>>::set_scoped_collection_properties(267				collection_id,268				PropertyScope::Rmrk,269				[270					<PalletCore<T>>::encode_rmrk_property(271						CollectionType,272						&misc::CollectionType::Base,273					)?,274					<PalletCore<T>>::encode_rmrk_property(BaseType, &base_type)?,275				]276				.into_iter(),277			)?;278279			let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;280281			for part in parts {282				Self::create_part(&cross_sender, &collection, part)?;283			}284285			Self::deposit_event(Event::BaseCreated {286				issuer: sender,287				base_id: collection_id.0,288			});289290			Ok(())291		}292293		/// Add a Theme to a Base.294		/// A Theme named "default" is required prior to adding other Themes.295		///296		/// Modeled after [Themeadd interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/themeadd.md).297		///298		/// # Permissions:299		/// - Base issuer300		///301		/// # Arguments:302		/// - `origin`: sender of the transaction303		/// - `base_id`: Base ID containing the Theme to be updated.304		/// - `theme`: Theme to add to the Base.  A Theme has a name and properties, which are an305		///   array of [key, value, inherit].306		///   - `key`: Arbitrary BoundedString, defined by client.307		///   - `value`: Arbitrary BoundedString, defined by client.308		///   - `inherit`: Optional bool.309		#[pallet::weight(<SelfWeightOf<T>>::theme_add(theme.properties.len() as u32))]310		pub fn theme_add(311			origin: OriginFor<T>,312			base_id: RmrkBaseId,313			theme: RmrkBoundedTheme,314		) -> DispatchResult {315			let sender = ensure_signed(origin)?;316317			let sender = T::CrossAccountId::from_sub(sender);318			let owner = &sender;319320			let collection_id: CollectionId = base_id.into();321322			let collection = Self::get_base(collection_id)?;323324			if theme.name.as_slice() == b"default" {325				<BaseHasDefaultTheme<T>>::insert(collection_id, true);326			} else if !Self::base_has_default_theme(collection_id) {327				return Err(<Error<T>>::NeedsDefaultThemeFirst.into());328			}329330			let token_id = <PalletCore<T>>::create_nft(331				&sender,332				owner,333				&collection,334				[335					<PalletCore<T>>::encode_rmrk_property(TokenType, &NftType::Theme)?,336					<PalletCore<T>>::encode_rmrk_property(ThemeName, &theme.name)?,337					<PalletCore<T>>::encode_rmrk_property(ThemeInherit, &theme.inherit)?,338				]339				.into_iter(),340			)341			.map_err(|_| <Error<T>>::PermissionError)?;342343			for property in theme.properties {344				<PalletNft<T>>::set_scoped_token_property(345					collection_id,346					token_id,347					PropertyScope::Rmrk,348					<PalletCore<T>>::encode_rmrk_property(349						UserProperty(property.key.as_slice()),350						&property.value,351					)?,352				)?;353			}354355			Ok(())356		}357358		/// Update the array of Collections allowed to be equipped to a Base's specified Slot Part.359		///360		/// Modeled after [equippable interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/equippable.md).361		///362		/// # Permissions:363		/// - Base issuer364		///365		/// # Arguments:366		/// - `origin`: sender of the transaction367		/// - `base_id`: Base containing the Slot Part to be updated.368		/// - `slot_id`: Slot Part whose Equippable List is being updated .369		/// - `equippables`: List of equippables that will override the current Equippables list.370		#[pallet::weight(<SelfWeightOf<T>>::equippable())]371		pub fn equippable(372			origin: OriginFor<T>,373			base_id: RmrkBaseId,374			slot_id: RmrkSlotId,375			equippables: RmrkEquippableList,376		) -> DispatchResult {377			let sender = ensure_signed(origin)?;378379			let base_collection_id = base_id.into();380			let collection = Self::get_base(base_collection_id)?;381382			<PalletCore<T>>::check_collection_owner(383				&collection,384				&T::CrossAccountId::from_sub(sender),385			)386			.map_err(|err| {387				if err == <CoreError<T>>::NoPermission.into() {388					<Error<T>>::PermissionError.into()389				} else {390					err391				}392			})?;393394			let part_id = Self::internal_part_id(base_collection_id, slot_id)395				.ok_or(<Error<T>>::PartDoesntExist)?;396397			let nft_type = <PalletCore<T>>::get_nft_type(base_collection_id, part_id)398				.map_err(|_| <Error<T>>::PartDoesntExist)?;399400			match nft_type {401				NftType::Regular | NftType::Theme => return Err(<Error<T>>::PermissionError.into()),402				NftType::FixedPart => return Err(<Error<T>>::NoEquippableOnFixedPart.into()),403				NftType::SlotPart => {404					<PalletNft<T>>::set_scoped_token_property(405						base_collection_id,406						part_id,407						PropertyScope::Rmrk,408						<PalletCore<T>>::encode_rmrk_property(EquippableList, &equippables)?,409					)?;410				}411			}412413			Self::deposit_event(Event::EquippablesUpdated { base_id, slot_id });414415			Ok(())416		}417	}418}419420impl<T: Config> Pallet<T> {421	/// Create (or overwrite) a Part in a Base.422	/// The Part and the Base are represented as an NFT and a Collection.423	fn create_part(424		sender: &T::CrossAccountId,425		collection: &NonfungibleHandle<T>,426		part: RmrkPartType,427	) -> DispatchResult {428		let owner = sender;429430		let part_id = part.id();431		let src = part.src();432		let z_index = part.z_index();433434		let nft_type = match part {435			RmrkPartType::FixedPart(_) => NftType::FixedPart,436			RmrkPartType::SlotPart(_) => NftType::SlotPart,437		};438439		let token_id = match Self::internal_part_id(collection.id, part_id) {440			Some(token_id) => token_id,441			None => {442				let token_id =443					<PalletCore<T>>::create_nft(sender, owner, collection, [].into_iter())444						.map_err(|err| match err {445							DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),446							err => err,447						})?;448449				<InernalPartId<T>>::insert(collection.id, part_id, token_id);450451				<PalletNft<T>>::set_scoped_token_property(452					collection.id,453					token_id,454					PropertyScope::Rmrk,455					<PalletCore<T>>::encode_rmrk_property(ExternalPartId, &part_id)?,456				)?;457458				token_id459			}460		};461462		<PalletNft<T>>::set_scoped_token_properties(463			collection.id,464			token_id,465			PropertyScope::Rmrk,466			[467				<PalletCore<T>>::encode_rmrk_property(TokenType, &nft_type)?,468				<PalletCore<T>>::encode_rmrk_property(Src, &src)?,469				<PalletCore<T>>::encode_rmrk_property(ZIndex, &z_index)?,470			]471			.into_iter(),472		)?;473474		if let RmrkPartType::SlotPart(part) = part {475			<PalletNft<T>>::set_scoped_token_property(476				collection.id,477				token_id,478				PropertyScope::Rmrk,479				<PalletCore<T>>::encode_rmrk_property(EquippableList, &part.equippable)?,480			)?;481		}482483		Ok(())484	}485486	/// Ensure that the collection under the Base ID is a Base collection,487	/// and fetch it.488	fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {489		let collection =490			<PalletCore<T>>::get_typed_nft_collection(base_id, misc::CollectionType::Base)491				.map_err(|err| {492					if err == <CoreError<T>>::CollectionUnknown.into() {493						<Error<T>>::BaseDoesntExist.into()494					} else {495						err496					}497				})?;498		collection.check_is_external()?;499500		Ok(collection)501	}502}
after · pallets/proxy-rmrk-equip/src/lib.rs
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//! # RMRK Core Proxy Pallet18//!19//! A pallet used as proxy for RMRK Core (<https://rmrk-team.github.io/rmrk-substrate/#/pallets/rmrk-core>).20//!21//! - [`Config`]22//! - [`Call`]23//! - [`Pallet`]24//!25//! ## Overview26//!27//! The RMRK Equip Proxy pallet mirrors the functionality of RMRK Equip,28//! binding its externalities to Unique's own underlying structure.29//! It is purposed to mimic RMRK Equip exactly, allowing seamless integrations30//! of solutions based on RMRK.31//!32//! RMRK Equip itself contains functionality to equip NFTs, and work with Bases,33//! Parts, and Themes. See [Proxy Implementation](#proxy-implementation) for details.34//!35//! Equip Proxy is responsible for a more specific area of RMRK, and heavily relies on the Core.36//! For a more foundational description of proxy implementation, please refer to [`pallet_rmrk_core`].37//!38//! *Note*, that while RMRK itself is subject to active development and restructuring,39//! the proxy may be caught temporarily out of date.40//!41//! ### What is RMRK?42//!43//! RMRK is a set of NFT standards which compose several "NFT 2.0 lego" primitives.44//! Putting these legos together allows a user to create NFT systems of arbitrary complexity.45//!46//! Meaning, RMRK NFTs are dynamic, able to nest into each other and form a hierarchy,47//! make use of specific changeable and partially shared metadata in the form of resources,48//! and more.49//!50//! Visit RMRK documentation and repositories to learn more:51//! - Docs: <https://docs.rmrk.app/getting-started/>52//! - FAQ: <https://coda.io/@rmrk/faq>53//! - Substrate code repository: <https://github.com/rmrk-team/rmrk-substrate>54//! - RMRK spec repository: <https://github.com/rmrk-team/rmrk-spec>55//!56//! ## Terminology57//!58//! For more information on RMRK, see RMRK's own documentation.59//!60//! ### Intro to RMRK61//!62//! - **Resource:** Additional piece of metadata of an NFT usually serving to add63//! a piece of media on top of the root metadata (NFT's own), be it a different wing64//! on the root template bird or something entirely unrelated.65//!66//! - **Base:** A list of possible "components" - Parts, a combination of which can67//! be appended/equipped to/on an NFT.68//!69//! - **Part:** Something that, together with other Parts, can constitute an NFT.70//! Parts are defined in the Base to which they belong. Parts can be either71//! of the `slot` type or `fixed` type. Slots are intended for equippables.72//! Note that "part of something" and "Part of a Base" can be easily confused,73//! and so in this documentation these words are distinguished by the capital letter.74//!75//! - **Theme:** Named objects of variable => value pairs which get interpolated into76//! the Base's `themable` Parts. Themes can hold any value, but are often represented77//! in RMRK's examples as colors applied to visible Parts.78//!79//! ### Peculiarities in Unique80//!81//! - **Scoped properties:** Properties that are normally obscured from users.82//! Their purpose is to contain structured metadata that was not included in the Unique standard83//! for collections and tokens, meant to be operated on by proxies and other outliers.84//! Scoped property keys are prefixed with `some-scope:`, where `some-scope` is85//! an arbitrary keyword, like "rmrk". `:` is considered an unacceptable symbol in user-defined86//! properties, which, along with other safeguards, makes scoped ones impossible to tamper with.87//!88//! - **Auxiliary properties:** A slightly different structure of properties,89//! trading universality of use for more convenient storage, writes and access.90//! Meant to be inaccessible to end users.91//!92//! ## Proxy Implementation93//!94//! An external user is supposed to be able to utilize this proxy as they would95//! utilize RMRK, and get exactly the same results. Normally, Unique transactions96//! are off-limits to RMRK collections and tokens, and vice versa. However,97//! the information stored on chain can be freely interpreted by storage reads and Unique RPCs.98//!99//! ### ID Mapping100//!101//! RMRK's collections' IDs are counted independently of Unique's and start at 0.102//! Note that tokens' IDs still start at 1.103//! The collections themselves, as well as tokens, are stored as Unique collections,104//! and thus RMRK IDs are mapped to Unique IDs (but not vice versa).105//!106//! ### External/Internal Collection Insulation107//!108//! A Unique transaction cannot target collections purposed for RMRK,109//! and they are flagged as `external` to specify that. On the other hand,110//! due to the mapping, RMRK transactions and RPCs simply cannot reach Unique collections.111//!112//! ### Native Properties113//!114//! Many of RMRK's native parameters are stored as scoped properties of a collection115//! or an NFT on the chain. Scoped properties are prefixed with `rmrk:`, where `:`116//! is an unacceptable symbol in user-defined properties, which, along with other safeguards,117//! makes them impossible to tamper with.118//!119//! ### Collection and NFT Types, or Base, Parts and Themes Handling120//!121//! RMRK introduces the concept of a Base, which is a catalogue of Parts,122//! possible components of an NFT. Due to its similarity with the functionality123//! of a token collection, a Base is stored and handled as one, and the Base's Parts and Themes124//! are this collection's NFTs. See [`CollectionType`] and [`NftType`].125//!126//! ## Interface127//!128//! ### Dispatchables129//!130//! - `create_base` - Create a new Base.131//! - `theme_add` - Add a Theme to a Base.132//! - `equippable` - Update the array of Collections allowed to be equipped to a Base's specified Slot Part.133134#![cfg_attr(not(feature = "std"), no_std)]135136use frame_support::{pallet_prelude::*, BoundedVec, dispatch::DispatchResult};137use frame_system::{pallet_prelude::*, ensure_signed};138use sp_runtime::DispatchError;139use up_data_structs::*;140use pallet_common::{Pallet as PalletCommon, Error as CommonError};141use pallet_rmrk_core::{142	Pallet as PalletCore, Error as CoreError,143	misc::{self, *},144	property::RmrkProperty::*,145};146use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};147use pallet_evm::account::CrossAccountId;148use weights::WeightInfo;149150pub use pallet::*;151152#[cfg(feature = "runtime-benchmarks")]153pub mod benchmarking;154pub mod rpc;155pub mod weights;156157pub type SelfWeightOf<T> = <T as Config>::WeightInfo;158159#[frame_support::pallet]160pub mod pallet {161	use super::*;162163	#[pallet::config]164	pub trait Config: frame_system::Config + pallet_rmrk_core::Config {165		/// Overarching event type.166		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;167168		/// The weight information of this pallet.169		type WeightInfo: WeightInfo;170	}171172	/// Map of a Base ID and a Part ID to an NFT in the Base collection serving as the Part.173	#[pallet::storage]174	#[pallet::getter(fn internal_part_id)]175	pub type InernalPartId<T: Config> =176		StorageDoubleMap<_, Twox64Concat, CollectionId, Twox64Concat, RmrkPartId, TokenId>;177178	/// Checkmark that a Base has a Theme NFT named "default".179	#[pallet::storage]180	#[pallet::getter(fn base_has_default_theme)]181	pub type BaseHasDefaultTheme<T: Config> =182		StorageMap<_, Twox64Concat, CollectionId, bool, ValueQuery>;183184	#[pallet::pallet]185	#[pallet::generate_store(pub(super) trait Store)]186	pub struct Pallet<T>(_);187188	#[pallet::event]189	#[pallet::generate_deposit(pub(super) fn deposit_event)]190	pub enum Event<T: Config> {191		BaseCreated {192			issuer: T::AccountId,193			base_id: RmrkBaseId,194		},195		EquippablesUpdated {196			base_id: RmrkBaseId,197			slot_id: RmrkSlotId,198		},199	}200201	#[pallet::error]202	pub enum Error<T> {203		/// No permission to perform action.204		PermissionError,205		/// Could not find an ID for a Base collection. It is likely there were too many collections created on the chain, causing an overflow.206		NoAvailableBaseId,207		/// Could not find a suitable ID for a Part, likely too many Part tokens were created in the Base, causing an overflow208		NoAvailablePartId,209		/// Base collection linked to this ID does not exist.210		BaseDoesntExist,211		/// No Theme named "default" is associated with the Base.212		NeedsDefaultThemeFirst,213		/// Part linked to this ID does not exist.214		PartDoesntExist,215		/// Cannot assign equippables to a fixed Part.216		NoEquippableOnFixedPart,217	}218219	#[pallet::call]220	impl<T: Config> Pallet<T> {221		/// Create a new Base.222		///223		/// Modeled after the [Base interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/base.md)224		///225		/// # Permissions226		/// - Anyone - will be assigned as the issuer of the Base.227		///228		/// # Arguments:229		/// - `origin`: Caller, will be assigned as the issuer of the Base230		/// - `base_type`: Arbitrary media type, e.g. "svg".231		/// - `symbol`: Arbitrary client-chosen symbol.232		/// - `parts`: Array of Fixed and Slot Parts composing the Base,233		/// confined in length by [`RmrkPartsLimit`](up_data_structs::RmrkPartsLimit).234		#[pallet::weight(<SelfWeightOf<T>>::create_base(parts.len() as u32))]235		pub fn create_base(236			origin: OriginFor<T>,237			base_type: RmrkString,238			symbol: RmrkBaseSymbol,239			parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,240		) -> DispatchResult {241			let sender = ensure_signed(origin)?;242			let cross_sender = T::CrossAccountId::from_sub(sender.clone());243244			let data = CreateCollectionData {245				limits: None,246				token_prefix: symbol247					.into_inner()248					.try_into()249					.map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,250				..Default::default()251			};252253			let collection_id_res = <PalletNft<T>>::init_collection(254				cross_sender.clone(),255				cross_sender.clone(),256				data,257				up_data_structs::CollectionFlags {258					external: true,259					..Default::default()260				},261			);262263			if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {264				return Err(<Error<T>>::NoAvailableBaseId.into());265			}266267			let collection_id = collection_id_res?;268269			<PalletCommon<T>>::set_scoped_collection_properties(270				collection_id,271				PropertyScope::Rmrk,272				[273					<PalletCore<T>>::encode_rmrk_property(274						CollectionType,275						&misc::CollectionType::Base,276					)?,277					<PalletCore<T>>::encode_rmrk_property(BaseType, &base_type)?,278				]279				.into_iter(),280			)?;281282			let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;283284			for part in parts {285				Self::create_part(&cross_sender, &collection, part)?;286			}287288			Self::deposit_event(Event::BaseCreated {289				issuer: sender,290				base_id: collection_id.0,291			});292293			Ok(())294		}295296		/// Add a Theme to a Base.297		/// A Theme named "default" is required prior to adding other Themes.298		///299		/// Modeled after [Themeadd interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/themeadd.md).300		///301		/// # Permissions:302		/// - Base issuer303		///304		/// # Arguments:305		/// - `origin`: sender of the transaction306		/// - `base_id`: Base ID containing the Theme to be updated.307		/// - `theme`: Theme to add to the Base.  A Theme has a name and properties, which are an308		///   array of [key, value, inherit].309		///   - `key`: Arbitrary BoundedString, defined by client.310		///   - `value`: Arbitrary BoundedString, defined by client.311		///   - `inherit`: Optional bool.312		#[pallet::weight(<SelfWeightOf<T>>::theme_add(theme.properties.len() as u32))]313		pub fn theme_add(314			origin: OriginFor<T>,315			base_id: RmrkBaseId,316			theme: RmrkBoundedTheme,317		) -> DispatchResult {318			let sender = ensure_signed(origin)?;319320			let sender = T::CrossAccountId::from_sub(sender);321			let owner = &sender;322323			let collection_id: CollectionId = base_id.into();324325			let collection = Self::get_base(collection_id)?;326327			if theme.name.as_slice() == b"default" {328				<BaseHasDefaultTheme<T>>::insert(collection_id, true);329			} else if !Self::base_has_default_theme(collection_id) {330				return Err(<Error<T>>::NeedsDefaultThemeFirst.into());331			}332333			let token_id = <PalletCore<T>>::create_nft(334				&sender,335				owner,336				&collection,337				[338					<PalletCore<T>>::encode_rmrk_property(TokenType, &NftType::Theme)?,339					<PalletCore<T>>::encode_rmrk_property(ThemeName, &theme.name)?,340					<PalletCore<T>>::encode_rmrk_property(ThemeInherit, &theme.inherit)?,341				]342				.into_iter(),343			)344			.map_err(|_| <Error<T>>::PermissionError)?;345346			for property in theme.properties {347				<PalletNft<T>>::set_scoped_token_property(348					collection_id,349					token_id,350					PropertyScope::Rmrk,351					<PalletCore<T>>::encode_rmrk_property(352						UserProperty(property.key.as_slice()),353						&property.value,354					)?,355				)?;356			}357358			Ok(())359		}360361		/// Update the array of Collections allowed to be equipped to a Base's specified Slot Part.362		///363		/// Modeled after [equippable interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/equippable.md).364		///365		/// # Permissions:366		/// - Base issuer367		///368		/// # Arguments:369		/// - `origin`: sender of the transaction370		/// - `base_id`: Base containing the Slot Part to be updated.371		/// - `slot_id`: Slot Part whose Equippable List is being updated .372		/// - `equippables`: List of equippables that will override the current Equippables list.373		#[pallet::weight(<SelfWeightOf<T>>::equippable())]374		pub fn equippable(375			origin: OriginFor<T>,376			base_id: RmrkBaseId,377			slot_id: RmrkSlotId,378			equippables: RmrkEquippableList,379		) -> DispatchResult {380			let sender = ensure_signed(origin)?;381382			let base_collection_id = base_id.into();383			let collection = Self::get_base(base_collection_id)?;384385			<PalletCore<T>>::check_collection_owner(386				&collection,387				&T::CrossAccountId::from_sub(sender),388			)389			.map_err(|err| {390				if err == <CoreError<T>>::NoPermission.into() {391					<Error<T>>::PermissionError.into()392				} else {393					err394				}395			})?;396397			let part_id = Self::internal_part_id(base_collection_id, slot_id)398				.ok_or(<Error<T>>::PartDoesntExist)?;399400			let nft_type = <PalletCore<T>>::get_nft_type(base_collection_id, part_id)401				.map_err(|_| <Error<T>>::PartDoesntExist)?;402403			match nft_type {404				NftType::Regular | NftType::Theme => return Err(<Error<T>>::PermissionError.into()),405				NftType::FixedPart => return Err(<Error<T>>::NoEquippableOnFixedPart.into()),406				NftType::SlotPart => {407					<PalletNft<T>>::set_scoped_token_property(408						base_collection_id,409						part_id,410						PropertyScope::Rmrk,411						<PalletCore<T>>::encode_rmrk_property(EquippableList, &equippables)?,412					)?;413				}414			}415416			Self::deposit_event(Event::EquippablesUpdated { base_id, slot_id });417418			Ok(())419		}420	}421}422423impl<T: Config> Pallet<T> {424	/// Create (or overwrite) a Part in a Base.425	/// The Part and the Base are represented as an NFT and a Collection.426	fn create_part(427		sender: &T::CrossAccountId,428		collection: &NonfungibleHandle<T>,429		part: RmrkPartType,430	) -> DispatchResult {431		let owner = sender;432433		let part_id = part.id();434		let src = part.src();435		let z_index = part.z_index();436437		let nft_type = match part {438			RmrkPartType::FixedPart(_) => NftType::FixedPart,439			RmrkPartType::SlotPart(_) => NftType::SlotPart,440		};441442		let token_id = match Self::internal_part_id(collection.id, part_id) {443			Some(token_id) => token_id,444			None => {445				let token_id =446					<PalletCore<T>>::create_nft(sender, owner, collection, [].into_iter())447						.map_err(|err| match err {448							DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),449							err => err,450						})?;451452				<InernalPartId<T>>::insert(collection.id, part_id, token_id);453454				<PalletNft<T>>::set_scoped_token_property(455					collection.id,456					token_id,457					PropertyScope::Rmrk,458					<PalletCore<T>>::encode_rmrk_property(ExternalPartId, &part_id)?,459				)?;460461				token_id462			}463		};464465		<PalletNft<T>>::set_scoped_token_properties(466			collection.id,467			token_id,468			PropertyScope::Rmrk,469			[470				<PalletCore<T>>::encode_rmrk_property(TokenType, &nft_type)?,471				<PalletCore<T>>::encode_rmrk_property(Src, &src)?,472				<PalletCore<T>>::encode_rmrk_property(ZIndex, &z_index)?,473			]474			.into_iter(),475		)?;476477		if let RmrkPartType::SlotPart(part) = part {478			<PalletNft<T>>::set_scoped_token_property(479				collection.id,480				token_id,481				PropertyScope::Rmrk,482				<PalletCore<T>>::encode_rmrk_property(EquippableList, &part.equippable)?,483			)?;484		}485486		Ok(())487	}488489	/// Ensure that the collection under the Base ID is a Base collection,490	/// and fetch it.491	fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {492		let collection =493			<PalletCore<T>>::get_typed_nft_collection(base_id, misc::CollectionType::Base)494				.map_err(|err| {495					if err == <CoreError<T>>::CollectionUnknown.into() {496						<Error<T>>::BaseDoesntExist.into()497					} else {498						err499					}500				})?;501		collection.check_is_external()?;502503		Ok(collection)504	}505}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -371,8 +371,9 @@
 		owner: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError> {
-		<PalletCommon<T>>::init_collection(owner, payer, data, CollectionFlags::default())
+		<PalletCommon<T>>::init_collection(owner, payer, data, flags)
 	}
 
 	/// Destroy RFT collection
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -34,7 +34,7 @@
 use sp_std::vec;
 use up_data_structs::{
 	CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,
-	CollectionMode, PropertyValue,
+	CollectionMode, PropertyValue, CollectionFlags,
 };
 
 use crate::{Config, SelfWeightOf, weights::WeightInfo};
@@ -186,9 +186,16 @@
 	let collection_helpers_address =
 		T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
 
-	let collection_id =
-		T::CollectionDispatch::create(caller.clone(), collection_helpers_address, data)
-			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+	let collection_id = T::CollectionDispatch::create(
+		caller.clone(),
+		collection_helpers_address,
+		data,
+		CollectionFlags {
+			erc721metadata: add_properties,
+			..Default::default()
+		},
+	)
+	.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 	let address = pallet_common::eth::collection_id_to_address(collection_id);
 	Ok(address)
 }
@@ -243,8 +250,13 @@
 		check_sent_amount_equals_collection_creation_price::<T>(value)?;
 		let collection_helpers_address =
 			T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
-		let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
-			.map_err(dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(
+			caller,
+			collection_helpers_address,
+			data,
+			Default::default(),
+		)
+		.map_err(dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
@@ -291,8 +303,16 @@
 		check_sent_amount_equals_collection_creation_price::<T>(value)?;
 		let collection_helpers_address =
 			T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
-		let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
-			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(
+			caller,
+			collection_helpers_address,
+			data,
+			CollectionFlags {
+				erc721metadata: true,
+				..Default::default()
+			},
+		)
+		.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -345,7 +345,7 @@
 
 			// =========
 			let sender = T::CrossAccountId::from_sub(sender);
-			let _id = T::CollectionDispatch::create(sender.clone(), sender, data)?;
+			let _id = T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;
 
 			Ok(())
 		}
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -31,7 +31,7 @@
 };
 use up_data_structs::{
 	CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,
-	CollectionId,
+	CollectionId, CollectionFlags,
 };
 
 #[cfg(not(feature = "refungible"))]
@@ -57,10 +57,11 @@
 		sender: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError> {
 		let id = match data.mode {
 			CollectionMode::NFT => {
-				<PalletNonfungible<T>>::init_collection(sender, payer, data, false)?
+				<PalletNonfungible<T>>::init_collection(sender, payer, data, flags)?
 			}
 			CollectionMode::Fungible(decimal_points) => {
 				// check params
@@ -68,11 +69,13 @@
 					decimal_points <= MAX_DECIMAL_POINTS,
 					pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded
 				);
-				<PalletFungible<T>>::init_collection(sender, payer, data)?
+				<PalletFungible<T>>::init_collection(sender, payer, data, flags)?
 			}
 
 			#[cfg(feature = "refungible")]
-			CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, payer, data)?,
+			CollectionMode::ReFungible => {
+				<PalletRefungible<T>>::init_collection(sender, payer, data, flags)?
+			}
 
 			#[cfg(not(feature = "refungible"))]
 			CollectionMode::ReFungible => return unsupported!(T),