git.delta.rocks / unique-network / refs/commits / 7b0d1cf9062a

difftreelog

source

primitives/data-structs/src/rmrk.rs14.6 KiBsourcehistory
1use codec::{Decode, Encode, MaxEncodedLen};2use scale_info::TypeInfo;34use derivative::Derivative;56#[cfg(feature = "std")]7use serde::Serialize;89use primitives::*;1011pub mod primitives {12	pub type CollectionId = u32;13	pub type ResourceId = u32;14	pub type NftId = u32;15	pub type BaseId = u32;16	pub type SlotId = u32;17	pub type PartId = u32;18	pub type ZIndex = u32;19}2021#[cfg(feature = "std")]22mod serialize {23	use core::convert::AsRef;24	use serde::ser::{self, Serialize};2526	pub mod vec {27		use super::*;2829		pub fn serialize<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>30		where31			D: ser::Serializer,32			V: Serialize,33			C: AsRef<[V]>,34		{35			value.as_ref().serialize(serializer)36		}37	}3839	pub mod opt_vec {40		use super::*;4142		pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>43		where44			D: ser::Serializer,45			V: Serialize,46			C: AsRef<[V]>,47		{48			match value {49				Some(value) => super::vec::serialize(value, serializer),50				None => serializer.serialize_none(),51			}52		}53	}54}5556/// Collection info.57#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]58#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]59#[cfg_attr(60	feature = "std",61	serde(bound = r#"62			AccountId: Serialize,63			BoundedString: AsRef<[u8]>,64			BoundedSymbol: AsRef<[u8]>65		"#)66)]67pub struct CollectionInfo<BoundedString, BoundedSymbol, AccountId> {68	/// Current bidder and bid price.69	pub issuer: AccountId,7071	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]72	pub metadata: BoundedString,73	pub max: Option<u32>,7475	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]76	pub symbol: BoundedSymbol,77	pub nfts_count: u32,78}7980#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, Debug, TypeInfo, MaxEncodedLen)]81#[cfg_attr(feature = "std", derive(Serialize))]82pub enum AccountIdOrCollectionNftTuple<AccountId> {83	AccountId(AccountId),84	CollectionAndNftTuple(CollectionId, NftId),85}8687/// Royalty information (recipient and amount)88#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]89#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]90pub struct RoyaltyInfo<AccountId, RoyaltyAmount> {91	/// Recipient (AccountId) of the royalty92	pub recipient: AccountId,93	/// Amount (Permill) of the royalty94	pub amount: RoyaltyAmount,95}9697/// Nft info.98#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]99#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]100#[cfg_attr(101	feature = "std",102	serde(bound = r#"103			AccountId: Serialize,104			RoyaltyAmount: Serialize,105			BoundedString: AsRef<[u8]>106		"#)107)]108pub struct NftInfo<AccountId, RoyaltyAmount, BoundedString> {109	/// The owner of the NFT, can be either an Account or a tuple (CollectionId, NftId)110	pub owner: AccountIdOrCollectionNftTuple<AccountId>,111	/// Royalty (optional)112	pub royalty: Option<RoyaltyInfo<AccountId, RoyaltyAmount>>,113114	/// Arbitrary data about an instance, e.g. IPFS hash115	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]116	pub metadata: BoundedString,117118	/// Equipped state119	pub equipped: bool,120	/// Pending state (if sent to NFT)121	pub pending: bool,122}123124#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]125#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]126pub struct NftChild {127	pub collection_id: CollectionId,128	pub nft_id: NftId,129}130131#[cfg_attr(feature = "std", derive(Serialize))]132#[derive(Encode, Decode, PartialEq, TypeInfo)]133#[cfg_attr(134	feature = "std",135	serde(bound = r#"136			BoundedKey: AsRef<[u8]>,137			BoundedValue: AsRef<[u8]>138		"#)139)]140pub struct PropertyInfo<BoundedKey, BoundedValue> {141	/// Key of the property142	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]143	pub key: BoundedKey,144145	/// Value of the property146	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]147	pub value: BoundedValue,148}149150#[derive(Encode, Decode, Default, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]151#[cfg_attr(feature = "std", derive(Serialize))]152#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]153pub struct BasicResource<BoundedString> {154	/// If the resource is Media, the base property is absent. Media src should be a URI like an155	/// IPFS hash.156	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]157	pub src: Option<BoundedString>,158159	/// Reference to IPFS location of metadata160	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]161	pub metadata: Option<BoundedString>,162163	/// Optional location or identier of license164	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]165	pub license: Option<BoundedString>,166167	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given168	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is169	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns170	/// another bird, showing the full render of one bird inside the other's inventory might be a171	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an172	/// image that is lighter and faster to load but representative of this resource.173	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]174	pub thumb: Option<BoundedString>,175}176177#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]178#[cfg_attr(feature = "std", derive(Serialize))]179#[cfg_attr(180	feature = "std",181	serde(bound = r#"182			BoundedString: AsRef<[u8]>,183			BoundedParts: AsRef<[PartId]>184		"#)185)]186pub struct ComposableResource<BoundedString, BoundedParts> {187	/// If a resource is composed, it will have an array of parts that compose it188	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]189	pub parts: BoundedParts,190191	/// A Base is uniquely identified by the combination of the word `base`, its minting block192	/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.193	/// base-4477293-kanaria_superbird.194	pub base: BaseId,195196	/// If the resource is Media, the base property is absent. Media src should be a URI like an197	/// IPFS hash.198	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]199	pub src: Option<BoundedString>,200201	/// Reference to IPFS location of metadata202	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]203	pub metadata: Option<BoundedString>,204205	/// If the resource has the slot property, it was designed to fit into a specific Base's slot.206	/// The baseslot will be composed of two dot-delimited values, like so:207	/// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is208	/// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird209210	/// Optional location or identier of license211	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]212	pub license: Option<BoundedString>,213214	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given215	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is216	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns217	/// another bird, showing the full render of one bird inside the other's inventory might be a218	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an219	/// image that is lighter and faster to load but representative of this resource.220	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]221	pub thumb: Option<BoundedString>,222}223224#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]225#[cfg_attr(feature = "std", derive(Serialize))]226#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]227pub struct SlotResource<BoundedString> {228	/// A Base is uniquely identified by the combination of the word `base`, its minting block229	/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.230	/// base-4477293-kanaria_superbird.231	pub base: BaseId,232233	/// If the resource is Media, the base property is absent. Media src should be a URI like an234	/// IPFS hash.235	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]236	pub src: Option<BoundedString>,237238	/// Reference to IPFS location of metadata239	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]240	pub metadata: Option<BoundedString>,241242	/// If the resource has the slot property, it was designed to fit into a specific Base's slot.243	/// The baseslot will be composed of two dot-delimited values, like so:244	/// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is245	/// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird246	pub slot: SlotId,247248	/// The license field, if present, should contain a link to a license (IPFS or static HTTP249	/// url), or an identifier, like RMRK_nocopy or ipfs://ipfs/someHashOfLicense.250	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]251	pub license: Option<BoundedString>,252253	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given254	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is255	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns256	/// another bird, showing the full render of one bird inside the other's inventory might be a257	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an258	/// image that is lighter and faster to load but representative of this resource.259	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]260	pub thumb: Option<BoundedString>,261}262263#[derive(Encode, Decode, Derivative, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]264#[cfg_attr(feature = "std", derive(Serialize))]265#[cfg_attr(266	feature = "std",267	serde(bound = r#"268			BoundedString: AsRef<[u8]>,269			BoundedParts: AsRef<[PartId]>270		"#)271)]272#[derivative(Default(bound = ""))]273pub enum ResourceTypes<BoundedString: Default, BoundedParts> {274	#[derivative(Default)]275	Basic(BasicResource<BoundedString>),276	Composable(ComposableResource<BoundedString, BoundedParts>),277	Slot(SlotResource<BoundedString>),278}279280#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]281#[cfg_attr(feature = "std", derive(Serialize))]282#[cfg_attr(283	feature = "std",284	serde(bound = r#"285			BoundedResource: AsRef<[u8]>,286			BoundedString: AsRef<[u8]>,287			BoundedParts: AsRef<[PartId]>288		"#)289)]290pub struct ResourceInfo<BoundedResource, BoundedString: Default, BoundedParts> {291	/// id is a 5-character string of reasonable uniqueness.292	/// The combination of base ID and resource id should be unique across the entire RMRK293	/// ecosystem which294	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]295	pub id: BoundedResource,296297	/// Resource298	pub resource: ResourceTypes<BoundedString, BoundedParts>,299300	/// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted301	pub pending: bool,302303	/// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted304	pub pending_removal: bool,305}306307#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]308#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]309#[cfg_attr(310	feature = "std",311	serde(bound = r#"312			AccountId: Serialize,313			BoundedString: AsRef<[u8]>314		"#)315)]316pub struct BaseInfo<AccountId, BoundedString> {317	/// Original creator of the Base318	pub issuer: AccountId,319320	/// Specifies how an NFT should be rendered, ie "svg"321	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]322	pub base_type: BoundedString,323324	/// User provided symbol during Base creation325	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]326	pub symbol: BoundedString,327}328329#[cfg_attr(feature = "std", derive(Serialize))]330#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]331#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]332pub struct FixedPart<BoundedString> {333	pub id: PartId,334	pub z: ZIndex,335336	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]337	pub src: BoundedString,338}339340#[cfg_attr(feature = "std", derive(Serialize))]341#[derive(Encode, Decode, Debug, Derivative, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]342#[cfg_attr(343	feature = "std",344	serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")345)]346#[derivative(Default(bound = ""))]347pub enum EquippableList<BoundedCollectionList> {348	All,349350	#[derivative(Default)]351	Empty,352353	Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),354}355356#[cfg_attr(feature = "std", derive(Serialize))]357#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]358#[cfg_attr(359	feature = "std",360	serde(bound = r#"361			BoundedString: AsRef<[u8]>,362			BoundedCollectionList: AsRef<[CollectionId]>363		"#)364)]365pub struct SlotPart<BoundedString, BoundedCollectionList> {366	pub id: PartId,367	pub equippable: EquippableList<BoundedCollectionList>,368369	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]370	pub src: BoundedString,371372	pub z: ZIndex,373}374375#[cfg_attr(feature = "std", derive(Serialize))]376#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]377#[cfg_attr(378	feature = "std",379	serde(bound = r#"380			BoundedString: AsRef<[u8]>,381			BoundedCollectionList: AsRef<[CollectionId]>382		"#)383)]384pub enum PartType<BoundedString, BoundedCollectionList> {385	FixedPart(FixedPart<BoundedString>),386	SlotPart(SlotPart<BoundedString, BoundedCollectionList>),387}388389impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {390	pub fn id(&self) -> PartId {391		match self {392			Self::FixedPart(part) => part.id,393			Self::SlotPart(part) => part.id,394		}395	}396397	pub fn src(&self) -> &BoundedString {398		match self {399			Self::FixedPart(part) => &part.src,400			Self::SlotPart(part) => &part.src,401		}402	}403404	pub fn z_index(&self) -> ZIndex {405		match self {406			Self::FixedPart(part) => part.z,407			Self::SlotPart(part) => part.z,408		}409	}410}411412#[cfg_attr(feature = "std", derive(Eq, Serialize))]413#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]414#[cfg_attr(415	feature = "std",416	serde(bound = r#"417			BoundedString: AsRef<[u8]>,418			PropertyList: AsRef<[ThemeProperty<BoundedString>]>,419		"#)420)]421pub struct Theme<BoundedString, PropertyList> {422	/// Name of the theme423	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]424	pub name: BoundedString,425426	/// Theme properties427	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]428	pub properties: PropertyList,429	/// Inheritability430	pub inherit: bool,431}432433#[cfg_attr(feature = "std", derive(Eq, Serialize))]434#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]435#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]436pub struct ThemeProperty<BoundedString> {437	/// Key of the property438	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]439	pub key: BoundedString,440441	/// Value of the property442	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]443	pub value: BoundedString,444}