difftreelog
fix(rmrk) move rmrk specific types to rmrk-traits
in: master
19 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6338,6 +6338,7 @@
"pallet-nonfungible",
"pallet-structure",
"parity-scale-codec 3.1.2",
+ "rmrk-traits",
"scale-info",
"sp-core",
"sp-runtime",
@@ -6357,6 +6358,7 @@
"pallet-nonfungible",
"pallet-rmrk-core",
"parity-scale-codec 3.1.2",
+ "rmrk-traits",
"scale-info",
"sp-core",
"sp-runtime",
@@ -8999,15 +9001,24 @@
version = "0.0.1"
dependencies = [
"parity-scale-codec 2.3.1",
+ "rmrk-traits",
"serde",
"sp-api",
"sp-core",
"sp-runtime",
"sp-std",
- "up-data-structs",
]
[[package]]
+name = "rmrk-traits"
+version = "0.1.0"
+dependencies = [
+ "parity-scale-codec 3.1.2",
+ "scale-info",
+ "serde",
+]
+
+[[package]]
name = "rocksdb"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -12723,6 +12734,7 @@
"frame-system",
"pallet-evm",
"parity-scale-codec 3.1.2",
+ "rmrk-traits",
"scale-info",
"serde",
"sp-core",
pallets/proxy-rmrk-core/Cargo.tomldiffbeforeafterboth--- a/pallets/proxy-rmrk-core/Cargo.toml
+++ b/pallets/proxy-rmrk-core/Cargo.toml
@@ -22,6 +22,7 @@
up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.22" }
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" }
+rmrk-traits = { default-features = false, path = "../../primitives/rmrk-traits" }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
derivative = { version = "2.2.0", features = ["use_core"] }
@@ -33,6 +34,7 @@
"sp-runtime/std",
"sp-std/std",
"up-data-structs/std",
+ "rmrk-traits/std",
"pallet-common/std",
"pallet-nonfungible/std",
"pallet-structure/std",
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -289,7 +289,7 @@
let sender = T::CrossAccountId::from_sub(sender);
let cross_owner = T::CrossAccountId::from_sub(owner.clone());
- let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {
+ let royalty_info = royalty_amount.map(|amount| rmrk_traits::RoyaltyInfo {
recipient: recipient.unwrap_or_else(|| owner.clone()),
amount,
});
pallets/proxy-rmrk-equip/Cargo.tomldiffbeforeafterboth--- a/pallets/proxy-rmrk-equip/Cargo.toml
+++ b/pallets/proxy-rmrk-equip/Cargo.toml
@@ -21,6 +21,7 @@
up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.22" }
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" }
+rmrk-traits = { default-features = false, path = "../../primitives/rmrk-traits" }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
pallet-rmrk-core = { default-features = false, path = "../proxy-rmrk-core" }
@@ -32,6 +33,7 @@
"sp-runtime/std",
"sp-std/std",
"up-data-structs/std",
+ "rmrk-traits/std",
"pallet-common/std",
"pallet-nonfungible/std",
"pallet-rmrk-core/std",
primitives/data-structs/Cargo.tomldiffbeforeafterboth--- a/primitives/data-structs/Cargo.toml
+++ b/primitives/data-structs/Cargo.toml
@@ -26,6 +26,7 @@
derivative = { version = "2.2.0", features = ["use_core"] }
struct-versioning = { path = "../../crates/struct-versioning" }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.22" }
+rmrk-traits = { default-features = false, path = "../rmrk-traits" }
[features]
default = ["std"]
@@ -39,7 +40,8 @@
"sp-core/std",
"sp-std/std",
"pallet-evm/std",
+ "rmrk-traits/std",
]
serde1 = ["serde/alloc"]
limit-testing = []
-runtime-benchmarks = []
\ No newline at end of file
+runtime-benchmarks = []
primitives/data-structs/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::{20 convert::{TryFrom, TryInto},21 fmt,22};23use frame_support::{24 storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},25 traits::Get,26 parameter_types,27};2829#[cfg(feature = "serde")]30use serde::{Serialize, Deserialize};3132use sp_core::U256;33use sp_runtime::{ArithmeticError, sp_std::prelude::Vec, Permill};34use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};35use frame_support::{BoundedVec, traits::ConstU32};36use derivative::Derivative;37use scale_info::TypeInfo;3839pub mod rmrk;4041// RMRK42use rmrk::{43 CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme, ThemeProperty,44 ResourceTypes, BasicResource, ComposableResource, SlotResource,45};46pub use rmrk::{47 primitives::{48 CollectionId as RmrkCollectionId, NftId as RmrkNftId, BaseId as RmrkBaseId,49 PartId as RmrkPartId, ResourceId as RmrkResourceId,50 },51 NftChild as RmrkNftChild, AccountIdOrCollectionNftTuple as RmrkAccountIdOrCollectionNftTuple,52 FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart, EquippableList as RmrkEquippableList,53};5455mod bounded;56pub mod budget;57pub mod mapping;58mod migration;5960pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;61pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;62pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;6364pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {65 100_00066} else {67 1068};69pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {70 100_00071} else {72 1073};74pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {75 204876} else {77 1078};79pub const COLLECTION_ADMINS_LIMIT: u32 = 5;80pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;81pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {82 1_000_00083} else {84 1085};8687// Timeouts for item types in passed blocks88pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;89pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;90pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;9192pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;9394// Schema limits95pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;96pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;97pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;9899pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;100101pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;102pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;103pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;104105pub const MAX_PROPERTY_KEY_LENGTH: u32 = 256;106pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;107pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;108109pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;110pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;111112// RMRK constants113pub const RMRK_STRING_LIMIT: u32 = 128;114pub const RMRK_COLLECTION_SYMBOL_LIMIT: u32 = 100;115pub const RMRK_RESOURCE_SYMBOL_LIMIT: u32 = 10;116pub const RMRK_KEY_LIMIT: u32 = 32;117pub const RMRK_VALUE_LIMIT: u32 = 256;118119/// How much items can be created per single120/// create_many call121pub const MAX_ITEMS_PER_BATCH: u32 = 200;122123pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;124125#[derive(126 Encode,127 Decode,128 PartialEq,129 Eq,130 PartialOrd,131 Ord,132 Clone,133 Copy,134 Debug,135 Default,136 TypeInfo,137 MaxEncodedLen,138)]139#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]140pub struct CollectionId(pub u32);141impl EncodeLike<u32> for CollectionId {}142impl EncodeLike<CollectionId> for u32 {}143144#[derive(145 Encode,146 Decode,147 PartialEq,148 Eq,149 PartialOrd,150 Ord,151 Clone,152 Copy,153 Debug,154 Default,155 TypeInfo,156 MaxEncodedLen,157)]158#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]159pub struct TokenId(pub u32);160impl EncodeLike<u32> for TokenId {}161impl EncodeLike<TokenId> for u32 {}162163impl TokenId {164 pub fn try_next(self) -> Result<TokenId, ArithmeticError> {165 self.0166 .checked_add(1)167 .ok_or(ArithmeticError::Overflow)168 .map(Self)169 }170}171172impl From<TokenId> for U256 {173 fn from(t: TokenId) -> Self {174 t.0.into()175 }176}177178impl TryFrom<U256> for TokenId {179 type Error = &'static str;180181 fn try_from(value: U256) -> Result<Self, Self::Error> {182 Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))183 }184}185186#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]187#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]188pub struct TokenData<CrossAccountId> {189 pub properties: Vec<Property>,190 pub owner: Option<CrossAccountId>,191}192193pub struct OverflowError;194impl From<OverflowError> for &'static str {195 fn from(_: OverflowError) -> Self {196 "overflow occured"197 }198}199200pub type DecimalPoints = u8;201202#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]203#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]204pub enum CollectionMode {205 NFT,206 // decimal points207 Fungible(DecimalPoints),208 ReFungible,209}210211impl CollectionMode {212 pub fn id(&self) -> u8 {213 match self {214 CollectionMode::NFT => 1,215 CollectionMode::Fungible(_) => 2,216 CollectionMode::ReFungible => 3,217 }218 }219}220221pub trait SponsoringResolve<AccountId, Call> {222 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;223}224225#[derive(Encode, Decode, Eq, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]226#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]227pub enum AccessMode {228 Normal,229 AllowList,230}231impl Default for AccessMode {232 fn default() -> Self {233 Self::Normal234 }235}236237#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]238#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]239pub enum SchemaVersion {240 ImageURL,241 Unique,242}243impl Default for SchemaVersion {244 fn default() -> Self {245 Self::ImageURL246 }247}248249#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]250#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]251pub struct Ownership<AccountId> {252 pub owner: AccountId,253 pub fraction: u128,254}255256#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]257#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]258pub enum SponsorshipState<AccountId> {259 /// The fees are applied to the transaction sender260 Disabled,261 Unconfirmed(AccountId),262 /// Transactions are sponsored by specified account263 Confirmed(AccountId),264}265266impl<AccountId> SponsorshipState<AccountId> {267 pub fn sponsor(&self) -> Option<&AccountId> {268 match self {269 Self::Confirmed(sponsor) => Some(sponsor),270 _ => None,271 }272 }273274 pub fn pending_sponsor(&self) -> Option<&AccountId> {275 match self {276 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),277 _ => None,278 }279 }280281 pub fn confirmed(&self) -> bool {282 matches!(self, Self::Confirmed(_))283 }284}285286impl<T> Default for SponsorshipState<T> {287 fn default() -> Self {288 Self::Disabled289 }290}291292/// Used in storage293#[struct_versioning::versioned(version = 2, upper)]294#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]295pub struct Collection<AccountId> {296 pub owner: AccountId,297 pub mode: CollectionMode,298 #[version(..2)]299 pub access: AccessMode,300 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,301 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,302 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,303304 #[version(..2)]305 pub mint_mode: bool,306307 #[version(..2)]308 pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,309310 #[version(..2)]311 pub schema_version: SchemaVersion,312 pub sponsorship: SponsorshipState<AccountId>,313314 pub limits: CollectionLimits,315316 #[version(2.., upper(Default::default()))]317 pub permissions: CollectionPermissions,318319 /// Marks that this collection is not "unique", and managed from external.320 #[version(2.., upper(false))]321 pub external_collection: bool,322323 #[version(..2)]324 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,325326 #[version(..2)]327 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,328329 #[version(..2)]330 pub meta_update_permission: MetaUpdatePermission,331}332333/// Used in RPC calls334#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]335#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]336pub struct RpcCollection<AccountId> {337 pub owner: AccountId,338 pub mode: CollectionMode,339 pub name: Vec<u16>,340 pub description: Vec<u16>,341 pub token_prefix: Vec<u8>,342 pub sponsorship: SponsorshipState<AccountId>,343 pub limits: CollectionLimits,344 pub permissions: CollectionPermissions,345 pub token_property_permissions: Vec<PropertyKeyPermission>,346 pub properties: Vec<Property>,347 pub read_only: bool,348}349350#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Derivative, MaxEncodedLen)]351#[derivative(Debug, Default(bound = ""))]352pub struct CreateCollectionData<AccountId> {353 #[derivative(Default(value = "CollectionMode::NFT"))]354 pub mode: CollectionMode,355 pub access: Option<AccessMode>,356 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,357 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,358 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,359 pub pending_sponsor: Option<AccountId>,360 pub limits: Option<CollectionLimits>,361 pub permissions: Option<CollectionPermissions>,362 pub token_property_permissions: CollectionPropertiesPermissionsVec,363 pub properties: CollectionPropertiesVec,364}365366pub type CollectionPropertiesPermissionsVec =367 BoundedVec<PropertyKeyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;368369pub type CollectionPropertiesVec = BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;370371/// All fields are wrapped in `Option`s, where None means chain default372// When adding/removing fields from this struct - don't forget to also update clamp_limits373#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]374#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]375pub struct CollectionLimits {376 pub account_token_ownership_limit: Option<u32>,377 pub sponsored_data_size: Option<u32>,378379 /// FIXME should we delete this or repurpose it?380 /// None - setVariableMetadata is not sponsored381 /// Some(v) - setVariableMetadata is sponsored382 /// if there is v block between txs383 pub sponsored_data_rate_limit: Option<SponsoringRateLimit>,384 pub token_limit: Option<u32>,385386 // Timeouts for item types in passed blocks387 pub sponsor_transfer_timeout: Option<u32>,388 pub sponsor_approve_timeout: Option<u32>,389 pub owner_can_transfer: Option<bool>,390 pub owner_can_destroy: Option<bool>,391 pub transfers_enabled: Option<bool>,392}393394impl CollectionLimits {395 pub fn account_token_ownership_limit(&self) -> u32 {396 self.account_token_ownership_limit397 .unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)398 .min(MAX_TOKEN_OWNERSHIP)399 }400 pub fn sponsored_data_size(&self) -> u32 {401 self.sponsored_data_size402 .unwrap_or(CUSTOM_DATA_LIMIT)403 .min(CUSTOM_DATA_LIMIT)404 }405 pub fn token_limit(&self) -> u32 {406 self.token_limit407 .unwrap_or(COLLECTION_TOKEN_LIMIT)408 .min(COLLECTION_TOKEN_LIMIT)409 }410 pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {411 self.sponsor_transfer_timeout412 .unwrap_or(default)413 .min(MAX_SPONSOR_TIMEOUT)414 }415 pub fn sponsor_approve_timeout(&self) -> u32 {416 self.sponsor_approve_timeout417 .unwrap_or(SPONSOR_APPROVE_TIMEOUT)418 .min(MAX_SPONSOR_TIMEOUT)419 }420 pub fn owner_can_transfer(&self) -> bool {421 self.owner_can_transfer.unwrap_or(true)422 }423 pub fn owner_can_destroy(&self) -> bool {424 self.owner_can_destroy.unwrap_or(true)425 }426 pub fn transfers_enabled(&self) -> bool {427 self.transfers_enabled.unwrap_or(true)428 }429 pub fn sponsored_data_rate_limit(&self) -> Option<u32> {430 match self431 .sponsored_data_rate_limit432 .unwrap_or(SponsoringRateLimit::SponsoringDisabled)433 {434 SponsoringRateLimit::SponsoringDisabled => None,435 SponsoringRateLimit::Blocks(v) => Some(v.min(MAX_SPONSOR_TIMEOUT)),436 }437 }438}439440// When adding/removing fields from this struct - don't forget to also update clamp_limits441#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]442#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]443pub struct CollectionPermissions {444 pub access: Option<AccessMode>,445 pub mint_mode: Option<bool>,446 pub nesting: Option<NestingRule>,447}448449impl CollectionPermissions {450 pub fn access(&self) -> AccessMode {451 self.access.unwrap_or(AccessMode::Normal)452 }453 pub fn mint_mode(&self) -> bool {454 self.mint_mode.unwrap_or(false)455 }456 pub fn nesting(&self) -> &NestingRule {457 static DEFAULT: NestingRule = NestingRule::Disabled;458 self.nesting.as_ref().unwrap_or(&DEFAULT)459 }460}461462pub type OwnerRestrictedSet = BoundedBTreeSet<CollectionId, ConstU32<16>>;463464#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen, Derivative)]465#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]466#[derivative(Debug)]467pub enum NestingRule {468 /// No one can nest tokens469 Disabled,470 /// Owner can nest any tokens471 Owner,472 /// Owner can nest tokens from specified collections473 OwnerRestricted(474 #[cfg_attr(feature = "serde1", serde(with = "bounded::set_serde"))]475 #[derivative(Debug(format_with = "bounded::set_debug"))]476 OwnerRestrictedSet,477 ),478 /// Used for tests479 Permissive,480}481482#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]483#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]484pub enum SponsoringRateLimit {485 SponsoringDisabled,486 Blocks(u32),487}488489#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]490#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]491#[derivative(Debug)]492pub struct CreateNftData {493 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]494 #[derivative(Debug(format_with = "bounded::vec_debug"))]495 pub properties: CollectionPropertiesVec,496}497498#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]499#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]500pub struct CreateFungibleData {501 pub value: u128,502}503504#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]505#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]506#[derivative(Debug)]507pub struct CreateReFungibleData {508 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]509 #[derivative(Debug(format_with = "bounded::vec_debug"))]510 pub const_data: BoundedVec<u8, CustomDataLimit>,511 pub pieces: u128,512}513514#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]515#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]516pub enum MetaUpdatePermission {517 ItemOwner,518 Admin,519 None,520}521522#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]523#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]524pub enum CreateItemData {525 NFT(CreateNftData),526 Fungible(CreateFungibleData),527 ReFungible(CreateReFungibleData),528}529530#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]531#[derivative(Debug)]532pub struct CreateNftExData<CrossAccountId> {533 #[derivative(Debug(format_with = "bounded::vec_debug"))]534 pub properties: CollectionPropertiesVec,535 pub owner: CrossAccountId,536}537538#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]539#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]540pub struct CreateRefungibleExData<CrossAccountId> {541 #[derivative(Debug(format_with = "bounded::vec_debug"))]542 pub const_data: BoundedVec<u8, CustomDataLimit>,543 #[derivative(Debug(format_with = "bounded::map_debug"))]544 pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,545}546547#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]548#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]549pub enum CreateItemExData<CrossAccountId> {550 NFT(551 #[derivative(Debug(format_with = "bounded::vec_debug"))]552 BoundedVec<CreateNftExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,553 ),554 Fungible(555 #[derivative(Debug(format_with = "bounded::map_debug"))]556 BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,557 ),558 /// Many tokens, each may have only one owner559 RefungibleMultipleItems(560 #[derivative(Debug(format_with = "bounded::vec_debug"))]561 BoundedVec<CreateRefungibleExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,562 ),563 /// Single token, which may have many owners564 RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),565}566567impl CreateItemData {568 pub fn data_size(&self) -> usize {569 match self {570 CreateItemData::ReFungible(data) => data.const_data.len(),571 _ => 0,572 }573 }574}575576impl From<CreateNftData> for CreateItemData {577 fn from(item: CreateNftData) -> Self {578 CreateItemData::NFT(item)579 }580}581582impl From<CreateReFungibleData> for CreateItemData {583 fn from(item: CreateReFungibleData) -> Self {584 CreateItemData::ReFungible(item)585 }586}587588impl From<CreateFungibleData> for CreateItemData {589 fn from(item: CreateFungibleData) -> Self {590 CreateItemData::Fungible(item)591 }592}593594#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]595#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]596// todo possibly rename to be used generally as an address pair597pub struct TokenChild {598 pub token: TokenId,599 pub collection: CollectionId,600}601602#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]603#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]604pub struct CollectionStats {605 pub created: u32,606 pub destroyed: u32,607 pub alive: u32,608}609610#[derive(Encode, Decode, Clone, Debug)]611#[cfg_attr(feature = "std", derive(PartialEq))]612pub struct PhantomType<T>(core::marker::PhantomData<T>);613614impl<T: TypeInfo + 'static> TypeInfo for PhantomType<T> {615 type Identity = PhantomType<T>;616617 fn type_info() -> scale_info::Type {618 use scale_info::{619 Type, Path,620 build::{FieldsBuilder, UnnamedFields},621 type_params,622 };623 Type::builder()624 .path(Path::new("up_data_structs", "PhantomType"))625 .type_params(type_params!(T))626 .composite(<FieldsBuilder<UnnamedFields>>::default().field(|b| b.ty::<[T; 0]>()))627 }628}629impl<T> MaxEncodedLen for PhantomType<T> {630 fn max_encoded_len() -> usize {631 0632 }633}634635pub type PropertyKey = BoundedVec<u8, ConstU32<MAX_PROPERTY_KEY_LENGTH>>;636pub type PropertyValue = BoundedVec<u8, ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;637638#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]639#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]640pub struct PropertyPermission {641 pub mutable: bool,642 pub collection_admin: bool,643 pub token_owner: bool,644}645646impl PropertyPermission {647 pub fn none() -> Self {648 Self {649 mutable: true,650 collection_admin: false,651 token_owner: false,652 }653 }654}655656#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, MaxEncodedLen)]657#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]658pub struct Property {659 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]660 pub key: PropertyKey,661662 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]663 pub value: PropertyValue,664}665666impl Into<(PropertyKey, PropertyValue)> for Property {667 fn into(self) -> (PropertyKey, PropertyValue) {668 (self.key, self.value)669 }670}671672#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]673#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]674pub struct PropertyKeyPermission {675 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]676 pub key: PropertyKey,677678 pub permission: PropertyPermission,679}680681impl Into<(PropertyKey, PropertyPermission)> for PropertyKeyPermission {682 fn into(self) -> (PropertyKey, PropertyPermission) {683 (self.key, self.permission)684 }685}686687#[derive(Debug)]688pub enum PropertiesError {689 NoSpaceForProperty,690 PropertyLimitReached,691 InvalidCharacterInPropertyKey,692 PropertyKeyIsTooLong,693 EmptyPropertyKey,694}695696#[derive(Clone, Copy)]697pub enum PropertyScope {698 None,699 Rmrk,700}701702impl PropertyScope {703 pub fn apply(self, key: PropertyKey) -> Result<PropertyKey, PropertiesError> {704 let scope_str: &[u8] = match self {705 Self::None => return Ok(key),706 Self::Rmrk => b"rmrk",707 };708709 [scope_str, b":", key.as_slice()]710 .concat()711 .try_into()712 .map_err(|_| PropertiesError::PropertyKeyIsTooLong)713 }714}715716pub trait TrySetProperty: Sized {717 type Value;718719 fn try_scoped_set(720 &mut self,721 scope: PropertyScope,722 key: PropertyKey,723 value: Self::Value,724 ) -> Result<(), PropertiesError>;725726 fn try_scoped_set_from_iter<I, KV>(727 &mut self,728 scope: PropertyScope,729 iter: I,730 ) -> Result<(), PropertiesError>731 where732 I: Iterator<Item = KV>,733 KV: Into<(PropertyKey, Self::Value)>,734 {735 for kv in iter {736 let (key, value) = kv.into();737 self.try_scoped_set(scope, key, value)?;738 }739740 Ok(())741 }742743 fn try_set(&mut self, key: PropertyKey, value: Self::Value) -> Result<(), PropertiesError> {744 self.try_scoped_set(PropertyScope::None, key, value)745 }746747 fn try_set_from_iter<I, KV>(&mut self, iter: I) -> Result<(), PropertiesError>748 where749 I: Iterator<Item = KV>,750 KV: Into<(PropertyKey, Self::Value)>,751 {752 self.try_scoped_set_from_iter(PropertyScope::None, iter)753 }754}755756#[derive(Encode, Decode, TypeInfo, Derivative, Clone, PartialEq, MaxEncodedLen)]757#[derivative(Default(bound = ""))]758pub struct PropertiesMap<Value>(759 BoundedBTreeMap<PropertyKey, Value, ConstU32<MAX_PROPERTIES_PER_ITEM>>,760);761762impl<Value> PropertiesMap<Value> {763 pub fn new() -> Self {764 Self(BoundedBTreeMap::new())765 }766767 pub fn remove(&mut self, key: &PropertyKey) -> Result<Option<Value>, PropertiesError> {768 Self::check_property_key(key)?;769770 Ok(self.0.remove(key))771 }772773 pub fn get(&self, key: &PropertyKey) -> Option<&Value> {774 self.0.get(key)775 }776777 pub fn contains_key(&self, key: &PropertyKey) -> bool {778 self.0.contains_key(key)779 }780781 fn check_property_key(key: &PropertyKey) -> Result<(), PropertiesError> {782 if key.is_empty() {783 return Err(PropertiesError::EmptyPropertyKey);784 }785786 for byte in key.as_slice().iter() {787 let byte = *byte;788789 if !byte.is_ascii_alphanumeric() && byte != b'_' && byte != b'-' {790 return Err(PropertiesError::InvalidCharacterInPropertyKey);791 }792 }793794 Ok(())795 }796}797798impl<Value> IntoIterator for PropertiesMap<Value> {799 type Item = (PropertyKey, Value);800 type IntoIter = <801 BoundedBTreeMap<802 PropertyKey,803 Value,804 ConstU32<MAX_PROPERTIES_PER_ITEM>805 > as IntoIterator806 >::IntoIter;807808 fn into_iter(self) -> Self::IntoIter {809 self.0.into_iter()810 }811}812813impl<Value> TrySetProperty for PropertiesMap<Value> {814 type Value = Value;815816 fn try_scoped_set(817 &mut self,818 scope: PropertyScope,819 key: PropertyKey,820 value: Self::Value,821 ) -> Result<(), PropertiesError> {822 Self::check_property_key(&key)?;823824 let key = scope.apply(key)?;825 self.0826 .try_insert(key, value)827 .map_err(|_| PropertiesError::PropertyLimitReached)?;828829 Ok(())830 }831}832833pub type PropertiesPermissionMap = PropertiesMap<PropertyPermission>;834835#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, MaxEncodedLen)]836pub struct Properties {837 map: PropertiesMap<PropertyValue>,838 consumed_space: u32,839 space_limit: u32,840}841842impl Properties {843 pub fn new(space_limit: u32) -> Self {844 Self {845 map: PropertiesMap::new(),846 consumed_space: 0,847 space_limit,848 }849 }850851 pub fn remove(&mut self, key: &PropertyKey) -> Result<Option<PropertyValue>, PropertiesError> {852 let value = self.map.remove(key)?;853854 if let Some(ref value) = value {855 let value_len = value.len() as u32;856 self.consumed_space -= value_len;857 }858859 Ok(value)860 }861862 pub fn get(&self, key: &PropertyKey) -> Option<&PropertyValue> {863 self.map.get(key)864 }865}866867impl IntoIterator for Properties {868 type Item = (PropertyKey, PropertyValue);869 type IntoIter = <PropertiesMap<PropertyValue> as IntoIterator>::IntoIter;870871 fn into_iter(self) -> Self::IntoIter {872 self.map.into_iter()873 }874}875876impl TrySetProperty for Properties {877 type Value = PropertyValue;878879 fn try_scoped_set(880 &mut self,881 scope: PropertyScope,882 key: PropertyKey,883 value: Self::Value,884 ) -> Result<(), PropertiesError> {885 let value_len = value.len();886887 if self.consumed_space as usize + value_len > self.space_limit as usize888 && !cfg!(feature = "runtime-benchmarks")889 {890 return Err(PropertiesError::NoSpaceForProperty);891 }892893 self.map.try_scoped_set(scope, key, value)?;894895 self.consumed_space += value_len as u32;896897 Ok(())898 }899}900901pub struct CollectionProperties;902903impl Get<Properties> for CollectionProperties {904 fn get() -> Properties {905 Properties::new(MAX_COLLECTION_PROPERTIES_SIZE)906 }907}908909pub struct TokenProperties;910911impl Get<Properties> for TokenProperties {912 fn get() -> Properties {913 Properties::new(MAX_TOKEN_PROPERTIES_SIZE)914 }915}916917// RMRK918// todo document?919parameter_types! {920 #[derive(PartialEq, TypeInfo)]921 pub const RmrkStringLimit: u32 = 128;922 #[derive(PartialEq)]923 pub const RmrkCollectionSymbolLimit: u32 = 100;924 #[derive(PartialEq)]925 pub const RmrkResourceSymbolLimit: u32 = 10;926 #[derive(PartialEq)]927 pub const RmrkKeyLimit: u32 = 32;928 #[derive(PartialEq)]929 pub const RmrkValueLimit: u32 = 256;930 #[derive(PartialEq)]931 pub const RmrkMaxCollectionsEquippablePerPart: u32 = 100;932 #[derive(PartialEq)]933 pub const RmrkPartsLimit: u32 = 3;934}935936impl From<RmrkCollectionId> for CollectionId {937 fn from(id: RmrkCollectionId) -> Self {938 Self(id)939 }940}941942impl From<RmrkNftId> for TokenId {943 fn from(id: RmrkNftId) -> Self {944 Self(id)945 }946}947948pub type RmrkCollectionInfo<AccountId> =949 CollectionInfo<RmrkString, RmrkCollectionSymbol, AccountId>;950pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;951pub type RmrkResourceInfo = ResourceInfo<RmrkString, RmrkBoundedParts>;952pub type RmrkPropertyInfo = PropertyInfo<RmrkKeyString, RmrkValueString>;953pub type RmrkBaseInfo<AccountId> = BaseInfo<AccountId, RmrkString>;954pub type RmrkPartType =955 PartType<RmrkString, BoundedVec<RmrkCollectionId, RmrkMaxCollectionsEquippablePerPart>>;956pub type RmrkThemeProperty = ThemeProperty<RmrkString>;957pub type RmrkTheme = Theme<RmrkString, Vec<RmrkThemeProperty>>;958pub type RmrkResourceTypes = ResourceTypes<RmrkString, RmrkBoundedParts>;959960pub type RmrkBasicResource = BasicResource<RmrkString>;961pub type RmrkComposableResource = ComposableResource<RmrkString, RmrkBoundedParts>;962pub type RmrkSlotResource = SlotResource<RmrkString>;963964pub type RmrkString = BoundedVec<u8, RmrkStringLimit>;965pub type RmrkCollectionSymbol = BoundedVec<u8, RmrkCollectionSymbolLimit>;966pub type RmrkKeyString = BoundedVec<u8, RmrkKeyLimit>;967pub type RmrkValueString = BoundedVec<u8, RmrkValueLimit>;968pub type RmrkBoundedResource = BoundedVec<u8, RmrkResourceSymbolLimit>;969pub type RmrkBoundedParts = BoundedVec<RmrkPartId, RmrkPartsLimit>; // todo make sure it is needed970971pub type RmrkRpcString = Vec<u8>;972pub type RmrkThemeName = RmrkRpcString;973pub type RmrkPropertyKey = RmrkRpcString;1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::{20 convert::{TryFrom, TryInto},21 fmt,22};23use frame_support::{24 storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},25 traits::Get,26 parameter_types,27};2829#[cfg(feature = "serde")]30use serde::{Serialize, Deserialize};3132use sp_core::U256;33use sp_runtime::{ArithmeticError, sp_std::prelude::Vec, Permill};34use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};35use frame_support::{BoundedVec, traits::ConstU32};36use derivative::Derivative;37use scale_info::TypeInfo;3839// RMRK40use rmrk_traits::{41 CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme, ThemeProperty,42 ResourceTypes, BasicResource, ComposableResource, SlotResource,43};44pub use rmrk_traits::{45 primitives::{46 CollectionId as RmrkCollectionId, NftId as RmrkNftId, BaseId as RmrkBaseId,47 PartId as RmrkPartId, ResourceId as RmrkResourceId,48 },49 NftChild as RmrkNftChild, AccountIdOrCollectionNftTuple as RmrkAccountIdOrCollectionNftTuple,50 FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart, EquippableList as RmrkEquippableList,51};5253mod bounded;54pub mod budget;55pub mod mapping;56mod migration;5758pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;59pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;60pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;6162pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {63 100_00064} else {65 1066};67pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {68 100_00069} else {70 1071};72pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {73 204874} else {75 1076};77pub const COLLECTION_ADMINS_LIMIT: u32 = 5;78pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;79pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {80 1_000_00081} else {82 1083};8485// Timeouts for item types in passed blocks86pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;87pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;88pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;8990pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;9192// Schema limits93pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;94pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;95pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;9697pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;9899pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;100pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;101pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;102103pub const MAX_PROPERTY_KEY_LENGTH: u32 = 256;104pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;105pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;106107pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;108pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;109110// RMRK constants111pub const RMRK_STRING_LIMIT: u32 = 128;112pub const RMRK_COLLECTION_SYMBOL_LIMIT: u32 = 100;113pub const RMRK_RESOURCE_SYMBOL_LIMIT: u32 = 10;114pub const RMRK_KEY_LIMIT: u32 = 32;115pub const RMRK_VALUE_LIMIT: u32 = 256;116117/// How much items can be created per single118/// create_many call119pub const MAX_ITEMS_PER_BATCH: u32 = 200;120121pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;122123#[derive(124 Encode,125 Decode,126 PartialEq,127 Eq,128 PartialOrd,129 Ord,130 Clone,131 Copy,132 Debug,133 Default,134 TypeInfo,135 MaxEncodedLen,136)]137#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]138pub struct CollectionId(pub u32);139impl EncodeLike<u32> for CollectionId {}140impl EncodeLike<CollectionId> for u32 {}141142#[derive(143 Encode,144 Decode,145 PartialEq,146 Eq,147 PartialOrd,148 Ord,149 Clone,150 Copy,151 Debug,152 Default,153 TypeInfo,154 MaxEncodedLen,155)]156#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]157pub struct TokenId(pub u32);158impl EncodeLike<u32> for TokenId {}159impl EncodeLike<TokenId> for u32 {}160161impl TokenId {162 pub fn try_next(self) -> Result<TokenId, ArithmeticError> {163 self.0164 .checked_add(1)165 .ok_or(ArithmeticError::Overflow)166 .map(Self)167 }168}169170impl From<TokenId> for U256 {171 fn from(t: TokenId) -> Self {172 t.0.into()173 }174}175176impl TryFrom<U256> for TokenId {177 type Error = &'static str;178179 fn try_from(value: U256) -> Result<Self, Self::Error> {180 Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))181 }182}183184#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]185#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]186pub struct TokenData<CrossAccountId> {187 pub properties: Vec<Property>,188 pub owner: Option<CrossAccountId>,189}190191pub struct OverflowError;192impl From<OverflowError> for &'static str {193 fn from(_: OverflowError) -> Self {194 "overflow occured"195 }196}197198pub type DecimalPoints = u8;199200#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]201#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]202pub enum CollectionMode {203 NFT,204 // decimal points205 Fungible(DecimalPoints),206 ReFungible,207}208209impl CollectionMode {210 pub fn id(&self) -> u8 {211 match self {212 CollectionMode::NFT => 1,213 CollectionMode::Fungible(_) => 2,214 CollectionMode::ReFungible => 3,215 }216 }217}218219pub trait SponsoringResolve<AccountId, Call> {220 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;221}222223#[derive(Encode, Decode, Eq, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]224#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]225pub enum AccessMode {226 Normal,227 AllowList,228}229impl Default for AccessMode {230 fn default() -> Self {231 Self::Normal232 }233}234235#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]236#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]237pub enum SchemaVersion {238 ImageURL,239 Unique,240}241impl Default for SchemaVersion {242 fn default() -> Self {243 Self::ImageURL244 }245}246247#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]248#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]249pub struct Ownership<AccountId> {250 pub owner: AccountId,251 pub fraction: u128,252}253254#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]255#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]256pub enum SponsorshipState<AccountId> {257 /// The fees are applied to the transaction sender258 Disabled,259 Unconfirmed(AccountId),260 /// Transactions are sponsored by specified account261 Confirmed(AccountId),262}263264impl<AccountId> SponsorshipState<AccountId> {265 pub fn sponsor(&self) -> Option<&AccountId> {266 match self {267 Self::Confirmed(sponsor) => Some(sponsor),268 _ => None,269 }270 }271272 pub fn pending_sponsor(&self) -> Option<&AccountId> {273 match self {274 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),275 _ => None,276 }277 }278279 pub fn confirmed(&self) -> bool {280 matches!(self, Self::Confirmed(_))281 }282}283284impl<T> Default for SponsorshipState<T> {285 fn default() -> Self {286 Self::Disabled287 }288}289290/// Used in storage291#[struct_versioning::versioned(version = 2, upper)]292#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]293pub struct Collection<AccountId> {294 pub owner: AccountId,295 pub mode: CollectionMode,296 #[version(..2)]297 pub access: AccessMode,298 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,299 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,300 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,301302 #[version(..2)]303 pub mint_mode: bool,304305 #[version(..2)]306 pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,307308 #[version(..2)]309 pub schema_version: SchemaVersion,310 pub sponsorship: SponsorshipState<AccountId>,311312 pub limits: CollectionLimits,313314 #[version(2.., upper(Default::default()))]315 pub permissions: CollectionPermissions,316317 /// Marks that this collection is not "unique", and managed from external.318 #[version(2.., upper(false))]319 pub external_collection: bool,320321 #[version(..2)]322 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,323324 #[version(..2)]325 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,326327 #[version(..2)]328 pub meta_update_permission: MetaUpdatePermission,329}330331/// Used in RPC calls332#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]333#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]334pub struct RpcCollection<AccountId> {335 pub owner: AccountId,336 pub mode: CollectionMode,337 pub name: Vec<u16>,338 pub description: Vec<u16>,339 pub token_prefix: Vec<u8>,340 pub sponsorship: SponsorshipState<AccountId>,341 pub limits: CollectionLimits,342 pub permissions: CollectionPermissions,343 pub token_property_permissions: Vec<PropertyKeyPermission>,344 pub properties: Vec<Property>,345 pub read_only: bool,346}347348#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Derivative, MaxEncodedLen)]349#[derivative(Debug, Default(bound = ""))]350pub struct CreateCollectionData<AccountId> {351 #[derivative(Default(value = "CollectionMode::NFT"))]352 pub mode: CollectionMode,353 pub access: Option<AccessMode>,354 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,355 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,356 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,357 pub pending_sponsor: Option<AccountId>,358 pub limits: Option<CollectionLimits>,359 pub permissions: Option<CollectionPermissions>,360 pub token_property_permissions: CollectionPropertiesPermissionsVec,361 pub properties: CollectionPropertiesVec,362}363364pub type CollectionPropertiesPermissionsVec =365 BoundedVec<PropertyKeyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;366367pub type CollectionPropertiesVec = BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;368369/// All fields are wrapped in `Option`s, where None means chain default370// When adding/removing fields from this struct - don't forget to also update clamp_limits371#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]372#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]373pub struct CollectionLimits {374 pub account_token_ownership_limit: Option<u32>,375 pub sponsored_data_size: Option<u32>,376377 /// FIXME should we delete this or repurpose it?378 /// None - setVariableMetadata is not sponsored379 /// Some(v) - setVariableMetadata is sponsored380 /// if there is v block between txs381 pub sponsored_data_rate_limit: Option<SponsoringRateLimit>,382 pub token_limit: Option<u32>,383384 // Timeouts for item types in passed blocks385 pub sponsor_transfer_timeout: Option<u32>,386 pub sponsor_approve_timeout: Option<u32>,387 pub owner_can_transfer: Option<bool>,388 pub owner_can_destroy: Option<bool>,389 pub transfers_enabled: Option<bool>,390}391392impl CollectionLimits {393 pub fn account_token_ownership_limit(&self) -> u32 {394 self.account_token_ownership_limit395 .unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)396 .min(MAX_TOKEN_OWNERSHIP)397 }398 pub fn sponsored_data_size(&self) -> u32 {399 self.sponsored_data_size400 .unwrap_or(CUSTOM_DATA_LIMIT)401 .min(CUSTOM_DATA_LIMIT)402 }403 pub fn token_limit(&self) -> u32 {404 self.token_limit405 .unwrap_or(COLLECTION_TOKEN_LIMIT)406 .min(COLLECTION_TOKEN_LIMIT)407 }408 pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {409 self.sponsor_transfer_timeout410 .unwrap_or(default)411 .min(MAX_SPONSOR_TIMEOUT)412 }413 pub fn sponsor_approve_timeout(&self) -> u32 {414 self.sponsor_approve_timeout415 .unwrap_or(SPONSOR_APPROVE_TIMEOUT)416 .min(MAX_SPONSOR_TIMEOUT)417 }418 pub fn owner_can_transfer(&self) -> bool {419 self.owner_can_transfer.unwrap_or(true)420 }421 pub fn owner_can_destroy(&self) -> bool {422 self.owner_can_destroy.unwrap_or(true)423 }424 pub fn transfers_enabled(&self) -> bool {425 self.transfers_enabled.unwrap_or(true)426 }427 pub fn sponsored_data_rate_limit(&self) -> Option<u32> {428 match self429 .sponsored_data_rate_limit430 .unwrap_or(SponsoringRateLimit::SponsoringDisabled)431 {432 SponsoringRateLimit::SponsoringDisabled => None,433 SponsoringRateLimit::Blocks(v) => Some(v.min(MAX_SPONSOR_TIMEOUT)),434 }435 }436}437438// When adding/removing fields from this struct - don't forget to also update clamp_limits439#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]440#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]441pub struct CollectionPermissions {442 pub access: Option<AccessMode>,443 pub mint_mode: Option<bool>,444 pub nesting: Option<NestingRule>,445}446447impl CollectionPermissions {448 pub fn access(&self) -> AccessMode {449 self.access.unwrap_or(AccessMode::Normal)450 }451 pub fn mint_mode(&self) -> bool {452 self.mint_mode.unwrap_or(false)453 }454 pub fn nesting(&self) -> &NestingRule {455 static DEFAULT: NestingRule = NestingRule::Disabled;456 self.nesting.as_ref().unwrap_or(&DEFAULT)457 }458}459460pub type OwnerRestrictedSet = BoundedBTreeSet<CollectionId, ConstU32<16>>;461462#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen, Derivative)]463#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]464#[derivative(Debug)]465pub enum NestingRule {466 /// No one can nest tokens467 Disabled,468 /// Owner can nest any tokens469 Owner,470 /// Owner can nest tokens from specified collections471 OwnerRestricted(472 #[cfg_attr(feature = "serde1", serde(with = "bounded::set_serde"))]473 #[derivative(Debug(format_with = "bounded::set_debug"))]474 OwnerRestrictedSet,475 ),476 /// Used for tests477 Permissive,478}479480#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]481#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]482pub enum SponsoringRateLimit {483 SponsoringDisabled,484 Blocks(u32),485}486487#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]488#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]489#[derivative(Debug)]490pub struct CreateNftData {491 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]492 #[derivative(Debug(format_with = "bounded::vec_debug"))]493 pub properties: CollectionPropertiesVec,494}495496#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]497#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]498pub struct CreateFungibleData {499 pub value: u128,500}501502#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]503#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]504#[derivative(Debug)]505pub struct CreateReFungibleData {506 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]507 #[derivative(Debug(format_with = "bounded::vec_debug"))]508 pub const_data: BoundedVec<u8, CustomDataLimit>,509 pub pieces: u128,510}511512#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]513#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]514pub enum MetaUpdatePermission {515 ItemOwner,516 Admin,517 None,518}519520#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]521#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]522pub enum CreateItemData {523 NFT(CreateNftData),524 Fungible(CreateFungibleData),525 ReFungible(CreateReFungibleData),526}527528#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]529#[derivative(Debug)]530pub struct CreateNftExData<CrossAccountId> {531 #[derivative(Debug(format_with = "bounded::vec_debug"))]532 pub properties: CollectionPropertiesVec,533 pub owner: CrossAccountId,534}535536#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]537#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]538pub struct CreateRefungibleExData<CrossAccountId> {539 #[derivative(Debug(format_with = "bounded::vec_debug"))]540 pub const_data: BoundedVec<u8, CustomDataLimit>,541 #[derivative(Debug(format_with = "bounded::map_debug"))]542 pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,543}544545#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]546#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]547pub enum CreateItemExData<CrossAccountId> {548 NFT(549 #[derivative(Debug(format_with = "bounded::vec_debug"))]550 BoundedVec<CreateNftExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,551 ),552 Fungible(553 #[derivative(Debug(format_with = "bounded::map_debug"))]554 BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,555 ),556 /// Many tokens, each may have only one owner557 RefungibleMultipleItems(558 #[derivative(Debug(format_with = "bounded::vec_debug"))]559 BoundedVec<CreateRefungibleExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,560 ),561 /// Single token, which may have many owners562 RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),563}564565impl CreateItemData {566 pub fn data_size(&self) -> usize {567 match self {568 CreateItemData::ReFungible(data) => data.const_data.len(),569 _ => 0,570 }571 }572}573574impl From<CreateNftData> for CreateItemData {575 fn from(item: CreateNftData) -> Self {576 CreateItemData::NFT(item)577 }578}579580impl From<CreateReFungibleData> for CreateItemData {581 fn from(item: CreateReFungibleData) -> Self {582 CreateItemData::ReFungible(item)583 }584}585586impl From<CreateFungibleData> for CreateItemData {587 fn from(item: CreateFungibleData) -> Self {588 CreateItemData::Fungible(item)589 }590}591592#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]593#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]594// todo possibly rename to be used generally as an address pair595pub struct TokenChild {596 pub token: TokenId,597 pub collection: CollectionId,598}599600#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]601#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]602pub struct CollectionStats {603 pub created: u32,604 pub destroyed: u32,605 pub alive: u32,606}607608#[derive(Encode, Decode, Clone, Debug)]609#[cfg_attr(feature = "std", derive(PartialEq))]610pub struct PhantomType<T>(core::marker::PhantomData<T>);611612impl<T: TypeInfo + 'static> TypeInfo for PhantomType<T> {613 type Identity = PhantomType<T>;614615 fn type_info() -> scale_info::Type {616 use scale_info::{617 Type, Path,618 build::{FieldsBuilder, UnnamedFields},619 type_params,620 };621 Type::builder()622 .path(Path::new("up_data_structs", "PhantomType"))623 .type_params(type_params!(T))624 .composite(<FieldsBuilder<UnnamedFields>>::default().field(|b| b.ty::<[T; 0]>()))625 }626}627impl<T> MaxEncodedLen for PhantomType<T> {628 fn max_encoded_len() -> usize {629 0630 }631}632633pub type PropertyKey = BoundedVec<u8, ConstU32<MAX_PROPERTY_KEY_LENGTH>>;634pub type PropertyValue = BoundedVec<u8, ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;635636#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]637#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]638pub struct PropertyPermission {639 pub mutable: bool,640 pub collection_admin: bool,641 pub token_owner: bool,642}643644impl PropertyPermission {645 pub fn none() -> Self {646 Self {647 mutable: true,648 collection_admin: false,649 token_owner: false,650 }651 }652}653654#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, MaxEncodedLen)]655#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]656pub struct Property {657 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]658 pub key: PropertyKey,659660 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]661 pub value: PropertyValue,662}663664impl Into<(PropertyKey, PropertyValue)> for Property {665 fn into(self) -> (PropertyKey, PropertyValue) {666 (self.key, self.value)667 }668}669670#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]671#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]672pub struct PropertyKeyPermission {673 #[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]674 pub key: PropertyKey,675676 pub permission: PropertyPermission,677}678679impl Into<(PropertyKey, PropertyPermission)> for PropertyKeyPermission {680 fn into(self) -> (PropertyKey, PropertyPermission) {681 (self.key, self.permission)682 }683}684685#[derive(Debug)]686pub enum PropertiesError {687 NoSpaceForProperty,688 PropertyLimitReached,689 InvalidCharacterInPropertyKey,690 PropertyKeyIsTooLong,691 EmptyPropertyKey,692}693694#[derive(Clone, Copy)]695pub enum PropertyScope {696 None,697 Rmrk,698}699700impl PropertyScope {701 pub fn apply(self, key: PropertyKey) -> Result<PropertyKey, PropertiesError> {702 let scope_str: &[u8] = match self {703 Self::None => return Ok(key),704 Self::Rmrk => b"rmrk",705 };706707 [scope_str, b":", key.as_slice()]708 .concat()709 .try_into()710 .map_err(|_| PropertiesError::PropertyKeyIsTooLong)711 }712}713714pub trait TrySetProperty: Sized {715 type Value;716717 fn try_scoped_set(718 &mut self,719 scope: PropertyScope,720 key: PropertyKey,721 value: Self::Value,722 ) -> Result<(), PropertiesError>;723724 fn try_scoped_set_from_iter<I, KV>(725 &mut self,726 scope: PropertyScope,727 iter: I,728 ) -> Result<(), PropertiesError>729 where730 I: Iterator<Item = KV>,731 KV: Into<(PropertyKey, Self::Value)>,732 {733 for kv in iter {734 let (key, value) = kv.into();735 self.try_scoped_set(scope, key, value)?;736 }737738 Ok(())739 }740741 fn try_set(&mut self, key: PropertyKey, value: Self::Value) -> Result<(), PropertiesError> {742 self.try_scoped_set(PropertyScope::None, key, value)743 }744745 fn try_set_from_iter<I, KV>(&mut self, iter: I) -> Result<(), PropertiesError>746 where747 I: Iterator<Item = KV>,748 KV: Into<(PropertyKey, Self::Value)>,749 {750 self.try_scoped_set_from_iter(PropertyScope::None, iter)751 }752}753754#[derive(Encode, Decode, TypeInfo, Derivative, Clone, PartialEq, MaxEncodedLen)]755#[derivative(Default(bound = ""))]756pub struct PropertiesMap<Value>(757 BoundedBTreeMap<PropertyKey, Value, ConstU32<MAX_PROPERTIES_PER_ITEM>>,758);759760impl<Value> PropertiesMap<Value> {761 pub fn new() -> Self {762 Self(BoundedBTreeMap::new())763 }764765 pub fn remove(&mut self, key: &PropertyKey) -> Result<Option<Value>, PropertiesError> {766 Self::check_property_key(key)?;767768 Ok(self.0.remove(key))769 }770771 pub fn get(&self, key: &PropertyKey) -> Option<&Value> {772 self.0.get(key)773 }774775 pub fn contains_key(&self, key: &PropertyKey) -> bool {776 self.0.contains_key(key)777 }778779 fn check_property_key(key: &PropertyKey) -> Result<(), PropertiesError> {780 if key.is_empty() {781 return Err(PropertiesError::EmptyPropertyKey);782 }783784 for byte in key.as_slice().iter() {785 let byte = *byte;786787 if !byte.is_ascii_alphanumeric() && byte != b'_' && byte != b'-' {788 return Err(PropertiesError::InvalidCharacterInPropertyKey);789 }790 }791792 Ok(())793 }794}795796impl<Value> IntoIterator for PropertiesMap<Value> {797 type Item = (PropertyKey, Value);798 type IntoIter = <799 BoundedBTreeMap<800 PropertyKey,801 Value,802 ConstU32<MAX_PROPERTIES_PER_ITEM>803 > as IntoIterator804 >::IntoIter;805806 fn into_iter(self) -> Self::IntoIter {807 self.0.into_iter()808 }809}810811impl<Value> TrySetProperty for PropertiesMap<Value> {812 type Value = Value;813814 fn try_scoped_set(815 &mut self,816 scope: PropertyScope,817 key: PropertyKey,818 value: Self::Value,819 ) -> Result<(), PropertiesError> {820 Self::check_property_key(&key)?;821822 let key = scope.apply(key)?;823 self.0824 .try_insert(key, value)825 .map_err(|_| PropertiesError::PropertyLimitReached)?;826827 Ok(())828 }829}830831pub type PropertiesPermissionMap = PropertiesMap<PropertyPermission>;832833#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, MaxEncodedLen)]834pub struct Properties {835 map: PropertiesMap<PropertyValue>,836 consumed_space: u32,837 space_limit: u32,838}839840impl Properties {841 pub fn new(space_limit: u32) -> Self {842 Self {843 map: PropertiesMap::new(),844 consumed_space: 0,845 space_limit,846 }847 }848849 pub fn remove(&mut self, key: &PropertyKey) -> Result<Option<PropertyValue>, PropertiesError> {850 let value = self.map.remove(key)?;851852 if let Some(ref value) = value {853 let value_len = value.len() as u32;854 self.consumed_space -= value_len;855 }856857 Ok(value)858 }859860 pub fn get(&self, key: &PropertyKey) -> Option<&PropertyValue> {861 self.map.get(key)862 }863}864865impl IntoIterator for Properties {866 type Item = (PropertyKey, PropertyValue);867 type IntoIter = <PropertiesMap<PropertyValue> as IntoIterator>::IntoIter;868869 fn into_iter(self) -> Self::IntoIter {870 self.map.into_iter()871 }872}873874impl TrySetProperty for Properties {875 type Value = PropertyValue;876877 fn try_scoped_set(878 &mut self,879 scope: PropertyScope,880 key: PropertyKey,881 value: Self::Value,882 ) -> Result<(), PropertiesError> {883 let value_len = value.len();884885 if self.consumed_space as usize + value_len > self.space_limit as usize886 && !cfg!(feature = "runtime-benchmarks")887 {888 return Err(PropertiesError::NoSpaceForProperty);889 }890891 self.map.try_scoped_set(scope, key, value)?;892893 self.consumed_space += value_len as u32;894895 Ok(())896 }897}898899pub struct CollectionProperties;900901impl Get<Properties> for CollectionProperties {902 fn get() -> Properties {903 Properties::new(MAX_COLLECTION_PROPERTIES_SIZE)904 }905}906907pub struct TokenProperties;908909impl Get<Properties> for TokenProperties {910 fn get() -> Properties {911 Properties::new(MAX_TOKEN_PROPERTIES_SIZE)912 }913}914915// RMRK916// todo document?917parameter_types! {918 #[derive(PartialEq, TypeInfo)]919 pub const RmrkStringLimit: u32 = 128;920 #[derive(PartialEq)]921 pub const RmrkCollectionSymbolLimit: u32 = 100;922 #[derive(PartialEq)]923 pub const RmrkResourceSymbolLimit: u32 = 10;924 #[derive(PartialEq)]925 pub const RmrkKeyLimit: u32 = 32;926 #[derive(PartialEq)]927 pub const RmrkValueLimit: u32 = 256;928 #[derive(PartialEq)]929 pub const RmrkMaxCollectionsEquippablePerPart: u32 = 100;930 #[derive(PartialEq)]931 pub const RmrkPartsLimit: u32 = 3;932}933934impl From<RmrkCollectionId> for CollectionId {935 fn from(id: RmrkCollectionId) -> Self {936 Self(id)937 }938}939940impl From<RmrkNftId> for TokenId {941 fn from(id: RmrkNftId) -> Self {942 Self(id)943 }944}945946pub type RmrkCollectionInfo<AccountId> =947 CollectionInfo<RmrkString, RmrkCollectionSymbol, AccountId>;948pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;949pub type RmrkResourceInfo = ResourceInfo<RmrkString, RmrkBoundedParts>;950pub type RmrkPropertyInfo = PropertyInfo<RmrkKeyString, RmrkValueString>;951pub type RmrkBaseInfo<AccountId> = BaseInfo<AccountId, RmrkString>;952pub type RmrkPartType =953 PartType<RmrkString, BoundedVec<RmrkCollectionId, RmrkMaxCollectionsEquippablePerPart>>;954pub type RmrkThemeProperty = ThemeProperty<RmrkString>;955pub type RmrkTheme = Theme<RmrkString, Vec<RmrkThemeProperty>>;956pub type RmrkResourceTypes = ResourceTypes<RmrkString, RmrkBoundedParts>;957958pub type RmrkBasicResource = BasicResource<RmrkString>;959pub type RmrkComposableResource = ComposableResource<RmrkString, RmrkBoundedParts>;960pub type RmrkSlotResource = SlotResource<RmrkString>;961962pub type RmrkString = BoundedVec<u8, RmrkStringLimit>;963pub type RmrkCollectionSymbol = BoundedVec<u8, RmrkCollectionSymbolLimit>;964pub type RmrkKeyString = BoundedVec<u8, RmrkKeyLimit>;965pub type RmrkValueString = BoundedVec<u8, RmrkValueLimit>;966pub type RmrkBoundedResource = BoundedVec<u8, RmrkResourceSymbolLimit>;967pub type RmrkBoundedParts = BoundedVec<RmrkPartId, RmrkPartsLimit>; // todo make sure it is needed968969pub type RmrkRpcString = Vec<u8>;970pub type RmrkThemeName = RmrkRpcString;971pub type RmrkPropertyKey = RmrkRpcString;primitives/data-structs/src/rmrk.rsdiffbeforeafterboth--- a/primitives/data-structs/src/rmrk.rs
+++ /dev/null
@@ -1,435 +0,0 @@
-use codec::{Decode, Encode, MaxEncodedLen};
-use scale_info::TypeInfo;
-
-#[cfg(feature = "std")]
-use serde::Serialize;
-
-use primitives::*;
-
-pub mod primitives {
- pub type CollectionId = u32;
- pub type ResourceId = u32;
- pub type NftId = u32;
- pub type BaseId = u32;
- pub type SlotId = u32;
- pub type PartId = u32;
- pub type ZIndex = u32;
-}
-
-#[cfg(feature = "std")]
-mod serialize {
- use core::convert::AsRef;
- use serde::ser::{self, Serialize};
-
- pub mod vec {
- use super::*;
-
- pub fn serialize<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>
- where
- D: ser::Serializer,
- V: Serialize,
- C: AsRef<[V]>,
- {
- value.as_ref().serialize(serializer)
- }
- }
-
- pub mod opt_vec {
- use super::*;
-
- pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>
- where
- D: ser::Serializer,
- V: Serialize,
- C: AsRef<[V]>,
- {
- match value {
- Some(value) => super::vec::serialize(value, serializer),
- None => serializer.serialize_none(),
- }
- }
- }
-}
-
-/// Collection info.
-#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- AccountId: Serialize,
- BoundedString: AsRef<[u8]>,
- BoundedSymbol: AsRef<[u8]>
- "#)
-)]
-pub struct CollectionInfo<BoundedString, BoundedSymbol, AccountId> {
- /// Current bidder and bid price.
- pub issuer: AccountId,
-
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub metadata: BoundedString,
- pub max: Option<u32>,
-
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub symbol: BoundedSymbol,
- pub nfts_count: u32,
-}
-
-#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(feature = "std", derive(Serialize))]
-pub enum AccountIdOrCollectionNftTuple<AccountId> {
- AccountId(AccountId),
- CollectionAndNftTuple(CollectionId, NftId),
-}
-
-/// Royalty information (recipient and amount)
-#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
-pub struct RoyaltyInfo<AccountId, RoyaltyAmount> {
- /// Recipient (AccountId) of the royalty
- pub recipient: AccountId,
- /// Amount (Permill) of the royalty
- pub amount: RoyaltyAmount,
-}
-
-/// Nft info.
-#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- AccountId: Serialize,
- RoyaltyAmount: Serialize,
- BoundedString: AsRef<[u8]>
- "#)
-)]
-pub struct NftInfo<AccountId, RoyaltyAmount, BoundedString> {
- /// The owner of the NFT, can be either an Account or a tuple (CollectionId, NftId)
- pub owner: AccountIdOrCollectionNftTuple<AccountId>,
- /// Royalty (optional)
- pub royalty: Option<RoyaltyInfo<AccountId, RoyaltyAmount>>,
-
- /// Arbitrary data about an instance, e.g. IPFS hash
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub metadata: BoundedString,
-
- /// Equipped state
- pub equipped: bool,
- /// Pending state (if sent to NFT)
- pub pending: bool,
-}
-
-#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
-#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]
-pub struct NftChild {
- pub collection_id: CollectionId,
- pub nft_id: NftId,
-}
-
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[derive(Encode, Decode, PartialEq, TypeInfo)]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- BoundedKey: AsRef<[u8]>,
- BoundedValue: AsRef<[u8]>
- "#)
-)]
-pub struct PropertyInfo<BoundedKey, BoundedValue> {
- /// Key of the property
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub key: BoundedKey,
-
- /// Value of the property
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub value: BoundedValue,
-}
-
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
-pub struct BasicResource<BoundedString> {
- /// If the resource is Media, the base property is absent. Media src should be a URI like an
- /// IPFS hash.
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub src: Option<BoundedString>,
-
- /// Reference to IPFS location of metadata
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub metadata: Option<BoundedString>,
-
- /// Optional location or identier of license
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub license: Option<BoundedString>,
-
- /// If the resource has the thumb property, this will be a URI to a thumbnail of the given
- /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is
- /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns
- /// another bird, showing the full render of one bird inside the other's inventory might be a
- /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an
- /// image that is lighter and faster to load but representative of this resource.
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub thumb: Option<BoundedString>,
-}
-
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- BoundedString: AsRef<[u8]>,
- BoundedParts: AsRef<[PartId]>
- "#)
-)]
-pub struct ComposableResource<BoundedString, BoundedParts> {
- /// If a resource is composed, it will have an array of parts that compose it
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub parts: BoundedParts,
-
- /// A Base is uniquely identified by the combination of the word `base`, its minting block
- /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.
- /// base-4477293-kanaria_superbird.
- pub base: BaseId,
-
- /// If the resource is Media, the base property is absent. Media src should be a URI like an
- /// IPFS hash.
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub src: Option<BoundedString>,
-
- /// Reference to IPFS location of metadata
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub metadata: Option<BoundedString>,
-
- /// If the resource has the slot property, it was designed to fit into a specific Base's slot.
- /// The baseslot will be composed of two dot-delimited values, like so:
- /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is
- /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird
-
- /// Optional location or identier of license
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub license: Option<BoundedString>,
-
- /// If the resource has the thumb property, this will be a URI to a thumbnail of the given
- /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is
- /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns
- /// another bird, showing the full render of one bird inside the other's inventory might be a
- /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an
- /// image that is lighter and faster to load but representative of this resource.
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub thumb: Option<BoundedString>,
-}
-
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
-pub struct SlotResource<BoundedString> {
- /// A Base is uniquely identified by the combination of the word `base`, its minting block
- /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.
- /// base-4477293-kanaria_superbird.
- pub base: BaseId,
-
- /// If the resource is Media, the base property is absent. Media src should be a URI like an
- /// IPFS hash.
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub src: Option<BoundedString>,
-
- /// Reference to IPFS location of metadata
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub metadata: Option<BoundedString>,
-
- /// If the resource has the slot property, it was designed to fit into a specific Base's slot.
- /// The baseslot will be composed of two dot-delimited values, like so:
- /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is
- /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird
- pub slot: SlotId,
-
- /// The license field, if present, should contain a link to a license (IPFS or static HTTP
- /// url), or an identifier, like RMRK_nocopy or ipfs://ipfs/someHashOfLicense.
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub license: Option<BoundedString>,
-
- /// If the resource has the thumb property, this will be a URI to a thumbnail of the given
- /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is
- /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns
- /// another bird, showing the full render of one bird inside the other's inventory might be a
- /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an
- /// image that is lighter and faster to load but representative of this resource.
- #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
- pub thumb: Option<BoundedString>,
-}
-
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- BoundedString: AsRef<[u8]>,
- BoundedParts: AsRef<[PartId]>
- "#)
-)]
-pub enum ResourceTypes<BoundedString, BoundedParts> {
- Basic(BasicResource<BoundedString>),
- Composable(ComposableResource<BoundedString, BoundedParts>),
- Slot(SlotResource<BoundedString>),
-}
-
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- BoundedString: AsRef<[u8]>,
- BoundedParts: AsRef<[PartId]>
- "#)
-)]
-pub struct ResourceInfo<BoundedString, BoundedParts> {
- /// id is a 5-character string of reasonable uniqueness.
- /// The combination of base ID and resource id should be unique across the entire RMRK
- /// ecosystem which
- //#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub id: ResourceId,
-
- /// Resource
- pub resource: ResourceTypes<BoundedString, BoundedParts>,
-
- /// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted
- pub pending: bool,
-
- /// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted
- pub pending_removal: bool,
-}
-
-#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- AccountId: Serialize,
- BoundedString: AsRef<[u8]>
- "#)
-)]
-pub struct BaseInfo<AccountId, BoundedString> {
- /// Original creator of the Base
- pub issuer: AccountId,
-
- /// Specifies how an NFT should be rendered, ie "svg"
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub base_type: BoundedString,
-
- /// User provided symbol during Base creation
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub symbol: BoundedString,
-}
-
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
-#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
-pub struct FixedPart<BoundedString> {
- pub id: PartId,
- pub z: ZIndex,
-
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub src: BoundedString,
-}
-
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
-#[cfg_attr(
- feature = "std",
- serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")
-)]
-pub enum EquippableList<BoundedCollectionList> {
- All,
- Empty,
- Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),
-}
-
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- BoundedString: AsRef<[u8]>,
- BoundedCollectionList: AsRef<[CollectionId]>
- "#)
-)]
-pub struct SlotPart<BoundedString, BoundedCollectionList> {
- pub id: PartId,
- pub equippable: EquippableList<BoundedCollectionList>,
-
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub src: BoundedString,
-
- pub z: ZIndex,
-}
-
-#[cfg_attr(feature = "std", derive(Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- BoundedString: AsRef<[u8]>,
- BoundedCollectionList: AsRef<[CollectionId]>
- "#)
-)]
-pub enum PartType<BoundedString, BoundedCollectionList> {
- FixedPart(FixedPart<BoundedString>),
- SlotPart(SlotPart<BoundedString, BoundedCollectionList>),
-}
-
-impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {
- pub fn id(&self) -> PartId {
- match self {
- Self::FixedPart(part) => part.id,
- Self::SlotPart(part) => part.id,
- }
- }
-
- pub fn src(&self) -> &BoundedString {
- match self {
- Self::FixedPart(part) => &part.src,
- Self::SlotPart(part) => &part.src,
- }
- }
-
- pub fn z_index(&self) -> ZIndex {
- match self {
- Self::FixedPart(part) => part.z,
- Self::SlotPart(part) => part.z,
- }
- }
-}
-
-#[cfg_attr(feature = "std", derive(Eq, Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]
-#[cfg_attr(
- feature = "std",
- serde(bound = r#"
- BoundedString: AsRef<[u8]>,
- PropertyList: AsRef<[ThemeProperty<BoundedString>]>,
- "#)
-)]
-pub struct Theme<BoundedString, PropertyList> {
- /// Name of the theme
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub name: BoundedString,
-
- /// Theme properties
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub properties: PropertyList,
- /// Inheritability
- pub inherit: bool,
-}
-
-#[cfg_attr(feature = "std", derive(Eq, Serialize))]
-#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]
-#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
-pub struct ThemeProperty<BoundedString> {
- /// Key of the property
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub key: BoundedString,
-
- /// Value of the property
- #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
- pub value: BoundedString,
-}
primitives/rmrk-rpc/Cargo.tomldiffbeforeafterboth--- a/primitives/rmrk-rpc/Cargo.toml
+++ b/primitives/rmrk-rpc/Cargo.toml
@@ -11,7 +11,7 @@
sp-api = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.22' }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.22' }
serde = { version = "1.0.130", default-features = false, features = ["derive"] }
-up-data-structs = { default-features = false, path = '../data-structs' }
+rmrk-traits = { default-features = false, path = "../rmrk-traits" }
[features]
default = ["std"]
@@ -22,5 +22,5 @@
"sp-api/std",
"sp-runtime/std",
"serde/std",
- "up-data-structs/std",
+ "rmrk-traits/std",
]
primitives/rmrk-rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rmrk-rpc/src/lib.rs
+++ b/primitives/rmrk-rpc/src/lib.rs
@@ -3,7 +3,7 @@
use sp_api::{Encode, Decode};
use sp_std::vec::Vec;
use sp_runtime::DispatchError;
-use up_data_structs::rmrk::{primitives::*, NftChild};
+use rmrk_traits::{primitives::*, NftChild};
pub type Result<T> = core::result::Result<T, DispatchError>;
primitives/rmrk-traits/Cargo.tomldiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/Cargo.toml
@@ -0,0 +1,23 @@
+[package]
+name = "rmrk-traits"
+authors = ["Unique Network <support@uniquenetwork.io>"]
+description = "RMRK proxy data structs definitions"
+edition = "2021"
+license = 'GPLv3'
+homepage = "https://unique.network"
+repository = 'https://github.com/UniqueNetwork/unique-chain'
+version = '0.1.0'
+
+[dependencies]
+scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
+codec = { package = "parity-scale-codec", version = "3.1.2", default-features = false, features = ["derive"] }
+serde = { version = "1.0.130", features = ["derive"], default-features = false, optional = true }
+
+[features]
+default = ["std"]
+std = [
+ "serde1",
+ "serde/std",
+ "codec/std",
+]
+serde1 = ["serde/alloc"]
primitives/rmrk-traits/src/base.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/base.rs
@@ -0,0 +1,30 @@
+use codec::{Decode, Encode, MaxEncodedLen};
+use scale_info::TypeInfo;
+
+#[cfg(feature = "std")]
+use serde::Serialize;
+
+#[cfg(feature = "std")]
+use crate::serialize;
+
+#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ AccountId: Serialize,
+ BoundedString: AsRef<[u8]>
+ "#)
+)]
+pub struct BaseInfo<AccountId, BoundedString> {
+ /// Original creator of the Base
+ pub issuer: AccountId,
+
+ /// Specifies how an NFT should be rendered, ie "svg"
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub base_type: BoundedString,
+
+ /// User provided symbol during Base creation
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub symbol: BoundedString,
+}
primitives/rmrk-traits/src/collection.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/collection.rs
@@ -0,0 +1,31 @@
+use codec::{Decode, Encode, MaxEncodedLen};
+use scale_info::TypeInfo;
+
+#[cfg(feature = "std")]
+use serde::Serialize;
+
+#[cfg(feature = "std")]
+use crate::serialize;
+
+#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ AccountId: Serialize,
+ BoundedString: AsRef<[u8]>,
+ BoundedSymbol: AsRef<[u8]>
+ "#)
+)]
+pub struct CollectionInfo<BoundedString, BoundedSymbol, AccountId> {
+ /// Current bidder and bid price.
+ pub issuer: AccountId,
+
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub metadata: BoundedString,
+ pub max: Option<u32>,
+
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub symbol: BoundedSymbol,
+ pub nfts_count: u32,
+}
primitives/rmrk-traits/src/lib.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/lib.rs
@@ -0,0 +1,31 @@
+#![cfg_attr(not(feature = "std"), no_std)]
+
+pub mod base;
+pub mod collection;
+pub mod nft;
+pub mod part;
+pub mod property;
+pub mod resource;
+pub mod theme;
+
+#[cfg(feature = "std")]
+mod serialize;
+
+pub use base::BaseInfo;
+pub use part::{EquippableList, FixedPart, PartType, SlotPart};
+pub use theme::{Theme, ThemeProperty};
+pub use collection::CollectionInfo;
+pub use nft::{AccountIdOrCollectionNftTuple, NftInfo, RoyaltyInfo, NftChild};
+pub use property::PropertyInfo;
+pub use resource::{
+ BasicResource, ComposableResource, ResourceInfo, ResourceTypes, SlotResource,
+};
+pub mod primitives {
+ pub type CollectionId = u32;
+ pub type ResourceId = u32;
+ pub type NftId = u32;
+ pub type BaseId = u32;
+ pub type SlotId = u32;
+ pub type PartId = u32;
+ pub type ZIndex = u32;
+}
primitives/rmrk-traits/src/nft.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/nft.rs
@@ -0,0 +1,61 @@
+use codec::{Decode, Encode, MaxEncodedLen};
+use scale_info::TypeInfo;
+
+#[cfg(feature = "std")]
+use serde::Serialize;
+
+#[cfg(feature = "std")]
+use crate::serialize;
+
+use crate::primitives::*;
+
+#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(feature = "std", derive(Serialize))]
+pub enum AccountIdOrCollectionNftTuple<AccountId> {
+ AccountId(AccountId),
+ CollectionAndNftTuple(CollectionId, NftId),
+}
+
+/// Royalty information (recipient and amount)
+#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
+pub struct RoyaltyInfo<AccountId, RoyaltyAmount> {
+ /// Recipient (AccountId) of the royalty
+ pub recipient: AccountId,
+ /// Amount (Permill) of the royalty
+ pub amount: RoyaltyAmount,
+}
+
+/// Nft info.
+#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ AccountId: Serialize,
+ RoyaltyAmount: Serialize,
+ BoundedString: AsRef<[u8]>
+ "#)
+)]
+pub struct NftInfo<AccountId, RoyaltyAmount, BoundedString> {
+ /// The owner of the NFT, can be either an Account or a tuple (CollectionId, NftId)
+ pub owner: AccountIdOrCollectionNftTuple<AccountId>,
+ /// Royalty (optional)
+ pub royalty: Option<RoyaltyInfo<AccountId, RoyaltyAmount>>,
+
+ /// Arbitrary data about an instance, e.g. IPFS hash
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub metadata: BoundedString,
+
+ /// Equipped state
+ pub equipped: bool,
+ /// Pending state (if sent to NFT)
+ pub pending: bool,
+}
+
+#[cfg_attr(feature = "std", derive(PartialEq, Eq, Serialize))]
+#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]
+pub struct NftChild {
+ pub collection_id: CollectionId,
+ pub nft_id: NftId,
+}
primitives/rmrk-traits/src/part.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/part.rs
@@ -0,0 +1,89 @@
+use codec::{Decode, Encode, MaxEncodedLen};
+use scale_info::TypeInfo;
+
+#[cfg(feature = "std")]
+use serde::Serialize;
+
+#[cfg(feature = "std")]
+use crate::serialize;
+
+use crate::primitives::*;
+
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
+pub struct FixedPart<BoundedString> {
+ pub id: PartId,
+ pub z: ZIndex,
+
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub src: BoundedString,
+}
+
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")
+)]
+pub enum EquippableList<BoundedCollectionList> {
+ All,
+ Empty,
+ Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),
+}
+
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ BoundedString: AsRef<[u8]>,
+ BoundedCollectionList: AsRef<[CollectionId]>
+ "#)
+)]
+pub struct SlotPart<BoundedString, BoundedCollectionList> {
+ pub id: PartId,
+ pub equippable: EquippableList<BoundedCollectionList>,
+
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub src: BoundedString,
+
+ pub z: ZIndex,
+}
+
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ BoundedString: AsRef<[u8]>,
+ BoundedCollectionList: AsRef<[CollectionId]>
+ "#)
+)]
+pub enum PartType<BoundedString, BoundedCollectionList> {
+ FixedPart(FixedPart<BoundedString>),
+ SlotPart(SlotPart<BoundedString, BoundedCollectionList>),
+}
+
+impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {
+ pub fn id(&self) -> PartId {
+ match self {
+ Self::FixedPart(part) => part.id,
+ Self::SlotPart(part) => part.id,
+ }
+ }
+
+ pub fn src(&self) -> &BoundedString {
+ match self {
+ Self::FixedPart(part) => &part.src,
+ Self::SlotPart(part) => &part.src,
+ }
+ }
+
+ pub fn z_index(&self) -> ZIndex {
+ match self {
+ Self::FixedPart(part) => part.z,
+ Self::SlotPart(part) => part.z,
+ }
+ }
+}
primitives/rmrk-traits/src/property.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/property.rs
@@ -0,0 +1,27 @@
+use codec::{Decode, Encode};
+use scale_info::TypeInfo;
+
+#[cfg(feature = "std")]
+use serde::Serialize;
+
+#[cfg(feature = "std")]
+use crate::serialize;
+
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[derive(Encode, Decode, PartialEq, TypeInfo)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ BoundedKey: AsRef<[u8]>,
+ BoundedValue: AsRef<[u8]>
+ "#)
+)]
+pub struct PropertyInfo<BoundedKey, BoundedValue> {
+ /// Key of the property
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub key: BoundedKey,
+
+ /// Value of the property
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub value: BoundedValue,
+}
primitives/rmrk-traits/src/resource.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/resource.rs
@@ -0,0 +1,164 @@
+use codec::{Decode, Encode, MaxEncodedLen};
+use scale_info::TypeInfo;
+
+#[cfg(feature = "std")]
+use serde::Serialize;
+
+#[cfg(feature = "std")]
+use crate::serialize;
+
+use crate::primitives::*;
+
+#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
+pub struct BasicResource<BoundedString> {
+ /// If the resource is Media, the base property is absent. Media src should be a URI like an
+ /// IPFS hash.
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub src: Option<BoundedString>,
+
+ /// Reference to IPFS location of metadata
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub metadata: Option<BoundedString>,
+
+ /// Optional location or identier of license
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub license: Option<BoundedString>,
+
+ /// If the resource has the thumb property, this will be a URI to a thumbnail of the given
+ /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is
+ /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns
+ /// another bird, showing the full render of one bird inside the other's inventory might be a
+ /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an
+ /// image that is lighter and faster to load but representative of this resource.
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub thumb: Option<BoundedString>,
+}
+
+#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ BoundedString: AsRef<[u8]>,
+ BoundedParts: AsRef<[PartId]>
+ "#)
+)]
+pub struct ComposableResource<BoundedString, BoundedParts> {
+ /// If a resource is composed, it will have an array of parts that compose it
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub parts: BoundedParts,
+
+ /// A Base is uniquely identified by the combination of the word `base`, its minting block
+ /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.
+ /// base-4477293-kanaria_superbird.
+ pub base: BaseId,
+
+ /// If the resource is Media, the base property is absent. Media src should be a URI like an
+ /// IPFS hash.
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub src: Option<BoundedString>,
+
+ /// Reference to IPFS location of metadata
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub metadata: Option<BoundedString>,
+
+ /// If the resource has the slot property, it was designed to fit into a specific Base's slot.
+ /// The baseslot will be composed of two dot-delimited values, like so:
+ /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is
+ /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird
+
+ /// Optional location or identier of license
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub license: Option<BoundedString>,
+
+ /// If the resource has the thumb property, this will be a URI to a thumbnail of the given
+ /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is
+ /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns
+ /// another bird, showing the full render of one bird inside the other's inventory might be a
+ /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an
+ /// image that is lighter and faster to load but representative of this resource.
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub thumb: Option<BoundedString>,
+}
+
+#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
+pub struct SlotResource<BoundedString> {
+ /// A Base is uniquely identified by the combination of the word `base`, its minting block
+ /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.
+ /// base-4477293-kanaria_superbird.
+ pub base: BaseId,
+
+ /// If the resource is Media, the base property is absent. Media src should be a URI like an
+ /// IPFS hash.
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub src: Option<BoundedString>,
+
+ /// Reference to IPFS location of metadata
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub metadata: Option<BoundedString>,
+
+ /// If the resource has the slot property, it was designed to fit into a specific Base's slot.
+ /// The baseslot will be composed of two dot-delimited values, like so:
+ /// "base-4477293-kanaria_superbird.machine_gun_scope". This means: "This resource is
+ /// compatible with the machine_gun_scope slot of base base-4477293-kanaria_superbird
+ pub slot: SlotId,
+
+ /// The license field, if present, should contain a link to a license (IPFS or static HTTP
+ /// url), or an identifier, like RMRK_nocopy or ipfs://ipfs/someHashOfLicense.
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub license: Option<BoundedString>,
+
+ /// If the resource has the thumb property, this will be a URI to a thumbnail of the given
+ /// resource. For example, if we have a composable NFT like a Kanaria bird, the resource is
+ /// complex and too detailed to show in a search-results page or a list. Also, if a bird owns
+ /// another bird, showing the full render of one bird inside the other's inventory might be a
+ /// bit of a strain on the browser. For this reason, the thumb value can contain a URI to an
+ /// image that is lighter and faster to load but representative of this resource.
+ #[cfg_attr(feature = "std", serde(with = "serialize::opt_vec"))]
+ pub thumb: Option<BoundedString>,
+}
+
+#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ BoundedString: AsRef<[u8]>,
+ BoundedParts: AsRef<[PartId]>
+ "#)
+)]
+pub enum ResourceTypes<BoundedString, BoundedParts> {
+ Basic(BasicResource<BoundedString>),
+ Composable(ComposableResource<BoundedString, BoundedParts>),
+ Slot(SlotResource<BoundedString>),
+}
+
+#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ BoundedString: AsRef<[u8]>,
+ BoundedParts: AsRef<[PartId]>
+ "#)
+)]
+pub struct ResourceInfo<BoundedString, BoundedParts> {
+ /// id is a 5-character string of reasonable uniqueness.
+ /// The combination of base ID and resource id should be unique across the entire RMRK
+ /// ecosystem which
+ //#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub id: ResourceId,
+
+ /// Resource
+ pub resource: ResourceTypes<BoundedString, BoundedParts>,
+
+ /// If resource is sent to non-rootowned NFT, pending will be false and need to be accepted
+ pub pending: bool,
+
+ /// If resource removal request is sent by non-rootowned NFT, pending will be true and need to be accepted
+ pub pending_removal: bool,
+}
primitives/rmrk-traits/src/serialize.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/serialize.rs
@@ -0,0 +1,31 @@
+use core::convert::AsRef;
+use serde::ser::{self, Serialize};
+
+pub mod vec {
+ use super::*;
+
+ pub fn serialize<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>
+ where
+ D: ser::Serializer,
+ V: Serialize,
+ C: AsRef<[V]>,
+ {
+ value.as_ref().serialize(serializer)
+ }
+}
+
+pub mod opt_vec {
+ use super::*;
+
+ pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>
+ where
+ D: ser::Serializer,
+ V: Serialize,
+ C: AsRef<[V]>,
+ {
+ match value {
+ Some(value) => super::vec::serialize(value, serializer),
+ None => serializer.serialize_none(),
+ }
+ }
+}
primitives/rmrk-traits/src/theme.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/rmrk-traits/src/theme.rs
@@ -0,0 +1,42 @@
+use codec::{Decode, Encode};
+use scale_info::TypeInfo;
+
+#[cfg(feature = "std")]
+use serde::Serialize;
+
+#[cfg(feature = "std")]
+use crate::serialize;
+
+#[cfg_attr(feature = "std", derive(Eq, Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]
+#[cfg_attr(
+ feature = "std",
+ serde(bound = r#"
+ BoundedString: AsRef<[u8]>,
+ PropertyList: AsRef<[ThemeProperty<BoundedString>]>,
+ "#)
+)]
+pub struct Theme<BoundedString, PropertyList> {
+ /// Name of the theme
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub name: BoundedString,
+
+ /// Theme properties
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub properties: PropertyList,
+ /// Inheritability
+ pub inherit: bool,
+}
+
+#[cfg_attr(feature = "std", derive(Eq, Serialize))]
+#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
+pub struct ThemeProperty<BoundedString> {
+ /// Key of the property
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub key: BoundedString,
+
+ /// Value of the property
+ #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
+ pub value: BoundedString,
+}