difftreelog
refactorprimitives): purge defaultness from rmrk
in: master
1 file changed
primitives/data-structs/src/rmrk.rsdiffbeforeafterboth1use 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 BoundedString: AsRef<[u8]>,286 BoundedParts: AsRef<[PartId]>287 "#)288)]289pub struct ResourceInfo<BoundedString: Default, BoundedParts> {290 /// id is a 5-character string of reasonable uniqueness.291 /// The combination of base ID and resource id should be unique across the entire RMRK292 /// ecosystem which293 //#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]294 pub id: ResourceId,295296 /// Resource297 pub resource: ResourceTypes<BoundedString, BoundedParts>,298299 /// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted300 pub pending: bool,301302 /// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted303 pub pending_removal: bool,304}305306#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]307#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]308#[cfg_attr(309 feature = "std",310 serde(bound = r#"311 AccountId: Serialize,312 BoundedString: AsRef<[u8]>313 "#)314)]315pub struct BaseInfo<AccountId, BoundedString> {316 /// Original creator of the Base317 pub issuer: AccountId,318319 /// Specifies how an NFT should be rendered, ie "svg"320 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]321 pub base_type: BoundedString,322323 /// User provided symbol during Base creation324 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]325 pub symbol: BoundedString,326}327328#[cfg_attr(feature = "std", derive(Serialize))]329#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]330#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]331pub struct FixedPart<BoundedString> {332 pub id: PartId,333 pub z: ZIndex,334335 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]336 pub src: BoundedString,337}338339#[cfg_attr(feature = "std", derive(Serialize))]340#[derive(Encode, Decode, Debug, Derivative, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]341#[cfg_attr(342 feature = "std",343 serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")344)]345#[derivative(Default(bound = ""))]346pub enum EquippableList<BoundedCollectionList> {347 All,348349 #[derivative(Default)]350 Empty,351352 Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),353}354355#[cfg_attr(feature = "std", derive(Serialize))]356#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]357#[cfg_attr(358 feature = "std",359 serde(bound = r#"360 BoundedString: AsRef<[u8]>,361 BoundedCollectionList: AsRef<[CollectionId]>362 "#)363)]364pub struct SlotPart<BoundedString, BoundedCollectionList> {365 pub id: PartId,366 pub equippable: EquippableList<BoundedCollectionList>,367368 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]369 pub src: BoundedString,370371 pub z: ZIndex,372}373374#[cfg_attr(feature = "std", derive(Serialize))]375#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]376#[cfg_attr(377 feature = "std",378 serde(bound = r#"379 BoundedString: AsRef<[u8]>,380 BoundedCollectionList: AsRef<[CollectionId]>381 "#)382)]383pub enum PartType<BoundedString, BoundedCollectionList> {384 FixedPart(FixedPart<BoundedString>),385 SlotPart(SlotPart<BoundedString, BoundedCollectionList>),386}387388impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {389 pub fn id(&self) -> PartId {390 match self {391 Self::FixedPart(part) => part.id,392 Self::SlotPart(part) => part.id,393 }394 }395396 pub fn src(&self) -> &BoundedString {397 match self {398 Self::FixedPart(part) => &part.src,399 Self::SlotPart(part) => &part.src,400 }401 }402403 pub fn z_index(&self) -> ZIndex {404 match self {405 Self::FixedPart(part) => part.z,406 Self::SlotPart(part) => part.z,407 }408 }409}410411#[cfg_attr(feature = "std", derive(Eq, Serialize))]412#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]413#[cfg_attr(414 feature = "std",415 serde(bound = r#"416 BoundedString: AsRef<[u8]>,417 PropertyList: AsRef<[ThemeProperty<BoundedString>]>,418 "#)419)]420pub struct Theme<BoundedString, PropertyList> {421 /// Name of the theme422 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]423 pub name: BoundedString,424425 /// Theme properties426 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]427 pub properties: PropertyList,428 /// Inheritability429 pub inherit: bool,430}431432#[cfg_attr(feature = "std", derive(Eq, Serialize))]433#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]434#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]435pub struct ThemeProperty<BoundedString> {436 /// Key of the property437 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]438 pub key: BoundedString,439440 /// Value of the property441 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]442 pub value: BoundedString,443}