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.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//! Realizations of RMRK RPCs (remote procedure calls) related to the Core pallet.1819use super::*;2021/// Get the latest created collection ID.22pub fn last_collection_idx<T: Config>() -> Result<RmrkCollectionId, DispatchError> {23 Ok(<Pallet<T>>::last_collection_idx())24}2526/// Get collection info by ID.27pub fn collection_by_id<T: Config>(28 collection_id: RmrkCollectionId,29) -> Result<Option<RmrkCollectionInfo<T::AccountId>>, DispatchError> {30 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(31 collection_id,32 misc::CollectionType::Regular,33 ) {34 Ok(c) => c,35 Err(_) => return Ok(None),36 };3738 let nfts_count = collection.total_supply();3940 Ok(Some(RmrkCollectionInfo {41 issuer: collection.owner.clone(),42 metadata: <Pallet<T>>::get_collection_property_decoded(43 collection_id,44 RmrkProperty::Metadata,45 )?,46 max: collection.limits.token_limit,47 symbol: <Pallet<T>>::rebind(&collection.token_prefix)?,48 nfts_count,49 }))50}5152/// Get NFT info by collection and NFT IDs.53pub fn nft_by_id<T: Config>(54 collection_id: RmrkCollectionId,55 nft_by_id: RmrkNftId,56) -> Result<Option<RmrkInstanceInfo<T::AccountId>>, DispatchError> {57 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(58 collection_id,59 misc::CollectionType::Regular,60 ) {61 Ok(c) => c,62 Err(_) => return Ok(None),63 };6465 let nft_id = TokenId(nft_by_id);66 if !<Pallet<T>>::nft_exists(collection_id, nft_id) {67 return Ok(None);68 }6970 let owner = match collection.token_owner(nft_id) {71 Some(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {72 Some((col, tok)) => {73 let rmrk_collection = <Pallet<T>>::rmrk_collection_id(col)?;7475 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)76 }77 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone()),78 },79 None => return Ok(None),80 };8182 Ok(Some(RmrkInstanceInfo {83 owner: owner,84 royalty: <Pallet<T>>::get_nft_property_decoded(85 collection_id,86 nft_id,87 RmrkProperty::RoyaltyInfo,88 )?,89 metadata: <Pallet<T>>::get_nft_property_decoded(90 collection_id,91 nft_id,92 RmrkProperty::Metadata,93 )?,94 equipped: <Pallet<T>>::get_nft_property_decoded(95 collection_id,96 nft_id,97 RmrkProperty::Equipped,98 )?,99 pending: <Pallet<T>>::get_nft_property_decoded(100 collection_id,101 nft_id,102 RmrkProperty::PendingNftAccept,103 )?,104 }))105}106107108/// Get tokens owned by an account in a collection.109pub fn account_tokens<T: Config>(110 account_id: T::AccountId,111 collection_id: RmrkCollectionId,112) -> Result<Vec<RmrkNftId>, DispatchError> {113 let cross_account_id = CrossAccountId::from_sub(account_id);114115 let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(116 collection_id,117 misc::CollectionType::Regular,118 ) {119 Ok(c) => c,120 Err(_) => return Ok(Vec::new()),121 };122123 let tokens = collection124 .account_tokens(cross_account_id)125 .into_iter()126 .filter(|token| {127 let is_pending = <Pallet<T>>::get_nft_property_decoded(128 collection_id,129 *token,130 RmrkProperty::PendingNftAccept,131 )132 .unwrap_or(true);133134 !is_pending135 })136 .map(|token| token.0)137 .collect();138139 Ok(tokens)140}141142/// Get tokens nested in an NFT - its direct children (not the children's children).143pub fn nft_children<T: Config>(144 collection_id: RmrkCollectionId,145 nft_id: RmrkNftId,146) -> Result<Vec<RmrkNftChild>, DispatchError> {147 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {148 Ok(id) => id,149 Err(_) => return Ok(Vec::new()),150 };151 let nft_id = TokenId(nft_id);152 if !<Pallet<T>>::nft_exists(collection_id, nft_id) {153 return Ok(Vec::new());154 }155156 Ok(157 pallet_nonfungible::TokenChildren::<T>::iter_prefix((collection_id, nft_id))158 .filter_map(|((child_collection, child_token), _)| {159 let rmrk_child_collection =160 <Pallet<T>>::rmrk_collection_id(child_collection).ok()?;161162 Some(RmrkNftChild {163 collection_id: rmrk_child_collection,164 nft_id: child_token.0,165 })166 })167 .chain(168 <Pallet<T>>::iterate_pending_children(collection_id, nft_id)?.map(169 |(child_collection, child_nft_id)| RmrkNftChild {170 collection_id: child_collection,171 nft_id: child_nft_id,172 },173 ),174 )175 .collect(),176 )177}178179/// Get collection properties, created by the user - not the proxy-specific properties.180pub fn collection_properties<T: Config>(181 collection_id: RmrkCollectionId,182 filter_keys: Option<Vec<RmrkPropertyKey>>,183) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {184 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {185 Ok(id) => id,186 Err(_) => return Ok(Vec::new()),187 };188 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {189 return Ok(Vec::new());190 }191192 let properties = <Pallet<T>>::filter_user_properties(193 collection_id,194 /* token_id = */ None,195 filter_keys,196 |key, value| RmrkPropertyInfo { key, value },197 )?;198199 Ok(properties)200}201202/// Get NFT properties, created by the user - not the proxy-specific properties.203pub fn nft_properties<T: Config>(204 collection_id: RmrkCollectionId,205 nft_id: RmrkNftId,206 filter_keys: Option<Vec<RmrkPropertyKey>>,207) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {208 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {209 Ok(id) => id,210 Err(_) => return Ok(Vec::new()),211 };212 let token_id = TokenId(nft_id);213214 if <Pallet<T>>::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {215 return Ok(Vec::new());216 }217218 let properties = <Pallet<T>>::filter_user_properties(219 collection_id,220 Some(token_id),221 filter_keys,222 |key, value| RmrkPropertyInfo { key, value },223 )?;224225 Ok(properties)226}227228/// Get data of resources of an NFT.229pub fn nft_resources<T: Config>(230 collection_id: RmrkCollectionId,231 nft_id: RmrkNftId,232) -> Result<Vec<RmrkResourceInfo>, DispatchError> {233 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {234 Ok(id) => id,235 Err(_) => return Ok(Vec::new()),236 };237 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {238 return Ok(Vec::new());239 }240241 let nft_id = TokenId(nft_id);242 if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {243 return Ok(Vec::new());244 }245246 let resources = <pallet_nonfungible::Pallet<T>>::iterate_token_aux_properties(247 collection_id,248 nft_id,249 PropertyScope::Rmrk,250 )251 .filter_map(|(key, value)| {252 if !is_valid_key_prefix(&key, RESOURCE_ID_PREFIX) {253 return None;254 }255256 let resource_info: RmrkResourceInfo = <Pallet<T>>::decode_property_value(&value).ok()?;257258 Some(resource_info)259 })260 .collect();261262 Ok(resources)263}264265/// Get the priority of a resource in an NFT.266pub fn nft_resource_priority<T: Config>(267 collection_id: RmrkCollectionId,268 nft_id: RmrkNftId,269 resource_id: RmrkResourceId,270) -> Result<Option<u32>, DispatchError> {271 let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {272 Ok(id) => id,273 Err(_) => return Ok(None),274 };275 if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {276 return Ok(None);277 }278279 let nft_id = TokenId(nft_id);280 if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {281 return Ok(None);282 }283284 let priorities: Vec<_> = <Pallet<T>>::get_nft_property_decoded(285 collection_id,286 nft_id,287 RmrkProperty::ResourcePriorities,288 )?;289 Ok(priorities290 .into_iter()291 .enumerate()292 .find(|(_, id)| *id == resource_id)293 .map(|(priority, _): (usize, RmrkResourceId)| priority as u32))294}pallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/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 Equip Proxy pallet mirrors the functionality of RMRK Equip,
+//!
+//! The RMRK Equip Proxy pallet mirrors the functionality of RMRK Equip,
//! binding its externalities to Unique's own underlying structure.
//! It is purposed to mimic RMRK Equip exactly, allowing seamless integrations
//! of solutions based on RMRK.
-//!
+//!
//! RMRK Equip itself contains functionality to equip NFTs, and work with Bases,
//! Parts, and Themes.
-//!
-//! Equip Proxy is responsible for a more specific area of RMRK, and heavily relies on the Core.
+//!
+//! Equip Proxy is responsible for a more specific area of RMRK, and heavily relies on the Core.
//! For a more foundational description of proxy implementation, please refer to [`pallet_rmrk_core`].
-//!
+//!
//! *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_base` - Create a new Base.
//! - `theme_add` - Add a Theme to a Base.
//! - `equippable` - Update the array of Collections allowed to be equipped to a Base's specified Slot Part.
@@ -184,16 +184,16 @@
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Create a new Base.
- ///
+ ///
/// Modeled after the [base interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/base.md)
- ///
+ ///
/// # Permissions
/// - Anyone - will be assigned as the issuer of the base.
///
/// # Arguments:
/// - `base_type`: Arbitrary media type, e.g. "svg".
/// - `symbol`: Arbitrary client-chosen symbol.
- /// - `parts`: Array of Fixed and Slot parts composing the base,
+ /// - `parts`: Array of Fixed and Slot parts composing the base,
/// confined in length by [`RmrkPartsLimit`](up_data_structs::RmrkPartsLimit).
#[transactional]
#[pallet::weight(<SelfWeightOf<T>>::create_base(parts.len() as u32))]
@@ -228,7 +228,10 @@
collection_id,
PropertyScope::Rmrk,
[
- <PalletCore<T>>::encode_rmrk_property(CollectionType, &misc::CollectionType::Base)?,
+ <PalletCore<T>>::encode_rmrk_property(
+ CollectionType,
+ &misc::CollectionType::Base,
+ )?,
<PalletCore<T>>::encode_rmrk_property(BaseType, &base_type)?,
]
.into_iter(),
@@ -250,12 +253,12 @@
/// Add a Theme to a Base.
/// A Theme named "default" is required prior to adding other Themes.
- ///
+ ///
/// Modeled after [themeadd interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/themeadd.md).
///
/// # Permissions:
/// - Base issuer
- ///
+ ///
/// # Arguments:
/// - `base_id`: Base ID containing the Theme to be updated.
/// - `theme`: Theme to add to the Base. A Theme has a name and properties, which are an
@@ -314,12 +317,12 @@
}
/// Update the array of Collections allowed to be equipped to a Base's specified Slot Part.
- ///
+ ///
/// Modeled after [equippable interaction](https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk2.0.0/interactions/equippable.md).
///
/// # Permissions:
/// - Base issuer
- ///
+ ///
/// # Arguments:
/// - `base_id`: Base containing the Slot Part to be updated.
/// - `part_id`: Slot Part whose Equippable List is being updated.