difftreelog
style reformat code
in: master
19 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- 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;
node/cli/src/service.rsdiffbeforeafterboth--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -364,7 +364,8 @@
RmrkBaseInfo<AccountId>,
RmrkPartType,
RmrkTheme,
- >*/ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ >*/
+ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ sp_api::Metadata<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>,
@@ -656,7 +657,8 @@
RmrkBaseInfo<AccountId>,
RmrkPartType,
RmrkTheme,
- >*/ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ >*/
+ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ sp_api::Metadata<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
@@ -800,7 +802,8 @@
RmrkBaseInfo<AccountId>,
RmrkPartType,
RmrkTheme,
- >*/ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ >*/
+ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ sp_api::Metadata<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -501,7 +501,6 @@
PhantomType<(
TokenData<T::CrossAccountId>,
RpcCollection<T::AccountId>,
-
// RMRK
RmrkCollectionInfo<T::AccountId>,
RmrkInstanceInfo<T::AccountId>,
@@ -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 = <CollectionPropertyPermissions<T>>::get(collection)
.into_iter()
- .map(|(key, permission)| PropertyKeyPermission {
- key,
- permission,
- })
+ .map(|(key, permission)| PropertyKeyPermission { key, permission })
.collect();
let properties = <CollectionProperties<T>>::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<TokenId>;
fn collection_tokens(&self) -> Vec<TokenId>;
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -298,17 +298,9 @@
fail!(<Error<T>>::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<TokenId> {
vec![TokenId::default()]
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -184,11 +184,7 @@
if balance == 0 {
<Balance<T>>::remove((collection.id, owner));
- <PalletStructure<T>>::unnest_if_nested(
- owner,
- collection.id,
- TokenId::default()
- );
+ <PalletStructure<T>>::unnest_if_nested(owner, collection.id, TokenId::default());
} else {
<Balance<T>>::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 {
<Balance<T>>::remove((collection.id, from));
- <PalletStructure<T>>::unnest_if_nested(
- from,
- collection.id,
- TokenId::default()
- );
+ <PalletStructure<T>>::unnest_if_nested(from, collection.id, TokenId::default());
} else {
<Balance<T>>::insert((collection.id, from), balance_from);
}
@@ -333,7 +325,11 @@
<TotalSupply<T>>::insert(collection.id, total_supply);
for (user, amount) in balances {
<Balance<T>>::insert((collection.id, &user), amount);
- <PalletStructure<T>>::nest_if_sent_to_token_unchecked(&user, collection.id, TokenId::default());
+ <PalletStructure<T>>::nest_if_sent_to_token_unchecked(
+ &user,
+ collection.id,
+ TokenId::default(),
+ );
<PalletEvm<T>>::deposit_log(
ERC20Events::Transfer {
from: H160::default(),
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- 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 @@
<Pallet<T>>::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)) {
<Pallet<T>>::nest((self.id, under), to_nest);
}
- fn unnest(
- &self,
- under: TokenId,
- to_unnest: (CollectionId, TokenId)
- ) {
+ fn unnest(&self, under: TokenId, to_unnest: (CollectionId, TokenId)) {
<Pallet<T>>::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()
})
}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -426,11 +426,10 @@
Ok(a)
}
-fn has_token_permission<T: Config>(
- collection_id: CollectionId,
- key: &PropertyKey,
-) -> bool {
- if let Ok(token_property_permissions) = CollectionPropertyPermissions::<T>::try_get(collection_id) {
+fn has_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> bool {
+ if let Ok(token_property_permissions) =
+ CollectionPropertyPermissions::<T>::try_get(collection_id)
+ {
return token_property_permissions.contains_key(key);
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -164,31 +164,44 @@
fn on_runtime_upgrade() -> Weight {
if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
let mut had_consts = BTreeSet::new();
- <TokenData<T>>::translate::<ItemDataVersion1<T::CrossAccountId>, _>(|(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(<ItemDataVersion2<T::CrossAccountId>>::from(v))
- });
+ <TokenData<T>>::translate::<ItemDataVersion1<T::CrossAccountId>, _>(
+ |(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(<ItemDataVersion2<T::CrossAccountId>>::from(v))
+ },
+ );
for collection in had_consts {
<PalletCommon<T>>::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<Item=Property>,
+ properties: impl Iterator<Item = Property>,
) -> DispatchResult {
TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {
stored_properties.try_scoped_set_from_iter(scope, properties)
@@ -347,11 +361,7 @@
<AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);
}
- <PalletStructure<T>>::unnest_if_nested(
- &token_data.owner,
- collection.id,
- token
- );
+ <PalletStructure<T>>::unnest_if_nested(&token_data.owner, collection.id, token);
<Owned<T>>::remove((collection.id, &token_data.owner, token));
<TokensBurnt<T>>::insert(collection.id, burnt);
@@ -589,16 +599,12 @@
to,
collection.id,
token,
- nesting_budget
+ nesting_budget,
)?;
// =========
- <PalletStructure<T>>::unnest_if_nested(
- from,
- collection.id,
- token
- );
+ <PalletStructure<T>>::unnest_if_nested(from, collection.id, token);
<TokenData<T>>::insert(
(collection.id, token),
@@ -709,7 +715,11 @@
},
);
- <PalletStructure<T>>::nest_if_sent_to_token_unchecked(&data.owner, collection.id, TokenId(token));
+ <PalletStructure<T>>::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),
- ) {
- <TokenChildren<T>>::insert(
- (under.0, under.1, (to_nest.0, to_nest.1)),
- true
- );
+ fn nest(under: (CollectionId, TokenId), to_nest: (CollectionId, TokenId)) {
+ <TokenChildren<T>>::insert((under.0, under.1, (to_nest.0, to_nest.1)), true);
}
- fn unnest(
- under: (CollectionId, TokenId),
- to_unnest: (CollectionId, TokenId),
- ) {
- <TokenChildren<T>>::remove(
- (under.0, under.1, to_unnest)
- );
+ fn unnest(under: (CollectionId, TokenId), to_unnest: (CollectionId, TokenId)) {
+ <TokenChildren<T>>::remove((under.0, under.1, to_unnest));
}
fn collection_has_tokens(collection_id: CollectionId) -> bool {
- <TokenData<T>>::iter_prefix((collection_id,)).next().is_some()
+ <TokenData<T>>::iter_prefix((collection_id,))
+ .next()
+ .is_some()
}
fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {
- <TokenChildren<T>>::iter_prefix((collection_id, token_id)).next().is_some()
+ <TokenChildren<T>>::iter_prefix((collection_id, token_id))
+ .next()
+ .is_some()
}
/// Delegated to `create_multiple_items`
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};20use frame_system::{pallet_prelude::*, ensure_signed};21use sp_runtime::{DispatchError, Permill, traits::StaticLookup};22use sp_std::vec::Vec;23use up_data_structs::*;24use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};25use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle, TokenData};26use pallet_evm::account::CrossAccountId;27use core::convert::AsRef;2829pub use pallet::*;3031pub mod misc;32pub mod property;3334use misc::*;35pub use property::*;3637use RmrkProperty::*;3839#[frame_support::pallet]40pub mod pallet {41 use super::*;42 use pallet_evm::account;4344 #[pallet::config]45 pub trait Config: frame_system::Config46 + pallet_common::Config47 + pallet_nonfungible::Config48 + account::Config {49 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;50 }5152 #[pallet::storage]53 #[pallet::getter(fn collection_index)]54 pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;5556 #[pallet::pallet]57 #[pallet::generate_store(pub(super) trait Store)]58 pub struct Pallet<T>(_);5960 #[pallet::event]61 #[pallet::generate_deposit(pub(super) fn deposit_event)]62 pub enum Event<T: Config> {63 CollectionCreated {64 issuer: T::AccountId,65 collection_id: RmrkCollectionId,66 },67 CollectionDestroyed {68 issuer: T::AccountId,69 collection_id: RmrkCollectionId,70 },71 IssuerChanged {72 old_issuer: T::AccountId,73 new_issuer: T::AccountId,74 collection_id: RmrkCollectionId,75 },76 CollectionLocked {77 issuer: T::AccountId,78 collection_id: RmrkCollectionId,79 },80 NftMinted {81 owner: T::AccountId,82 collection_id: RmrkCollectionId,83 nft_id: RmrkNftId,84 },85 NFTBurned {86 owner: T::AccountId,87 nft_id: RmrkNftId,88 },89 PropertySet {90 collection_id: RmrkCollectionId,91 maybe_nft_id: Option<RmrkNftId>,92 key: RmrkKeyString,93 value: RmrkValueString,94 },95 }9697 #[pallet::error]98 pub enum Error<T> {99 /* Unique-specific events */100 CorruptedCollectionType,101 NftTypeEncodeError,102 RmrkPropertyKeyIsTooLong,103 RmrkPropertyValueIsTooLong,104105 /* RMRK compatible events */106 CollectionNotEmpty,107 NoAvailableCollectionId,108 NoAvailableNftId,109 CollectionUnknown,110 NoPermission,111 CollectionFullOrLocked,112 }113114 #[pallet::call]115 impl<T: Config> Pallet<T> {116 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]117 #[transactional]118 pub fn create_collection(119 origin: OriginFor<T>,120 metadata: RmrkString,121 max: Option<u32>,122 symbol: RmrkCollectionSymbol,123 ) -> DispatchResult {124 let sender = ensure_signed(origin)?;125126 let limits = CollectionLimits {127 owner_can_transfer: Some(false),128 token_limit: max,129 ..Default::default()130 };131132 let data = CreateCollectionData {133 limits: Some(limits),134 token_prefix: symbol.into_inner()135 .try_into()136 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,137 ..Default::default()138 };139140 let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);141142 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {143 return Err(<Error<T>>::NoAvailableCollectionId.into());144 }145146 let collection_id = collection_id_res?;147148 <PalletCommon<T>>::set_scoped_collection_properties(149 collection_id,150 PropertyScope::Rmrk,151 [152 Self::rmrk_property(Metadata, &metadata)?,153 Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,154 ].into_iter()155 )?;156157 <CollectionIndex<T>>::mutate(|n| *n += 1);158159 Self::deposit_event(Event::CollectionCreated {160 issuer: sender,161 collection_id: collection_id.0162 });163164 Ok(())165 }166167 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]168 #[transactional]169 pub fn destroy_collection(170 origin: OriginFor<T>,171 collection_id: RmrkCollectionId,172 ) -> DispatchResult {173 let sender = ensure_signed(origin)?;174 let cross_sender = T::CrossAccountId::from_sub(sender.clone());175176 let unique_collection_id = collection_id.into();177178 let collection = Self::get_typed_nft_collection(unique_collection_id, misc::CollectionType::Regular)?;179180 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);181182 <PalletNft<T>>::destroy_collection(collection, &cross_sender)183 .map_err(Self::map_common_err_to_proxy)?;184185 Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });186187 Ok(())188 }189190 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]191 #[transactional]192 pub fn change_collection_issuer(193 origin: OriginFor<T>,194 collection_id: RmrkCollectionId,195 new_issuer: <T::Lookup as StaticLookup>::Source,196 ) -> DispatchResult {197 let sender = ensure_signed(origin)?;198199 let new_issuer = T::Lookup::lookup(new_issuer)?;200201 Self::change_collection_owner(202 collection_id.into(),203 misc::CollectionType::Regular,204 sender.clone(),205 new_issuer.clone()206 )?;207208 Self::deposit_event(Event::IssuerChanged {209 old_issuer: sender,210 new_issuer,211 collection_id,212 });213214 Ok(())215 }216217 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]218 #[transactional]219 pub fn lock_collection(220 origin: OriginFor<T>,221 collection_id: RmrkCollectionId,222 ) -> DispatchResult {223 let sender = ensure_signed(origin)?;224 let cross_sender = T::CrossAccountId::from_sub(sender.clone());225226 let collection = Self::get_typed_nft_collection(227 collection_id.into(),228 misc::CollectionType::Regular229 )?;230231 Self::check_collection_owner(&collection, &cross_sender)?;232233 let token_count = collection.total_supply();234235 let mut collection = collection.into_inner();236 collection.limits.token_limit = Some(token_count);237 collection.save()?;238239 Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });240241 Ok(())242 }243244 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]245 #[transactional]246 pub fn mint_nft(247 origin: OriginFor<T>,248 owner: T::AccountId,249 collection_id: RmrkCollectionId,250 recipient: Option<T::AccountId>,251 royalty_amount: Option<Permill>,252 metadata: RmrkString,253 ) -> DispatchResult {254 let sender = ensure_signed(origin)?;255 let sender = T::CrossAccountId::from_sub(sender);256 let cross_owner = T::CrossAccountId::from_sub(owner.clone());257258 let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {259 recipient: recipient.unwrap_or_else(|| owner.clone()),260 amount261 });262263 let collection = Self::get_typed_nft_collection(264 collection_id.into(),265 misc::CollectionType::Regular,266 )?;267268 let nft_id = Self::create_nft(269 &sender,270 &cross_owner,271 &collection,272 NftType::Regular,273 [274 Self::rmrk_property(RoyaltyInfo, &royalty_info)?,275 Self::rmrk_property(Metadata, &metadata)?,276 Self::rmrk_property(Equipped, &false)?,277 Self::rmrk_property(ResourceCollection, &None::<CollectionId>)?,278 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,279 ].into_iter()280 ).map_err(|err| match err {281 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailableNftId.into(),282 err => Self::map_common_err_to_proxy(err)283 })?;284285 Self::deposit_event(Event::NftMinted {286 owner,287 collection_id,288 nft_id: nft_id.0289 });290291 Ok(())292 }293294 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]295 #[transactional]296 pub fn burn_nft(297 origin: OriginFor<T>,298 collection_id: RmrkCollectionId,299 nft_id: RmrkNftId,300 ) -> DispatchResult {301 let sender = ensure_signed(origin)?;302 let cross_sender = T::CrossAccountId::from_sub(sender.clone());303304 Self::destroy_nft(305 cross_sender,306 collection_id.into(),307 misc::CollectionType::Regular,308 nft_id.into()309 )?;310311 Self::deposit_event(Event::NFTBurned { owner: sender, nft_id });312313 Ok(())314 }315316 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]317 #[transactional]318 pub fn set_property(319 origin: OriginFor<T>,320 #[pallet::compact] rmrk_collection_id: RmrkCollectionId,321 maybe_nft_id: Option<RmrkNftId>,322 key: RmrkKeyString,323 value: RmrkValueString,324 ) -> DispatchResult {325 let sender = ensure_signed(origin)?;326 let sender = T::CrossAccountId::from_sub(sender);327328 let collection_id: CollectionId = rmrk_collection_id.into();329330 match maybe_nft_id {331 Some(nft_id) => {332 let token_id: TokenId = nft_id.into();333334 Self::ensure_nft_owner(collection_id, token_id, &sender)?;335 Self::ensure_nft_type(collection_id, token_id, NftType::Regular)?;336337 <PalletNft<T>>::set_scoped_token_property(338 collection_id,339 token_id,340 PropertyScope::Rmrk,341 Self::rmrk_property(UserProperty(key.as_slice()), &value)?342 )?;343 },344 None => {345 let collection = Self::get_typed_nft_collection(346 collection_id,347 misc::CollectionType::Regular348 )?;349350 Self::check_collection_owner(&collection, &sender)?;351352 <PalletCommon<T>>::set_scoped_collection_property(353 collection_id,354 PropertyScope::Rmrk,355 Self::rmrk_property(UserProperty(key.as_slice()), &value)?356 )?;357 }358 }359360 Self::deposit_event(361 Event::PropertySet {362 collection_id: rmrk_collection_id,363 maybe_nft_id,364 key,365 value366 }367 );368369 Ok(())370 }371 }372}373374impl<T: Config> Pallet<T> {375 pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result<PropertyKey, DispatchError> {376 let key = rmrk_key.to_key::<T>()?;377378 let scoped_key = PropertyScope::Rmrk.apply(key)379 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)?;380381 Ok(scoped_key)382 }383384 pub fn rmrk_property<E: Encode>(rmrk_key: RmrkProperty, value: &E) -> Result<Property, DispatchError> {385 let key = rmrk_key.to_key::<T>()?;386387 let value = value.encode()388 .try_into()389 .map_err(|_| <Error<T>>::RmrkPropertyValueIsTooLong)?;390391 let property = Property {392 key,393 value,394 };395396 Ok(property)397 }398399 pub fn create_nft(400 sender: &T::CrossAccountId,401 owner: &T::CrossAccountId,402 collection: &NonfungibleHandle<T>,403 nft_type: NftType,404 properties: impl Iterator<Item=Property>405 ) -> Result<TokenId, DispatchError> {406 todo!("store nft type");407 let data = CreateNftExData {408 properties: BoundedVec::default(),409 owner: owner.clone(),410 };411412 let budget = budget::Value::new(2);413414 <PalletNft<T>>::create_item(415 collection,416 sender,417 data,418 &budget,419 )?;420421 let nft_id = <PalletNft<T>>::current_token_id(collection.id);422423 <PalletNft<T>>::set_scoped_token_properties(424 collection.id,425 nft_id,426 PropertyScope::Rmrk,427 properties428 )?;429430 Ok(nft_id)431 }432433 fn destroy_nft(434 sender: T::CrossAccountId,435 collection_id: CollectionId,436 collection_type: misc::CollectionType,437 token_id: TokenId438 ) -> DispatchResult {439 let collection = Self::get_typed_nft_collection(440 collection_id,441 collection_type442 )?;443444 <PalletNft<T>>::burn(&collection, &sender, token_id)445 .map_err(Self::map_common_err_to_proxy)?;446447 Ok(())448 }449450 fn change_collection_owner(451 collection_id: CollectionId,452 collection_type: misc::CollectionType,453 sender: T::AccountId,454 new_owner: T::AccountId,455 ) -> DispatchResult {456 let collection = Self::get_typed_nft_collection(457 collection_id,458 collection_type459 )?;460 Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?;461462 let mut collection = collection.into_inner();463464 collection.owner = new_owner;465 collection.save()466 }467468 fn check_collection_owner(collection: &NonfungibleHandle<T>, account: &T::CrossAccountId) -> DispatchResult {469 collection.check_is_owner(account)470 .map_err(Self::map_common_err_to_proxy)471 }472473 pub fn last_collection_idx() -> RmrkCollectionId {474 <CollectionIndex<T>>::get()475 }476477 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {478 let collection = <CollectionHandle<T>>::try_get(collection_id)479 .map_err(|_| <Error<T>>::CollectionUnknown)?;480481 match collection.mode {482 CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)),483 _ => Err(<Error<T>>::CollectionUnknown.into())484 }485 }486487 pub fn collection_exists(collection_id: CollectionId) -> bool {488 <CollectionHandle<T>>::try_get(collection_id).is_ok()489 }490491 pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool {492 <TokenData<T>>::contains_key((collection_id, nft_id))493 }494495 pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {496 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)497 .get(&Self::rmrk_property_key(key)?)498 .ok_or(<Error<T>>::CollectionUnknown)?499 .clone();500501 Ok(collection_property)502 }503504 pub fn get_collection_type(collection_id: CollectionId) -> Result<misc::CollectionType, DispatchError> {505 let value = Self::get_collection_property(collection_id, CollectionType)?;506507 let mut value = value.as_slice();508509 misc::CollectionType::decode(&mut value)510 .map_err(|_| <Error<T>>::CorruptedCollectionType.into())511 }512513 pub fn ensure_collection_type(collection_id: CollectionId, collection_type: misc::CollectionType) -> DispatchResult {514 let actual_type = Self::get_collection_type(collection_id)?;515 ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);516517 Ok(())518 }519520 pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {521 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))522 .get(&Self::rmrk_property_key(key)?)523 .ok_or(<Error<T>>::NoAvailableNftId)?524 .clone();525526 Ok(nft_property)527 }528529 pub fn get_nft_type(_collection_id: CollectionId, _token_id: TokenId) -> Result<NftType, DispatchError> {530 todo!("should get it from properties?")531 }532533 pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult {534 let actual_type = Self::get_nft_type(collection_id, token_id)?;535 ensure!(actual_type == nft_type, <Error<T>>::NoPermission);536537 Ok(())538 }539540 pub fn ensure_nft_owner(541 collection_id: CollectionId,542 token_id: TokenId,543 possible_owner: &T::CrossAccountId544 ) -> DispatchResult {545 let token_data = <TokenData<T>>::get((collection_id, token_id))546 .ok_or(<Error<T>>::NoAvailableNftId)?;547548 ensure!(token_data.owner == *possible_owner, <Error<T>>::NoPermission);549550 Ok(())551 }552553 pub fn filter_user_properties<Key, Value, R, Mapper>(554 collection_id: CollectionId,555 token_id: Option<TokenId>,556 filter_keys: Option<Vec<RmrkPropertyKey>>,557 mapper: Mapper,558 ) -> Result<Vec<R>, DispatchError>559 where560 Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,561 Value: Decode + Default,562 Mapper: Fn(Key, Value) -> R563 {564 filter_keys.map(|keys| {565 let properties = keys.into_iter()566 .filter_map(|key| {567 let key: Key = key.try_into().ok()?;568569 let value = match token_id {570 Some(token_id) => Self::get_nft_property(571 collection_id,572 token_id,573 UserProperty(key.as_ref())574 ),575 None => Self::get_collection_property(576 collection_id,577 UserProperty(key.as_ref())578 )579 }.ok()?.decode_or_default();580581 Some(mapper(key, value))582 })583 .collect();584585 Ok(properties)586 }).unwrap_or_else(|| {587 let properties = Self::iterate_user_properties(collection_id, token_id, mapper)?588 .collect();589590 Ok(properties)591 })592 }593594 pub fn iterate_user_properties<Key, Value, R, Mapper>(595 collection_id: CollectionId,596 token_id: Option<TokenId>,597 mapper: Mapper,598 ) -> Result<impl Iterator<Item=R>, DispatchError>599 where600 Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,601 Value: Decode + Default,602 Mapper: Fn(Key, Value) -> R603 {604 let key_prefix = Self::rmrk_property_key(UserProperty(b""))?;605606 let properties = match token_id {607 Some(token_id) => <PalletNft<T>>::token_properties((collection_id, token_id)),608 None => <PalletCommon<T>>::collection_properties(collection_id)609 };610611 let properties = properties612 .into_iter()613 .filter_map(move |(key, value)| {614 let key = key.as_slice().strip_prefix(key_prefix.as_slice())?;615616 let key: Key = key.to_vec().try_into().ok()?;617 let value: Value = value.decode_or_default();618619 Some(mapper(key, value))620 });621622 Ok(properties)623 }624625 pub fn get_typed_nft_collection(626 collection_id: CollectionId,627 collection_type: misc::CollectionType628 ) -> Result<NonfungibleHandle<T>, DispatchError> {629 Self::ensure_collection_type(collection_id, collection_type)?;630631 Self::get_nft_collection(collection_id)632 }633634 fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {635 map_common_err_to_proxy! {636 match err {637 NoPermission => NoPermission,638 CollectionTokenLimitExceeded => CollectionFullOrLocked,639 PublicMintingNotAllowed => NoPermission,640 TokenNotFound => NoAvailableNftId641 }642 }643 }644}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};20use frame_system::{pallet_prelude::*, ensure_signed};21use sp_runtime::{DispatchError, Permill, traits::StaticLookup};22use sp_std::vec::Vec;23use up_data_structs::*;24use pallet_common::{25 Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations,26};27use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle, TokenData};28use pallet_evm::account::CrossAccountId;29use core::convert::AsRef;3031pub use pallet::*;3233pub mod misc;34pub mod property;3536use misc::*;37pub use property::*;3839use RmrkProperty::*;4041#[frame_support::pallet]42pub mod pallet {43 use super::*;44 use pallet_evm::account;4546 #[pallet::config]47 pub trait Config:48 frame_system::Config + pallet_common::Config + pallet_nonfungible::Config + account::Config49 {50 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;51 }5253 #[pallet::storage]54 #[pallet::getter(fn collection_index)]55 pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;5657 #[pallet::pallet]58 #[pallet::generate_store(pub(super) trait Store)]59 pub struct Pallet<T>(_);6061 #[pallet::event]62 #[pallet::generate_deposit(pub(super) fn deposit_event)]63 pub enum Event<T: Config> {64 CollectionCreated {65 issuer: T::AccountId,66 collection_id: RmrkCollectionId,67 },68 CollectionDestroyed {69 issuer: T::AccountId,70 collection_id: RmrkCollectionId,71 },72 IssuerChanged {73 old_issuer: T::AccountId,74 new_issuer: T::AccountId,75 collection_id: RmrkCollectionId,76 },77 CollectionLocked {78 issuer: T::AccountId,79 collection_id: RmrkCollectionId,80 },81 NftMinted {82 owner: T::AccountId,83 collection_id: RmrkCollectionId,84 nft_id: RmrkNftId,85 },86 NFTBurned {87 owner: T::AccountId,88 nft_id: RmrkNftId,89 },90 PropertySet {91 collection_id: RmrkCollectionId,92 maybe_nft_id: Option<RmrkNftId>,93 key: RmrkKeyString,94 value: RmrkValueString,95 },96 }9798 #[pallet::error]99 pub enum Error<T> {100 /* Unique-specific events */101 CorruptedCollectionType,102 NftTypeEncodeError,103 RmrkPropertyKeyIsTooLong,104 RmrkPropertyValueIsTooLong,105106 /* RMRK compatible events */107 CollectionNotEmpty,108 NoAvailableCollectionId,109 NoAvailableNftId,110 CollectionUnknown,111 NoPermission,112 CollectionFullOrLocked,113 }114115 #[pallet::call]116 impl<T: Config> Pallet<T> {117 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]118 #[transactional]119 pub fn create_collection(120 origin: OriginFor<T>,121 metadata: RmrkString,122 max: Option<u32>,123 symbol: RmrkCollectionSymbol,124 ) -> DispatchResult {125 let sender = ensure_signed(origin)?;126127 let limits = CollectionLimits {128 owner_can_transfer: Some(false),129 token_limit: max,130 ..Default::default()131 };132133 let data = CreateCollectionData {134 limits: Some(limits),135 token_prefix: symbol136 .into_inner()137 .try_into()138 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,139 ..Default::default()140 };141142 let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);143144 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {145 return Err(<Error<T>>::NoAvailableCollectionId.into());146 }147148 let collection_id = collection_id_res?;149150 <PalletCommon<T>>::set_scoped_collection_properties(151 collection_id,152 PropertyScope::Rmrk,153 [154 Self::rmrk_property(Metadata, &metadata)?,155 Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,156 ]157 .into_iter(),158 )?;159160 <CollectionIndex<T>>::mutate(|n| *n += 1);161162 Self::deposit_event(Event::CollectionCreated {163 issuer: sender,164 collection_id: collection_id.0,165 });166167 Ok(())168 }169170 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]171 #[transactional]172 pub fn destroy_collection(173 origin: OriginFor<T>,174 collection_id: RmrkCollectionId,175 ) -> DispatchResult {176 let sender = ensure_signed(origin)?;177 let cross_sender = T::CrossAccountId::from_sub(sender.clone());178179 let unique_collection_id = collection_id.into();180181 let collection = Self::get_typed_nft_collection(182 unique_collection_id,183 misc::CollectionType::Regular,184 )?;185186 ensure!(187 collection.total_supply() == 0,188 <Error<T>>::CollectionNotEmpty189 );190191 <PalletNft<T>>::destroy_collection(collection, &cross_sender)192 .map_err(Self::map_common_err_to_proxy)?;193194 Self::deposit_event(Event::CollectionDestroyed {195 issuer: sender,196 collection_id,197 });198199 Ok(())200 }201202 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]203 #[transactional]204 pub fn change_collection_issuer(205 origin: OriginFor<T>,206 collection_id: RmrkCollectionId,207 new_issuer: <T::Lookup as StaticLookup>::Source,208 ) -> DispatchResult {209 let sender = ensure_signed(origin)?;210211 let new_issuer = T::Lookup::lookup(new_issuer)?;212213 Self::change_collection_owner(214 collection_id.into(),215 misc::CollectionType::Regular,216 sender.clone(),217 new_issuer.clone(),218 )?;219220 Self::deposit_event(Event::IssuerChanged {221 old_issuer: sender,222 new_issuer,223 collection_id,224 });225226 Ok(())227 }228229 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]230 #[transactional]231 pub fn lock_collection(232 origin: OriginFor<T>,233 collection_id: RmrkCollectionId,234 ) -> DispatchResult {235 let sender = ensure_signed(origin)?;236 let cross_sender = T::CrossAccountId::from_sub(sender.clone());237238 let collection = Self::get_typed_nft_collection(239 collection_id.into(),240 misc::CollectionType::Regular,241 )?;242243 Self::check_collection_owner(&collection, &cross_sender)?;244245 let token_count = collection.total_supply();246247 let mut collection = collection.into_inner();248 collection.limits.token_limit = Some(token_count);249 collection.save()?;250251 Self::deposit_event(Event::CollectionLocked {252 issuer: sender,253 collection_id,254 });255256 Ok(())257 }258259 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]260 #[transactional]261 pub fn mint_nft(262 origin: OriginFor<T>,263 owner: T::AccountId,264 collection_id: RmrkCollectionId,265 recipient: Option<T::AccountId>,266 royalty_amount: Option<Permill>,267 metadata: RmrkString,268 ) -> DispatchResult {269 let sender = ensure_signed(origin)?;270 let sender = T::CrossAccountId::from_sub(sender);271 let cross_owner = T::CrossAccountId::from_sub(owner.clone());272273 let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {274 recipient: recipient.unwrap_or_else(|| owner.clone()),275 amount,276 });277278 let collection = Self::get_typed_nft_collection(279 collection_id.into(),280 misc::CollectionType::Regular,281 )?;282283 let nft_id = Self::create_nft(284 &sender,285 &cross_owner,286 &collection,287 NftType::Regular,288 [289 Self::rmrk_property(RoyaltyInfo, &royalty_info)?,290 Self::rmrk_property(Metadata, &metadata)?,291 Self::rmrk_property(Equipped, &false)?,292 Self::rmrk_property(ResourceCollection, &None::<CollectionId>)?,293 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,294 ]295 .into_iter(),296 )297 .map_err(|err| match err {298 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailableNftId.into(),299 err => Self::map_common_err_to_proxy(err),300 })?;301302 Self::deposit_event(Event::NftMinted {303 owner,304 collection_id,305 nft_id: nft_id.0,306 });307308 Ok(())309 }310311 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]312 #[transactional]313 pub fn burn_nft(314 origin: OriginFor<T>,315 collection_id: RmrkCollectionId,316 nft_id: RmrkNftId,317 ) -> DispatchResult {318 let sender = ensure_signed(origin)?;319 let cross_sender = T::CrossAccountId::from_sub(sender.clone());320321 Self::destroy_nft(322 cross_sender,323 collection_id.into(),324 misc::CollectionType::Regular,325 nft_id.into(),326 )?;327328 Self::deposit_event(Event::NFTBurned {329 owner: sender,330 nft_id,331 });332333 Ok(())334 }335336 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]337 #[transactional]338 pub fn set_property(339 origin: OriginFor<T>,340 #[pallet::compact] rmrk_collection_id: RmrkCollectionId,341 maybe_nft_id: Option<RmrkNftId>,342 key: RmrkKeyString,343 value: RmrkValueString,344 ) -> DispatchResult {345 let sender = ensure_signed(origin)?;346 let sender = T::CrossAccountId::from_sub(sender);347348 let collection_id: CollectionId = rmrk_collection_id.into();349350 match maybe_nft_id {351 Some(nft_id) => {352 let token_id: TokenId = nft_id.into();353354 Self::ensure_nft_owner(collection_id, token_id, &sender)?;355 Self::ensure_nft_type(collection_id, token_id, NftType::Regular)?;356357 <PalletNft<T>>::set_scoped_token_property(358 collection_id,359 token_id,360 PropertyScope::Rmrk,361 Self::rmrk_property(UserProperty(key.as_slice()), &value)?,362 )?;363 }364 None => {365 let collection = Self::get_typed_nft_collection(366 collection_id,367 misc::CollectionType::Regular,368 )?;369370 Self::check_collection_owner(&collection, &sender)?;371372 <PalletCommon<T>>::set_scoped_collection_property(373 collection_id,374 PropertyScope::Rmrk,375 Self::rmrk_property(UserProperty(key.as_slice()), &value)?,376 )?;377 }378 }379380 Self::deposit_event(Event::PropertySet {381 collection_id: rmrk_collection_id,382 maybe_nft_id,383 key,384 value,385 });386387 Ok(())388 }389 }390}391392impl<T: Config> Pallet<T> {393 pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result<PropertyKey, DispatchError> {394 let key = rmrk_key.to_key::<T>()?;395396 let scoped_key = PropertyScope::Rmrk397 .apply(key)398 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)?;399400 Ok(scoped_key)401 }402403 pub fn rmrk_property<E: Encode>(404 rmrk_key: RmrkProperty,405 value: &E,406 ) -> Result<Property, DispatchError> {407 let key = rmrk_key.to_key::<T>()?;408409 let value = value410 .encode()411 .try_into()412 .map_err(|_| <Error<T>>::RmrkPropertyValueIsTooLong)?;413414 let property = Property { key, value };415416 Ok(property)417 }418419 pub fn create_nft(420 sender: &T::CrossAccountId,421 owner: &T::CrossAccountId,422 collection: &NonfungibleHandle<T>,423 nft_type: NftType,424 properties: impl Iterator<Item = Property>,425 ) -> Result<TokenId, DispatchError> {426 todo!("store nft type");427 let data = CreateNftExData {428 properties: BoundedVec::default(),429 owner: owner.clone(),430 };431432 let budget = budget::Value::new(2);433434 <PalletNft<T>>::create_item(collection, sender, data, &budget)?;435436 let nft_id = <PalletNft<T>>::current_token_id(collection.id);437438 <PalletNft<T>>::set_scoped_token_properties(439 collection.id,440 nft_id,441 PropertyScope::Rmrk,442 properties,443 )?;444445 Ok(nft_id)446 }447448 fn destroy_nft(449 sender: T::CrossAccountId,450 collection_id: CollectionId,451 collection_type: misc::CollectionType,452 token_id: TokenId,453 ) -> DispatchResult {454 let collection = Self::get_typed_nft_collection(collection_id, collection_type)?;455456 <PalletNft<T>>::burn(&collection, &sender, token_id)457 .map_err(Self::map_common_err_to_proxy)?;458459 Ok(())460 }461462 fn change_collection_owner(463 collection_id: CollectionId,464 collection_type: misc::CollectionType,465 sender: T::AccountId,466 new_owner: T::AccountId,467 ) -> DispatchResult {468 let collection = Self::get_typed_nft_collection(collection_id, collection_type)?;469 Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?;470471 let mut collection = collection.into_inner();472473 collection.owner = new_owner;474 collection.save()475 }476477 fn check_collection_owner(478 collection: &NonfungibleHandle<T>,479 account: &T::CrossAccountId,480 ) -> DispatchResult {481 collection482 .check_is_owner(account)483 .map_err(Self::map_common_err_to_proxy)484 }485486 pub fn last_collection_idx() -> RmrkCollectionId {487 <CollectionIndex<T>>::get()488 }489490 pub fn get_nft_collection(491 collection_id: CollectionId,492 ) -> Result<NonfungibleHandle<T>, DispatchError> {493 let collection = <CollectionHandle<T>>::try_get(collection_id)494 .map_err(|_| <Error<T>>::CollectionUnknown)?;495496 match collection.mode {497 CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)),498 _ => Err(<Error<T>>::CollectionUnknown.into()),499 }500 }501502 pub fn collection_exists(collection_id: CollectionId) -> bool {503 <CollectionHandle<T>>::try_get(collection_id).is_ok()504 }505506 pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool {507 <TokenData<T>>::contains_key((collection_id, nft_id))508 }509510 pub fn get_collection_property(511 collection_id: CollectionId,512 key: RmrkProperty,513 ) -> Result<PropertyValue, DispatchError> {514 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)515 .get(&Self::rmrk_property_key(key)?)516 .ok_or(<Error<T>>::CollectionUnknown)?517 .clone();518519 Ok(collection_property)520 }521522 pub fn get_collection_type(523 collection_id: CollectionId,524 ) -> Result<misc::CollectionType, DispatchError> {525 let value = Self::get_collection_property(collection_id, CollectionType)?;526527 let mut value = value.as_slice();528529 misc::CollectionType::decode(&mut value)530 .map_err(|_| <Error<T>>::CorruptedCollectionType.into())531 }532533 pub fn ensure_collection_type(534 collection_id: CollectionId,535 collection_type: misc::CollectionType,536 ) -> DispatchResult {537 let actual_type = Self::get_collection_type(collection_id)?;538 ensure!(539 actual_type == collection_type,540 <CommonError<T>>::NoPermission541 );542543 Ok(())544 }545546 pub fn get_nft_property(547 collection_id: CollectionId,548 nft_id: TokenId,549 key: RmrkProperty,550 ) -> Result<PropertyValue, DispatchError> {551 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))552 .get(&Self::rmrk_property_key(key)?)553 .ok_or(<Error<T>>::NoAvailableNftId)?554 .clone();555556 Ok(nft_property)557 }558559 pub fn get_nft_type(560 _collection_id: CollectionId,561 _token_id: TokenId,562 ) -> Result<NftType, DispatchError> {563 todo!("should get it from properties?")564 }565566 pub fn ensure_nft_type(567 collection_id: CollectionId,568 token_id: TokenId,569 nft_type: NftType,570 ) -> DispatchResult {571 let actual_type = Self::get_nft_type(collection_id, token_id)?;572 ensure!(actual_type == nft_type, <Error<T>>::NoPermission);573574 Ok(())575 }576577 pub fn ensure_nft_owner(578 collection_id: CollectionId,579 token_id: TokenId,580 possible_owner: &T::CrossAccountId,581 ) -> DispatchResult {582 let token_data =583 <TokenData<T>>::get((collection_id, token_id)).ok_or(<Error<T>>::NoAvailableNftId)?;584585 ensure!(586 token_data.owner == *possible_owner,587 <Error<T>>::NoPermission588 );589590 Ok(())591 }592593 pub fn filter_user_properties<Key, Value, R, Mapper>(594 collection_id: CollectionId,595 token_id: Option<TokenId>,596 filter_keys: Option<Vec<RmrkPropertyKey>>,597 mapper: Mapper,598 ) -> Result<Vec<R>, DispatchError>599 where600 Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,601 Value: Decode + Default,602 Mapper: Fn(Key, Value) -> R,603 {604 filter_keys605 .map(|keys| {606 let properties = keys607 .into_iter()608 .filter_map(|key| {609 let key: Key = key.try_into().ok()?;610611 let value = match token_id {612 Some(token_id) => Self::get_nft_property(613 collection_id,614 token_id,615 UserProperty(key.as_ref()),616 ),617 None => Self::get_collection_property(618 collection_id,619 UserProperty(key.as_ref()),620 ),621 }622 .ok()?623 .decode_or_default();624625 Some(mapper(key, value))626 })627 .collect();628629 Ok(properties)630 })631 .unwrap_or_else(|| {632 let properties =633 Self::iterate_user_properties(collection_id, token_id, mapper)?.collect();634635 Ok(properties)636 })637 }638639 pub fn iterate_user_properties<Key, Value, R, Mapper>(640 collection_id: CollectionId,641 token_id: Option<TokenId>,642 mapper: Mapper,643 ) -> Result<impl Iterator<Item = R>, DispatchError>644 where645 Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,646 Value: Decode + Default,647 Mapper: Fn(Key, Value) -> R,648 {649 let key_prefix = Self::rmrk_property_key(UserProperty(b""))?;650651 let properties = match token_id {652 Some(token_id) => <PalletNft<T>>::token_properties((collection_id, token_id)),653 None => <PalletCommon<T>>::collection_properties(collection_id),654 };655656 let properties = properties.into_iter().filter_map(move |(key, value)| {657 let key = key.as_slice().strip_prefix(key_prefix.as_slice())?;658659 let key: Key = key.to_vec().try_into().ok()?;660 let value: Value = value.decode_or_default();661662 Some(mapper(key, value))663 });664665 Ok(properties)666 }667668 pub fn get_typed_nft_collection(669 collection_id: CollectionId,670 collection_type: misc::CollectionType,671 ) -> Result<NonfungibleHandle<T>, DispatchError> {672 Self::ensure_collection_type(collection_id, collection_type)?;673674 Self::get_nft_collection(collection_id)675 }676677 fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {678 map_common_err_to_proxy! {679 match err {680 NoPermission => NoPermission,681 CollectionTokenLimitExceeded => CollectionFullOrLocked,682 PublicMintingNotAllowed => NoPermission,683 TokenNotFound => NoAvailableNftId684 }685 }686 }687}pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -15,41 +15,42 @@
}
pub trait RmrkDecode<T: Decode + Default, S> {
- fn decode_or_default(&self) -> T;
+ fn decode_or_default(&self) -> T;
}
impl<T: Decode + Default, S> RmrkDecode<T, S> for BoundedVec<u8, S> {
- 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<T, S> {
- fn rebind(&self) -> BoundedVec<u8, S>;
+ fn rebind(&self) -> BoundedVec<u8, S>;
}
-impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T> where BoundedVec<u8, S>: TryFrom<Vec<u8>> {
- fn rebind(&self) -> BoundedVec<u8, S> {
- BoundedVec::<u8, S>::try_from(
- self.clone().into_inner()
- ).unwrap_or_default()
- }
+impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>
+where
+ BoundedVec<u8, S>: TryFrom<Vec<u8>>,
+{
+ fn rebind(&self) -> BoundedVec<u8, S> {
+ BoundedVec::<u8, S>::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,
}
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth--- 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<T: Config>(self) -> Result<PropertyKey, Error<T>> {
- fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {
- container.as_ref()
- }
+ pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {
+ fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {
+ container.as_ref()
+ }
- macro_rules! key {
+ macro_rules! key {
($($component:expr),+) => {
PropertyKey::try_from([$(key!(@ &$component)),+].concat())
.map_err(|_| <Error<T>>::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),
+ }
+ }
}
pallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth--- 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<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}
- #[pallet::storage]
+ #[pallet::storage]
#[pallet::getter(fn internal_part_id)]
- pub type InernalPartId<T: Config> = StorageDoubleMap<
- _,
- Twox64Concat,
- CollectionId,
- Twox64Concat,
- RmrkPartId,
- TokenId
- >;
+ pub type InernalPartId<T: Config> =
+ StorageDoubleMap<_, Twox64Concat, CollectionId, Twox64Concat, RmrkPartId, TokenId>;
- #[pallet::storage]
+ #[pallet::storage]
#[pallet::getter(fn base_has_default_theme)]
- pub type BaseHasDefaultTheme<T: Config> = StorageMap<
- _,
- Twox64Concat,
- CollectionId,
- bool,
- ValueQuery
- >;
+ pub type BaseHasDefaultTheme<T: Config> =
+ StorageMap<_, Twox64Concat, CollectionId, bool, ValueQuery>;
- #[pallet::pallet]
+ #[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
- BaseCreated {
+ BaseCreated {
issuer: T::AccountId,
base_id: RmrkBaseId,
},
- }
+ }
- #[pallet::error]
+ #[pallet::error]
pub enum Error<T> {
- PermissionError,
- NoAvailableBaseId,
- NoAvailablePartId,
- BaseDoesntExist,
- NeedsDefaultThemeFirst,
- }
+ PermissionError,
+ NoAvailableBaseId,
+ NoAvailablePartId,
+ BaseDoesntExist,
+ NeedsDefaultThemeFirst,
+ }
- #[pallet::call]
+ #[pallet::call]
impl<T: Config> Pallet<T> {
- #[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<T>,
base_type: RmrkString,
symbol: RmrkString,
parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,
) -> 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(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
- ..Default::default()
- };
+ let data = CreateCollectionData {
+ limits: None,
+ token_prefix: symbol
+ .into_inner()
+ .try_into()
+ .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
+ ..Default::default()
+ };
- let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
+ let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
- if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
- return Err(<Error<T>>::NoAvailableBaseId.into());
- }
+ if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
+ return Err(<Error<T>>::NoAvailableBaseId.into());
+ }
- let collection_id = collection_id_res?;
+ let collection_id = collection_id_res?;
- <PalletCommon<T>>::set_scoped_collection_properties(
- collection_id,
- PropertyScope::Rmrk,
- [
- <PalletCore<T>>::rmrk_property(CollectionType, &misc::CollectionType::Base)?,
- <PalletCore<T>>::rmrk_property(BaseType, &base_type)?,
- ].into_iter()
- )?;
+ <PalletCommon<T>>::set_scoped_collection_properties(
+ collection_id,
+ PropertyScope::Rmrk,
+ [
+ <PalletCore<T>>::rmrk_property(CollectionType, &misc::CollectionType::Base)?,
+ <PalletCore<T>>::rmrk_property(BaseType, &base_type)?,
+ ]
+ .into_iter(),
+ )?;
- let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;
+ let collection = <PalletCore<T>>::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)?;
- <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);
+ <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);
- <PalletNft<T>>::set_scoped_token_property(
- collection_id,
- part_token_id,
- PropertyScope::Rmrk,
- <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?
- )?;
- }
+ <PalletNft<T>>::set_scoped_token_property(
+ collection_id,
+ part_token_id,
+ PropertyScope::Rmrk,
+ <PalletCore<T>>::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<T>,
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 = <PalletCore<T>>::get_typed_nft_collection(
- collection_id,
- misc::CollectionType::Base
- ).map_err(|_| <Error<T>>::BaseDoesntExist)?;
+ let collection = <PalletCore<T>>::get_typed_nft_collection(
+ collection_id,
+ misc::CollectionType::Base,
+ )
+ .map_err(|_| <Error<T>>::BaseDoesntExist)?;
- if theme.name.as_slice() == b"default" {
- <BaseHasDefaultTheme<T>>::insert(collection_id, true);
- } else if !Self::base_has_default_theme(collection_id) {
- return Err(<Error<T>>::NeedsDefaultThemeFirst.into());
- }
+ if theme.name.as_slice() == b"default" {
+ <BaseHasDefaultTheme<T>>::insert(collection_id, true);
+ } else if !Self::base_has_default_theme(collection_id) {
+ return Err(<Error<T>>::NeedsDefaultThemeFirst.into());
+ }
- let token_id = <PalletCore<T>>::create_nft(
- &sender,
- owner,
- &collection,
- NftType::Theme,
- [
- <PalletCore<T>>::rmrk_property(ThemeName, &theme.name)?,
- <PalletCore<T>>::rmrk_property(ThemeInherit, &theme.inherit)?
- ].into_iter()
- ).map_err(|_| <Error<T>>::PermissionError)?;
+ let token_id = <PalletCore<T>>::create_nft(
+ &sender,
+ owner,
+ &collection,
+ NftType::Theme,
+ [
+ <PalletCore<T>>::rmrk_property(ThemeName, &theme.name)?,
+ <PalletCore<T>>::rmrk_property(ThemeInherit, &theme.inherit)?,
+ ]
+ .into_iter(),
+ )
+ .map_err(|_| <Error<T>>::PermissionError)?;
- for property in theme.properties {
- <PalletNft<T>>::set_scoped_token_property(
- collection_id,
- token_id,
- PropertyScope::Rmrk,
- <PalletCore<T>>::rmrk_property(
- UserProperty(property.key.as_slice()),
- &property.value
- )?
- )?;
- }
+ for property in theme.properties {
+ <PalletNft<T>>::set_scoped_token_property(
+ collection_id,
+ token_id,
+ PropertyScope::Rmrk,
+ <PalletCore<T>>::rmrk_property(
+ UserProperty(property.key.as_slice()),
+ &property.value,
+ )?,
+ )?;
+ }
- Ok(())
- }
- }
+ Ok(())
+ }
+ }
}
impl<T: Config> Pallet<T> {
- fn create_part(
- sender: &T::CrossAccountId,
- collection: &NonfungibleHandle<T>,
- part: RmrkPartType
- ) -> Result<TokenId, DispatchError> {
- let owner = sender;
+ fn create_part(
+ sender: &T::CrossAccountId,
+ collection: &NonfungibleHandle<T>,
+ part: RmrkPartType,
+ ) -> Result<TokenId, DispatchError> {
+ 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 = <PalletCore<T>>::create_nft(
- sender,
- owner,
- collection,
- nft_type,
- [
- <PalletCore<T>>::rmrk_property(Src, &src)?,
- <PalletCore<T>>::rmrk_property(ZIndex, &z_index)?
- ].into_iter()
- ).map_err(|err| match err {
- DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),
- err => err
- })?;
+ let token_id = <PalletCore<T>>::create_nft(
+ sender,
+ owner,
+ collection,
+ nft_type,
+ [
+ <PalletCore<T>>::rmrk_property(Src, &src)?,
+ <PalletCore<T>>::rmrk_property(ZIndex, &z_index)?,
+ ]
+ .into_iter(),
+ )
+ .map_err(|err| match err {
+ DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),
+ err => err,
+ })?;
- if let RmrkPartType::SlotPart(part) = part {
- <PalletNft<T>>::set_scoped_token_property(
- collection.id,
- token_id,
- PropertyScope::Rmrk,
- <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?
- )?;
- }
+ if let RmrkPartType::SlotPart(part) = part {
+ <PalletNft<T>>::set_scoped_token_property(
+ collection.id,
+ token_id,
+ PropertyScope::Rmrk,
+ <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?,
+ )?;
+ }
- Ok(token_id)
- }
+ Ok(token_id)
+ }
}
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -313,17 +313,9 @@
fail!(<Error<T>>::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<TokenId> {
<Owned<T>>::iter_prefix((self.id, account))
pallets/refungible/src/lib.rsdiffbeforeafterboth--- 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 {
- <TokenData<T>>::iter_prefix((collection_id,)).next().is_some()
+ <TokenData<T>>::iter_prefix((collection_id,))
+ .next()
+ .is_some()
}
pub fn burn_token(collection: &RefungibleHandle<T>, 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 {
<Balance<T>>::remove((collection.id, token, from));
- <PalletStructure<T>>::unnest_if_nested(
- from,
- collection.id,
- token
- );
+ <PalletStructure<T>>::unnest_if_nested(from, collection.id, token);
} else {
<Balance<T>>::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() {
-
<PalletStructure<T>>::check_nesting(
sender.clone(),
to,
@@ -531,7 +526,11 @@
}
<Balance<T>>::insert((collection.id, token_id, &user), amount);
<Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);
- <PalletStructure<T>>::nest_if_sent_to_token_unchecked(&user, collection.id, TokenId(token_id));
+ <PalletStructure<T>>::nest_if_sent_to_token_unchecked(
+ &user,
+ collection.id,
+ TokenId(token_id),
+ );
// TODO: ERC20 transfer event
<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(
pallets/structure/src/lib.rsdiffbeforeafterboth--- 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<T>, TokenId)
+ action: impl FnOnce(&dyn CommonCollectionOperations<T>, 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<T>, TokenId) -> DispatchResult
+ action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId) -> DispatchResult,
) -> DispatchResult {
let account = T::CrossTokenAddressMapping::address_to_token(account);
pallets/unique/src/lib.rsdiffbeforeafterboth--- 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::{
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- 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<PropertyKeyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
-pub type CollectionPropertiesVec =
- BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
+pub type CollectionPropertiesVec = BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
/// 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<Value> TrySetProperty for PropertiesMap<Value> {
@@ -853,8 +853,8 @@
type IntoIter = <PropertiesMap<PropertyValue> 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<AccountId> =
CollectionInfo<RmrkString, RmrkCollectionSymbol, AccountId>;
pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;
-pub type RmrkResourceInfo = ResourceInfo<
- RmrkBoundedResource,
- RmrkString,
- RmrkBoundedParts,
->;
+pub type RmrkResourceInfo = ResourceInfo<RmrkBoundedResource, RmrkString, RmrkBoundedParts>;
pub type RmrkPropertyInfo = PropertyInfo<RmrkKeyString, RmrkValueString>;
pub type RmrkBaseInfo<AccountId> = BaseInfo<AccountId, RmrkString>;
pub type RmrkPartType =
primitives/data-structs/src/rmrk.rsdiffbeforeafterboth--- 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<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>
- where
- D: ser::Serializer,
- V: Serialize,
- C: AsRef<[V]>,
- {
- value.as_ref().serialize(serializer)
- }
- }
+ pub fn serialize<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>
+ where
+ D: ser::Serializer,
+ V: Serialize,
+ C: AsRef<[V]>,
+ {
+ value.as_ref().serialize(serializer)
+ }
+ }
- pub mod opt_vec {
- use super::*;
+ pub mod opt_vec {
+ use super::*;
- pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>
- where
- D: ser::Serializer,
- V: Serialize,
- C: AsRef<[V]>,
- {
- match value {
- Some(value) => super::vec::serialize(value, serializer),
- None => serializer.serialize_none()
- }
- }
- }
+ pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>
+ where
+ D: ser::Serializer,
+ V: Serialize,
+ C: AsRef<[V]>,
+ {
+ match value {
+ Some(value) => super::vec::serialize(value, serializer),
+ None => serializer.serialize_none(),
+ }
+ }
+ }
}
/// Collection info.
@@ -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<BoundedString, BoundedSymbol, AccountId> {
/// Current bidder and bid price.
@@ -91,9 +89,9 @@
#[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub struct RoyaltyInfo<AccountId, RoyaltyAmount> {
/// 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<AccountId, RoyaltyAmount, BoundedString> {
/// 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<BoundedKey, BoundedValue>
-{
+pub struct PropertyInfo<BoundedKey, BoundedValue> {
/// 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<BoundedString> {
/// 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<BoundedString, BoundedParts> {
/// 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<BoundedString> {
/// A Base is uniquely identified by the combination of the word `base`, its minting block
/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.
@@ -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<BoundedString: Default, BoundedParts> {
#[derivative(Default)]
Basic(BasicResource<BoundedString>),
@@ -294,18 +277,15 @@
Slot(SlotResource<BoundedString>),
}
-
#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(
feature = "std",
- serde(
- bound = r#"
+ serde(bound = r#"
BoundedResource: AsRef<[u8]>,
BoundedString: AsRef<[u8]>,
BoundedParts: AsRef<[PartId]>
- "#
- )
+ "#)
)]
pub struct ResourceInfo<BoundedResource, BoundedString: Default, BoundedParts> {
/// 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<AccountId, BoundedString> {
/// 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<BoundedString> {
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<BoundedCollectionList> {
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<BoundedString, BoundedCollectionList> {
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<BoundedString, BoundedCollectionList> {
FixedPart(FixedPart<BoundedString>),
@@ -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<BoundedString>]>,
- "#
- )
+ "#)
)]
pub struct Theme<BoundedString, PropertyList> {
/// 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<BoundedString> {
/// Key of the property
#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
runtime/tests/src/tests.rsdiffbeforeafterboth--- 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<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let token_prefix1: Vec<u8> = 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<u64> = CreateCollectionData {
name: col_name1.try_into().unwrap(),
@@ -150,30 +151,21 @@
fn get_collection_property_permissions(collection_id: CollectionId) -> Vec<PropertyKeyPermission> {
<pallet_common::Pallet<Test>>::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<Property> {
<pallet_common::Pallet<Test>>::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<Property> {
<pallet_nonfungible::Pallet<Test>>::token_properties((collection_id, token_id))
.into_iter()
- .map(|(key, value)| Property {
- key,
- value,
- })
+ .map(|(key, value)| Property { key, value })
.collect()
}