git.delta.rocks / unique-network / refs/commits / 5ca51b5e5337

difftreelog

source

primitives/data-structs/src/rmrk.rs14.3 KiBsourcehistory
1use codec::{Decode, Encode, MaxEncodedLen};2use scale_info::TypeInfo;34#[cfg(feature = "std")]5use serde::Serialize;67use primitives::*;89pub mod primitives {10	pub type CollectionId = u32;11	pub type ResourceId = u32;12	pub type NftId = u32;13	pub type BaseId = u32;14	pub type SlotId = u32;15	pub type PartId = u32;16	pub type ZIndex = u32;17}1819#[cfg(feature = "std")]20mod serialize {21	use core::convert::AsRef;22	use serde::ser::{self, Serialize};2324	pub mod vec {25		use super::*;2627		pub fn serialize<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>28		where29			D: ser::Serializer,30			V: Serialize,31			C: AsRef<[V]>,32		{33			value.as_ref().serialize(serializer)34		}35	}3637	pub mod opt_vec {38		use super::*;3940		pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>41		where42			D: ser::Serializer,43			V: Serialize,44			C: AsRef<[V]>,45		{46			match value {47				Some(value) => super::vec::serialize(value, serializer),48				None => serializer.serialize_none(),49			}50		}51	}52}5354/// Collection info.55#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]56#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]57#[cfg_attr(58	feature = "std",59	serde(bound = r#"60			AccountId: Serialize,61			BoundedString: AsRef<[u8]>,62			BoundedSymbol: AsRef<[u8]>63		"#)64)]65pub struct CollectionInfo<BoundedString, BoundedSymbol, AccountId> {66	/// Current bidder and bid price.67	pub issuer: AccountId,6869	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]70	pub metadata: BoundedString,71	pub max: Option<u32>,7273	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]74	pub symbol: BoundedSymbol,75	pub nfts_count: u32,76}7778#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, Debug, TypeInfo, MaxEncodedLen)]79#[cfg_attr(feature = "std", derive(Serialize))]80pub enum AccountIdOrCollectionNftTuple<AccountId> {81	AccountId(AccountId),82	CollectionAndNftTuple(CollectionId, NftId),83}8485/// Royalty information (recipient and amount)86#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]87#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]88pub struct RoyaltyInfo<AccountId, RoyaltyAmount> {89	/// Recipient (AccountId) of the royalty90	pub recipient: AccountId,91	/// Amount (Permill) of the royalty92	pub amount: RoyaltyAmount,93}9495/// Nft info.96#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]97#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]98#[cfg_attr(99	feature = "std",100	serde(bound = r#"101			AccountId: Serialize,102			RoyaltyAmount: Serialize,103			BoundedString: AsRef<[u8]>104		"#)105)]106pub struct NftInfo<AccountId, RoyaltyAmount, BoundedString> {107	/// The owner of the NFT, can be either an Account or a tuple (CollectionId, NftId)108	pub owner: AccountIdOrCollectionNftTuple<AccountId>,109	/// Royalty (optional)110	pub royalty: Option<RoyaltyInfo<AccountId, RoyaltyAmount>>,111112	/// Arbitrary data about an instance, e.g. IPFS hash113	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]114	pub metadata: BoundedString,115116	/// Equipped state117	pub equipped: bool,118	/// Pending state (if sent to NFT)119	pub pending: bool,120}121122#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]123#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]124pub struct NftChild {125	pub collection_id: CollectionId,126	pub nft_id: NftId,127}128129#[cfg_attr(feature = "std", derive(Serialize))]130#[derive(Encode, Decode, PartialEq, TypeInfo)]131#[cfg_attr(132	feature = "std",133	serde(bound = r#"134			BoundedKey: AsRef<[u8]>,135			BoundedValue: AsRef<[u8]>136		"#)137)]138pub struct PropertyInfo<BoundedKey, BoundedValue> {139	/// Key of the property140	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]141	pub key: BoundedKey,142143	/// Value of the property144	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]145	pub value: BoundedValue,146}147148#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]149#[cfg_attr(feature = "std", derive(Serialize))]150#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]151pub struct BasicResource<BoundedString> {152	/// If the resource is Media, the base property is absent. Media src should be a URI like an153	/// IPFS hash.154	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]155	pub src: Option<BoundedString>,156157	/// Reference to IPFS location of metadata158	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]159	pub metadata: Option<BoundedString>,160161	/// Optional location or identier of license162	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]163	pub license: Option<BoundedString>,164165	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given166	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is167	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns168	/// another bird, showing the full render of one bird inside the other's inventory might be a169	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an170	/// image that is lighter and faster to load but representative of this resource.171	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]172	pub thumb: Option<BoundedString>,173}174175#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]176#[cfg_attr(feature = "std", derive(Serialize))]177#[cfg_attr(178	feature = "std",179	serde(bound = r#"180			BoundedString: AsRef<[u8]>,181			BoundedParts: AsRef<[PartId]>182		"#)183)]184pub struct ComposableResource<BoundedString, BoundedParts> {185	/// If a resource is composed, it will have an array of parts that compose it186	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]187	pub parts: BoundedParts,188189	/// A Base is uniquely identified by the combination of the word `base`, its minting block190	/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.191	/// base-4477293-kanaria_superbird.192	pub base: BaseId,193194	/// If the resource is Media, the base property is absent. Media src should be a URI like an195	/// IPFS hash.196	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]197	pub src: Option<BoundedString>,198199	/// Reference to IPFS location of metadata200	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]201	pub metadata: Option<BoundedString>,202203	/// If the resource has the slot property, it was designed to fit into a specific Base's slot.204	/// The baseslot will be composed of two dot-delimited values, like so:205	/// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is206	/// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird207208	/// Optional location or identier of license209	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]210	pub license: Option<BoundedString>,211212	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given213	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is214	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns215	/// another bird, showing the full render of one bird inside the other's inventory might be a216	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an217	/// image that is lighter and faster to load but representative of this resource.218	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]219	pub thumb: Option<BoundedString>,220}221222#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]223#[cfg_attr(feature = "std", derive(Serialize))]224#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]225pub struct SlotResource<BoundedString> {226	/// A Base is uniquely identified by the combination of the word `base`, its minting block227	/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.228	/// base-4477293-kanaria_superbird.229	pub base: BaseId,230231	/// If the resource is Media, the base property is absent. Media src should be a URI like an232	/// IPFS hash.233	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]234	pub src: Option<BoundedString>,235236	/// Reference to IPFS location of metadata237	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]238	pub metadata: Option<BoundedString>,239240	/// If the resource has the slot property, it was designed to fit into a specific Base's slot.241	/// The baseslot will be composed of two dot-delimited values, like so:242	/// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is243	/// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird244	pub slot: SlotId,245246	/// The license field, if present, should contain a link to a license (IPFS or static HTTP247	/// url), or an identifier, like RMRK_nocopy or ipfs://ipfs/someHashOfLicense.248	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]249	pub license: Option<BoundedString>,250251	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given252	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is253	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns254	/// another bird, showing the full render of one bird inside the other's inventory might be a255	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an256	/// image that is lighter and faster to load but representative of this resource.257	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]258	pub thumb: Option<BoundedString>,259}260261#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]262#[cfg_attr(feature = "std", derive(Serialize))]263#[cfg_attr(264	feature = "std",265	serde(bound = r#"266			BoundedString: AsRef<[u8]>,267			BoundedParts: AsRef<[PartId]>268		"#)269)]270pub enum ResourceTypes<BoundedString, BoundedParts> {271	Basic(BasicResource<BoundedString>),272	Composable(ComposableResource<BoundedString, BoundedParts>),273	Slot(SlotResource<BoundedString>),274}275276#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]277#[cfg_attr(feature = "std", derive(Serialize))]278#[cfg_attr(279	feature = "std",280	serde(bound = r#"281			BoundedString: AsRef<[u8]>,282			BoundedParts: AsRef<[PartId]>283		"#)284)]285pub struct ResourceInfo<BoundedString, BoundedParts> {286	/// id is a 5-character string of reasonable uniqueness.287	/// The combination of base ID and resource id should be unique across the entire RMRK288	/// ecosystem which289	//#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]290	pub id: ResourceId,291292	/// Resource293	pub resource: ResourceTypes<BoundedString, BoundedParts>,294295	/// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted296	pub pending: bool,297298	/// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted299	pub pending_removal: bool,300}301302#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]303#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]304#[cfg_attr(305	feature = "std",306	serde(bound = r#"307			AccountId: Serialize,308			BoundedString: AsRef<[u8]>309		"#)310)]311pub struct BaseInfo<AccountId, BoundedString> {312	/// Original creator of the Base313	pub issuer: AccountId,314315	/// Specifies how an NFT should be rendered, ie "svg"316	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]317	pub base_type: BoundedString,318319	/// User provided symbol during Base creation320	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]321	pub symbol: BoundedString,322}323324#[cfg_attr(feature = "std", derive(Serialize))]325#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]326#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]327pub struct FixedPart<BoundedString> {328	pub id: PartId,329	pub z: ZIndex,330331	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]332	pub src: BoundedString,333}334335#[cfg_attr(feature = "std", derive(Serialize))]336#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]337#[cfg_attr(338	feature = "std",339	serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")340)]341pub enum EquippableList<BoundedCollectionList> {342	All,343	Empty,344	Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),345}346347#[cfg_attr(feature = "std", derive(Serialize))]348#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]349#[cfg_attr(350	feature = "std",351	serde(bound = r#"352			BoundedString: AsRef<[u8]>,353			BoundedCollectionList: AsRef<[CollectionId]>354		"#)355)]356pub struct SlotPart<BoundedString, BoundedCollectionList> {357	pub id: PartId,358	pub equippable: EquippableList<BoundedCollectionList>,359360	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]361	pub src: BoundedString,362363	pub z: ZIndex,364}365366#[cfg_attr(feature = "std", derive(Serialize))]367#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]368#[cfg_attr(369	feature = "std",370	serde(bound = r#"371			BoundedString: AsRef<[u8]>,372			BoundedCollectionList: AsRef<[CollectionId]>373		"#)374)]375pub enum PartType<BoundedString, BoundedCollectionList> {376	FixedPart(FixedPart<BoundedString>),377	SlotPart(SlotPart<BoundedString, BoundedCollectionList>),378}379380impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {381	pub fn id(&self) -> PartId {382		match self {383			Self::FixedPart(part) => part.id,384			Self::SlotPart(part) => part.id,385		}386	}387388	pub fn src(&self) -> &BoundedString {389		match self {390			Self::FixedPart(part) => &part.src,391			Self::SlotPart(part) => &part.src,392		}393	}394395	pub fn z_index(&self) -> ZIndex {396		match self {397			Self::FixedPart(part) => part.z,398			Self::SlotPart(part) => part.z,399		}400	}401}402403#[cfg_attr(feature = "std", derive(Eq, Serialize))]404#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]405#[cfg_attr(406	feature = "std",407	serde(bound = r#"408			BoundedString: AsRef<[u8]>,409			PropertyList: AsRef<[ThemeProperty<BoundedString>]>,410		"#)411)]412pub struct Theme<BoundedString, PropertyList> {413	/// Name of the theme414	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]415	pub name: BoundedString,416417	/// Theme properties418	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]419	pub properties: PropertyList,420	/// Inheritability421	pub inherit: bool,422}423424#[cfg_attr(feature = "std", derive(Eq, Serialize))]425#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]426#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]427pub struct ThemeProperty<BoundedString> {428	/// Key of the property429	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]430	pub key: BoundedString,431432	/// Value of the property433	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]434	pub value: BoundedString,435}