1use codec::{Decode, Encode, MaxEncodedLen};2use scale_info::TypeInfo;34#[cfg(feature = "std")]5use serde::Serialize;67#[cfg(feature = "std")]8use crate::serialize;910use crate::primitives::*;1112#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]13#[cfg_attr(feature = "std", derive(Serialize))]14#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]15pub struct BasicResource<BoundedString> {16 /// If the resource is Media, the base property is absent. Media src should be a URI like an17 /// IPFS hash.18 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]19 pub src: Option<BoundedString>,2021 /// Reference to IPFS location of metadata22 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]23 pub metadata: Option<BoundedString>,2425 /// Optional location or identier of license26 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]27 pub license: Option<BoundedString>,2829 /// If the resource has the thumb property, this will be a URI to a thumbnail of the given30 /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is31 /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns32 /// another bird, showing the full render of one bird inside the other's inventory might be a33 /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an34 /// image that is lighter and faster to load but representative of this resource.35 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]36 pub thumb: Option<BoundedString>,37}3839#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]40#[cfg_attr(feature = "std", derive(Serialize))]41#[cfg_attr(42 feature = "std",43 serde(bound = r#"44 BoundedString: AsRef<[u8]>,45 BoundedParts: AsRef<[PartId]>46 "#)47)]48pub struct ComposableResource<BoundedString, BoundedParts> {49 /// If a resource is composed, it will have an array of parts that compose it50 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]51 pub parts: BoundedParts,5253 /// A Base is uniquely identified by the combination of the word `base`, its minting block54 /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.55 /// base-4477293-kanaria_superbird.56 pub base: BaseId,5758 /// If the resource is Media, the base property is absent. Media src should be a URI like an59 /// IPFS hash.60 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]61 pub src: Option<BoundedString>,6263 /// Reference to IPFS location of metadata64 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]65 pub metadata: Option<BoundedString>,6667 /// If the resource has the slot property, it was designed to fit into a specific Base's slot.68 /// The baseslot will be composed of two dot-delimited values, like so:69 /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is70 /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird7172 /// Optional location or identier of license73 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]74 pub license: Option<BoundedString>,7576 /// If the resource has the thumb property, this will be a URI to a thumbnail of the given77 /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is78 /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns79 /// another bird, showing the full render of one bird inside the other's inventory might be a80 /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an81 /// image that is lighter and faster to load but representative of this resource.82 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]83 pub thumb: Option<BoundedString>,84}8586#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]87#[cfg_attr(feature = "std", derive(Serialize))]88#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]89pub struct SlotResource<BoundedString> {90 /// A Base is uniquely identified by the combination of the word `base`, its minting block91 /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.92 /// base-4477293-kanaria_superbird.93 pub base: BaseId,9495 /// If the resource is Media, the base property is absent. Media src should be a URI like an96 /// IPFS hash.97 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]98 pub src: Option<BoundedString>,99100 /// Reference to IPFS location of metadata101 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]102 pub metadata: Option<BoundedString>,103104 /// If the resource has the slot property, it was designed to fit into a specific Base's slot.105 /// The baseslot will be composed of two dot-delimited values, like so:106 /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is107 /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird108 pub slot: SlotId,109110 /// The license field, if present, should contain a link to a license (IPFS or static HTTP111 /// url), or an identifier, like RMRK_nocopy or ipfs://ipfs/someHashOfLicense.112 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]113 pub license: Option<BoundedString>,114115 /// If the resource has the thumb property, this will be a URI to a thumbnail of the given116 /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is117 /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns118 /// another bird, showing the full render of one bird inside the other's inventory might be a119 /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an120 /// image that is lighter and faster to load but representative of this resource.121 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]122 pub thumb: Option<BoundedString>,123}124125#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]126#[cfg_attr(feature = "std", derive(Serialize))]127#[cfg_attr(128 feature = "std",129 serde(bound = r#"130 BoundedString: AsRef<[u8]>,131 BoundedParts: AsRef<[PartId]>132 "#)133)]134pub enum ResourceTypes<BoundedString, BoundedParts> {135 Basic(BasicResource<BoundedString>),136 Composable(ComposableResource<BoundedString, BoundedParts>),137 Slot(SlotResource<BoundedString>),138}139140#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]141#[cfg_attr(feature = "std", derive(Serialize))]142#[cfg_attr(143 feature = "std",144 serde(bound = r#"145 BoundedString: AsRef<[u8]>,146 BoundedParts: AsRef<[PartId]>147 "#)148)]149pub struct ResourceInfo<BoundedString, BoundedParts> {150 /// id is a 5-character string of reasonable uniqueness.151 /// The combination of base ID and resource id should be unique across the entire RMRK152 /// ecosystem which153 //#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]154 pub id: ResourceId,155156 /// Resource157 pub resource: ResourceTypes<BoundedString, BoundedParts>,158159 /// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted160 pub pending: bool,161162 /// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted163 pub pending_removal: bool,164}difftreelog
source
primitives/rmrk-traits/src/resource.rs7.1 KiBsourcehistory