difftreelog
doc: minor fixes + typos
in: master
7 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -50,6 +50,7 @@
account: CrossAccountId,
at: Option<BlockHash>,
) -> Result<Vec<TokenId>>;
+
/// Get tokens contained in collection
#[method(name = "unique_collectionTokens")]
fn collection_tokens(
@@ -57,6 +58,7 @@
collection: CollectionId,
at: Option<BlockHash>,
) -> Result<Vec<TokenId>>;
+
/// Check if token exists
#[method(name = "unique_tokenExists")]
fn token_exists(
@@ -65,6 +67,7 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<bool>;
+
/// Get token owner
#[method(name = "unique_tokenOwner")]
fn token_owner(
@@ -73,6 +76,7 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<Option<CrossAccountId>>;
+
/// Get token owner, in case of nested token - find the parent recursively
#[method(name = "unique_topmostTokenOwner")]
fn topmost_token_owner(
@@ -81,6 +85,7 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<Option<CrossAccountId>>;
+
/// Get tokens nested directly into the token
#[method(name = "unique_tokenChildren")]
fn token_children(
@@ -89,6 +94,7 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<Vec<TokenChild>>;
+
/// Get collection properties
#[method(name = "unique_collectionProperties")]
fn collection_properties(
@@ -97,6 +103,7 @@
keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<Property>>;
+
/// Get token properties
#[method(name = "unique_tokenProperties")]
fn token_properties(
@@ -106,6 +113,7 @@
keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<Property>>;
+
/// Get property permissions
#[method(name = "unique_propertyPermissions")]
fn property_permissions(
@@ -114,6 +122,7 @@
keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<PropertyKeyPermission>>;
+
/// Get token data
#[method(name = "unique_tokenData")]
fn token_data(
@@ -123,9 +132,11 @@
keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<TokenData<CrossAccountId>>;
+
/// Get amount of unique collection tokens
#[method(name = "unique_totalSupply")]
fn total_supply(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;
+
/// Get owned amount of any user tokens
#[method(name = "unique_accountBalance")]
fn account_balance(
@@ -134,6 +145,7 @@
account: CrossAccountId,
at: Option<BlockHash>,
) -> Result<u32>;
+
/// Get owned amount of specific account token
#[method(name = "unique_balance")]
fn balance(
@@ -143,6 +155,7 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<String>;
+
/// Get allowed amount
#[method(name = "unique_allowance")]
fn allowance(
@@ -153,6 +166,7 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<String>;
+
/// Get admin list
#[method(name = "unique_adminlist")]
fn adminlist(
@@ -160,6 +174,7 @@
collection: CollectionId,
at: Option<BlockHash>,
) -> Result<Vec<CrossAccountId>>;
+
/// Get allowlist
#[method(name = "unique_allowlist")]
fn allowlist(
@@ -167,6 +182,7 @@
collection: CollectionId,
at: Option<BlockHash>,
) -> Result<Vec<CrossAccountId>>;
+
/// Check if user is allowed to use collection
#[method(name = "unique_allowed")]
fn allowed(
@@ -175,9 +191,11 @@
user: CrossAccountId,
at: Option<BlockHash>,
) -> Result<bool>;
+
/// Get last token ID created in a collection
#[method(name = "unique_lastTokenId")]
fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;
+
/// Get collection by specified ID
#[method(name = "unique_collectionById")]
fn collection_by_id(
@@ -185,9 +203,11 @@
collection: CollectionId,
at: Option<BlockHash>,
) -> Result<Option<RpcCollection<AccountId>>>;
+
/// Get collection stats
#[method(name = "unique_collectionStats")]
fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;
+
/// Get number of blocks when sponsored transaction is available
#[method(name = "unique_nextSponsored")]
fn next_sponsored(
@@ -197,6 +217,7 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<Option<u64>>;
+
/// Get effective collection limits
#[method(name = "unique_effectiveCollectionLimits")]
fn effective_collection_limits(
@@ -204,6 +225,7 @@
collection_id: CollectionId,
at: Option<BlockHash>,
) -> Result<Option<CollectionLimits>>;
+
/// Get total pieces of token
#[method(name = "unique_totalPieces")]
fn total_pieces(
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -334,7 +334,7 @@
///
/// * collection_id: ID of the collection to which the item belongs.
///
- /// * item_id: ID of the item trasnferred.
+ /// * item_id: ID of the item transferred.
///
/// * sender: Original owner of the item.
///
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -58,13 +58,13 @@
pub enum Error<T> {
/// Not Fungible item data used to mint in Fungible collection.
NotFungibleDataUsedToMintFungibleCollectionToken,
- /// Not default id passed as TokenId argument
+ /// Not default id passed as TokenId argument.
FungibleItemsHaveNoId,
- /// Tried to set data for fungible item
+ /// Tried to set data for fungible item.
FungibleItemsDontHaveData,
- /// Fungible token does not support nested
+ /// Fungible token does not support nesting.
FungibleDisallowsNesting,
- /// Setting item properties is not allowed
+ /// Setting item properties is not allowed.
SettingPropertiesNotAllowed,
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -171,7 +171,7 @@
QueryKind = ValueQuery,
>;
- /// Amount of tokens owned in a collection.s
+ /// Amount of tokens owned in a collection.
#[pallet::storage]
pub type AccountBalance<T: Config> = StorageNMap<
Key = (
@@ -182,7 +182,7 @@
QueryKind = ValueQuery,
>;
- /// todo doc
+ /// todo:doc
#[pallet::storage]
pub type Allowance<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -64,13 +64,13 @@
pub enum Error<T> {
/// Not Refungible item data used to mint in Refungible collection.
NotRefungibleDataUsedToMintFungibleCollectionToken,
- /// Maximum refungibility exceeded
+ /// Maximum refungibility exceeded.
WrongRefungiblePieces,
- /// Refungible token can't be repartitioned by user who isn't owns all pieces
+ /// Refungible token can't be repartitioned by user who isn't owns all pieces.
RepartitionWhileNotOwningAllPieces,
- /// Refungible token can't nest other tokens
+ /// Refungible token can't nest other tokens.
RefungibleDisallowsNesting,
- /// Setting item properties is not allowed
+ /// Setting item properties is not allowed.
SettingPropertiesNotAllowed,
}
@@ -605,7 +605,6 @@
Ok(())
}
- /// todo:doc oh look, a precedent. not pub, too. but it has an unclear use-case.
/// Returns allowance, which should be set after transaction
fn check_allowed(
collection: &RefungibleHandle<T>,
pallets/structure/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23use pallet_common::CommonCollectionOperations;4use sp_std::collections::btree_set::BTreeSet;56use frame_support::dispatch::{DispatchError, DispatchResult, DispatchResultWithPostInfo};7use frame_support::fail;8pub use pallet::*;9use pallet_common::{dispatch::CollectionDispatch, CollectionHandle};10use up_data_structs::{CollectionId, TokenId, mapping::TokenAddressMapping, budget::Budget};1112#[cfg(feature = "runtime-benchmarks")]13pub mod benchmarking;14pub mod weights;1516pub type SelfWeightOf<T> = <T as crate::Config>::WeightInfo;1718#[frame_support::pallet]19pub mod pallet {20 use frame_support::Parameter;21 use frame_support::dispatch::{GetDispatchInfo, UnfilteredDispatchable};22 use frame_support::pallet_prelude::*;2324 use super::*;2526 #[pallet::error]27 pub enum Error<T> {28 /// While searching for the owner, encountered an already checked account, detecting a loop.29 OuroborosDetected,30 /// While searching for the owner, reached the depth limit.31 DepthLimit,32 /// While iterating over children, reached the breadth limit.33 BreadthLimit,34 /// Couldn't find the token owner that is a token. Perhaps, it does not yet exist. todo:doc? rephrase?35 TokenNotFound,36 }3738 #[pallet::event]39 pub enum Event<T> {40 /// Executed call on behalf of the token.41 Executed(DispatchResult),42 }4344 #[pallet::config]45 pub trait Config: frame_system::Config + pallet_common::Config {46 type WeightInfo: weights::WeightInfo;47 type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;48 type Call: Parameter + UnfilteredDispatchable<Origin = Self::Origin> + GetDispatchInfo;49 }5051 #[pallet::pallet]52 pub struct Pallet<T>(_);5354 #[pallet::call]55 impl<T: Config> Pallet<T> {56 // #[pallet::weight({57 // let dispatch_info = call.get_dispatch_info();5859 // (60 // dispatch_info.weight61 // // Cost of dereferencing parent62 // .saturating_add(T::DbWeight::get().reads(2 * *max_depth as Weight))63 // .saturating_add(4000 * *max_depth as Weight),64 // dispatch_info.class)65 // })]66 // pub fn execute(67 // origin: OriginFor<T>,68 // call: Box<<T as Config>::Call>,69 // max_depth: u32,70 // ) -> DispatchResult {71 }72}7374#[derive(PartialEq)]75pub enum Parent<CrossAccountId> {76 /// Token owned by a normal account.77 User(CrossAccountId),78 /// Could not find the token provided as the owner.79 TokenNotFound,80 /// Token owner is another token (still, the target token may not exist).81 Token(CollectionId, TokenId),82}8384impl<T: Config> Pallet<T> {85 pub fn find_parent(86 collection: CollectionId,87 token: TokenId,88 ) -> Result<Parent<T::CrossAccountId>, DispatchError> {89 // TODO: Reduce cost by not reading collection config90 let handle = match CollectionHandle::try_get(collection) {91 Ok(v) => v,92 Err(_) => return Ok(Parent::TokenNotFound),93 };94 let handle = T::CollectionDispatch::dispatch(handle);95 let handle = handle.as_dyn();9697 Ok(match handle.token_owner(token) {98 Some(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {99 Some((collection, token)) => Parent::Token(collection, token),100 None => Parent::User(owner),101 },102 None => Parent::TokenNotFound,103 })104 }105106 pub fn parent_chain(107 mut collection: CollectionId,108 mut token: TokenId,109 ) -> impl Iterator<Item = Result<Parent<T::CrossAccountId>, DispatchError>> {110 let mut finished = false;111 let mut visited = BTreeSet::new();112 visited.insert((collection, token));113 core::iter::from_fn(move || {114 if finished {115 return None;116 }117 let parent = Self::find_parent(collection, token);118 match parent {119 Ok(Parent::Token(new_collection, new_token)) => {120 collection = new_collection;121 token = new_token;122 if !visited.insert((new_collection, new_token)) {123 finished = true;124 return Some(Err(<Error<T>>::OuroborosDetected.into()));125 }126 }127 _ => finished = true,128 }129 Some(parent as Result<_, DispatchError>)130 })131 }132133 /// Try to dereference address, until finding top level owner134 ///135 /// May return token address if parent token not yet exists136 pub fn find_topmost_owner(137 collection: CollectionId,138 token: TokenId,139 budget: &dyn Budget,140 ) -> Result<T::CrossAccountId, DispatchError> {141 let owner = Self::parent_chain(collection, token)142 .take_while(|_| budget.consume())143 .find(|p| matches!(p, Ok(Parent::User(_) | Parent::TokenNotFound)))144 .ok_or(<Error<T>>::DepthLimit)??;145146 Ok(match owner {147 Parent::User(v) => v,148 _ => fail!(<Error<T>>::TokenNotFound),149 })150 }151152 pub fn get_checked_topmost_owner(153 collection: CollectionId,154 token: TokenId,155 for_nest: Option<(CollectionId, TokenId)>,156 budget: &dyn Budget,157 ) -> Result<T::CrossAccountId, DispatchError> {158 // Tried to nest token in itself159 if Some((collection, token)) == for_nest {160 return Err(<Error<T>>::OuroborosDetected.into());161 }162163 for parent in Self::parent_chain(collection, token).take_while(|_| budget.consume()) {164 match parent? {165 // Tried to nest token in chain, which has this token as one of parents166 Parent::Token(collection, token) if Some((collection, token)) == for_nest => {167 return Err(<Error<T>>::OuroborosDetected.into())168 }169 // Token is owned by other user170 Parent::User(user) => return Ok(user),171 Parent::TokenNotFound => return Err(<Error<T>>::TokenNotFound.into()),172 // Continue parent chain173 Parent::Token(_, _) => {}174 }175 }176177 Err(<Error<T>>::DepthLimit.into())178 }179180 pub fn burn_item_recursively(181 from: T::CrossAccountId,182 collection: CollectionId,183 token: TokenId,184 self_budget: &dyn Budget,185 breadth_budget: &dyn Budget,186 ) -> DispatchResultWithPostInfo {187 let handle = <CollectionHandle<T>>::try_get(collection)?;188 let dispatch = T::CollectionDispatch::dispatch(handle);189 let dispatch = dispatch.as_dyn();190 dispatch.burn_item_recursively(from.clone(), token, self_budget, breadth_budget)191 }192193 /// Check if token indirectly owned by specified user194 pub fn check_indirectly_owned(195 user: T::CrossAccountId,196 collection: CollectionId,197 token: TokenId,198 for_nest: Option<(CollectionId, TokenId)>,199 budget: &dyn Budget,200 ) -> Result<bool, DispatchError> {201 let target_parent = match T::CrossTokenAddressMapping::address_to_token(&user) {202 Some((collection, token)) => Self::find_topmost_owner(collection, token, budget)?,203 None => user,204 };205206 Self::get_checked_topmost_owner(collection, token, for_nest, budget)207 .map(|indirect_owner| indirect_owner == target_parent)208 }209210 pub fn check_nesting(211 from: T::CrossAccountId,212 under: &T::CrossAccountId,213 collection_id: CollectionId,214 token_id: TokenId,215 nesting_budget: &dyn Budget,216 ) -> DispatchResult {217 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {218 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)219 })220 }221222 pub fn nest_if_sent_to_token(223 from: T::CrossAccountId,224 under: &T::CrossAccountId,225 collection_id: CollectionId,226 token_id: TokenId,227 nesting_budget: &dyn Budget,228 ) -> DispatchResult {229 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {230 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;231232 collection.nest(parent_id, (collection_id, token_id));233234 Ok(())235 })236 }237238 pub fn nest_if_sent_to_token_unchecked(239 owner: &T::CrossAccountId,240 collection_id: CollectionId,241 token_id: TokenId,242 ) {243 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {244 collection.nest(parent_id, (collection_id, token_id))245 });246 }247248 pub fn unnest_if_nested(249 owner: &T::CrossAccountId,250 collection_id: CollectionId,251 token_id: TokenId,252 ) {253 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {254 collection.unnest(parent_id, (collection_id, token_id))255 });256 }257258 fn exec_if_owner_is_valid_nft(259 account: &T::CrossAccountId,260 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),261 ) {262 Self::try_exec_if_owner_is_valid_nft(account, |collection, id| {263 action(collection, id);264 Ok(())265 })266 .unwrap();267 }268269 fn try_exec_if_owner_is_valid_nft(270 account: &T::CrossAccountId,271 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId) -> DispatchResult,272 ) -> DispatchResult {273 let account = T::CrossTokenAddressMapping::address_to_token(account);274275 if account.is_none() {276 return Ok(());277 }278279 let account = account.unwrap();280281 let handle = <CollectionHandle<T>>::try_get(account.0);282283 if handle.is_err() {284 return Ok(());285 }286287 let handle = handle.unwrap();288289 let dispatch = T::CollectionDispatch::dispatch(handle);290 let dispatch = dispatch.as_dyn();291292 action(dispatch, account.1)293 }294}1#![cfg_attr(not(feature = "std"), no_std)]23use pallet_common::CommonCollectionOperations;4use sp_std::collections::btree_set::BTreeSet;56use frame_support::dispatch::{DispatchError, DispatchResult, DispatchResultWithPostInfo};7use frame_support::fail;8pub use pallet::*;9use pallet_common::{dispatch::CollectionDispatch, CollectionHandle};10use up_data_structs::{CollectionId, TokenId, mapping::TokenAddressMapping, budget::Budget};1112#[cfg(feature = "runtime-benchmarks")]13pub mod benchmarking;14pub mod weights;1516pub type SelfWeightOf<T> = <T as crate::Config>::WeightInfo;1718#[frame_support::pallet]19pub mod pallet {20 use frame_support::Parameter;21 use frame_support::dispatch::{GetDispatchInfo, UnfilteredDispatchable};22 use frame_support::pallet_prelude::*;2324 use super::*;2526 #[pallet::error]27 pub enum Error<T> {28 /// While searching for the owner, encountered an already checked account, detecting a loop.29 OuroborosDetected,30 /// While searching for the owner, reached the depth limit.31 DepthLimit,32 /// While iterating over children, reached the breadth limit.33 BreadthLimit,34 /// Couldn't find the token owner that is itself a token.35 TokenNotFound,36 }3738 #[pallet::event]39 pub enum Event<T> {40 /// Executed call on behalf of the token.41 Executed(DispatchResult),42 }4344 #[pallet::config]45 pub trait Config: frame_system::Config + pallet_common::Config {46 type WeightInfo: weights::WeightInfo;47 type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;48 type Call: Parameter + UnfilteredDispatchable<Origin = Self::Origin> + GetDispatchInfo;49 }5051 #[pallet::pallet]52 pub struct Pallet<T>(_);5354 #[pallet::call]55 impl<T: Config> Pallet<T> {56 // #[pallet::weight({57 // let dispatch_info = call.get_dispatch_info();5859 // (60 // dispatch_info.weight61 // // Cost of dereferencing parent62 // .saturating_add(T::DbWeight::get().reads(2 * *max_depth as Weight))63 // .saturating_add(4000 * *max_depth as Weight),64 // dispatch_info.class)65 // })]66 // pub fn execute(67 // origin: OriginFor<T>,68 // call: Box<<T as Config>::Call>,69 // max_depth: u32,70 // ) -> DispatchResult {71 }72}7374#[derive(PartialEq)]75pub enum Parent<CrossAccountId> {76 /// Token owned by a normal account.77 User(CrossAccountId),78 /// Could not find the token provided as the owner.79 TokenNotFound,80 /// Token owner is another token (still, the target token may not exist).81 Token(CollectionId, TokenId),82}8384impl<T: Config> Pallet<T> {85 pub fn find_parent(86 collection: CollectionId,87 token: TokenId,88 ) -> Result<Parent<T::CrossAccountId>, DispatchError> {89 // TODO: Reduce cost by not reading collection config90 let handle = match CollectionHandle::try_get(collection) {91 Ok(v) => v,92 Err(_) => return Ok(Parent::TokenNotFound),93 };94 let handle = T::CollectionDispatch::dispatch(handle);95 let handle = handle.as_dyn();9697 Ok(match handle.token_owner(token) {98 Some(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {99 Some((collection, token)) => Parent::Token(collection, token),100 None => Parent::User(owner),101 },102 None => Parent::TokenNotFound,103 })104 }105106 pub fn parent_chain(107 mut collection: CollectionId,108 mut token: TokenId,109 ) -> impl Iterator<Item = Result<Parent<T::CrossAccountId>, DispatchError>> {110 let mut finished = false;111 let mut visited = BTreeSet::new();112 visited.insert((collection, token));113 core::iter::from_fn(move || {114 if finished {115 return None;116 }117 let parent = Self::find_parent(collection, token);118 match parent {119 Ok(Parent::Token(new_collection, new_token)) => {120 collection = new_collection;121 token = new_token;122 if !visited.insert((new_collection, new_token)) {123 finished = true;124 return Some(Err(<Error<T>>::OuroborosDetected.into()));125 }126 }127 _ => finished = true,128 }129 Some(parent as Result<_, DispatchError>)130 })131 }132133 /// Try to dereference address, until finding top level owner134 ///135 /// May return token address if parent token not yet exists136 pub fn find_topmost_owner(137 collection: CollectionId,138 token: TokenId,139 budget: &dyn Budget,140 ) -> Result<T::CrossAccountId, DispatchError> {141 let owner = Self::parent_chain(collection, token)142 .take_while(|_| budget.consume())143 .find(|p| matches!(p, Ok(Parent::User(_) | Parent::TokenNotFound)))144 .ok_or(<Error<T>>::DepthLimit)??;145146 Ok(match owner {147 Parent::User(v) => v,148 _ => fail!(<Error<T>>::TokenNotFound),149 })150 }151152 pub fn get_checked_topmost_owner(153 collection: CollectionId,154 token: TokenId,155 for_nest: Option<(CollectionId, TokenId)>,156 budget: &dyn Budget,157 ) -> Result<T::CrossAccountId, DispatchError> {158 // Tried to nest token in itself159 if Some((collection, token)) == for_nest {160 return Err(<Error<T>>::OuroborosDetected.into());161 }162163 for parent in Self::parent_chain(collection, token).take_while(|_| budget.consume()) {164 match parent? {165 // Tried to nest token in chain, which has this token as one of parents166 Parent::Token(collection, token) if Some((collection, token)) == for_nest => {167 return Err(<Error<T>>::OuroborosDetected.into())168 }169 // Token is owned by other user170 Parent::User(user) => return Ok(user),171 Parent::TokenNotFound => return Err(<Error<T>>::TokenNotFound.into()),172 // Continue parent chain173 Parent::Token(_, _) => {}174 }175 }176177 Err(<Error<T>>::DepthLimit.into())178 }179180 pub fn burn_item_recursively(181 from: T::CrossAccountId,182 collection: CollectionId,183 token: TokenId,184 self_budget: &dyn Budget,185 breadth_budget: &dyn Budget,186 ) -> DispatchResultWithPostInfo {187 let handle = <CollectionHandle<T>>::try_get(collection)?;188 let dispatch = T::CollectionDispatch::dispatch(handle);189 let dispatch = dispatch.as_dyn();190 dispatch.burn_item_recursively(from.clone(), token, self_budget, breadth_budget)191 }192193 /// Check if token indirectly owned by specified user194 pub fn check_indirectly_owned(195 user: T::CrossAccountId,196 collection: CollectionId,197 token: TokenId,198 for_nest: Option<(CollectionId, TokenId)>,199 budget: &dyn Budget,200 ) -> Result<bool, DispatchError> {201 let target_parent = match T::CrossTokenAddressMapping::address_to_token(&user) {202 Some((collection, token)) => Self::find_topmost_owner(collection, token, budget)?,203 None => user,204 };205206 Self::get_checked_topmost_owner(collection, token, for_nest, budget)207 .map(|indirect_owner| indirect_owner == target_parent)208 }209210 pub fn check_nesting(211 from: T::CrossAccountId,212 under: &T::CrossAccountId,213 collection_id: CollectionId,214 token_id: TokenId,215 nesting_budget: &dyn Budget,216 ) -> DispatchResult {217 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {218 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)219 })220 }221222 pub fn nest_if_sent_to_token(223 from: T::CrossAccountId,224 under: &T::CrossAccountId,225 collection_id: CollectionId,226 token_id: TokenId,227 nesting_budget: &dyn Budget,228 ) -> DispatchResult {229 Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {230 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;231232 collection.nest(parent_id, (collection_id, token_id));233234 Ok(())235 })236 }237238 pub fn nest_if_sent_to_token_unchecked(239 owner: &T::CrossAccountId,240 collection_id: CollectionId,241 token_id: TokenId,242 ) {243 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {244 collection.nest(parent_id, (collection_id, token_id))245 });246 }247248 pub fn unnest_if_nested(249 owner: &T::CrossAccountId,250 collection_id: CollectionId,251 token_id: TokenId,252 ) {253 Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {254 collection.unnest(parent_id, (collection_id, token_id))255 });256 }257258 fn exec_if_owner_is_valid_nft(259 account: &T::CrossAccountId,260 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),261 ) {262 Self::try_exec_if_owner_is_valid_nft(account, |collection, id| {263 action(collection, id);264 Ok(())265 })266 .unwrap();267 }268269 fn try_exec_if_owner_is_valid_nft(270 account: &T::CrossAccountId,271 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId) -> DispatchResult,272 ) -> DispatchResult {273 let account = T::CrossTokenAddressMapping::address_to_token(account);274275 if account.is_none() {276 return Ok(());277 }278279 let account = account.unwrap();280281 let handle = <CollectionHandle<T>>::try_get(account.0);282283 if handle.is_err() {284 return Ok(());285 }286287 let handle = handle.unwrap();288289 let dispatch = T::CollectionDispatch::dispatch(handle);290 let dispatch = dispatch.as_dyn();291292 action(dispatch, account.1)293 }294}primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -286,7 +286,7 @@
}
}
-/// Collection parameters, used in storage (see [`RpcCollection`] for the RPC version)
+/// Collection parameters, used in storage (see [`RpcCollection`] for the RPC version).
#[struct_versioning::versioned(version = 2, upper)]
#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
pub struct Collection<AccountId> {
@@ -327,7 +327,7 @@
pub meta_update_permission: MetaUpdatePermission,
}
-/// Collection parameters, used in RPC calls (see [`Collection`] for the storage version)
+/// Collection parameters, used in RPC calls (see [`Collection`] for the storage version).
#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct RpcCollection<AccountId> {
@@ -568,7 +568,7 @@
ReFungible(CreateReFungibleData),
}
-/// Explicit NFT creation data with meta parameters
+/// Explicit NFT creation data with meta parameters.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
#[derivative(Debug)]
pub struct CreateNftExData<CrossAccountId> {
@@ -577,7 +577,7 @@
pub owner: CrossAccountId,
}
-/// Explicit RFT creation data with meta parameters
+/// Explicit RFT creation data with meta parameters.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
pub struct CreateRefungibleExData<CrossAccountId> {
@@ -587,7 +587,7 @@
pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,
}
-/// Explicit item creation data with meta parameters, namely the owner
+/// Explicit item creation data with meta parameters, namely the owner.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
pub enum CreateItemExData<CrossAccountId> {
@@ -635,7 +635,7 @@
}
}
-/// Token's address, dictated by its collection and token IDs
+/// Token's address, dictated by its collection and token IDs.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
// todo possibly rename to be used generally as an address pair