difftreelog
style cargo fmt
in: master
5 files changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -15,83 +15,83 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
//! # RMRK Core Proxy Pallet
-//!
+//!
//! A pallet used as proxy for RMRK Core (<https://rmrk-team.github.io/rmrk-substrate/#/pallets/rmrk-core>).
-//!
+//!
//! - [`Config`]
//! - [`Call`]
//! - [`Pallet`]
-//!
+//!
//! ## Overview
-//!
-//! The RMRK Core Proxy pallet mirrors the functionality of RMRK Core,
+//!
+//! The RMRK Core Proxy pallet mirrors the functionality of RMRK Core,
//! binding its externalities to Unique's own underlying structure.
//! It is purposed to mimic RMRK Core exactly, allowing seamless integrations
//! of solutions based on RMRK.
-//!
+//!
//! RMRK Core itself contains essential functionality for RMRK's nested and
//! multi-resourced NFTs.
-//!
+//!
//! *Note*, that while RMRK itself is subject to active development and restructuring,
//! the proxy may be caught temporarily out of date.
-//!
+//!
//! ### What is RMRK?
-//!
-//! RMRK is a set of NFT standards which compose several "NFT 2.0 lego" primitives.
+//!
+//! RMRK is a set of NFT standards which compose several "NFT 2.0 lego" primitives.
//! Putting these legos together allows a user to create NFT systems of arbitrary complexity.
-//!
+//!
//! Meaning, RMRK NFTs are dynamic, able to nest into each other and form a hierarchy,
-//! make use of specific changeable and partially shared metadata in the form of resources,
+//! make use of specific changeable and partially shared metadata in the form of resources,
//! and more.
-//!
+//!
//! Visit RMRK documentation and repositories to learn more:
//! - Docs: <https://docs.rmrk.app/getting-started/>
//! - FAQ: <https://coda.io/@rmrk/faq>
//! - Substrate code repository: <https://github.com/rmrk-team/rmrk-substrate>
//! - RMRK spec repository: <https://github.com/rmrk-team/rmrk-spec>
-//!
+//!
//! ## Proxy Implementation
-//!
+//!
//! An external user is supposed to be able to utilize this proxy as they would
//! utilize RMRK, and get exactly the same results. Normally, Unique transactions
//! are off-limits to RMRK collections and tokens, and vice versa. However,
//! the information stored on chain can be freely interpreted by storage reads and RPCs.
-//!
+//!
//! ### ID Mapping
-//!
+//!
//! RMRK's collections' IDs are counted independently of Unique's and start at 0.
//! Note that tokens' IDs still start at 1.
//! The collections themselves, as well as tokens, are stored as Unique collections,
//! and thus RMRK IDs are mapped to Unique IDs (but not vice versa).
-//!
+//!
//! ### External/Internal Collection Insulation
-//!
+//!
//! A Unique transaction cannot target collections purposed for RMRK,
-//! and they are flagged as `external` to specify that. On the other hand,
+//! and they are flagged as `external` to specify that. On the other hand,
//! due to the mapping, RMRK transactions and RPCs simply cannot reach Unique collections.
-//!
+//!
//! ### Native Properties
-//!
-//! Many of RMRK's native parameters are stored as scoped properties of a collection
+//!
+//! Many of RMRK's native parameters are stored as scoped properties of a collection
//! or an NFT on the chain. Scoped properties are prefixed with `rmrk:`, where `:`
//! is an unacceptable symbol in user-defined proeprties, which, along with other safeguards,
//! makes them impossible to tamper with.
-//!
+//!
//! ### Collection and NFT Types
-//!
-//! RMRK introduces the concept of a Base, which is a catalgoue of Parts,
+//!
+//! RMRK introduces the concept of a Base, which is a catalgoue of Parts,
//! possible components of an NFT. Due to its similarity with the functionality
//! of a token collection, a Base is stored and handled as one, and the Base's Parts and Themes
-//! are the collection's NFTs. See [`CollectionType`](pallet_rmrk_core::misc::CollectionType) and
+//! are the collection's NFTs. See [`CollectionType`](pallet_rmrk_core::misc::CollectionType) and
//! [`NftType`](pallet_rmrk_core::misc::NftType).
-//!
+//!
//! ## Interface
-//!
+//!
//! ### Dispatchables
-//!
+//!
//! - `create_collection` - Create a new collection of NFTs.
//! - `destroy_collection` - Destroy a collection.
-//! - `change_collection_issuer` - Change the issuer of a collection.
+//! - `change_collection_issuer` - Change the issuer of a collection.
//! Analogous to Unique's collection's [`owner`](up_data_structs::Collection).
//! - `lock_collection` - "Lock" the collection and prevent new token creation. **Cannot be undone.**
//! - `mint_nft` - Mint an NFT in a specified collection.
@@ -163,7 +163,7 @@
{
/// Overarching event type.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
-
+
/// The weight information of this pallet.
type WeightInfo: WeightInfo;
}
@@ -269,7 +269,7 @@
RmrkPropertyValueIsTooLong,
/// Could not find a property by the supplied key.
RmrkPropertyIsNotFound,
- /// Something went wrong when decoding encoded data from the storage.
+ /// Something went wrong when decoding encoded data from the storage.
/// Perhaps, there was a wrong key supplied for the type, or the data was improperly stored.
UnableToDecodeRmrkData,
@@ -290,7 +290,7 @@
CollectionFullOrLocked,
/// No such resource found.
ResourceDoesntExist,
- /// If an NFT is sent to a descendant, that would form a nesting loop, an ouroboros.
+ /// If an NFT is sent to a descendant, that would form a nesting loop, an ouroboros.
/// Sending to self is redundant.
CannotSendToDescendentOrSelf,
/// Not the target owner of the sent NFT.
@@ -317,7 +317,7 @@
/// # Arguments:
/// - `metadata`: Metadata describing the collection, e.g. IPFS hash. Cannot be changed.
/// - `max`: Optional maximum number of tokens.
- /// - `symbol`: UTF-8 string with token prefix, by which to represent the token in wallets and UIs.
+ /// - `symbol`: UTF-8 string with token prefix, by which to represent the token in wallets and UIs.
/// Analogous to Unique's [`token_prefix`](up_data_structs::Collection). Cannot be changed.
#[transactional]
#[pallet::weight(<SelfWeightOf<T>>::create_collection())]
@@ -383,8 +383,8 @@
Ok(())
}
- /// Destroy a collection.
- ///
+ /// Destroy a collection.
+ ///
/// Only empty collections can be destroyed. If it has any tokens, they must be burned first.
///
/// # Permissions:
@@ -419,7 +419,7 @@
}
/// Change the issuer of a collection. Analogous to Unique's collection's [`owner`](up_data_structs::Collection).
- ///
+ ///
/// # Permissions:
/// * Collection issuer
///
@@ -457,7 +457,7 @@
}
/// "Lock" the collection and prevent new token creation. Cannot be undone.
- ///
+ ///
/// # Permissions:
/// * Collection issuer
///
@@ -498,7 +498,7 @@
///
/// # Permissions:
/// * Collection issuer
- ///
+ ///
/// # Arguments:
/// - `owner`: Owner account of the NFT. If set to None, defaults to the sender (collection issuer).
/// - `collection_id`: RMRK collection ID for the NFT to be minted within. Cannot be changed.
@@ -574,20 +574,20 @@
Ok(())
}
- /// Burn an NFT, destroying it and its nested tokens up to the specified limit.
+ /// Burn an NFT, destroying it and its nested tokens up to the specified limit.
/// If the burning budget is exceeded, the transaction is reverted.
- ///
+ ///
/// This is the way to burn a nested token as well.
- ///
+ ///
/// For more information, see [`burn_recursively`](pallet_nonfungible::pallet::Pallet::burn_recursively).
- ///
+ ///
/// # Permissions:
/// * Token owner
- ///
+ ///
/// # Arguments:
/// - `collection_id`: RMRK ID of the collection in which the NFT to burn belongs to.
/// - `nft_id`: ID of the NFT to be destroyed.
- /// - `max_burns`: Maximum number of tokens to burn, used for nesting. The transaction
+ /// - `max_burns`: Maximum number of tokens to burn, used for nesting. The transaction
/// is reverted if there are more tokens to burn in the nesting tree than this number.
#[transactional]
#[pallet::weight(<SelfWeightOf<T>>::burn_nft(*max_burns))]
@@ -625,13 +625,13 @@
/// Transfer an NFT from an account/NFT A to another account/NFT B.
/// The token must be transferable. Nesting cannot occur deeper than the [`NESTING_BUDGET`].
- ///
+ ///
/// If the target owner is an NFT owned by another account, then the NFT will enter
/// the pending state and will have to be accepted by the other account.
///
/// # Permissions:
/// - Token owner
- ///
+ ///
/// # Arguments:
/// - `collection_id`: RMRK ID of the collection of the NFT to be transferred.
/// - `nft_id`: ID of the NFT to be transferred.
@@ -750,16 +750,16 @@
}
/// Accept an NFT sent from another account to self or an owned NFT.
- ///
+ ///
/// The NFT in question must be pending, and, thus, be [sent](`crate::pallet::Call::send`) first.
- ///
+ ///
/// # Permissions:
/// - Token-owner-to-be
///
/// # Arguments:
/// - `rmrk_collection_id`: RMRK collection ID of the NFT to be accepted.
/// - `rmrk_nft_id`: ID of the NFT to be accepted.
- /// - `new_owner`: Either the sender's account ID or a sender-owned NFT,
+ /// - `new_owner`: Either the sender's account ID or a sender-owned NFT,
/// whichever the accepted NFT was sent to.
#[transactional]
#[pallet::weight(<SelfWeightOf<T>>::accept_nft())]
@@ -842,12 +842,12 @@
/// Reject an NFT sent from another account to self or owned NFT.
/// The NFT in question will not be sent back and burnt instead.
- ///
+ ///
/// The NFT in question must be pending, and, thus, be [sent](`crate::pallet::Call::send`) first.
- ///
+ ///
/// # Permissions:
/// - Token-owner-to-be-not
- ///
+ ///
/// # Arguments:
/// - `rmrk_collection_id`: RMRK ID of the NFT to be rejected.
/// - `rmrk_nft_id`: ID of the NFT to be rejected.
@@ -905,11 +905,11 @@
}
/// Accept the addition of a newly created pending resource to an existing NFT.
- ///
+ ///
/// This transaction is needed when a resource is created and assigned to an NFT
- /// by a non-owner, i.e. the collection issuer, with one of the
+ /// by a non-owner, i.e. the collection issuer, with one of the
/// [`add_...` transactions](crate::pallet::Call::add_basic_resource).
- ///
+ ///
/// # Permissions:
/// - Token owner
///
@@ -960,10 +960,10 @@
}
/// Accept the removal of a removal-pending resource from an NFT.
- ///
- /// This transaction is needed when a non-owner, i.e. the collection issuer,
+ ///
+ /// This transaction is needed when a non-owner, i.e. the collection issuer,
/// requests a [removal](`crate::pallet::Call::remove_resource`) of a resource from an NFT.
- ///
+ ///
/// # Permissions:
/// - Token owner
///
@@ -1036,13 +1036,13 @@
Ok(())
}
- /// Add or edit a custom user property, a key-value pair, describing the metadata
+ /// Add or edit a custom user property, a key-value pair, describing the metadata
/// of a token or a collection, on either one of these.
- ///
- /// Note that in this proxy implementation many details regarding RMRK are stored
- /// as scoped properties prefixed with "rmrk:", normally inaccessible
+ ///
+ /// Note that in this proxy implementation many details regarding RMRK are stored
+ /// as scoped properties prefixed with "rmrk:", normally inaccessible
/// to external transactions and RPCs.
- ///
+ ///
/// # Permissions:
/// - Collection issuer - in case of collection property
/// - Token owner - in case of NFT property
@@ -1113,11 +1113,11 @@
/// Set a different order of resource priorities for an NFT. Priorities can be used,
/// for example, for order of rendering.
- ///
+ ///
/// Note that the priorities are not updated automatically, and are an empty vector
/// by default. There is no pre-set definition for the order to be particular,
/// it can be interpreted arbitrarily use-case by use-case.
- ///
+ ///
/// # Permissions:
/// - Token owner
///
@@ -1164,16 +1164,16 @@
}
/// Create and set/propose a basic resource for an NFT.
- ///
+ ///
/// A resource is considered a part of an NFT, an additional piece of metadata
/// usually serving to add a piece of media on top of the root metadata, be it
/// a different wing on the root template bird or something entirely unrelated.
/// A basic resource is the simplest, lacking a base or composables.
- ///
+ ///
/// See RMRK docs for more information and examples.
- ///
+ ///
/// # Permissions:
- /// - Collection issuer - if not the token owner, adding the resource will warrant
+ /// - Collection issuer - if not the token owner, adding the resource will warrant
/// the owner's [acceptance](crate::pallet::Call::accept_resource).
///
/// # Arguments:
@@ -1210,16 +1210,16 @@
}
/// Create and set/propose a composable resource for an NFT.
- ///
+ ///
/// A resource is considered a part of an NFT, an additional piece of metadata
/// usually serving to add a piece of media on top of the root metadata, be it
/// a different wing on the root template bird or something entirely unrelated.
/// A composable resource links to a base and has a subset of its parts it is composed of.
- ///
+ ///
/// See RMRK docs for more information and examples.
- ///
+ ///
/// # Permissions:
- /// - Collection issuer - if not the token owner, adding the resource will warrant
+ /// - Collection issuer - if not the token owner, adding the resource will warrant
/// the owner's [acceptance](crate::pallet::Call::accept_resource).
///
/// # Arguments:
@@ -1276,16 +1276,16 @@
}
/// Create and set/propose a slot resource for an NFT.
- ///
+ ///
/// A resource is considered a part of an NFT, an additional piece of metadata
/// usually serving to add a piece of media on top of the root metadata, be it
/// a different wing on the root template bird or something entirely unrelated.
/// A slot resource links to a base and a slot in it which it now occupies.
- ///
+ ///
/// See RMRK docs for more information and examples.
- ///
+ ///
/// # Permissions:
- /// - Collection issuer - if not the token owner, adding the resource will warrant
+ /// - Collection issuer - if not the token owner, adding the resource will warrant
/// the owner's [acceptance](crate::pallet::Call::accept_resource).
///
/// # Arguments:
@@ -1322,13 +1322,13 @@
}
/// Remove and erase a resource from an NFT.
- ///
+ ///
/// If the sender does not own the NFT, then it will be pending confirmation,
/// and will have to be [accepted](crate::pallet::Call::accept_resource_removal) by the token owner.
- ///
+ ///
/// # Permissions
/// - Collection issuer
- ///
+ ///
/// # Arguments
/// - `collection_id`: RMRK ID of a collection to which the NFT making use of the resource belongs to.
/// - `nft_id`: ID of the NFT with a resource to be removed.
@@ -1371,7 +1371,7 @@
Ok(scoped_key)
}
- /// Form a Unique property, transforming a RMRK key into bytes (without assigning the scope yet)
+ /// Form a Unique property, transforming a RMRK key into bytes (without assigning the scope yet)
/// and encoding the value from an arbitrary type into bytes.
pub fn encode_rmrk_property<E: Encode>(
rmrk_key: RmrkProperty,
@@ -1416,7 +1416,7 @@
}
/// Initialize a new NFT collection with certain RMRK-scoped properties.
- ///
+ ///
/// See [`init_collection`](pallet_nonfungible::pallet::Pallet::init_collection) for more details.
fn init_collection(
sender: T::CrossAccountId,
@@ -1439,7 +1439,7 @@
}
/// Mint a new NFT with certain RMRK-scoped properties. Sender must be the collection owner.
- ///
+ ///
/// See [`create_item`](pallet_nonfungible::pallet::Pallet::create_item) for more details.
pub fn create_nft(
sender: &T::CrossAccountId,
@@ -1458,18 +1458,13 @@
let nft_id = <PalletNft<T>>::current_token_id(collection.id);
- <PalletNft<T>>::set_scoped_token_properties(
- collection.id,
- nft_id,
- RMRK_SCOPE,
- properties,
- )?;
+ <PalletNft<T>>::set_scoped_token_properties(collection.id, nft_id, RMRK_SCOPE, properties)?;
Ok(nft_id)
}
/// Burn an NFT, along with its nested children, limited by `max_burns`. The sender must be the token owner.
- ///
+ ///
/// See [`burn_recursively`](pallet_nonfungible::pallet::Pallet::burn_recursively) for more details.
fn destroy_nft(
sender: T::CrossAccountId,
@@ -1531,7 +1526,7 @@
})
}
- /// Apply a mutation to the property of a token containing sent tokens
+ /// Apply a mutation to the property of a token containing sent tokens
/// that are currently pending acceptance.
fn mutate_pending_children(
(target_collection_id, target_nft_id): (CollectionId, TokenId),
@@ -1557,7 +1552,7 @@
)
}
- /// Get an iterator from a token's property containing tokens sent to it
+ /// Get an iterator from a token's property containing tokens sent to it
/// that are currently pending acceptance.
fn iterate_pending_children(
collection_id: CollectionId,
@@ -1601,7 +1596,7 @@
Ok(resource_id)
}
- /// Create and add a resource for a regular NFT, mark it as pending if the sender
+ /// Create and add a resource for a regular NFT, mark it as pending if the sender
/// is not the token owner. The sender must be the collection owner.
fn resource_add(
sender: T::AccountId,
@@ -1698,7 +1693,7 @@
Ok(())
}
- /// Remove one usage of a base from an NFT's property of associated bases. The base will stay, however,
+ /// Remove one usage of a base from an NFT's property of associated bases. The base will stay, however,
/// if the count of resources using the base is still non-zero.
fn remove_associated_base_id(
collection_id: CollectionId,
@@ -1843,7 +1838,7 @@
}
/// Get the type of a collection stored in it as a scoped property.
- ///
+ ///
/// RMRK Core proxy differentiates between regular collections as well as RMRK bases as collections.
pub fn get_collection_type(
collection_id: CollectionId,
@@ -1882,7 +1877,7 @@
Self::get_nft_collection(collection_id)
}
- /// Same as [`get_typed_nft_collection`](crate::pallet::Pallet::get_typed_nft_collection),
+ /// Same as [`get_typed_nft_collection`](crate::pallet::Pallet::get_typed_nft_collection),
/// but also return the Unique collection ID.
pub fn get_typed_nft_collection_mapped(
rmrk_collection_id: RmrkCollectionId,
@@ -1927,7 +1922,7 @@
}
/// Get the type of an NFT stored in it as a scoped property.
- ///
+ ///
/// RMRK Core proxy differentiates between regular NFTs, and RMRK parts and themes.
pub fn get_nft_type(
collection_id: CollectionId,
@@ -1949,7 +1944,7 @@
Ok(())
}
- /// Ensure that an account is the owner of the token, either directly
+ /// Ensure that an account is the owner of the token, either directly
/// or at the top of the nesting hierarchy; return an error if it is not.
pub fn ensure_nft_owner(
collection_id: CollectionId,
@@ -1971,7 +1966,7 @@
Ok(())
}
- /// Fetch non-scoped properties of a collection or a token that match the filter keys supplied,
+ /// Fetch non-scoped properties of a collection or a token that match the filter keys supplied,
/// or, if None are provided, return all non-scoped properties.
pub fn filter_user_properties<Key, Value, R, Mapper>(
collection_id: CollectionId,
@@ -2018,7 +2013,7 @@
})
}
- /// Get all non-scoped properties from a collection or a token, and apply some transformation
+ /// Get all non-scoped properties from a collection or a token, and apply some transformation
/// to each key-value pair.
pub fn iterate_user_properties<Key, Value, R, Mapper>(
collection_id: CollectionId,
pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -19,7 +19,7 @@
use super::*;
use codec::{Encode, Decode, Error};
-/// Match errors from one type to another and return an error
+/// Match errors from one type to another and return an error
/// if a match is successful.
#[macro_export]
macro_rules! map_unique_err_to_proxy {
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/property.rs
+++ b/pallets/proxy-rmrk-core/src/property.rs
@@ -24,7 +24,7 @@
pub const RESOURCE_ID_PREFIX: &str = "rsid-";
/// Property prefix for storing custom user-defined properties.
pub const USER_PROPERTY_PREFIX: &str = "userprop-";
-/// Property scope for RMRK, used to signify that this property
+/// Property scope for RMRK, used to signify that this property
/// was created and is used by RMRK.
pub const RMRK_SCOPE: PropertyScope = PropertyScope::Rmrk;
pallets/proxy-rmrk-core/src/rpc.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/rpc.rs
+++ b/pallets/proxy-rmrk-core/src/rpc.rs
@@ -104,7 +104,6 @@
}))
}
-
/// Get tokens owned by an account in a collection.
pub fn account_tokens<T: Config>(
account_id: T::AccountId,
pallets/proxy-rmrk-equip/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//! # RMRK Core Proxy Pallet18//! 19//! A pallet used as proxy for RMRK Core (<https://rmrk-team.github.io/rmrk-substrate/#/pallets/rmrk-core>).20//! 21//! - [`Config`]22//! - [`Call`]23//! - [`Pallet`]24//! 25//! ## Overview26//! 27//! The RMRK Equip Proxy pallet mirrors the functionality of RMRK Equip, 28//! binding its externalities to Unique's own underlying structure.29//! It is purposed to mimic RMRK Equip exactly, allowing seamless integrations30//! of solutions based on RMRK.31//! 32//! RMRK Equip itself contains functionality to equip NFTs, and work with Bases,33//! Parts, and Themes.34//! 35//! Equip Proxy is responsible for a more specific area of RMRK, and heavily relies on the Core. 36//! For a more foundational description of proxy implementation, please refer to [`pallet_rmrk_core`].37//! 38//! *Note*, that while RMRK itself is subject to active development and restructuring,39//! the proxy may be caught temporarily out of date.40//! 41//! ### What is RMRK?42//! 43//! RMRK is a set of NFT standards which compose several "NFT 2.0 lego" primitives. 44//! Putting these legos together allows a user to create NFT systems of arbitrary complexity.45//! 46//! Meaning, RMRK NFTs are dynamic, able to nest into each other and form a hierarchy,47//! make use of specific changeable and partially shared metadata in the form of resources, 48//! and more.49//! 50//! Visit RMRK documentation and repositories to learn more:51//! - Docs: <https://docs.rmrk.app/getting-started/>52//! - FAQ: <https://coda.io/@rmrk/faq>53//! - Substrate code repository: <https://github.com/rmrk-team/rmrk-substrate>54//! - RMRK spec repository: <https://github.com/rmrk-team/rmrk-spec>55//! 56//! ## Proxy Implementation57//! 58//! An external user is supposed to be able to utilize this proxy as they would59//! utilize RMRK, and get exactly the same results. Normally, Unique transactions60//! are off-limits to RMRK collections and tokens, and vice versa. However,61//! the information stored on chain can be freely interpreted by storage reads and RPCs.62//! 63//! ### ID Mapping64//! 65//! RMRK's collections' IDs are counted independently of Unique's and start at 0.66//! Note that tokens' IDs still start at 1.67//! The collections themselves, as well as tokens, are stored as Unique collections,68//! and thus RMRK IDs are mapped to Unique IDs (but not vice versa).69//! 70//! ### External/Internal Collection Insulation71//! 72//! A Unique transaction cannot target collections purposed for RMRK,73//! and they are flagged as `external` to specify that. On the other hand, 74//! due to the mapping, RMRK transactions and RPCs simply cannot reach Unique collections.75//! 76//! ### Native Properties77//! 78//! Many of RMRK's native parameters are stored as scoped properties of a collection 79//! or an NFT on the chain. Scoped properties are prefixed with `rmrk:`, where `:`80//! is an unacceptable symbol in user-defined proeprties, which, along with other safeguards,81//! makes them impossible to tamper with.82//! 83//! ### Collection and NFT Types84//! 85//! RMRK introduces the concept of a Base, which is a catalgoue of Parts, 86//! possible components of an NFT. Due to its similarity with the functionality87//! of a token collection, a Base is stored and handled as one, and the Base's Parts and Themes88//! are the collection's NFTs. See [`CollectionType`](pallet_rmrk_core::misc::CollectionType) and 89//! [`NftType`](pallet_rmrk_core::misc::NftType).90//! 91//! ## Interface92//! 93//! ### Dispatchables94//! 95//! - `create_base` - Create a new Base.96//! - `theme_add` - Add a Theme to a Base.97//! - `equippable` - Update the array of Collections allowed to be equipped to a Base's specified Slot Part.9899#![cfg_attr(not(feature = "std"), no_std)]100101use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};102use frame_system::{pallet_prelude::*, ensure_signed};103use sp_runtime::DispatchError;104use up_data_structs::*;105use pallet_common::{Pallet as PalletCommon, Error as CommonError};106use pallet_rmrk_core::{107 Pallet as PalletCore, Error as CoreError,108 misc::{self, *},109 property::RmrkProperty::*,110};111use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};112use pallet_evm::account::CrossAccountId;113use weights::WeightInfo;114115pub use pallet::*;116117#[cfg(feature = "runtime-benchmarks")]118pub mod benchmarking;119pub mod rpc;120pub mod weights;121122pub type SelfWeightOf<T> = <T as Config>::WeightInfo;123124#[frame_support::pallet]125pub mod pallet {126 use super::*;127128 #[pallet::config]129 pub trait Config: frame_system::Config + pallet_rmrk_core::Config {130 /// Overarching event type.131 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;132133 /// The weight information of this pallet.134 type WeightInfo: WeightInfo;135 }136137 /// Map of a base ID and a part ID to an NFT in the base collection serving as the part.138 #[pallet::storage]139 #[pallet::getter(fn internal_part_id)]140 pub type InernalPartId<T: Config> =141 StorageDoubleMap<_, Twox64Concat, CollectionId, Twox64Concat, RmrkPartId, TokenId>;142143 /// Checkmark that a base has a Theme NFT named "default".144 #[pallet::storage]145 #[pallet::getter(fn base_has_default_theme)]146 pub type BaseHasDefaultTheme<T: Config> =147 StorageMap<_, Twox64Concat, CollectionId, bool, ValueQuery>;148149 #[pallet::pallet]150 #[pallet::generate_store(pub(super) trait Store)]151 pub struct Pallet<T>(_);152153 #[pallet::event]154 #[pallet::generate_deposit(pub(super) fn deposit_event)]155 pub enum Event<T: Config> {156 BaseCreated {157 issuer: T::AccountId,158 base_id: RmrkBaseId,159 },160 EquippablesUpdated {161 base_id: RmrkBaseId,162 slot_id: RmrkSlotId,163 },164 }165166 #[pallet::error]167 pub enum Error<T> {168 /// No permission to perform action.169 PermissionError,170 /// Could not find an ID for a base collection. It is likely there were too many collections created on the chain.171 NoAvailableBaseId,172 /// Could not find a suitable ID for a part, likely too many part tokens were created in the base.173 NoAvailablePartId,174 /// Base collection linked to this ID does not exist.175 BaseDoesntExist,176 /// No theme named "default" is associated with the Base.177 NeedsDefaultThemeFirst,178 /// Part linked to this ID does not exist.179 PartDoesntExist,180 /// Cannot assign equippables to a fixed part.181 NoEquippableOnFixedPart,182 }183184 #[pallet::call]185 impl<T: Config> Pallet<T> {186 /// Create a new Base.187 /// 188 /// Modeled after the [base interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/base.md)189 /// 190 /// # Permissions191 /// - Anyone - will be assigned as the issuer of the base.192 ///193 /// # Arguments:194 /// - `base_type`: Arbitrary media type, e.g. "svg".195 /// - `symbol`: Arbitrary client-chosen symbol.196 /// - `parts`: Array of Fixed and Slot parts composing the base, 197 /// confined in length by [`RmrkPartsLimit`](up_data_structs::RmrkPartsLimit).198 #[transactional]199 #[pallet::weight(<SelfWeightOf<T>>::create_base(parts.len() as u32))]200 pub fn create_base(201 origin: OriginFor<T>,202 base_type: RmrkString,203 symbol: RmrkBaseSymbol,204 parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,205 ) -> DispatchResult {206 let sender = ensure_signed(origin)?;207 let cross_sender = T::CrossAccountId::from_sub(sender.clone());208209 let data = CreateCollectionData {210 limits: None,211 token_prefix: symbol212 .into_inner()213 .try_into()214 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,215 ..Default::default()216 };217218 let collection_id_res =219 <PalletNft<T>>::init_collection(cross_sender.clone(), data, true);220221 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {222 return Err(<Error<T>>::NoAvailableBaseId.into());223 }224225 let collection_id = collection_id_res?;226227 <PalletCommon<T>>::set_scoped_collection_properties(228 collection_id,229 PropertyScope::Rmrk,230 [231 <PalletCore<T>>::encode_rmrk_property(CollectionType, &misc::CollectionType::Base)?,232 <PalletCore<T>>::encode_rmrk_property(BaseType, &base_type)?,233 ]234 .into_iter(),235 )?;236237 let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;238239 for part in parts {240 Self::create_part(&cross_sender, &collection, part)?;241 }242243 Self::deposit_event(Event::BaseCreated {244 issuer: sender,245 base_id: collection_id.0,246 });247248 Ok(())249 }250251 /// Add a Theme to a Base.252 /// A Theme named "default" is required prior to adding other Themes.253 /// 254 /// Modeled after [themeadd interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/themeadd.md).255 ///256 /// # Permissions:257 /// - Base issuer258 /// 259 /// # Arguments:260 /// - `base_id`: Base ID containing the Theme to be updated.261 /// - `theme`: Theme to add to the Base. A Theme has a name and properties, which are an262 /// array of [key, value, inherit].263 /// - `key`: Arbitrary BoundedString, defined by client.264 /// - `value`: Arbitrary BoundedString, defined by client.265 /// - `inherit`: Optional bool.266 #[transactional]267 #[pallet::weight(<SelfWeightOf<T>>::theme_add(theme.properties.len() as u32))]268 pub fn theme_add(269 origin: OriginFor<T>,270 base_id: RmrkBaseId,271 theme: RmrkBoundedTheme,272 ) -> DispatchResult {273 let sender = ensure_signed(origin)?;274275 let sender = T::CrossAccountId::from_sub(sender);276 let owner = &sender;277278 let collection_id: CollectionId = base_id.into();279280 let collection = Self::get_base(collection_id)?;281282 if theme.name.as_slice() == b"default" {283 <BaseHasDefaultTheme<T>>::insert(collection_id, true);284 } else if !Self::base_has_default_theme(collection_id) {285 return Err(<Error<T>>::NeedsDefaultThemeFirst.into());286 }287288 let token_id = <PalletCore<T>>::create_nft(289 &sender,290 owner,291 &collection,292 [293 <PalletCore<T>>::encode_rmrk_property(TokenType, &NftType::Theme)?,294 <PalletCore<T>>::encode_rmrk_property(ThemeName, &theme.name)?,295 <PalletCore<T>>::encode_rmrk_property(ThemeInherit, &theme.inherit)?,296 ]297 .into_iter(),298 )299 .map_err(|_| <Error<T>>::PermissionError)?;300301 for property in theme.properties {302 <PalletNft<T>>::set_scoped_token_property(303 collection_id,304 token_id,305 PropertyScope::Rmrk,306 <PalletCore<T>>::encode_rmrk_property(307 UserProperty(property.key.as_slice()),308 &property.value,309 )?,310 )?;311 }312313 Ok(())314 }315316 /// Update the array of Collections allowed to be equipped to a Base's specified Slot Part.317 /// 318 /// Modeled after [equippable interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/equippable.md).319 ///320 /// # Permissions:321 /// - Base issuer322 /// 323 /// # Arguments:324 /// - `base_id`: Base containing the Slot Part to be updated.325 /// - `part_id`: Slot Part whose Equippable List is being updated.326 /// - `equippables`: List of equippables that will override the current Equippables list.327 #[transactional]328 #[pallet::weight(<SelfWeightOf<T>>::equippable())]329 pub fn equippable(330 origin: OriginFor<T>,331 base_id: RmrkBaseId,332 slot_id: RmrkSlotId,333 equippables: RmrkEquippableList,334 ) -> DispatchResult {335 let sender = ensure_signed(origin)?;336337 let base_collection_id = base_id.into();338 let collection = Self::get_base(base_collection_id)?;339340 <PalletCore<T>>::check_collection_owner(341 &collection,342 &T::CrossAccountId::from_sub(sender),343 )344 .map_err(|err| {345 if err == <CoreError<T>>::NoPermission.into() {346 <Error<T>>::PermissionError.into()347 } else {348 err349 }350 })?;351352 let part_id = Self::internal_part_id(base_collection_id, slot_id)353 .ok_or(<Error<T>>::PartDoesntExist)?;354355 let nft_type = <PalletCore<T>>::get_nft_type(base_collection_id, part_id)356 .map_err(|_| <Error<T>>::PartDoesntExist)?;357358 match nft_type {359 NftType::Regular | NftType::Theme => return Err(<Error<T>>::PermissionError.into()),360 NftType::FixedPart => return Err(<Error<T>>::NoEquippableOnFixedPart.into()),361 NftType::SlotPart => {362 <PalletNft<T>>::set_scoped_token_property(363 base_collection_id,364 part_id,365 PropertyScope::Rmrk,366 <PalletCore<T>>::encode_rmrk_property(EquippableList, &equippables)?,367 )?;368 }369 }370371 Self::deposit_event(Event::EquippablesUpdated { base_id, slot_id });372373 Ok(())374 }375 }376}377378impl<T: Config> Pallet<T> {379 /// Create or renew an NFT serving as a part, setting its properties380 /// to those of the part.381 fn create_part(382 sender: &T::CrossAccountId,383 collection: &NonfungibleHandle<T>,384 part: RmrkPartType,385 ) -> DispatchResult {386 let owner = sender;387388 let part_id = part.id();389 let src = part.src();390 let z_index = part.z_index();391392 let nft_type = match part {393 RmrkPartType::FixedPart(_) => NftType::FixedPart,394 RmrkPartType::SlotPart(_) => NftType::SlotPart,395 };396397 let token_id = match Self::internal_part_id(collection.id, part_id) {398 Some(token_id) => token_id,399 None => {400 let token_id =401 <PalletCore<T>>::create_nft(sender, owner, collection, [].into_iter())402 .map_err(|err| match err {403 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),404 err => err,405 })?;406407 <InernalPartId<T>>::insert(collection.id, part_id, token_id);408409 <PalletNft<T>>::set_scoped_token_property(410 collection.id,411 token_id,412 PropertyScope::Rmrk,413 <PalletCore<T>>::encode_rmrk_property(ExternalPartId, &part_id)?,414 )?;415416 token_id417 }418 };419420 <PalletNft<T>>::set_scoped_token_properties(421 collection.id,422 token_id,423 PropertyScope::Rmrk,424 [425 <PalletCore<T>>::encode_rmrk_property(TokenType, &nft_type)?,426 <PalletCore<T>>::encode_rmrk_property(Src, &src)?,427 <PalletCore<T>>::encode_rmrk_property(ZIndex, &z_index)?,428 ]429 .into_iter(),430 )?;431432 if let RmrkPartType::SlotPart(part) = part {433 <PalletNft<T>>::set_scoped_token_property(434 collection.id,435 token_id,436 PropertyScope::Rmrk,437 <PalletCore<T>>::encode_rmrk_property(EquippableList, &part.equippable)?,438 )?;439 }440441 Ok(())442 }443444 /// Ensure that the collection under the base ID is a base collection,445 /// and fetch it.446 fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {447 let collection =448 <PalletCore<T>>::get_typed_nft_collection(base_id, misc::CollectionType::Base)449 .map_err(|err| {450 if err == <CoreError<T>>::CollectionUnknown.into() {451 <Error<T>>::BaseDoesntExist.into()452 } else {453 err454 }455 })?;456 collection.check_is_external()?;457458 Ok(collection)459 }460}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//! # RMRK Core Proxy Pallet18//!19//! A pallet used as proxy for RMRK Core (<https://rmrk-team.github.io/rmrk-substrate/#/pallets/rmrk-core>).20//!21//! - [`Config`]22//! - [`Call`]23//! - [`Pallet`]24//!25//! ## Overview26//!27//! The RMRK Equip Proxy pallet mirrors the functionality of RMRK Equip,28//! binding its externalities to Unique's own underlying structure.29//! It is purposed to mimic RMRK Equip exactly, allowing seamless integrations30//! of solutions based on RMRK.31//!32//! RMRK Equip itself contains functionality to equip NFTs, and work with Bases,33//! Parts, and Themes.34//!35//! Equip Proxy is responsible for a more specific area of RMRK, and heavily relies on the Core.36//! For a more foundational description of proxy implementation, please refer to [`pallet_rmrk_core`].37//!38//! *Note*, that while RMRK itself is subject to active development and restructuring,39//! the proxy may be caught temporarily out of date.40//!41//! ### What is RMRK?42//!43//! RMRK is a set of NFT standards which compose several "NFT 2.0 lego" primitives.44//! Putting these legos together allows a user to create NFT systems of arbitrary complexity.45//!46//! Meaning, RMRK NFTs are dynamic, able to nest into each other and form a hierarchy,47//! make use of specific changeable and partially shared metadata in the form of resources,48//! and more.49//!50//! Visit RMRK documentation and repositories to learn more:51//! - Docs: <https://docs.rmrk.app/getting-started/>52//! - FAQ: <https://coda.io/@rmrk/faq>53//! - Substrate code repository: <https://github.com/rmrk-team/rmrk-substrate>54//! - RMRK spec repository: <https://github.com/rmrk-team/rmrk-spec>55//!56//! ## Proxy Implementation57//!58//! An external user is supposed to be able to utilize this proxy as they would59//! utilize RMRK, and get exactly the same results. Normally, Unique transactions60//! are off-limits to RMRK collections and tokens, and vice versa. However,61//! the information stored on chain can be freely interpreted by storage reads and RPCs.62//!63//! ### ID Mapping64//!65//! RMRK's collections' IDs are counted independently of Unique's and start at 0.66//! Note that tokens' IDs still start at 1.67//! The collections themselves, as well as tokens, are stored as Unique collections,68//! and thus RMRK IDs are mapped to Unique IDs (but not vice versa).69//!70//! ### External/Internal Collection Insulation71//!72//! A Unique transaction cannot target collections purposed for RMRK,73//! and they are flagged as `external` to specify that. On the other hand,74//! due to the mapping, RMRK transactions and RPCs simply cannot reach Unique collections.75//!76//! ### Native Properties77//!78//! Many of RMRK's native parameters are stored as scoped properties of a collection79//! or an NFT on the chain. Scoped properties are prefixed with `rmrk:`, where `:`80//! is an unacceptable symbol in user-defined proeprties, which, along with other safeguards,81//! makes them impossible to tamper with.82//!83//! ### Collection and NFT Types84//!85//! RMRK introduces the concept of a Base, which is a catalgoue of Parts,86//! possible components of an NFT. Due to its similarity with the functionality87//! of a token collection, a Base is stored and handled as one, and the Base's Parts and Themes88//! are the collection's NFTs. See [`CollectionType`](pallet_rmrk_core::misc::CollectionType) and89//! [`NftType`](pallet_rmrk_core::misc::NftType).90//!91//! ## Interface92//!93//! ### Dispatchables94//!95//! - `create_base` - Create a new Base.96//! - `theme_add` - Add a Theme to a Base.97//! - `equippable` - Update the array of Collections allowed to be equipped to a Base's specified Slot Part.9899#![cfg_attr(not(feature = "std"), no_std)]100101use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};102use frame_system::{pallet_prelude::*, ensure_signed};103use sp_runtime::DispatchError;104use up_data_structs::*;105use pallet_common::{Pallet as PalletCommon, Error as CommonError};106use pallet_rmrk_core::{107 Pallet as PalletCore, Error as CoreError,108 misc::{self, *},109 property::RmrkProperty::*,110};111use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};112use pallet_evm::account::CrossAccountId;113use weights::WeightInfo;114115pub use pallet::*;116117#[cfg(feature = "runtime-benchmarks")]118pub mod benchmarking;119pub mod rpc;120pub mod weights;121122pub type SelfWeightOf<T> = <T as Config>::WeightInfo;123124#[frame_support::pallet]125pub mod pallet {126 use super::*;127128 #[pallet::config]129 pub trait Config: frame_system::Config + pallet_rmrk_core::Config {130 /// Overarching event type.131 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;132133 /// The weight information of this pallet.134 type WeightInfo: WeightInfo;135 }136137 /// Map of a base ID and a part ID to an NFT in the base collection serving as the part.138 #[pallet::storage]139 #[pallet::getter(fn internal_part_id)]140 pub type InernalPartId<T: Config> =141 StorageDoubleMap<_, Twox64Concat, CollectionId, Twox64Concat, RmrkPartId, TokenId>;142143 /// Checkmark that a base has a Theme NFT named "default".144 #[pallet::storage]145 #[pallet::getter(fn base_has_default_theme)]146 pub type BaseHasDefaultTheme<T: Config> =147 StorageMap<_, Twox64Concat, CollectionId, bool, ValueQuery>;148149 #[pallet::pallet]150 #[pallet::generate_store(pub(super) trait Store)]151 pub struct Pallet<T>(_);152153 #[pallet::event]154 #[pallet::generate_deposit(pub(super) fn deposit_event)]155 pub enum Event<T: Config> {156 BaseCreated {157 issuer: T::AccountId,158 base_id: RmrkBaseId,159 },160 EquippablesUpdated {161 base_id: RmrkBaseId,162 slot_id: RmrkSlotId,163 },164 }165166 #[pallet::error]167 pub enum Error<T> {168 /// No permission to perform action.169 PermissionError,170 /// Could not find an ID for a base collection. It is likely there were too many collections created on the chain.171 NoAvailableBaseId,172 /// Could not find a suitable ID for a part, likely too many part tokens were created in the base.173 NoAvailablePartId,174 /// Base collection linked to this ID does not exist.175 BaseDoesntExist,176 /// No theme named "default" is associated with the Base.177 NeedsDefaultThemeFirst,178 /// Part linked to this ID does not exist.179 PartDoesntExist,180 /// Cannot assign equippables to a fixed part.181 NoEquippableOnFixedPart,182 }183184 #[pallet::call]185 impl<T: Config> Pallet<T> {186 /// Create a new Base.187 ///188 /// Modeled after the [base interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/base.md)189 ///190 /// # Permissions191 /// - Anyone - will be assigned as the issuer of the base.192 ///193 /// # Arguments:194 /// - `base_type`: Arbitrary media type, e.g. "svg".195 /// - `symbol`: Arbitrary client-chosen symbol.196 /// - `parts`: Array of Fixed and Slot parts composing the base,197 /// confined in length by [`RmrkPartsLimit`](up_data_structs::RmrkPartsLimit).198 #[transactional]199 #[pallet::weight(<SelfWeightOf<T>>::create_base(parts.len() as u32))]200 pub fn create_base(201 origin: OriginFor<T>,202 base_type: RmrkString,203 symbol: RmrkBaseSymbol,204 parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,205 ) -> DispatchResult {206 let sender = ensure_signed(origin)?;207 let cross_sender = T::CrossAccountId::from_sub(sender.clone());208209 let data = CreateCollectionData {210 limits: None,211 token_prefix: symbol212 .into_inner()213 .try_into()214 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,215 ..Default::default()216 };217218 let collection_id_res =219 <PalletNft<T>>::init_collection(cross_sender.clone(), data, true);220221 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {222 return Err(<Error<T>>::NoAvailableBaseId.into());223 }224225 let collection_id = collection_id_res?;226227 <PalletCommon<T>>::set_scoped_collection_properties(228 collection_id,229 PropertyScope::Rmrk,230 [231 <PalletCore<T>>::encode_rmrk_property(232 CollectionType,233 &misc::CollectionType::Base,234 )?,235 <PalletCore<T>>::encode_rmrk_property(BaseType, &base_type)?,236 ]237 .into_iter(),238 )?;239240 let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;241242 for part in parts {243 Self::create_part(&cross_sender, &collection, part)?;244 }245246 Self::deposit_event(Event::BaseCreated {247 issuer: sender,248 base_id: collection_id.0,249 });250251 Ok(())252 }253254 /// Add a Theme to a Base.255 /// A Theme named "default" is required prior to adding other Themes.256 ///257 /// Modeled after [themeadd interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/themeadd.md).258 ///259 /// # Permissions:260 /// - Base issuer261 ///262 /// # Arguments:263 /// - `base_id`: Base ID containing the Theme to be updated.264 /// - `theme`: Theme to add to the Base. A Theme has a name and properties, which are an265 /// array of [key, value, inherit].266 /// - `key`: Arbitrary BoundedString, defined by client.267 /// - `value`: Arbitrary BoundedString, defined by client.268 /// - `inherit`: Optional bool.269 #[transactional]270 #[pallet::weight(<SelfWeightOf<T>>::theme_add(theme.properties.len() as u32))]271 pub fn theme_add(272 origin: OriginFor<T>,273 base_id: RmrkBaseId,274 theme: RmrkBoundedTheme,275 ) -> DispatchResult {276 let sender = ensure_signed(origin)?;277278 let sender = T::CrossAccountId::from_sub(sender);279 let owner = &sender;280281 let collection_id: CollectionId = base_id.into();282283 let collection = Self::get_base(collection_id)?;284285 if theme.name.as_slice() == b"default" {286 <BaseHasDefaultTheme<T>>::insert(collection_id, true);287 } else if !Self::base_has_default_theme(collection_id) {288 return Err(<Error<T>>::NeedsDefaultThemeFirst.into());289 }290291 let token_id = <PalletCore<T>>::create_nft(292 &sender,293 owner,294 &collection,295 [296 <PalletCore<T>>::encode_rmrk_property(TokenType, &NftType::Theme)?,297 <PalletCore<T>>::encode_rmrk_property(ThemeName, &theme.name)?,298 <PalletCore<T>>::encode_rmrk_property(ThemeInherit, &theme.inherit)?,299 ]300 .into_iter(),301 )302 .map_err(|_| <Error<T>>::PermissionError)?;303304 for property in theme.properties {305 <PalletNft<T>>::set_scoped_token_property(306 collection_id,307 token_id,308 PropertyScope::Rmrk,309 <PalletCore<T>>::encode_rmrk_property(310 UserProperty(property.key.as_slice()),311 &property.value,312 )?,313 )?;314 }315316 Ok(())317 }318319 /// Update the array of Collections allowed to be equipped to a Base's specified Slot Part.320 ///321 /// Modeled after [equippable interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/equippable.md).322 ///323 /// # Permissions:324 /// - Base issuer325 ///326 /// # Arguments:327 /// - `base_id`: Base containing the Slot Part to be updated.328 /// - `part_id`: Slot Part whose Equippable List is being updated.329 /// - `equippables`: List of equippables that will override the current Equippables list.330 #[transactional]331 #[pallet::weight(<SelfWeightOf<T>>::equippable())]332 pub fn equippable(333 origin: OriginFor<T>,334 base_id: RmrkBaseId,335 slot_id: RmrkSlotId,336 equippables: RmrkEquippableList,337 ) -> DispatchResult {338 let sender = ensure_signed(origin)?;339340 let base_collection_id = base_id.into();341 let collection = Self::get_base(base_collection_id)?;342343 <PalletCore<T>>::check_collection_owner(344 &collection,345 &T::CrossAccountId::from_sub(sender),346 )347 .map_err(|err| {348 if err == <CoreError<T>>::NoPermission.into() {349 <Error<T>>::PermissionError.into()350 } else {351 err352 }353 })?;354355 let part_id = Self::internal_part_id(base_collection_id, slot_id)356 .ok_or(<Error<T>>::PartDoesntExist)?;357358 let nft_type = <PalletCore<T>>::get_nft_type(base_collection_id, part_id)359 .map_err(|_| <Error<T>>::PartDoesntExist)?;360361 match nft_type {362 NftType::Regular | NftType::Theme => return Err(<Error<T>>::PermissionError.into()),363 NftType::FixedPart => return Err(<Error<T>>::NoEquippableOnFixedPart.into()),364 NftType::SlotPart => {365 <PalletNft<T>>::set_scoped_token_property(366 base_collection_id,367 part_id,368 PropertyScope::Rmrk,369 <PalletCore<T>>::encode_rmrk_property(EquippableList, &equippables)?,370 )?;371 }372 }373374 Self::deposit_event(Event::EquippablesUpdated { base_id, slot_id });375376 Ok(())377 }378 }379}380381impl<T: Config> Pallet<T> {382 /// Create or renew an NFT serving as a part, setting its properties383 /// to those of the part.384 fn create_part(385 sender: &T::CrossAccountId,386 collection: &NonfungibleHandle<T>,387 part: RmrkPartType,388 ) -> DispatchResult {389 let owner = sender;390391 let part_id = part.id();392 let src = part.src();393 let z_index = part.z_index();394395 let nft_type = match part {396 RmrkPartType::FixedPart(_) => NftType::FixedPart,397 RmrkPartType::SlotPart(_) => NftType::SlotPart,398 };399400 let token_id = match Self::internal_part_id(collection.id, part_id) {401 Some(token_id) => token_id,402 None => {403 let token_id =404 <PalletCore<T>>::create_nft(sender, owner, collection, [].into_iter())405 .map_err(|err| match err {406 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),407 err => err,408 })?;409410 <InernalPartId<T>>::insert(collection.id, part_id, token_id);411412 <PalletNft<T>>::set_scoped_token_property(413 collection.id,414 token_id,415 PropertyScope::Rmrk,416 <PalletCore<T>>::encode_rmrk_property(ExternalPartId, &part_id)?,417 )?;418419 token_id420 }421 };422423 <PalletNft<T>>::set_scoped_token_properties(424 collection.id,425 token_id,426 PropertyScope::Rmrk,427 [428 <PalletCore<T>>::encode_rmrk_property(TokenType, &nft_type)?,429 <PalletCore<T>>::encode_rmrk_property(Src, &src)?,430 <PalletCore<T>>::encode_rmrk_property(ZIndex, &z_index)?,431 ]432 .into_iter(),433 )?;434435 if let RmrkPartType::SlotPart(part) = part {436 <PalletNft<T>>::set_scoped_token_property(437 collection.id,438 token_id,439 PropertyScope::Rmrk,440 <PalletCore<T>>::encode_rmrk_property(EquippableList, &part.equippable)?,441 )?;442 }443444 Ok(())445 }446447 /// Ensure that the collection under the base ID is a base collection,448 /// and fetch it.449 fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {450 let collection =451 <PalletCore<T>>::get_typed_nft_collection(base_id, misc::CollectionType::Base)452 .map_err(|err| {453 if err == <CoreError<T>>::CollectionUnknown.into() {454 <Error<T>>::BaseDoesntExist.into()455 } else {456 err457 }458 })?;459 collection.check_is_external()?;460461 Ok(collection)462 }463}