From 415353264b69509a8cf417981a4e2b8de4ff6423 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 30 May 2022 14:54:51 +0000 Subject: [PATCH] style: reformat code --- --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -30,8 +30,7 @@ // RMRK use rmrk_rpc::RmrkApi as RmrkRuntimeApi; use up_data_structs::{ - RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, - RmrkResourceId, + RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkResourceId, }; pub use rmrk_unique_rpc::RmrkApi; --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -364,7 +364,8 @@ RmrkBaseInfo, RmrkPartType, RmrkTheme, - >*/ + substrate_frame_rpc_system::AccountNonceApi + >*/ + + substrate_frame_rpc_system::AccountNonceApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi + cumulus_primitives_core::CollectCollationInfo, @@ -656,7 +657,8 @@ RmrkBaseInfo, RmrkPartType, RmrkTheme, - >*/ + substrate_frame_rpc_system::AccountNonceApi + >*/ + + substrate_frame_rpc_system::AccountNonceApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi + cumulus_primitives_core::CollectCollationInfo @@ -800,7 +802,8 @@ RmrkBaseInfo, RmrkPartType, RmrkTheme, - >*/ + substrate_frame_rpc_system::AccountNonceApi + >*/ + + substrate_frame_rpc_system::AccountNonceApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi + cumulus_primitives_core::CollectCollationInfo --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -501,7 +501,6 @@ PhantomType<( TokenData, RpcCollection, - // RMRK RmrkCollectionInfo, RmrkInstanceInfo, @@ -526,19 +525,34 @@ if !v.offchain_schema.is_empty() { props.push(Property { key: b"_old_offchainSchema".to_vec().try_into().unwrap(), - value: v.offchain_schema.clone().into_inner().try_into().expect("offchain schema too big"), + value: v + .offchain_schema + .clone() + .into_inner() + .try_into() + .expect("offchain schema too big"), }); } if !v.variable_on_chain_schema.is_empty() { props.push(Property { key: b"_old_variableOnChainSchema".to_vec().try_into().unwrap(), - value: v.variable_on_chain_schema.clone().into_inner().try_into().expect("offchain schema too big"), + value: v + .variable_on_chain_schema + .clone() + .into_inner() + .try_into() + .expect("offchain schema too big"), }); } if !v.const_on_chain_schema.is_empty() { props.push(Property { key: b"_old_constOnChainSchema".to_vec().try_into().unwrap(), - value: v.const_on_chain_schema.clone().into_inner().try_into().expect("offchain schema too big"), + value: v + .const_on_chain_schema + .clone() + .into_inner() + .try_into() + .expect("offchain schema too big"), }); } props.push(Property { @@ -546,13 +560,17 @@ value: match v.schema_version { SchemaVersion::ImageURL => b"ImageUrl".as_slice(), SchemaVersion::Unique => b"Unique".as_slice(), - }.to_vec().try_into().unwrap(), + } + .to_vec() + .try_into() + .unwrap(), }); Self::set_scoped_collection_properties( id, PropertyScope::None, props.into_iter(), - ).expect("existing data larger than properties"); + ) + .expect("existing data larger than properties"); let mut new = CollectionVersion2::from(v.clone()); new.permissions.access = Some(v.access); new.permissions.mint_mode = Some(v.mint_mode); @@ -644,18 +662,12 @@ let token_property_permissions = >::get(collection) .into_iter() - .map(|(key, permission)| PropertyKeyPermission { - key, - permission, - }) + .map(|(key, permission)| PropertyKeyPermission { key, permission }) .collect(); let properties = >::get(collection) .into_iter() - .map(|(key, value)| Property { - key, - value, - }) + .map(|(key, value)| Property { key, value }) .collect(); let permissions = CollectionPermissions { @@ -751,7 +763,9 @@ .unwrap_or_else(|| Ok(CollectionLimits::default()))?, permissions: data .permissions - .map(|permissions| Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)) + .map(|permissions| { + Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions) + }) .unwrap_or_else(|| Ok(CollectionPermissions::default()))?, }; @@ -1005,10 +1019,7 @@ .unwrap_or_else(|| { properties .into_iter() - .map(|(key, value)| Property { - key, - value, - }) + .map(|(key, value)| Property { key, value }) .collect() }); @@ -1037,10 +1048,7 @@ .unwrap_or_else(|| { permissions .into_iter() - .map(|(key, permission)| PropertyKeyPermission { - key, - permission, - }) + .map(|(key, permission)| PropertyKeyPermission { key, permission }) .collect() }); @@ -1276,17 +1284,9 @@ budget: &dyn Budget, ) -> DispatchResult; - fn nest( - &self, - under: TokenId, - to_nest: (CollectionId, TokenId) - ); + fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId)); - fn unnest( - &self, - under: TokenId, - to_nest: (CollectionId, TokenId) - ); + fn unnest(&self, under: TokenId, to_nest: (CollectionId, TokenId)); fn account_tokens(&self, account: T::CrossAccountId) -> Vec; fn collection_tokens(&self) -> Vec; --- a/pallets/fungible/src/common.rs +++ b/pallets/fungible/src/common.rs @@ -298,17 +298,9 @@ fail!(>::FungibleDisallowsNesting) } - fn nest( - &self, - _under: TokenId, - _to_nest: (CollectionId, TokenId) - ) {} + fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {} - fn unnest( - &self, - _under: TokenId, - _to_nest: (CollectionId, TokenId) - ) {} + fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {} fn collection_tokens(&self) -> Vec { vec![TokenId::default()] --- a/pallets/fungible/src/lib.rs +++ b/pallets/fungible/src/lib.rs @@ -184,11 +184,7 @@ if balance == 0 { >::remove((collection.id, owner)); - >::unnest_if_nested( - owner, - collection.id, - TokenId::default() - ); + >::unnest_if_nested(owner, collection.id, TokenId::default()); } else { >::insert((collection.id, owner), balance); } @@ -249,18 +245,14 @@ to, collection.id, TokenId::default(), - nesting_budget + nesting_budget, )?; if let Some(balance_to) = balance_to { // from != to if balance_from == 0 { >::remove((collection.id, from)); - >::unnest_if_nested( - from, - collection.id, - TokenId::default() - ); + >::unnest_if_nested(from, collection.id, TokenId::default()); } else { >::insert((collection.id, from), balance_from); } @@ -333,7 +325,11 @@ >::insert(collection.id, total_supply); for (user, amount) in balances { >::insert((collection.id, &user), amount); - >::nest_if_sent_to_token_unchecked(&user, collection.id, TokenId::default()); + >::nest_if_sent_to_token_unchecked( + &user, + collection.id, + TokenId::default(), + ); >::deposit_log( ERC20Events::Transfer { from: H160::default(), --- a/pallets/nonfungible/src/common.rs +++ b/pallets/nonfungible/src/common.rs @@ -22,7 +22,7 @@ PropertyKeyPermission, PropertyValue, }; use pallet_common::{ - CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _ + CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _, }; use sp_runtime::DispatchError; use sp_std::vec::Vec; @@ -353,19 +353,11 @@ >::check_nesting(self, sender, from, under, budget) } - fn nest( - &self, - under: TokenId, - to_nest: (CollectionId, TokenId) - ) { + fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId)) { >::nest((self.id, under), to_nest); } - fn unnest( - &self, - under: TokenId, - to_unnest: (CollectionId, TokenId) - ) { + fn unnest(&self, under: TokenId, to_unnest: (CollectionId, TokenId)) { >::unnest((self.id, under), to_unnest); } @@ -415,10 +407,7 @@ .unwrap_or_else(|| { properties .into_iter() - .map(|(key, value)| Property { - key, - value, - }) + .map(|(key, value)| Property { key, value }) .collect() }) } --- a/pallets/nonfungible/src/erc.rs +++ b/pallets/nonfungible/src/erc.rs @@ -426,11 +426,10 @@ Ok(a) } -fn has_token_permission( - collection_id: CollectionId, - key: &PropertyKey, -) -> bool { - if let Ok(token_property_permissions) = CollectionPropertyPermissions::::try_get(collection_id) { +fn has_token_permission(collection_id: CollectionId, key: &PropertyKey) -> bool { + if let Ok(token_property_permissions) = + CollectionPropertyPermissions::::try_get(collection_id) + { return token_property_permissions.contains_key(key); } --- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -164,31 +164,44 @@ fn on_runtime_upgrade() -> Weight { if StorageVersion::get::>() < StorageVersion::new(1) { let mut had_consts = BTreeSet::new(); - >::translate::, _>(|(collection, token), v| { - let mut props = vec![]; - if !v.const_data.is_empty() { - props.push(Property { - key: b"_old_constData".to_vec().try_into().unwrap(), - value: v.const_data.clone().into_inner().try_into().expect("const too long"), - }); - had_consts.insert(collection); - } - if !v.variable_data.is_empty() { - props.push(Property { - key: b"_old_variableData".to_vec().try_into().unwrap(), - value: v.variable_data.clone().into_inner().try_into().expect("variable too long"), - }) - } - if !props.is_empty() { - Self::set_scoped_token_properties( - collection, - token, - PropertyScope::None, - props.into_iter(), - ).expect("existing token data exceeds property storage"); - } - Some(>::from(v)) - }); + >::translate::, _>( + |(collection, token), v| { + let mut props = vec![]; + if !v.const_data.is_empty() { + props.push(Property { + key: b"_old_constData".to_vec().try_into().unwrap(), + value: v + .const_data + .clone() + .into_inner() + .try_into() + .expect("const too long"), + }); + had_consts.insert(collection); + } + if !v.variable_data.is_empty() { + props.push(Property { + key: b"_old_variableData".to_vec().try_into().unwrap(), + value: v + .variable_data + .clone() + .into_inner() + .try_into() + .expect("variable too long"), + }) + } + if !props.is_empty() { + Self::set_scoped_token_properties( + collection, + token, + PropertyScope::None, + props.into_iter(), + ) + .expect("existing token data exceeds property storage"); + } + Some(>::from(v)) + }, + ); for collection in had_consts { >::set_property_permission_unchecked( collection, @@ -199,8 +212,9 @@ collection_admin: true, token_owner: false, }, - } - ).expect("failed to configure permission"); + }, + ) + .expect("failed to configure permission"); } } @@ -263,7 +277,7 @@ collection_id: CollectionId, token_id: TokenId, scope: PropertyScope, - properties: impl Iterator, + properties: impl Iterator, ) -> DispatchResult { TokenProperties::::try_mutate((collection_id, token_id), |stored_properties| { stored_properties.try_scoped_set_from_iter(scope, properties) @@ -347,11 +361,7 @@ >::insert((collection.id, token_data.owner.clone()), balance); } - >::unnest_if_nested( - &token_data.owner, - collection.id, - token - ); + >::unnest_if_nested(&token_data.owner, collection.id, token); >::remove((collection.id, &token_data.owner, token)); >::insert(collection.id, burnt); @@ -589,16 +599,12 @@ to, collection.id, token, - nesting_budget + nesting_budget, )?; // ========= - >::unnest_if_nested( - from, - collection.id, - token - ); + >::unnest_if_nested(from, collection.id, token); >::insert( (collection.id, token), @@ -709,7 +715,11 @@ }, ); - >::nest_if_sent_to_token_unchecked(&data.owner, collection.id, TokenId(token)); + >::nest_if_sent_to_token_unchecked( + &data.owner, + collection.id, + TokenId(token), + ); if let Err(e) = Self::set_token_properties( collection, @@ -958,31 +968,24 @@ Ok(()) } - fn nest( - under: (CollectionId, TokenId), - to_nest: (CollectionId, TokenId), - ) { - >::insert( - (under.0, under.1, (to_nest.0, to_nest.1)), - true - ); + fn nest(under: (CollectionId, TokenId), to_nest: (CollectionId, TokenId)) { + >::insert((under.0, under.1, (to_nest.0, to_nest.1)), true); } - fn unnest( - under: (CollectionId, TokenId), - to_unnest: (CollectionId, TokenId), - ) { - >::remove( - (under.0, under.1, to_unnest) - ); + fn unnest(under: (CollectionId, TokenId), to_unnest: (CollectionId, TokenId)) { + >::remove((under.0, under.1, to_unnest)); } fn collection_has_tokens(collection_id: CollectionId) -> bool { - >::iter_prefix((collection_id,)).next().is_some() + >::iter_prefix((collection_id,)) + .next() + .is_some() } fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool { - >::iter_prefix((collection_id, token_id)).next().is_some() + >::iter_prefix((collection_id, token_id)) + .next() + .is_some() } /// Delegated to `create_multiple_items` --- a/pallets/proxy-rmrk-core/src/lib.rs +++ b/pallets/proxy-rmrk-core/src/lib.rs @@ -21,7 +21,9 @@ use sp_runtime::{DispatchError, Permill, traits::StaticLookup}; use sp_std::vec::Vec; use up_data_structs::*; -use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations}; +use pallet_common::{ + Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations, +}; use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle, TokenData}; use pallet_evm::account::CrossAccountId; use core::convert::AsRef; @@ -38,18 +40,17 @@ #[frame_support::pallet] pub mod pallet { - use super::*; - use pallet_evm::account; + use super::*; + use pallet_evm::account; #[pallet::config] - pub trait Config: frame_system::Config - + pallet_common::Config - + pallet_nonfungible::Config - + account::Config { + pub trait Config: + frame_system::Config + pallet_common::Config + pallet_nonfungible::Config + account::Config + { type Event: From> + IsType<::Event>; } - #[pallet::storage] + #[pallet::storage] #[pallet::getter(fn collection_index)] pub type CollectionIndex = StorageValue<_, RmrkCollectionId, ValueQuery>; @@ -60,33 +61,33 @@ #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - CollectionCreated { + CollectionCreated { issuer: T::AccountId, collection_id: RmrkCollectionId, }, - CollectionDestroyed { + CollectionDestroyed { issuer: T::AccountId, collection_id: RmrkCollectionId, }, - IssuerChanged { + IssuerChanged { old_issuer: T::AccountId, new_issuer: T::AccountId, collection_id: RmrkCollectionId, }, - CollectionLocked { + CollectionLocked { issuer: T::AccountId, collection_id: RmrkCollectionId, }, - NftMinted { + NftMinted { owner: T::AccountId, collection_id: RmrkCollectionId, nft_id: RmrkNftId, }, - NFTBurned { + NFTBurned { owner: T::AccountId, nft_id: RmrkNftId, }, - PropertySet { + PropertySet { collection_id: RmrkCollectionId, maybe_nft_id: Option, key: RmrkKeyString, @@ -96,24 +97,24 @@ #[pallet::error] pub enum Error { - /* Unique-specific events */ - CorruptedCollectionType, - NftTypeEncodeError, - RmrkPropertyKeyIsTooLong, - RmrkPropertyValueIsTooLong, + /* Unique-specific events */ + CorruptedCollectionType, + NftTypeEncodeError, + RmrkPropertyKeyIsTooLong, + RmrkPropertyValueIsTooLong, - /* RMRK compatible events */ - CollectionNotEmpty, - NoAvailableCollectionId, - NoAvailableNftId, - CollectionUnknown, - NoPermission, - CollectionFullOrLocked, + /* RMRK compatible events */ + CollectionNotEmpty, + NoAvailableCollectionId, + NoAvailableNftId, + CollectionUnknown, + NoPermission, + CollectionFullOrLocked, } #[pallet::call] impl Pallet { - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] #[transactional] pub fn create_collection( origin: OriginFor, @@ -121,127 +122,141 @@ max: Option, symbol: RmrkCollectionSymbol, ) -> DispatchResult { - let sender = ensure_signed(origin)?; + let sender = ensure_signed(origin)?; - let limits = CollectionLimits { - owner_can_transfer: Some(false), - token_limit: max, - ..Default::default() - }; + let limits = CollectionLimits { + owner_can_transfer: Some(false), + token_limit: max, + ..Default::default() + }; - let data = CreateCollectionData { - limits: Some(limits), - token_prefix: symbol.into_inner() - .try_into() - .map_err(|_| >::CollectionTokenPrefixLimitExceeded)?, - ..Default::default() - }; + let data = CreateCollectionData { + limits: Some(limits), + token_prefix: symbol + .into_inner() + .try_into() + .map_err(|_| >::CollectionTokenPrefixLimitExceeded)?, + ..Default::default() + }; - let collection_id_res = >::init_collection(sender.clone(), data); + let collection_id_res = >::init_collection(sender.clone(), data); - if let Err(DispatchError::Arithmetic(_)) = &collection_id_res { - return Err(>::NoAvailableCollectionId.into()); - } + if let Err(DispatchError::Arithmetic(_)) = &collection_id_res { + return Err(>::NoAvailableCollectionId.into()); + } - let collection_id = collection_id_res?; + let collection_id = collection_id_res?; - >::set_scoped_collection_properties( - collection_id, - PropertyScope::Rmrk, - [ - Self::rmrk_property(Metadata, &metadata)?, - Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?, - ].into_iter() - )?; + >::set_scoped_collection_properties( + collection_id, + PropertyScope::Rmrk, + [ + Self::rmrk_property(Metadata, &metadata)?, + Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?, + ] + .into_iter(), + )?; - >::mutate(|n| *n += 1); + >::mutate(|n| *n += 1); - Self::deposit_event(Event::CollectionCreated { - issuer: sender, - collection_id: collection_id.0 - }); + Self::deposit_event(Event::CollectionCreated { + issuer: sender, + collection_id: collection_id.0, + }); - Ok(()) - } + Ok(()) + } - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] #[transactional] pub fn destroy_collection( origin: OriginFor, collection_id: RmrkCollectionId, ) -> DispatchResult { - let sender = ensure_signed(origin)?; - let cross_sender = T::CrossAccountId::from_sub(sender.clone()); + let sender = ensure_signed(origin)?; + let cross_sender = T::CrossAccountId::from_sub(sender.clone()); - let unique_collection_id = collection_id.into(); + let unique_collection_id = collection_id.into(); - let collection = Self::get_typed_nft_collection(unique_collection_id, misc::CollectionType::Regular)?; + let collection = Self::get_typed_nft_collection( + unique_collection_id, + misc::CollectionType::Regular, + )?; - ensure!(collection.total_supply() == 0, >::CollectionNotEmpty); + ensure!( + collection.total_supply() == 0, + >::CollectionNotEmpty + ); - >::destroy_collection(collection, &cross_sender) - .map_err(Self::map_common_err_to_proxy)?; + >::destroy_collection(collection, &cross_sender) + .map_err(Self::map_common_err_to_proxy)?; - Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id }); + Self::deposit_event(Event::CollectionDestroyed { + issuer: sender, + collection_id, + }); - Ok(()) - } + Ok(()) + } - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] #[transactional] pub fn change_collection_issuer( origin: OriginFor, collection_id: RmrkCollectionId, new_issuer: ::Source, ) -> DispatchResult { - let sender = ensure_signed(origin)?; + let sender = ensure_signed(origin)?; - let new_issuer = T::Lookup::lookup(new_issuer)?; + let new_issuer = T::Lookup::lookup(new_issuer)?; - Self::change_collection_owner( - collection_id.into(), - misc::CollectionType::Regular, - sender.clone(), - new_issuer.clone() - )?; + Self::change_collection_owner( + collection_id.into(), + misc::CollectionType::Regular, + sender.clone(), + new_issuer.clone(), + )?; - Self::deposit_event(Event::IssuerChanged { + Self::deposit_event(Event::IssuerChanged { old_issuer: sender, new_issuer, collection_id, }); - Ok(()) - } + Ok(()) + } - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] #[transactional] pub fn lock_collection( origin: OriginFor, collection_id: RmrkCollectionId, ) -> DispatchResult { - let sender = ensure_signed(origin)?; - let cross_sender = T::CrossAccountId::from_sub(sender.clone()); + let sender = ensure_signed(origin)?; + let cross_sender = T::CrossAccountId::from_sub(sender.clone()); - let collection = Self::get_typed_nft_collection( - collection_id.into(), - misc::CollectionType::Regular - )?; + let collection = Self::get_typed_nft_collection( + collection_id.into(), + misc::CollectionType::Regular, + )?; - Self::check_collection_owner(&collection, &cross_sender)?; + Self::check_collection_owner(&collection, &cross_sender)?; - let token_count = collection.total_supply(); + let token_count = collection.total_supply(); - let mut collection = collection.into_inner(); - collection.limits.token_limit = Some(token_count); - collection.save()?; + let mut collection = collection.into_inner(); + collection.limits.token_limit = Some(token_count); + collection.save()?; - Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id }); + Self::deposit_event(Event::CollectionLocked { + issuer: sender, + collection_id, + }); - Ok(()) - } + Ok(()) + } - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] #[transactional] pub fn mint_nft( origin: OriginFor, @@ -251,47 +266,49 @@ royalty_amount: Option, metadata: RmrkString, ) -> DispatchResult { - let sender = ensure_signed(origin)?; - let sender = T::CrossAccountId::from_sub(sender); - let cross_owner = T::CrossAccountId::from_sub(owner.clone()); + let sender = ensure_signed(origin)?; + let sender = T::CrossAccountId::from_sub(sender); + let cross_owner = T::CrossAccountId::from_sub(owner.clone()); - let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo { - recipient: recipient.unwrap_or_else(|| owner.clone()), - amount - }); + let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo { + recipient: recipient.unwrap_or_else(|| owner.clone()), + amount, + }); - let collection = Self::get_typed_nft_collection( - collection_id.into(), - misc::CollectionType::Regular, - )?; + let collection = Self::get_typed_nft_collection( + collection_id.into(), + misc::CollectionType::Regular, + )?; - let nft_id = Self::create_nft( - &sender, - &cross_owner, - &collection, - NftType::Regular, - [ - Self::rmrk_property(RoyaltyInfo, &royalty_info)?, - Self::rmrk_property(Metadata, &metadata)?, - Self::rmrk_property(Equipped, &false)?, - Self::rmrk_property(ResourceCollection, &None::)?, - Self::rmrk_property(ResourcePriorities, &>::new())?, - ].into_iter() - ).map_err(|err| match err { - DispatchError::Arithmetic(_) => >::NoAvailableNftId.into(), - err => Self::map_common_err_to_proxy(err) - })?; + let nft_id = Self::create_nft( + &sender, + &cross_owner, + &collection, + NftType::Regular, + [ + Self::rmrk_property(RoyaltyInfo, &royalty_info)?, + Self::rmrk_property(Metadata, &metadata)?, + Self::rmrk_property(Equipped, &false)?, + Self::rmrk_property(ResourceCollection, &None::)?, + Self::rmrk_property(ResourcePriorities, &>::new())?, + ] + .into_iter(), + ) + .map_err(|err| match err { + DispatchError::Arithmetic(_) => >::NoAvailableNftId.into(), + err => Self::map_common_err_to_proxy(err), + })?; - Self::deposit_event(Event::NftMinted { - owner, - collection_id, - nft_id: nft_id.0 - }); + Self::deposit_event(Event::NftMinted { + owner, + collection_id, + nft_id: nft_id.0, + }); - Ok(()) - } + Ok(()) + } - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] #[transactional] pub fn burn_nft( origin: OriginFor, @@ -299,21 +316,24 @@ nft_id: RmrkNftId, ) -> DispatchResult { let sender = ensure_signed(origin)?; - let cross_sender = T::CrossAccountId::from_sub(sender.clone()); + let cross_sender = T::CrossAccountId::from_sub(sender.clone()); - Self::destroy_nft( - cross_sender, - collection_id.into(), - misc::CollectionType::Regular, - nft_id.into() - )?; + Self::destroy_nft( + cross_sender, + collection_id.into(), + misc::CollectionType::Regular, + nft_id.into(), + )?; - Self::deposit_event(Event::NFTBurned { owner: sender, nft_id }); + Self::deposit_event(Event::NFTBurned { + owner: sender, + nft_id, + }); - Ok(()) - } + Ok(()) + } - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] #[transactional] pub fn set_property( origin: OriginFor, @@ -322,323 +342,346 @@ key: RmrkKeyString, value: RmrkValueString, ) -> DispatchResult { - let sender = ensure_signed(origin)?; - let sender = T::CrossAccountId::from_sub(sender); + let sender = ensure_signed(origin)?; + let sender = T::CrossAccountId::from_sub(sender); - let collection_id: CollectionId = rmrk_collection_id.into(); + let collection_id: CollectionId = rmrk_collection_id.into(); - match maybe_nft_id { - Some(nft_id) => { - let token_id: TokenId = nft_id.into(); + match maybe_nft_id { + Some(nft_id) => { + let token_id: TokenId = nft_id.into(); - Self::ensure_nft_owner(collection_id, token_id, &sender)?; - Self::ensure_nft_type(collection_id, token_id, NftType::Regular)?; + Self::ensure_nft_owner(collection_id, token_id, &sender)?; + Self::ensure_nft_type(collection_id, token_id, NftType::Regular)?; - >::set_scoped_token_property( - collection_id, - token_id, - PropertyScope::Rmrk, - Self::rmrk_property(UserProperty(key.as_slice()), &value)? - )?; - }, - None => { - let collection = Self::get_typed_nft_collection( - collection_id, - misc::CollectionType::Regular - )?; + >::set_scoped_token_property( + collection_id, + token_id, + PropertyScope::Rmrk, + Self::rmrk_property(UserProperty(key.as_slice()), &value)?, + )?; + } + None => { + let collection = Self::get_typed_nft_collection( + collection_id, + misc::CollectionType::Regular, + )?; - Self::check_collection_owner(&collection, &sender)?; + Self::check_collection_owner(&collection, &sender)?; - >::set_scoped_collection_property( - collection_id, - PropertyScope::Rmrk, - Self::rmrk_property(UserProperty(key.as_slice()), &value)? - )?; - } - } + >::set_scoped_collection_property( + collection_id, + PropertyScope::Rmrk, + Self::rmrk_property(UserProperty(key.as_slice()), &value)?, + )?; + } + } - Self::deposit_event( - Event::PropertySet { - collection_id: rmrk_collection_id, - maybe_nft_id, - key, - value - } - ); + Self::deposit_event(Event::PropertySet { + collection_id: rmrk_collection_id, + maybe_nft_id, + key, + value, + }); - Ok(()) - } + Ok(()) + } } } impl Pallet { - pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result { - let key = rmrk_key.to_key::()?; + pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result { + let key = rmrk_key.to_key::()?; - let scoped_key = PropertyScope::Rmrk.apply(key) - .map_err(|_| >::RmrkPropertyKeyIsTooLong)?; + let scoped_key = PropertyScope::Rmrk + .apply(key) + .map_err(|_| >::RmrkPropertyKeyIsTooLong)?; - Ok(scoped_key) - } + Ok(scoped_key) + } - pub fn rmrk_property(rmrk_key: RmrkProperty, value: &E) -> Result { - let key = rmrk_key.to_key::()?; + pub fn rmrk_property( + rmrk_key: RmrkProperty, + value: &E, + ) -> Result { + let key = rmrk_key.to_key::()?; - let value = value.encode() - .try_into() - .map_err(|_| >::RmrkPropertyValueIsTooLong)?; + let value = value + .encode() + .try_into() + .map_err(|_| >::RmrkPropertyValueIsTooLong)?; - let property = Property { - key, - value, - }; + let property = Property { key, value }; - Ok(property) - } + Ok(property) + } - pub fn create_nft( - sender: &T::CrossAccountId, - owner: &T::CrossAccountId, - collection: &NonfungibleHandle, - nft_type: NftType, - properties: impl Iterator - ) -> Result { - todo!("store nft type"); - let data = CreateNftExData { - properties: BoundedVec::default(), - owner: owner.clone(), - }; + pub fn create_nft( + sender: &T::CrossAccountId, + owner: &T::CrossAccountId, + collection: &NonfungibleHandle, + nft_type: NftType, + properties: impl Iterator, + ) -> Result { + todo!("store nft type"); + let data = CreateNftExData { + properties: BoundedVec::default(), + owner: owner.clone(), + }; - let budget = budget::Value::new(2); + let budget = budget::Value::new(2); - >::create_item( - collection, - sender, - data, - &budget, - )?; + >::create_item(collection, sender, data, &budget)?; - let nft_id = >::current_token_id(collection.id); + let nft_id = >::current_token_id(collection.id); - >::set_scoped_token_properties( - collection.id, - nft_id, - PropertyScope::Rmrk, - properties - )?; + >::set_scoped_token_properties( + collection.id, + nft_id, + PropertyScope::Rmrk, + properties, + )?; - Ok(nft_id) - } + Ok(nft_id) + } - fn destroy_nft( - sender: T::CrossAccountId, - collection_id: CollectionId, - collection_type: misc::CollectionType, - token_id: TokenId - ) -> DispatchResult { - let collection = Self::get_typed_nft_collection( - collection_id, - collection_type - )?; + fn destroy_nft( + sender: T::CrossAccountId, + collection_id: CollectionId, + collection_type: misc::CollectionType, + token_id: TokenId, + ) -> DispatchResult { + let collection = Self::get_typed_nft_collection(collection_id, collection_type)?; - >::burn(&collection, &sender, token_id) - .map_err(Self::map_common_err_to_proxy)?; + >::burn(&collection, &sender, token_id) + .map_err(Self::map_common_err_to_proxy)?; - Ok(()) - } + Ok(()) + } - fn change_collection_owner( - collection_id: CollectionId, - collection_type: misc::CollectionType, - sender: T::AccountId, - new_owner: T::AccountId, - ) -> DispatchResult { - let collection = Self::get_typed_nft_collection( - collection_id, - collection_type - )?; - Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?; + fn change_collection_owner( + collection_id: CollectionId, + collection_type: misc::CollectionType, + sender: T::AccountId, + new_owner: T::AccountId, + ) -> DispatchResult { + let collection = Self::get_typed_nft_collection(collection_id, collection_type)?; + Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?; - let mut collection = collection.into_inner(); + let mut collection = collection.into_inner(); - collection.owner = new_owner; - collection.save() - } + collection.owner = new_owner; + collection.save() + } - fn check_collection_owner(collection: &NonfungibleHandle, account: &T::CrossAccountId) -> DispatchResult { - collection.check_is_owner(account) - .map_err(Self::map_common_err_to_proxy) - } + fn check_collection_owner( + collection: &NonfungibleHandle, + account: &T::CrossAccountId, + ) -> DispatchResult { + collection + .check_is_owner(account) + .map_err(Self::map_common_err_to_proxy) + } - pub fn last_collection_idx() -> RmrkCollectionId { - >::get() - } + pub fn last_collection_idx() -> RmrkCollectionId { + >::get() + } - pub fn get_nft_collection(collection_id: CollectionId) -> Result, DispatchError> { - let collection = >::try_get(collection_id) - .map_err(|_| >::CollectionUnknown)?; + pub fn get_nft_collection( + collection_id: CollectionId, + ) -> Result, DispatchError> { + let collection = >::try_get(collection_id) + .map_err(|_| >::CollectionUnknown)?; - match collection.mode { - CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)), - _ => Err(>::CollectionUnknown.into()) - } - } + match collection.mode { + CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)), + _ => Err(>::CollectionUnknown.into()), + } + } - pub fn collection_exists(collection_id: CollectionId) -> bool { - >::try_get(collection_id).is_ok() - } + pub fn collection_exists(collection_id: CollectionId) -> bool { + >::try_get(collection_id).is_ok() + } - pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool { - >::contains_key((collection_id, nft_id)) - } + pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool { + >::contains_key((collection_id, nft_id)) + } - pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result { - let collection_property = >::collection_properties(collection_id) - .get(&Self::rmrk_property_key(key)?) - .ok_or(>::CollectionUnknown)? - .clone(); + pub fn get_collection_property( + collection_id: CollectionId, + key: RmrkProperty, + ) -> Result { + let collection_property = >::collection_properties(collection_id) + .get(&Self::rmrk_property_key(key)?) + .ok_or(>::CollectionUnknown)? + .clone(); - Ok(collection_property) - } + Ok(collection_property) + } - pub fn get_collection_type(collection_id: CollectionId) -> Result { - let value = Self::get_collection_property(collection_id, CollectionType)?; + pub fn get_collection_type( + collection_id: CollectionId, + ) -> Result { + let value = Self::get_collection_property(collection_id, CollectionType)?; - let mut value = value.as_slice(); + let mut value = value.as_slice(); - misc::CollectionType::decode(&mut value) - .map_err(|_| >::CorruptedCollectionType.into()) - } + misc::CollectionType::decode(&mut value) + .map_err(|_| >::CorruptedCollectionType.into()) + } - pub fn ensure_collection_type(collection_id: CollectionId, collection_type: misc::CollectionType) -> DispatchResult { - let actual_type = Self::get_collection_type(collection_id)?; - ensure!(actual_type == collection_type, >::NoPermission); + pub fn ensure_collection_type( + collection_id: CollectionId, + collection_type: misc::CollectionType, + ) -> DispatchResult { + let actual_type = Self::get_collection_type(collection_id)?; + ensure!( + actual_type == collection_type, + >::NoPermission + ); - Ok(()) - } + Ok(()) + } - pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result { - let nft_property = >::token_properties((collection_id, nft_id)) - .get(&Self::rmrk_property_key(key)?) - .ok_or(>::NoAvailableNftId)? - .clone(); + pub fn get_nft_property( + collection_id: CollectionId, + nft_id: TokenId, + key: RmrkProperty, + ) -> Result { + let nft_property = >::token_properties((collection_id, nft_id)) + .get(&Self::rmrk_property_key(key)?) + .ok_or(>::NoAvailableNftId)? + .clone(); - Ok(nft_property) - } + Ok(nft_property) + } - pub fn get_nft_type(_collection_id: CollectionId, _token_id: TokenId) -> Result { - todo!("should get it from properties?") - } + pub fn get_nft_type( + _collection_id: CollectionId, + _token_id: TokenId, + ) -> Result { + todo!("should get it from properties?") + } - pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult { - let actual_type = Self::get_nft_type(collection_id, token_id)?; - ensure!(actual_type == nft_type, >::NoPermission); + pub fn ensure_nft_type( + collection_id: CollectionId, + token_id: TokenId, + nft_type: NftType, + ) -> DispatchResult { + let actual_type = Self::get_nft_type(collection_id, token_id)?; + ensure!(actual_type == nft_type, >::NoPermission); - Ok(()) - } + Ok(()) + } - pub fn ensure_nft_owner( - collection_id: CollectionId, - token_id: TokenId, - possible_owner: &T::CrossAccountId - ) -> DispatchResult { - let token_data = >::get((collection_id, token_id)) - .ok_or(>::NoAvailableNftId)?; + pub fn ensure_nft_owner( + collection_id: CollectionId, + token_id: TokenId, + possible_owner: &T::CrossAccountId, + ) -> DispatchResult { + let token_data = + >::get((collection_id, token_id)).ok_or(>::NoAvailableNftId)?; - ensure!(token_data.owner == *possible_owner, >::NoPermission); + ensure!( + token_data.owner == *possible_owner, + >::NoPermission + ); - Ok(()) - } + Ok(()) + } - pub fn filter_user_properties( - collection_id: CollectionId, - token_id: Option, - filter_keys: Option>, - mapper: Mapper, - ) -> Result, DispatchError> - where - Key: TryFrom + AsRef<[u8]>, - Value: Decode + Default, - Mapper: Fn(Key, Value) -> R - { - filter_keys.map(|keys| { - let properties = keys.into_iter() - .filter_map(|key| { - let key: Key = key.try_into().ok()?; + pub fn filter_user_properties( + collection_id: CollectionId, + token_id: Option, + filter_keys: Option>, + mapper: Mapper, + ) -> Result, DispatchError> + where + Key: TryFrom + AsRef<[u8]>, + Value: Decode + Default, + Mapper: Fn(Key, Value) -> R, + { + filter_keys + .map(|keys| { + let properties = keys + .into_iter() + .filter_map(|key| { + let key: Key = key.try_into().ok()?; - let value = match token_id { - Some(token_id) => Self::get_nft_property( - collection_id, - token_id, - UserProperty(key.as_ref()) - ), - None => Self::get_collection_property( - collection_id, - UserProperty(key.as_ref()) - ) - }.ok()?.decode_or_default(); + let value = match token_id { + Some(token_id) => Self::get_nft_property( + collection_id, + token_id, + UserProperty(key.as_ref()), + ), + None => Self::get_collection_property( + collection_id, + UserProperty(key.as_ref()), + ), + } + .ok()? + .decode_or_default(); - Some(mapper(key, value)) - }) - .collect(); + Some(mapper(key, value)) + }) + .collect(); - Ok(properties) - }).unwrap_or_else(|| { - let properties = Self::iterate_user_properties(collection_id, token_id, mapper)? - .collect(); + Ok(properties) + }) + .unwrap_or_else(|| { + let properties = + Self::iterate_user_properties(collection_id, token_id, mapper)?.collect(); - Ok(properties) - }) - } + Ok(properties) + }) + } - pub fn iterate_user_properties( - collection_id: CollectionId, - token_id: Option, - mapper: Mapper, - ) -> Result, DispatchError> - where - Key: TryFrom + AsRef<[u8]>, - Value: Decode + Default, - Mapper: Fn(Key, Value) -> R - { - let key_prefix = Self::rmrk_property_key(UserProperty(b""))?; + pub fn iterate_user_properties( + collection_id: CollectionId, + token_id: Option, + mapper: Mapper, + ) -> Result, DispatchError> + where + Key: TryFrom + AsRef<[u8]>, + Value: Decode + Default, + Mapper: Fn(Key, Value) -> R, + { + let key_prefix = Self::rmrk_property_key(UserProperty(b""))?; - let properties = match token_id { - Some(token_id) => >::token_properties((collection_id, token_id)), - None => >::collection_properties(collection_id) - }; + let properties = match token_id { + Some(token_id) => >::token_properties((collection_id, token_id)), + None => >::collection_properties(collection_id), + }; - let properties = properties - .into_iter() - .filter_map(move |(key, value)| { - let key = key.as_slice().strip_prefix(key_prefix.as_slice())?; + let properties = properties.into_iter().filter_map(move |(key, value)| { + let key = key.as_slice().strip_prefix(key_prefix.as_slice())?; - let key: Key = key.to_vec().try_into().ok()?; - let value: Value = value.decode_or_default(); + let key: Key = key.to_vec().try_into().ok()?; + let value: Value = value.decode_or_default(); - Some(mapper(key, value)) - }); + Some(mapper(key, value)) + }); - Ok(properties) - } + Ok(properties) + } - pub fn get_typed_nft_collection( - collection_id: CollectionId, - collection_type: misc::CollectionType - ) -> Result, DispatchError> { - Self::ensure_collection_type(collection_id, collection_type)?; + pub fn get_typed_nft_collection( + collection_id: CollectionId, + collection_type: misc::CollectionType, + ) -> Result, DispatchError> { + Self::ensure_collection_type(collection_id, collection_type)?; - Self::get_nft_collection(collection_id) - } + Self::get_nft_collection(collection_id) + } - fn map_common_err_to_proxy(err: DispatchError) -> DispatchError { - map_common_err_to_proxy! { - match err { - NoPermission => NoPermission, - CollectionTokenLimitExceeded => CollectionFullOrLocked, - PublicMintingNotAllowed => NoPermission, - TokenNotFound => NoAvailableNftId - } - } - } + fn map_common_err_to_proxy(err: DispatchError) -> DispatchError { + map_common_err_to_proxy! { + match err { + NoPermission => NoPermission, + CollectionTokenLimitExceeded => CollectionFullOrLocked, + PublicMintingNotAllowed => NoPermission, + TokenNotFound => NoAvailableNftId + } + } + } } --- a/pallets/proxy-rmrk-core/src/misc.rs +++ b/pallets/proxy-rmrk-core/src/misc.rs @@ -15,41 +15,42 @@ } pub trait RmrkDecode { - fn decode_or_default(&self) -> T; + fn decode_or_default(&self) -> T; } impl RmrkDecode for BoundedVec { - fn decode_or_default(&self) -> T { - let mut value = self.as_slice(); + fn decode_or_default(&self) -> T { + let mut value = self.as_slice(); - T::decode(&mut value).unwrap_or_default() - } + T::decode(&mut value).unwrap_or_default() + } } pub trait RmrkRebind { - fn rebind(&self) -> BoundedVec; + fn rebind(&self) -> BoundedVec; } -impl RmrkRebind for BoundedVec where BoundedVec: TryFrom> { - fn rebind(&self) -> BoundedVec { - BoundedVec::::try_from( - self.clone().into_inner() - ).unwrap_or_default() - } +impl RmrkRebind for BoundedVec +where + BoundedVec: TryFrom>, +{ + fn rebind(&self) -> BoundedVec { + BoundedVec::::try_from(self.clone().into_inner()).unwrap_or_default() + } } #[derive(Encode, Decode, PartialEq, Eq)] pub enum CollectionType { - Regular, - Resource, - Base, + Regular, + Resource, + Base, } #[derive(Encode, Decode, PartialEq, Eq)] pub enum NftType { - Regular, - Resource, - FixedPart, - SlotPart, - Theme + Regular, + Resource, + FixedPart, + SlotPart, + Theme, } --- a/pallets/proxy-rmrk-core/src/property.rs +++ b/pallets/proxy-rmrk-core/src/property.rs @@ -2,38 +2,38 @@ use core::convert::AsRef; pub enum RmrkProperty<'r> { - Metadata, - CollectionType, - RoyaltyInfo, - Equipped, - ResourceCollection, - ResourcePriorities, - ResourceType, - PendingResourceAccept, - PendingResourceRemoval, - Parts, - Base, - Src, - Slot, - License, - Thumb, - EquippedNft, - BaseType, - ExternalPartId, - EquippableList, - ZIndex, - ThemeName, - ThemeInherit, - UserProperty(&'r [u8]), + Metadata, + CollectionType, + RoyaltyInfo, + Equipped, + ResourceCollection, + ResourcePriorities, + ResourceType, + PendingResourceAccept, + PendingResourceRemoval, + Parts, + Base, + Src, + Slot, + License, + Thumb, + EquippedNft, + BaseType, + ExternalPartId, + EquippableList, + ZIndex, + ThemeName, + ThemeInherit, + UserProperty(&'r [u8]), } impl<'r> RmrkProperty<'r> { - pub fn to_key(self) -> Result> { - fn get_bytes>(container: &T) -> &[u8] { - container.as_ref() - } + pub fn to_key(self) -> Result> { + fn get_bytes>(container: &T) -> &[u8] { + container.as_ref() + } - macro_rules! key { + macro_rules! key { ($($component:expr),+) => { PropertyKey::try_from([$(key!(@ &$component)),+].concat()) .map_err(|_| >::RmrkPropertyKeyIsTooLong) @@ -44,30 +44,30 @@ }; } - match self { - Self::Metadata => key!("metadata"), - Self::CollectionType => key!("collection-type"), - Self::RoyaltyInfo => key!("royalty-info"), - Self::Equipped => key!("equipped"), - Self::ResourceCollection => key!("resource-collection"), - Self::ResourcePriorities => key!("resource-priorities"), - Self::ResourceType => key!("resource-type"), - Self::PendingResourceAccept => key!("pending-accept"), - Self::PendingResourceRemoval => key!("pending-removal"), - Self::Parts => key!("parts"), - Self::Base => key!("base"), - Self::Src => key!("src"), - Self::Slot => key!("slot"), - Self::License => key!("license"), - Self::Thumb => key!("thumb"), - Self::EquippedNft => key!("equipped-nft"), - Self::BaseType => key!("base-type"), - Self::ExternalPartId => key!("ext-part-id"), - Self::EquippableList => key!("equippable-list"), - Self::ZIndex => key!("z-index"), - Self::ThemeName => key!("theme-name"), - Self::ThemeInherit => key!("theme-inherit"), - Self::UserProperty(name) => key!("userprop-", name), - } - } + match self { + Self::Metadata => key!("metadata"), + Self::CollectionType => key!("collection-type"), + Self::RoyaltyInfo => key!("royalty-info"), + Self::Equipped => key!("equipped"), + Self::ResourceCollection => key!("resource-collection"), + Self::ResourcePriorities => key!("resource-priorities"), + Self::ResourceType => key!("resource-type"), + Self::PendingResourceAccept => key!("pending-accept"), + Self::PendingResourceRemoval => key!("pending-removal"), + Self::Parts => key!("parts"), + Self::Base => key!("base"), + Self::Src => key!("src"), + Self::Slot => key!("slot"), + Self::License => key!("license"), + Self::Thumb => key!("thumb"), + Self::EquippedNft => key!("equipped-nft"), + Self::BaseType => key!("base-type"), + Self::ExternalPartId => key!("ext-part-id"), + Self::EquippableList => key!("equippable-list"), + Self::ZIndex => key!("z-index"), + Self::ThemeName => key!("theme-name"), + Self::ThemeInherit => key!("theme-inherit"), + Self::UserProperty(name) => key!("userprop-", name), + } + } } --- a/pallets/proxy-rmrk-equip/src/lib.rs +++ b/pallets/proxy-rmrk-equip/src/lib.rs @@ -21,7 +21,11 @@ use sp_runtime::DispatchError; use up_data_structs::*; use pallet_common::{Pallet as PalletCommon, Error as CommonError}; -use pallet_rmrk_core::{Pallet as PalletCore, misc::{self, *}, property::RmrkProperty::*}; +use pallet_rmrk_core::{ + Pallet as PalletCore, + misc::{self, *}, + property::RmrkProperty::*, +}; use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle}; use pallet_evm::account::CrossAccountId; @@ -29,212 +33,206 @@ #[frame_support::pallet] pub mod pallet { - use super::*; + use super::*; #[pallet::config] - pub trait Config: frame_system::Config - + pallet_rmrk_core::Config { + pub trait Config: frame_system::Config + pallet_rmrk_core::Config { type Event: From> + IsType<::Event>; } - #[pallet::storage] + #[pallet::storage] #[pallet::getter(fn internal_part_id)] - pub type InernalPartId = StorageDoubleMap< - _, - Twox64Concat, - CollectionId, - Twox64Concat, - RmrkPartId, - TokenId - >; + pub type InernalPartId = + StorageDoubleMap<_, Twox64Concat, CollectionId, Twox64Concat, RmrkPartId, TokenId>; - #[pallet::storage] + #[pallet::storage] #[pallet::getter(fn base_has_default_theme)] - pub type BaseHasDefaultTheme = StorageMap< - _, - Twox64Concat, - CollectionId, - bool, - ValueQuery - >; + pub type BaseHasDefaultTheme = + StorageMap<_, Twox64Concat, CollectionId, bool, ValueQuery>; - #[pallet::pallet] + #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - BaseCreated { + BaseCreated { issuer: T::AccountId, base_id: RmrkBaseId, }, - } + } - #[pallet::error] + #[pallet::error] pub enum Error { - PermissionError, - NoAvailableBaseId, - NoAvailablePartId, - BaseDoesntExist, - NeedsDefaultThemeFirst, - } + PermissionError, + NoAvailableBaseId, + NoAvailablePartId, + BaseDoesntExist, + NeedsDefaultThemeFirst, + } - #[pallet::call] + #[pallet::call] impl Pallet { - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] - #[transactional] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[transactional] pub fn create_base( origin: OriginFor, base_type: RmrkString, symbol: RmrkString, parts: BoundedVec, ) -> DispatchResult { - let sender = ensure_signed(origin)?; - let cross_sender = T::CrossAccountId::from_sub(sender.clone()); + let sender = ensure_signed(origin)?; + let cross_sender = T::CrossAccountId::from_sub(sender.clone()); - let data = CreateCollectionData { - limits: None, - token_prefix: symbol.into_inner() - .try_into() - .map_err(|_| >::CollectionTokenPrefixLimitExceeded)?, - ..Default::default() - }; + let data = CreateCollectionData { + limits: None, + token_prefix: symbol + .into_inner() + .try_into() + .map_err(|_| >::CollectionTokenPrefixLimitExceeded)?, + ..Default::default() + }; - let collection_id_res = >::init_collection(sender.clone(), data); + let collection_id_res = >::init_collection(sender.clone(), data); - if let Err(DispatchError::Arithmetic(_)) = &collection_id_res { - return Err(>::NoAvailableBaseId.into()); - } + if let Err(DispatchError::Arithmetic(_)) = &collection_id_res { + return Err(>::NoAvailableBaseId.into()); + } - let collection_id = collection_id_res?; + let collection_id = collection_id_res?; - >::set_scoped_collection_properties( - collection_id, - PropertyScope::Rmrk, - [ - >::rmrk_property(CollectionType, &misc::CollectionType::Base)?, - >::rmrk_property(BaseType, &base_type)?, - ].into_iter() - )?; + >::set_scoped_collection_properties( + collection_id, + PropertyScope::Rmrk, + [ + >::rmrk_property(CollectionType, &misc::CollectionType::Base)?, + >::rmrk_property(BaseType, &base_type)?, + ] + .into_iter(), + )?; - let collection = >::get_nft_collection(collection_id)?; + let collection = >::get_nft_collection(collection_id)?; - for part in parts { - let part_id = part.id(); - let part_token_id = Self::create_part( - &cross_sender, - &collection, - part - )?; + for part in parts { + let part_id = part.id(); + let part_token_id = Self::create_part(&cross_sender, &collection, part)?; - >::insert(collection_id, part_id, part_token_id); + >::insert(collection_id, part_id, part_token_id); - >::set_scoped_token_property( - collection_id, - part_token_id, - PropertyScope::Rmrk, - >::rmrk_property(ExternalPartId, &part_id)? - )?; - } + >::set_scoped_token_property( + collection_id, + part_token_id, + PropertyScope::Rmrk, + >::rmrk_property(ExternalPartId, &part_id)?, + )?; + } - Self::deposit_event(Event::BaseCreated { issuer: sender, base_id: collection_id.0 }); + Self::deposit_event(Event::BaseCreated { + issuer: sender, + base_id: collection_id.0, + }); - Ok(()) - } + Ok(()) + } - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] - #[transactional] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[transactional] pub fn theme_add( origin: OriginFor, base_id: RmrkBaseId, theme: RmrkTheme, ) -> DispatchResult { - let sender = ensure_signed(origin)?; + let sender = ensure_signed(origin)?; - let sender = T::CrossAccountId::from_sub(sender); - let owner = &sender; + let sender = T::CrossAccountId::from_sub(sender); + let owner = &sender; - let collection_id: CollectionId = base_id.into(); + let collection_id: CollectionId = base_id.into(); - let collection = >::get_typed_nft_collection( - collection_id, - misc::CollectionType::Base - ).map_err(|_| >::BaseDoesntExist)?; + let collection = >::get_typed_nft_collection( + collection_id, + misc::CollectionType::Base, + ) + .map_err(|_| >::BaseDoesntExist)?; - if theme.name.as_slice() == b"default" { - >::insert(collection_id, true); - } else if !Self::base_has_default_theme(collection_id) { - return Err(>::NeedsDefaultThemeFirst.into()); - } + if theme.name.as_slice() == b"default" { + >::insert(collection_id, true); + } else if !Self::base_has_default_theme(collection_id) { + return Err(>::NeedsDefaultThemeFirst.into()); + } - let token_id = >::create_nft( - &sender, - owner, - &collection, - NftType::Theme, - [ - >::rmrk_property(ThemeName, &theme.name)?, - >::rmrk_property(ThemeInherit, &theme.inherit)? - ].into_iter() - ).map_err(|_| >::PermissionError)?; + let token_id = >::create_nft( + &sender, + owner, + &collection, + NftType::Theme, + [ + >::rmrk_property(ThemeName, &theme.name)?, + >::rmrk_property(ThemeInherit, &theme.inherit)?, + ] + .into_iter(), + ) + .map_err(|_| >::PermissionError)?; - for property in theme.properties { - >::set_scoped_token_property( - collection_id, - token_id, - PropertyScope::Rmrk, - >::rmrk_property( - UserProperty(property.key.as_slice()), - &property.value - )? - )?; - } + for property in theme.properties { + >::set_scoped_token_property( + collection_id, + token_id, + PropertyScope::Rmrk, + >::rmrk_property( + UserProperty(property.key.as_slice()), + &property.value, + )?, + )?; + } - Ok(()) - } - } + Ok(()) + } + } } impl Pallet { - fn create_part( - sender: &T::CrossAccountId, - collection: &NonfungibleHandle, - part: RmrkPartType - ) -> Result { - let owner = sender; + fn create_part( + sender: &T::CrossAccountId, + collection: &NonfungibleHandle, + part: RmrkPartType, + ) -> Result { + let owner = sender; - let src = part.src(); - let z_index = part.z_index(); + let src = part.src(); + let z_index = part.z_index(); - let nft_type = match part { - RmrkPartType::FixedPart(_) => NftType::FixedPart, - RmrkPartType::SlotPart(_) => NftType::SlotPart, - }; + let nft_type = match part { + RmrkPartType::FixedPart(_) => NftType::FixedPart, + RmrkPartType::SlotPart(_) => NftType::SlotPart, + }; - let token_id = >::create_nft( - sender, - owner, - collection, - nft_type, - [ - >::rmrk_property(Src, &src)?, - >::rmrk_property(ZIndex, &z_index)? - ].into_iter() - ).map_err(|err| match err { - DispatchError::Arithmetic(_) => >::NoAvailablePartId.into(), - err => err - })?; + let token_id = >::create_nft( + sender, + owner, + collection, + nft_type, + [ + >::rmrk_property(Src, &src)?, + >::rmrk_property(ZIndex, &z_index)?, + ] + .into_iter(), + ) + .map_err(|err| match err { + DispatchError::Arithmetic(_) => >::NoAvailablePartId.into(), + err => err, + })?; - if let RmrkPartType::SlotPart(part) = part { - >::set_scoped_token_property( - collection.id, - token_id, - PropertyScope::Rmrk, - >::rmrk_property(EquippableList, &part.equippable)? - )?; - } + if let RmrkPartType::SlotPart(part) = part { + >::set_scoped_token_property( + collection.id, + token_id, + PropertyScope::Rmrk, + >::rmrk_property(EquippableList, &part.equippable)?, + )?; + } - Ok(token_id) - } + Ok(token_id) + } } --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -313,17 +313,9 @@ fail!(>::RefungibleDisallowsNesting) } - fn nest( - &self, - _under: TokenId, - _to_nest: (CollectionId, TokenId) - ) {} + fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {} - fn unnest( - &self, - _under: TokenId, - _to_nest: (CollectionId, TokenId) - ) {} + fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {} fn account_tokens(&self, account: T::CrossAccountId) -> Vec { >::iter_prefix((self.id, account)) --- a/pallets/refungible/src/lib.rs +++ b/pallets/refungible/src/lib.rs @@ -22,9 +22,7 @@ CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget, }; use pallet_evm::account::CrossAccountId; -use pallet_common::{ - Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, -}; +use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon}; use pallet_structure::Pallet as PalletStructure; use sp_runtime::{ArithmeticError, DispatchError, DispatchResult}; use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap}; @@ -230,7 +228,9 @@ } fn collection_has_tokens(collection_id: CollectionId) -> bool { - >::iter_prefix((collection_id,)).next().is_some() + >::iter_prefix((collection_id,)) + .next() + .is_some() } pub fn burn_token(collection: &RefungibleHandle, token_id: TokenId) -> DispatchResult { @@ -388,18 +388,14 @@ to, collection.id, token, - nesting_budget + nesting_budget, )?; if let Some(balance_to) = balance_to { // from != to if balance_from == 0 { >::remove((collection.id, token, from)); - >::unnest_if_nested( - from, - collection.id, - token - ); + >::unnest_if_nested(from, collection.id, token); } else { >::insert((collection.id, token, from), balance_from); } @@ -497,7 +493,6 @@ for (i, token) in data.iter().enumerate() { let token_id = TokenId(first_token_id + i as u32 + 1); for (to, _) in token.users.iter() { - >::check_nesting( sender.clone(), to, @@ -531,7 +526,11 @@ } >::insert((collection.id, token_id, &user), amount); >::insert((collection.id, &user, TokenId(token_id)), true); - >::nest_if_sent_to_token_unchecked(&user, collection.id, TokenId(token_id)); + >::nest_if_sent_to_token_unchecked( + &user, + collection.id, + TokenId(token_id), + ); // TODO: ERC20 transfer event >::deposit_event(CommonEvent::ItemCreated( --- a/pallets/structure/src/lib.rs +++ b/pallets/structure/src/lib.rs @@ -189,17 +189,11 @@ under: &T::CrossAccountId, collection_id: CollectionId, token_id: TokenId, - nesting_budget: &dyn Budget + nesting_budget: &dyn Budget, ) -> DispatchResult { - Self::try_exec_if_owner_is_valid_nft( - under, - |d, parent_id| d.check_nesting( - from, - (collection_id, token_id), - parent_id, - nesting_budget - ) - ) + Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| { + d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget) + }) } pub fn nest_if_sent_to_token( @@ -207,69 +201,51 @@ under: &T::CrossAccountId, collection_id: CollectionId, token_id: TokenId, - nesting_budget: &dyn Budget + nesting_budget: &dyn Budget, ) -> DispatchResult { - Self::try_exec_if_owner_is_valid_nft( - under, - |d, parent_id| { - d.check_nesting( - from, - (collection_id, token_id), - parent_id, - nesting_budget - )?; + Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| { + d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?; - d.nest(parent_id, (collection_id, token_id)); + d.nest(parent_id, (collection_id, token_id)); - Ok(()) - } - ) + Ok(()) + }) } pub fn nest_if_sent_to_token_unchecked( owner: &T::CrossAccountId, collection_id: CollectionId, - token_id: TokenId + token_id: TokenId, ) { - Self::exec_if_owner_is_valid_nft( - owner, - |d, parent_id| d.nest( - parent_id, - (collection_id, token_id) - ) - ); + Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| { + d.nest(parent_id, (collection_id, token_id)) + }); } pub fn unnest_if_nested( owner: &T::CrossAccountId, collection_id: CollectionId, - token_id: TokenId + token_id: TokenId, ) { - Self::exec_if_owner_is_valid_nft( - owner, - |d, parent_id| d.unnest( - parent_id, - (collection_id, token_id) - ) - ); + Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| { + d.unnest(parent_id, (collection_id, token_id)) + }); } fn exec_if_owner_is_valid_nft( account: &T::CrossAccountId, - action: impl FnOnce(&dyn CommonCollectionOperations, TokenId) + action: impl FnOnce(&dyn CommonCollectionOperations, TokenId), ) { - Self::try_exec_if_owner_is_valid_nft( - account, - |d, id| { - action(d, id); - Ok(()) - } - ).unwrap(); + Self::try_exec_if_owner_is_valid_nft(account, |d, id| { + action(d, id); + Ok(()) + }) + .unwrap(); } fn try_exec_if_owner_is_valid_nft( account: &T::CrossAccountId, - action: impl FnOnce(&dyn CommonCollectionOperations, TokenId) -> DispatchResult + action: impl FnOnce(&dyn CommonCollectionOperations, TokenId) -> DispatchResult, ) -> DispatchResult { let account = T::CrossTokenAddressMapping::address_to_token(account); --- a/pallets/unique/src/lib.rs +++ b/pallets/unique/src/lib.rs @@ -37,11 +37,10 @@ use frame_system::{self as system, ensure_signed}; use sp_runtime::{sp_std::prelude::Vec}; use up_data_structs::{ - MAX_COLLECTION_NAME_LENGTH, - MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, - CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId, SponsorshipState, - CreateCollectionData, CreateItemExData, budget, Property, PropertyKey, - PropertyKeyPermission, + MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, + AccessMode, CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, + CollectionMode, TokenId, SponsorshipState, CreateCollectionData, CreateItemExData, budget, + Property, PropertyKey, PropertyKeyPermission, }; use pallet_evm::account::CrossAccountId; use pallet_common::{ --- a/primitives/data-structs/src/lib.rs +++ b/primitives/data-structs/src/lib.rs @@ -49,7 +49,8 @@ }, NftChild as RmrkNftChild, AccountIdOrCollectionNftTuple as RmrkAccountIdOrCollectionNftTuple, FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart, EquippableList as RmrkEquippableList, - BasicResource as RmrkBasicResource, ComposableResource as RmrkComposableResource, SlotResource as RmrkSlotResource, + BasicResource as RmrkBasicResource, ComposableResource as RmrkComposableResource, + SlotResource as RmrkSlotResource, }; mod bounded; @@ -361,8 +362,7 @@ pub type CollectionPropertiesPermissionsVec = BoundedVec>; -pub type CollectionPropertiesVec = - BoundedVec>; +pub type CollectionPropertiesVec = BoundedVec>; /// All fields are wrapped in `Option`s, where None means chain default // When adding/removing fields from this struct - don't forget to also update clamp_limits @@ -790,8 +790,8 @@ >::IntoIter; fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } + self.0.into_iter() + } } impl TrySetProperty for PropertiesMap { @@ -853,8 +853,8 @@ type IntoIter = as IntoIterator>::IntoIter; fn into_iter(self) -> Self::IntoIter { - self.map.into_iter() - } + self.map.into_iter() + } } impl TrySetProperty for Properties { @@ -932,11 +932,7 @@ pub type RmrkCollectionInfo = CollectionInfo; pub type RmrkInstanceInfo = NftInfo; -pub type RmrkResourceInfo = ResourceInfo< - RmrkBoundedResource, - RmrkString, - RmrkBoundedParts, ->; +pub type RmrkResourceInfo = ResourceInfo; pub type RmrkPropertyInfo = PropertyInfo; pub type RmrkBaseInfo = BaseInfo; pub type RmrkPartType = --- a/primitives/data-structs/src/rmrk.rs +++ b/primitives/data-structs/src/rmrk.rs @@ -20,37 +20,37 @@ #[cfg(feature = "std")] mod serialize { - use core::convert::AsRef; - use serde::ser::{self, Serialize}; + use core::convert::AsRef; + use serde::ser::{self, Serialize}; - pub mod vec { - use super::*; + pub mod vec { + use super::*; - pub fn serialize(value: &C, serializer: D) -> Result - where - D: ser::Serializer, - V: Serialize, - C: AsRef<[V]>, - { - value.as_ref().serialize(serializer) - } - } + pub fn serialize(value: &C, serializer: D) -> Result + where + D: ser::Serializer, + V: Serialize, + C: AsRef<[V]>, + { + value.as_ref().serialize(serializer) + } + } - pub mod opt_vec { - use super::*; + pub mod opt_vec { + use super::*; - pub fn serialize(value: &Option, serializer: D) -> Result - where - D: ser::Serializer, - V: Serialize, - C: AsRef<[V]>, - { - match value { - Some(value) => super::vec::serialize(value, serializer), - None => serializer.serialize_none() - } - } - } + pub fn serialize(value: &Option, serializer: D) -> Result + where + D: ser::Serializer, + V: Serialize, + C: AsRef<[V]>, + { + match value { + Some(value) => super::vec::serialize(value, serializer), + None => serializer.serialize_none(), + } + } + } } /// Collection info. @@ -58,13 +58,11 @@ #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" AccountId: Serialize, BoundedString: AsRef<[u8]>, BoundedSymbol: AsRef<[u8]> - "# - ) + "#) )] pub struct CollectionInfo { /// Current bidder and bid price. @@ -91,9 +89,9 @@ #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] pub struct RoyaltyInfo { /// Recipient (AccountId) of the royalty - pub recipient: AccountId, + pub recipient: AccountId, /// Amount (Permill) of the royalty - pub amount: RoyaltyAmount, + pub amount: RoyaltyAmount, } /// Nft info. @@ -101,13 +99,11 @@ #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" AccountId: Serialize, RoyaltyAmount: Serialize, BoundedString: AsRef<[u8]> - "# - ) + "#) )] pub struct NftInfo { /// The owner of the NFT, can be either an Account or a tuple (CollectionId, NftId) @@ -129,22 +125,19 @@ #[derive(Encode, Decode, TypeInfo, MaxEncodedLen)] pub struct NftChild { pub collection_id: CollectionId, - pub nft_id: NftId + pub nft_id: NftId, } #[cfg_attr(feature = "std", derive(Serialize))] #[derive(Encode, Decode, PartialEq, TypeInfo)] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" BoundedKey: AsRef<[u8]>, BoundedValue: AsRef<[u8]> - "# - ) + "#) )] -pub struct PropertyInfo -{ +pub struct PropertyInfo { /// Key of the property #[cfg_attr(feature = "std", serde(with = "serialize::vec"))] pub key: BoundedKey, @@ -156,10 +149,7 @@ #[derive(Encode, Decode, Default, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize))] -#[cfg_attr( - feature = "std", - serde(bound = "BoundedString: AsRef<[u8]>") -)] +#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))] pub struct BasicResource { /// If the resource is Media, the base property is absent. Media src should be a URI like an /// IPFS hash. @@ -188,12 +178,10 @@ #[cfg_attr(feature = "std", derive(Serialize))] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" BoundedString: AsRef<[u8]>, BoundedParts: AsRef<[PartId]> - "# - ) + "#) )] pub struct ComposableResource { /// If a resource is composed, it will have an array of parts that compose it @@ -235,10 +223,7 @@ #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize))] -#[cfg_attr( - feature = "std", - serde(bound = "BoundedString: AsRef<[u8]>") -)] +#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))] pub struct SlotResource { /// A Base is uniquely identified by the combination of the word `base`, its minting block /// number, and user provided symbol during Base creation, glued by dashes `-`, e.g. @@ -279,14 +264,12 @@ #[cfg_attr(feature = "std", derive(Serialize))] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" BoundedString: AsRef<[u8]>, BoundedParts: AsRef<[PartId]> - "# - ) + "#) )] -#[derivative(Default(bound=""))] +#[derivative(Default(bound = ""))] pub enum ResourceTypes { #[derivative(Default)] Basic(BasicResource), @@ -294,18 +277,15 @@ Slot(SlotResource), } - #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize))] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" BoundedResource: AsRef<[u8]>, BoundedString: AsRef<[u8]>, BoundedParts: AsRef<[PartId]> - "# - ) + "#) )] pub struct ResourceInfo { /// id is a 5-character string of reasonable uniqueness. @@ -328,12 +308,10 @@ #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" AccountId: Serialize, BoundedString: AsRef<[u8]> - "# - ) + "#) )] pub struct BaseInfo { /// Original creator of the Base @@ -350,10 +328,7 @@ #[cfg_attr(feature = "std", derive(Serialize))] #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)] -#[cfg_attr( - feature = "std", - serde(bound = "BoundedString: AsRef<[u8]>") -)] +#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))] pub struct FixedPart { pub id: PartId, pub z: ZIndex, @@ -368,29 +343,24 @@ feature = "std", serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>") )] -#[derivative(Default(bound=""))] +#[derivative(Default(bound = ""))] pub enum EquippableList { All, #[derivative(Default)] Empty, - Custom( - #[cfg_attr(feature = "std", serde(with = "serialize::vec"))] - BoundedCollectionList - ), + Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList), } #[cfg_attr(feature = "std", derive(Serialize))] #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" BoundedString: AsRef<[u8]>, BoundedCollectionList: AsRef<[CollectionId]> - "# - ) + "#) )] pub struct SlotPart { pub id: PartId, @@ -406,12 +376,10 @@ #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" BoundedString: AsRef<[u8]>, BoundedCollectionList: AsRef<[CollectionId]> - "# - ) + "#) )] pub enum PartType { FixedPart(FixedPart), @@ -422,21 +390,21 @@ pub fn id(&self) -> PartId { match self { Self::FixedPart(part) => part.id, - Self::SlotPart(part) => part.id + Self::SlotPart(part) => part.id, } } pub fn src(&self) -> &BoundedString { match self { Self::FixedPart(part) => &part.src, - Self::SlotPart(part) => &part.src + Self::SlotPart(part) => &part.src, } } pub fn z_index(&self) -> ZIndex { match self { Self::FixedPart(part) => part.z, - Self::SlotPart(part) => part.z + Self::SlotPart(part) => part.z, } } } @@ -445,12 +413,10 @@ #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)] #[cfg_attr( feature = "std", - serde( - bound = r#" + serde(bound = r#" BoundedString: AsRef<[u8]>, PropertyList: AsRef<[ThemeProperty]>, - "# - ) + "#) )] pub struct Theme { /// Name of the theme @@ -466,10 +432,7 @@ #[cfg_attr(feature = "std", derive(Eq, Serialize))] #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)] -#[cfg_attr( - feature = "std", - serde(bound = "BoundedString: AsRef<[u8]>") -)] +#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))] pub struct ThemeProperty { /// Key of the property #[cfg_attr(feature = "std", serde(with = "serialize::vec"))] --- a/runtime/tests/src/tests.rs +++ b/runtime/tests/src/tests.rs @@ -19,9 +19,9 @@ use up_data_structs::{ COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData, CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, TokenId, - MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionMode, - AccessMode, CollectionPermissions, PropertyKeyPermission, PropertyPermission, - Property, CollectionPropertiesVec, CollectionPropertiesPermissionsVec, + MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionMode, AccessMode, CollectionPermissions, + PropertyKeyPermission, PropertyPermission, Property, CollectionPropertiesVec, + CollectionPropertiesPermissionsVec, }; use frame_support::{assert_noop, assert_ok, assert_err}; use sp_std::convert::TryInto; @@ -47,12 +47,12 @@ fn default_nft_data() -> CreateNftData { CreateNftData { - properties: vec![ - Property { - key: b"test-prop".to_vec().try_into().unwrap(), - value: b"test-nft-prop".to_vec().try_into().unwrap(), - }, - ].try_into().unwrap(), + properties: vec![Property { + key: b"test-prop".to_vec().try_into().unwrap(), + value: b"test-nft-prop".to_vec().try_into().unwrap(), + }] + .try_into() + .unwrap(), } } @@ -77,22 +77,23 @@ let col_name1: Vec = "Test1\0".encode_utf16().collect::>(); let col_desc1: Vec = "TestDescription1\0".encode_utf16().collect::>(); let token_prefix1: Vec = b"token_prefix1\0".to_vec(); - let token_property_permissions: CollectionPropertiesPermissionsVec = vec![ - PropertyKeyPermission { + let token_property_permissions: CollectionPropertiesPermissionsVec = + vec![PropertyKeyPermission { key: b"test-prop".to_vec().try_into().unwrap(), permission: PropertyPermission { mutable: true, collection_admin: false, token_owner: true, }, - }, - ].try_into().unwrap(); - let properties: CollectionPropertiesVec = vec![ - Property { - key: b"test-collection-prop".to_vec().try_into().unwrap(), - value: b"test-collection-value".to_vec().try_into().unwrap(), - } - ].try_into().unwrap(); + }] + .try_into() + .unwrap(); + let properties: CollectionPropertiesVec = vec![Property { + key: b"test-collection-prop".to_vec().try_into().unwrap(), + value: b"test-collection-value".to_vec().try_into().unwrap(), + }] + .try_into() + .unwrap(); let data: CreateCollectionData = CreateCollectionData { name: col_name1.try_into().unwrap(), @@ -150,30 +151,21 @@ fn get_collection_property_permissions(collection_id: CollectionId) -> Vec { >::property_permissions(collection_id) .into_iter() - .map(|(key, permission)| PropertyKeyPermission { - key, - permission, - }) + .map(|(key, permission)| PropertyKeyPermission { key, permission }) .collect() } fn get_collection_properties(collection_id: CollectionId) -> Vec { >::collection_properties(collection_id) .into_iter() - .map(|(key, value)| Property { - key, - value, - }) + .map(|(key, value)| Property { key, value }) .collect() } fn get_token_properties(collection_id: CollectionId, token_id: TokenId) -> Vec { >::token_properties((collection_id, token_id)) .into_iter() - .map(|(key, value)| Property { - key, - value, - }) + .map(|(key, value)| Property { key, value }) .collect() } -- gitstuff