1// Copyright (C) 2021-2022 RMRK2// This file is part of rmrk-substrate.3// License: Apache 2.0 modified by RMRK, see https://github.com/rmrk-team/rmrk-substrate/blob/main/LICENSE45use codec::{Decode, Encode, MaxEncodedLen};6use scale_info::TypeInfo;78#[cfg(feature = "std")]9use serde::Serialize;1011#[cfg(feature = "std")]12use crate::serialize;1314use crate::primitives::*;1516#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]17#[cfg_attr(feature = "std", derive(Serialize))]18#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]19pub struct BasicResource<BoundedString> {20 /// If the resource is Media, the base property is absent. Media src should be a URI like an21 /// IPFS hash.22 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]23 pub src: Option<BoundedString>,2425 /// Reference to IPFS location of metadata26 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]27 pub metadata: Option<BoundedString>,2829 /// Optional location or identier of license30 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]31 pub license: Option<BoundedString>,3233 /// If the resource has the thumb property, this will be a URI to a thumbnail of the given34 /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is35 /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns36 /// another bird, showing the full render of one bird inside the other's inventory might be a37 /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an38 /// image that is lighter and faster to load but representative of this resource.39 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]40 pub thumb: Option<BoundedString>,41}4243#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]44#[cfg_attr(feature = "std", derive(Serialize))]45#[cfg_attr(46 feature = "std",47 serde(bound = r#"48 BoundedString: AsRef<[u8]>,49 BoundedParts: AsRef<[PartId]>50 "#)51)]52pub struct ComposableResource<BoundedString, BoundedParts> {53 /// If a resource is composed, it will have an array of parts that compose it54 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]55 pub parts: BoundedParts,5657 /// A Base is uniquely identified by the combination of the word `base`, its minting block58 /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.59 /// base-4477293-kanaria_superbird.60 pub base: BaseId,6162 /// If the resource is Media, the base property is absent. Media src should be a URI like an63 /// IPFS hash.64 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]65 pub src: Option<BoundedString>,6667 /// Reference to IPFS location of metadata68 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]69 pub metadata: Option<BoundedString>,7071 /// If the resource has the slot property, it was designed to fit into a specific Base's slot.72 /// The baseslot will be composed of two dot-delimited values, like so:73 /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is74 /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird7576 /// Optional location or identier of license77 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]78 pub license: Option<BoundedString>,7980 /// If the resource has the thumb property, this will be a URI to a thumbnail of the given81 /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is82 /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns83 /// another bird, showing the full render of one bird inside the other's inventory might be a84 /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an85 /// image that is lighter and faster to load but representative of this resource.86 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]87 pub thumb: Option<BoundedString>,88}8990#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]91#[cfg_attr(feature = "std", derive(Serialize))]92#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]93pub struct SlotResource<BoundedString> {94 /// A Base is uniquely identified by the combination of the word `base`, its minting block95 /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.96 /// base-4477293-kanaria_superbird.97 pub base: BaseId,9899 /// If the resource is Media, the base property is absent. Media src should be a URI like an100 /// IPFS hash.101 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]102 pub src: Option<BoundedString>,103104 /// Reference to IPFS location of metadata105 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]106 pub metadata: Option<BoundedString>,107108 /// If the resource has the slot property, it was designed to fit into a specific Base's slot.109 /// The baseslot will be composed of two dot-delimited values, like so:110 /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is111 /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird112 pub slot: SlotId,113114 /// The license field, if present, should contain a link to a license (IPFS or static HTTP115 /// url), or an identifier, like RMRK_nocopy or ipfs://ipfs/someHashOfLicense.116 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]117 pub license: Option<BoundedString>,118119 /// If the resource has the thumb property, this will be a URI to a thumbnail of the given120 /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is121 /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns122 /// another bird, showing the full render of one bird inside the other's inventory might be a123 /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an124 /// image that is lighter and faster to load but representative of this resource.125 #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]126 pub thumb: Option<BoundedString>,127}128129#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]130#[cfg_attr(feature = "std", derive(Serialize))]131#[cfg_attr(132 feature = "std",133 serde(bound = r#"134 BoundedString: AsRef<[u8]>,135 BoundedParts: AsRef<[PartId]>136 "#)137)]138pub enum ResourceTypes<BoundedString, BoundedParts> {139 Basic(BasicResource<BoundedString>),140 Composable(ComposableResource<BoundedString, BoundedParts>),141 Slot(SlotResource<BoundedString>),142}143144#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]145#[cfg_attr(feature = "std", derive(Serialize))]146#[cfg_attr(147 feature = "std",148 serde(bound = r#"149 BoundedString: AsRef<[u8]>,150 BoundedParts: AsRef<[PartId]>151 "#)152)]153pub struct ResourceInfo<BoundedString, BoundedParts> {154 /// ID is a unique identifier for a resource across all those of a single NFT.155 /// The combination of a collection ID, an NFT ID, and the resource ID must be156 /// unique across the entire RMRK ecosystem.157 //#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]158 pub id: ResourceId,159160 /// Resource type and the accordingly structured data stored161 pub resource: ResourceTypes<BoundedString, BoundedParts>,162163 /// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted164 pub pending: bool,165166 /// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted167 pub pending_removal: bool,168}difftreelog
source
primitives/rmrk-traits/src/resource.rs7.4 KiBsourcehistory