git.delta.rocks / unique-network / refs/commits / dbc2fd55cb28

difftreelog

source

primitives/data-structs/src/rmrk.rs14.8 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(62		bound = r#"63			AccountId: Serialize,64			BoundedString: AsRef<[u8]>,65			BoundedSymbol: AsRef<[u8]>66		"#67	)68)]69pub struct CollectionInfo<BoundedString, BoundedSymbol, AccountId> {70	/// Current bidder and bid price.71	pub issuer: AccountId,7273	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]74	pub metadata: BoundedString,75	pub max: Option<u32>,7677	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]78	pub symbol: BoundedSymbol,79	pub nfts_count: u32,80}8182#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, Debug, TypeInfo, MaxEncodedLen)]83#[cfg_attr(feature = "std", derive(Serialize))]84pub enum AccountIdOrCollectionNftTuple<AccountId> {85	AccountId(AccountId),86	CollectionAndNftTuple(CollectionId, NftId),87}8889/// Royalty information (recipient and amount)90#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]91#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]92pub struct RoyaltyInfo<AccountId, RoyaltyAmount> {93	/// Recipient (AccountId) of the royalty94    pub recipient: AccountId,95	/// Amount (Permill) of the royalty96    pub amount: RoyaltyAmount,97}9899/// Nft info.100#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]101#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]102#[cfg_attr(103	feature = "std",104	serde(105		bound = r#"106			AccountId: Serialize,107			RoyaltyAmount: Serialize,108			BoundedString: AsRef<[u8]>109		"#110	)111)]112pub struct NftInfo<AccountId, RoyaltyAmount, BoundedString> {113	/// The owner of the NFT, can be either an Account or a tuple (CollectionId, NftId)114	pub owner: AccountIdOrCollectionNftTuple<AccountId>,115	/// Royalty (optional)116	pub royalty: Option<RoyaltyInfo<AccountId, RoyaltyAmount>>,117118	/// Arbitrary data about an instance, e.g. IPFS hash119	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]120	pub metadata: BoundedString,121122	/// Equipped state123	pub equipped: bool,124	/// Pending state (if sent to NFT)125	pub pending: bool,126}127128#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]129#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]130pub struct NftChild {131	pub collection_id: CollectionId,132	pub nft_id: NftId133}134135#[cfg_attr(feature = "std", derive(Serialize))]136#[derive(Encode, Decode, PartialEq, TypeInfo)]137#[cfg_attr(138	feature = "std",139	serde(140		bound = r#"141			BoundedKey: AsRef<[u8]>,142			BoundedValue: AsRef<[u8]>143		"#144	)145)]146pub struct PropertyInfo<BoundedKey, BoundedValue>147{148	/// Key of the property149	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]150	pub key: BoundedKey,151152	/// Value of the property153	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]154	pub value: BoundedValue,155}156157#[derive(Encode, Decode, Default, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]158#[cfg_attr(feature = "std", derive(Serialize))]159#[cfg_attr(160	feature = "std",161	serde(bound = "BoundedString: AsRef<[u8]>")162)]163pub struct BasicResource<BoundedString> {164	/// If the resource is Media, the base property is absent. Media src should be a URI like an165	/// IPFS hash.166	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]167	pub src: Option<BoundedString>,168169	/// Reference to IPFS location of metadata170	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]171	pub metadata: Option<BoundedString>,172173	/// Optional location or identier of license174	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]175	pub license: Option<BoundedString>,176177	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given178	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is179	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns180	/// another bird, showing the full render of one bird inside the other's inventory might be a181	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an182	/// image that is lighter and faster to load but representative of this resource.183	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]184	pub thumb: Option<BoundedString>,185}186187#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]188#[cfg_attr(feature = "std", derive(Serialize))]189#[cfg_attr(190	feature = "std",191	serde(192		bound = r#"193			BoundedString: AsRef<[u8]>,194			BoundedParts: AsRef<[PartId]>195		"#196	)197)]198pub struct ComposableResource<BoundedString, BoundedParts> {199	/// If a resource is composed, it will have an array of parts that compose it200	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]201	pub parts: BoundedParts,202203	/// A Base is uniquely identified by the combination of the word `base`, its minting block204	/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.205	/// base-4477293-kanaria_superbird.206	pub base: BaseId,207208	/// If the resource is Media, the base property is absent. Media src should be a URI like an209	/// IPFS hash.210	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]211	pub src: Option<BoundedString>,212213	/// Reference to IPFS location of metadata214	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]215	pub metadata: Option<BoundedString>,216217	/// If the resource has the slot property, it was designed to fit into a specific Base's slot.218	/// The baseslot will be composed of two dot-delimited values, like so:219	/// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is220	/// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird221222	/// Optional location or identier of license223	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]224	pub license: Option<BoundedString>,225226	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given227	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is228	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns229	/// another bird, showing the full render of one bird inside the other's inventory might be a230	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an231	/// image that is lighter and faster to load but representative of this resource.232	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]233	pub thumb: Option<BoundedString>,234}235236#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]237#[cfg_attr(feature = "std", derive(Serialize))]238#[cfg_attr(239	feature = "std",240	serde(bound = "BoundedString: AsRef<[u8]>")241)]242pub struct SlotResource<BoundedString> {243	/// A Base is uniquely identified by the combination of the word `base`, its minting block244	/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.245	/// base-4477293-kanaria_superbird.246	pub base: BaseId,247248	/// If the resource is Media, the base property is absent. Media src should be a URI like an249	/// IPFS hash.250	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]251	pub src: Option<BoundedString>,252253	/// Reference to IPFS location of metadata254	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]255	pub metadata: Option<BoundedString>,256257	/// If the resource has the slot property, it was designed to fit into a specific Base's slot.258	/// The baseslot will be composed of two dot-delimited values, like so:259	/// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is260	/// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird261	pub slot: SlotId,262263	/// The license field, if present, should contain a link to a license (IPFS or static HTTP264	/// url), or an identifier, like RMRK_nocopy or ipfs://ipfs/someHashOfLicense.265	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]266	pub license: Option<BoundedString>,267268	/// If the resource has the thumb property, this will be a URI to a thumbnail of the given269	/// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is270	/// complex and too detailed to show in a search-results page or a list. Also, if a bird owns271	/// another bird, showing the full render of one bird inside the other's inventory might be a272	/// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an273	/// image that is lighter and faster to load but representative of this resource.274	#[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]275	pub thumb: Option<BoundedString>,276}277278#[derive(Encode, Decode, Derivative, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]279#[cfg_attr(feature = "std", derive(Serialize))]280#[cfg_attr(281	feature = "std",282	serde(283		bound = r#"284			BoundedString: AsRef<[u8]>,285			BoundedParts: AsRef<[PartId]>286		"#287	)288)]289#[derivative(Default(bound=""))]290pub enum ResourceTypes<BoundedString: Default, BoundedParts> {291	#[derivative(Default)]292	Basic(BasicResource<BoundedString>),293	Composable(ComposableResource<BoundedString, BoundedParts>),294	Slot(SlotResource<BoundedString>),295}296297298#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]299#[cfg_attr(feature = "std", derive(Serialize))]300#[cfg_attr(301	feature = "std",302	serde(303		bound = r#"304			BoundedResource: AsRef<[u8]>,305			BoundedString: AsRef<[u8]>,306			BoundedParts: AsRef<[PartId]>307		"#308	)309)]310pub struct ResourceInfo<BoundedResource, BoundedString: Default, BoundedParts> {311	/// id is a 5-character string of reasonable uniqueness.312	/// The combination of base ID and resource id should be unique across the entire RMRK313	/// ecosystem which314	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]315	pub id: BoundedResource,316317	/// Resource318	pub resource: ResourceTypes<BoundedString, BoundedParts>,319320	/// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted321	pub pending: bool,322323	/// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted324	pub pending_removal: bool,325}326327#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]328#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]329#[cfg_attr(330	feature = "std",331	serde(332		bound = r#"333			AccountId: Serialize,334			BoundedString: AsRef<[u8]>335		"#336	)337)]338pub struct BaseInfo<AccountId, BoundedString> {339	/// Original creator of the Base340	pub issuer: AccountId,341342	/// Specifies how an NFT should be rendered, ie "svg"343	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]344	pub base_type: BoundedString,345346	/// User provided symbol during Base creation347	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]348	pub symbol: BoundedString,349}350351#[cfg_attr(feature = "std", derive(Serialize))]352#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]353#[cfg_attr(354	feature = "std",355	serde(bound = "BoundedString: AsRef<[u8]>")356)]357pub struct FixedPart<BoundedString> {358	pub id: PartId,359	pub z: ZIndex,360361	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]362	pub src: BoundedString,363}364365#[cfg_attr(feature = "std", derive(Serialize))]366#[derive(Encode, Decode, Debug, Derivative, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]367#[cfg_attr(368	feature = "std",369	serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")370)]371#[derivative(Default(bound=""))]372pub enum EquippableList<BoundedCollectionList> {373	All,374375	#[derivative(Default)]376	Empty,377378	Custom(379		#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]380		BoundedCollectionList381	),382}383384#[cfg_attr(feature = "std", derive(Serialize))]385#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]386#[cfg_attr(387	feature = "std",388	serde(389		bound = r#"390			BoundedString: AsRef<[u8]>,391			BoundedCollectionList: AsRef<[CollectionId]>392		"#393	)394)]395pub struct SlotPart<BoundedString, BoundedCollectionList> {396	pub id: PartId,397	pub equippable: EquippableList<BoundedCollectionList>,398399	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]400	pub src: BoundedString,401402	pub z: ZIndex,403}404405#[cfg_attr(feature = "std", derive(Serialize))]406#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]407#[cfg_attr(408	feature = "std",409	serde(410		bound = r#"411			BoundedString: AsRef<[u8]>,412			BoundedCollectionList: AsRef<[CollectionId]>413		"#414	)415)]416pub enum PartType<BoundedString, BoundedCollectionList> {417	FixedPart(FixedPart<BoundedString>),418	SlotPart(SlotPart<BoundedString, BoundedCollectionList>),419}420421impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {422	pub fn id(&self) -> PartId {423		match self {424			Self::FixedPart(part) => part.id,425			Self::SlotPart(part) => part.id426		}427	}428429	pub fn src(&self) -> &BoundedString {430		match self {431			Self::FixedPart(part) => &part.src,432			Self::SlotPart(part) => &part.src433		}434	}435436	pub fn z_index(&self) -> ZIndex {437		match self {438			Self::FixedPart(part) => part.z,439			Self::SlotPart(part) => part.z440		}441	}442}443444#[cfg_attr(feature = "std", derive(Eq, Serialize))]445#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]446#[cfg_attr(447	feature = "std",448	serde(449		bound = r#"450			BoundedString: AsRef<[u8]>,451			PropertyList: AsRef<[ThemeProperty<BoundedString>]>,452		"#453	)454)]455pub struct Theme<BoundedString, PropertyList> {456	/// Name of the theme457	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]458	pub name: BoundedString,459460	/// Theme properties461	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]462	pub properties: PropertyList,463	/// Inheritability464	pub inherit: bool,465}466467#[cfg_attr(feature = "std", derive(Eq, Serialize))]468#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]469#[cfg_attr(470	feature = "std",471	serde(bound = "BoundedString: AsRef<[u8]>")472)]473pub struct ThemeProperty<BoundedString> {474	/// Key of the property475	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]476	pub key: BoundedString,477478	/// Value of the property479	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]480	pub value: BoundedString,481}