difftreelog
refactor rmrk proxy, add add_theme rmrk proxy
in: master
8 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -30,7 +30,7 @@
// RMRK
use rmrk_rpc::RmrkApi as RmrkRuntimeApi;
use up_data_structs::{
- RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkPropertyKey,
+ RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName,
RmrkResourceId,
};
@@ -248,7 +248,7 @@
fn collection_properties(
&self,
collection_id: RmrkCollectionId,
- filter_keys: Option<Vec<RmrkPropertyKey>>, //String
+ filter_keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<PropertyInfo>>;
@@ -258,7 +258,7 @@
&self,
collection_id: RmrkCollectionId,
nft_id: RmrkNftId,
- filter_keys: Option<Vec<RmrkPropertyKey>>,
+ filter_keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Vec<PropertyInfo>>;
@@ -299,8 +299,8 @@
fn theme(
&self,
base_id: RmrkBaseId,
- theme_name: RmrkThemeName, // String
- filter_keys: Option<Vec<RmrkPropertyKey>>,
+ theme_name: String,
+ filter_keys: Option<Vec<String>>,
at: Option<BlockHash>,
) -> Result<Option<Theme>>;
}
@@ -523,11 +523,22 @@
pass_method!(account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Vec<RmrkNftId>, rmrk_api);
pass_method!(nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<RmrkNftChild>, rmrk_api);
pass_method!(
- collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Vec<PropertyInfo>,
+ collection_properties(
+ collection_id: RmrkCollectionId,
+
+ #[map(|keys| string_keys_to_bytes_keys(keys))]
+ filter_keys: Option<Vec<String>>
+ ) -> Vec<PropertyInfo>,
rmrk_api
);
pass_method!(
- nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Vec<PropertyInfo>,
+ nft_properties(
+ collection_id: RmrkCollectionId,
+ nft_id: RmrkNftId,
+
+ #[map(|keys| string_keys_to_bytes_keys(keys))]
+ filter_keys: Option<Vec<String>>
+ ) -> Vec<PropertyInfo>,
rmrk_api
);
pass_method!(nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<ResourceInfo>, rmrk_api);
@@ -535,7 +546,16 @@
pass_method!(base(base_id: RmrkBaseId) -> Option<BaseInfo>, rmrk_api);
pass_method!(base_parts(base_id: RmrkBaseId) -> Vec<PartType>, rmrk_api);
pass_method!(theme_names(base_id: RmrkBaseId) -> Vec<RmrkThemeName>, rmrk_api);
- pass_method!(theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Option<Theme>, rmrk_api);
+ pass_method!(
+ theme(
+ base_id: RmrkBaseId,
+
+ #[map(|n| n.into_bytes())]
+ theme_name: String,
+
+ #[map(|keys| string_keys_to_bytes_keys(keys))]
+ filter_keys: Option<Vec<String>>
+ ) -> Option<Theme>, rmrk_api);
}
fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -795,11 +795,11 @@
}
pub fn set_scoped_collection_property(
- collection: &CollectionHandle<T>,
+ collection_id: CollectionId,
scope: PropertyScope,
property: Property,
) -> DispatchResult {
- CollectionProperties::<T>::try_mutate(collection.id, |properties| {
+ CollectionProperties::<T>::try_mutate(collection_id, |properties| {
properties.try_scoped_set(scope, property.key, property.value)
})
.map_err(<Error<T>>::from)?;
@@ -807,13 +807,12 @@
Ok(())
}
- #[transactional]
pub fn set_scoped_collection_properties(
- collection: &CollectionHandle<T>,
+ collection_id: CollectionId,
scope: PropertyScope,
properties: impl Iterator<Item = Property>,
) -> DispatchResult {
- CollectionProperties::<T>::try_mutate(collection.id, |stored_properties| {
+ CollectionProperties::<T>::try_mutate(collection_id, |stored_properties| {
stored_properties.try_scoped_set_from_iter(scope, properties)
})
.map_err(<Error<T>>::from)?;
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -195,12 +195,12 @@
}
pub fn set_scoped_token_property(
- collection: &CollectionHandle<T>,
+ collection_id: CollectionId,
token_id: TokenId,
scope: PropertyScope,
property: Property,
) -> DispatchResult {
- TokenProperties::<T>::try_mutate((collection.id, token_id), |properties| {
+ TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {
properties.try_scoped_set(scope, property.key, property.value)
})
.map_err(<CommonError<T>>::from)?;
@@ -209,12 +209,12 @@
}
pub fn set_scoped_token_properties(
- collection: &CollectionHandle<T>,
+ collection_id: CollectionId,
token_id: TokenId,
scope: PropertyScope,
properties: impl Iterator<Item=Property>,
) -> DispatchResult {
- TokenProperties::<T>::try_mutate((collection.id, token_id), |stored_properties| {
+ TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {
stored_properties.try_scoped_set_from_iter(scope, properties)
})
.map_err(<CommonError<T>>::from)?;
@@ -222,8 +222,8 @@
Ok(())
}
- pub fn current_token_id(collection: &CollectionHandle<T>) -> TokenId {
- TokenId(<TokensMinted<T>>::get(collection.id))
+ pub fn current_token_id(collection_id: CollectionId) -> TokenId {
+ TokenId(<TokensMinted<T>>::get(collection_id))
}
}
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;2728pub use pallet::*;2930pub mod misc;31pub mod property;3233use misc::*;34pub use property::*;3536#[frame_support::pallet]37pub mod pallet {38 use super::*;39 use pallet_evm::account;4041 #[pallet::config]42 pub trait Config: frame_system::Config43 + pallet_common::Config44 + pallet_nonfungible::Config45 + account::Config {46 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;47 }4849 #[pallet::storage]50 #[pallet::getter(fn collection_index)]51 pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;5253 #[pallet::pallet]54 #[pallet::generate_store(pub(super) trait Store)]55 pub struct Pallet<T>(_);5657 #[pallet::event]58 #[pallet::generate_deposit(pub(super) fn deposit_event)]59 pub enum Event<T: Config> {60 CollectionCreated {61 issuer: T::AccountId,62 collection_id: RmrkCollectionId,63 },64 CollectionDestroyed {65 issuer: T::AccountId,66 collection_id: RmrkCollectionId,67 },68 IssuerChanged {69 old_issuer: T::AccountId,70 new_issuer: T::AccountId,71 collection_id: RmrkCollectionId,72 },73 CollectionLocked {74 issuer: T::AccountId,75 collection_id: RmrkCollectionId,76 },77 NftMinted {78 owner: T::AccountId,79 collection_id: RmrkCollectionId,80 nft_id: RmrkNftId,81 },82 NFTBurned {83 owner: T::AccountId,84 nft_id: RmrkNftId,85 },86 }8788 #[pallet::error]89 pub enum Error<T> {90 /* Unique-specific events */91 CorruptedCollectionType,92 NftTypeEncodeError,93 RmrkPropertyKeyIsTooLong,94 RmrkPropertyValueIsTooLong,9596 /* RMRK compatible events */97 CollectionNotEmpty,98 NoAvailableCollectionId,99 NoAvailableNftId,100 CollectionUnknown,101 NoPermission,102 CollectionFullOrLocked,103 }104105 #[pallet::call]106 impl<T: Config> Pallet<T> {107 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]108 #[transactional]109 pub fn create_collection(110 origin: OriginFor<T>,111 metadata: RmrkString,112 max: Option<u32>,113 symbol: RmrkCollectionSymbol,114 ) -> DispatchResult {115 let sender = ensure_signed(origin)?;116117 let limits = CollectionLimits {118 owner_can_transfer: Some(false),119 token_limit: max,120 ..Default::default()121 };122123 let data = CreateCollectionData {124 limits: Some(limits),125 token_prefix: symbol.into_inner()126 .try_into()127 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,128 ..Default::default()129 };130131 let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);132133 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {134 return Err(<Error<T>>::NoAvailableCollectionId.into());135 }136137 let collection_id = collection_id_res?;138139 let collection = Self::get_nft_collection(collection_id)?.into_inner();140141 <PalletCommon<T>>::set_scoped_collection_properties(142 &collection,143 PropertyScope::Rmrk,144 [145 rmrk_property!(Config=T, Metadata: metadata)?,146 rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,147 ].into_iter()148 )?;149150 <CollectionIndex<T>>::mutate(|n| *n += 1);151152 Self::deposit_event(Event::CollectionCreated {153 issuer: sender,154 collection_id: collection_id.0155 });156157 Ok(())158 }159160 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]161 #[transactional]162 pub fn destroy_collection(163 origin: OriginFor<T>,164 collection_id: RmrkCollectionId,165 ) -> DispatchResult {166 let sender = ensure_signed(origin)?;167 let cross_sender = T::CrossAccountId::from_sub(sender.clone());168169 let unique_collection_id = collection_id.into();170171 let collection = Self::get_typed_nft_collection(unique_collection_id, CollectionType::Regular)?;172173 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);174175 <PalletNft<T>>::destroy_collection(collection, &cross_sender)176 .map_err(Self::map_common_err_to_proxy)?;177178 Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });179180 Ok(())181 }182183 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]184 #[transactional]185 pub fn change_collection_issuer(186 origin: OriginFor<T>,187 collection_id: RmrkCollectionId,188 new_issuer: <T::Lookup as StaticLookup>::Source,189 ) -> DispatchResult {190 let sender = ensure_signed(origin)?;191192 let new_issuer = T::Lookup::lookup(new_issuer)?;193194 Self::change_collection_owner(195 collection_id.into(),196 CollectionType::Regular,197 sender.clone(),198 new_issuer.clone()199 )?;200201 Self::deposit_event(Event::IssuerChanged {202 old_issuer: sender,203 new_issuer,204 collection_id,205 });206207 Ok(())208 }209210 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]211 #[transactional]212 pub fn lock_collection(213 origin: OriginFor<T>,214 collection_id: RmrkCollectionId,215 ) -> DispatchResult {216 let sender = ensure_signed(origin)?;217 let cross_sender = T::CrossAccountId::from_sub(sender.clone());218219 let collection = Self::get_typed_nft_collection(220 collection_id.into(),221 CollectionType::Regular222 )?;223224 Self::check_collection_owner(&collection, &cross_sender)?;225226 let token_count = collection.total_supply();227228 let mut collection = collection.into_inner();229 collection.limits.token_limit = Some(token_count);230 collection.save()?;231232 Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });233234 Ok(())235 }236237 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]238 #[transactional]239 pub fn mint_nft(240 origin: OriginFor<T>,241 owner: T::AccountId,242 collection_id: RmrkCollectionId,243 recipient: Option<T::AccountId>,244 royalty_amount: Option<Permill>,245 metadata: RmrkString,246 ) -> DispatchResult {247 let sender = ensure_signed(origin)?;248 let sender = T::CrossAccountId::from_sub(sender);249 let cross_owner = T::CrossAccountId::from_sub(owner.clone());250251 let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {252 recipient: recipient.unwrap_or_else(|| owner.clone()),253 amount254 });255256 let nft_id = Self::create_nft(257 &sender,258 &cross_owner,259 collection_id.into(),260 CollectionType::Regular,261 NftType::Regular,262 [263 rmrk_property!(Config=T, RoyaltyInfo: royalty_info)?,264 rmrk_property!(Config=T, Metadata: metadata)?,265 rmrk_property!(Config=T, Equipped: false)?,266 rmrk_property!(Config=T, ResourceCollection: None::<CollectionId>)?,267 rmrk_property!(Config=T, ResourcePriorities: <Vec<u8>>::new())?,268 ].into_iter()269 )?;270271 Self::deposit_event(Event::NftMinted {272 owner,273 collection_id,274 nft_id: nft_id.0275 });276277 Ok(())278 }279280 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]281 #[transactional]282 pub fn burn_nft(283 origin: OriginFor<T>,284 collection_id: RmrkCollectionId,285 nft_id: RmrkNftId,286 ) -> DispatchResult {287 let sender = ensure_signed(origin.clone())?;288 let cross_sender = T::CrossAccountId::from_sub(sender.clone());289290 Self::destroy_nft(291 cross_sender,292 collection_id.into(),293 CollectionType::Regular,294 nft_id.into()295 )?;296297 Self::deposit_event(Event::NFTBurned { owner: sender, nft_id });298299 Ok(())300 }301 }302}303304impl<T: Config> Pallet<T> {305 pub fn create_nft(306 sender: &T::CrossAccountId,307 owner: &T::CrossAccountId,308 collection_id: CollectionId,309 collection_type: CollectionType,310 nft_type: NftType,311 properties: impl Iterator<Item=Property>312 ) -> Result<TokenId, DispatchError> {313 let collection = Self::get_typed_nft_collection(314 collection_id,315 collection_type316 )?;317318 let data = CreateNftExData {319 const_data: nft_type.encode()320 .try_into()321 .map_err(|_| <Error<T>>::NftTypeEncodeError)?,322 properties: BoundedVec::default(),323 owner: owner.clone(),324 };325326 let budget = budget::Value::new(2);327328 <PalletNft<T>>::create_item(329 &collection,330 sender,331 data,332 &budget,333 ).map_err(Self::map_common_err_to_proxy)?;334335 let nft_id = <PalletNft<T>>::current_token_id(&collection);336337 <PalletNft<T>>::set_scoped_token_properties(338 &collection,339 nft_id,340 PropertyScope::Rmrk,341 properties342 )?;343344 Ok(nft_id)345 }346347 fn destroy_nft(348 sender: T::CrossAccountId,349 collection_id: CollectionId,350 collection_type: CollectionType,351 token_id: TokenId352 ) -> DispatchResult {353 let collection = Self::get_typed_nft_collection(354 collection_id,355 collection_type356 )?;357358 <PalletNft<T>>::burn(&collection, &sender, token_id)359 .map_err(Self::map_common_err_to_proxy)?;360361 Ok(())362 }363364 fn change_collection_owner(365 collection_id: CollectionId,366 collection_type: CollectionType,367 sender: T::AccountId,368 new_owner: T::AccountId,369 ) -> DispatchResult {370 let collection = Self::get_typed_nft_collection(371 collection_id,372 collection_type373 )?;374 Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?;375376 let mut collection = collection.into_inner();377378 collection.owner = new_owner;379 collection.save()380 }381382 fn check_collection_owner(collection: &NonfungibleHandle<T>, account: &T::CrossAccountId) -> DispatchResult {383 collection.check_is_owner(account)384 .map_err(Self::map_common_err_to_proxy)385 }386387 pub fn last_collection_idx() -> RmrkCollectionId {388 <CollectionIndex<T>>::get()389 }390391 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {392 let collection = <CollectionHandle<T>>::try_get(collection_id)393 .map_err(|_| <Error<T>>::CollectionUnknown)?394 .into_nft_collection()?;395396 Ok(collection)397 }398399 // should this even be here, might displace it to common/nonfungible -- but they did not need it, only rmrk does400 pub fn collection_exists(collection_id: CollectionId) -> bool {401 <pallet_common::CollectionById<T>>::contains_key(collection_id)402 }403404 pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool {405 <TokenData<T>>::contains_key((collection_id, nft_id))406 }407408 pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {409 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)410 .get(&rmrk_property!(Config=T, key)?)411 .ok_or(<Error<T>>::CollectionUnknown)?412 .clone();413414 Ok(collection_property)415 }416417 pub fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {418 let value = Self::get_collection_property(collection_id, RmrkProperty::CollectionType)?;419 let collection_type: CollectionType = (&value)420 .try_into()421 .map_err(<Error<T>>::from)?;422423 Ok(collection_type)424 }425426 pub fn ensure_collection_type(collection_id: CollectionId, collection_type: CollectionType) -> DispatchResult {427 let actual_type = Self::get_collection_type(collection_id)?;428 ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);429430 Ok(())431 }432433 pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {434 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))435 .get(&rmrk_property!(Config=T, key)?)436 .ok_or(<Error<T>>::NoAvailableNftId)?437 .clone();438439 Ok(nft_property)440 }441442 pub fn get_nft_type(collection_id: CollectionId, token_id: TokenId) -> Result<NftType, DispatchError> {443 <TokenData<T>>::get((collection_id, token_id))444 .unwrap()445 .rmrk_nft_type()446 .ok_or_else(|| <Error<T>>::NoAvailableNftId.into())447 }448449 pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult {450 let actual_type = Self::get_nft_type(collection_id, token_id)?;451 ensure!(actual_type == nft_type, <CommonError<T>>::NoPermission);452453 Ok(())454 }455456 pub fn filter_theme_properties(457 collection_id: CollectionId,458 token_id: TokenId,459 filter_keys: Option<Vec<RmrkPropertyKey>>460 ) -> Result<Vec<RmrkThemeProperty>, DispatchError> {461 filter_keys.map(|keys| {462 let properties = keys.into_iter()463 .filter_map(|key| {464 let key: RmrkString = key.try_into().ok()?;465466 let value = Self::get_nft_property(467 collection_id,468 token_id,469 RmrkProperty::ThemeProperty(&key)470 ).ok()?.decode_or_default();471472 let property = RmrkThemeProperty {473 key,474 value475 };476477 Some(property)478 })479 .collect();480481 Ok(properties)482 }).unwrap_or_else(|| {483 let properties = Self::iterate_theme_properties(collection_id, token_id)?484 .collect();485486 Ok(properties)487 })488 }489490 pub fn iterate_theme_properties(491 collection_id: CollectionId,492 token_id: TokenId493 ) -> Result<impl Iterator<Item=RmrkThemeProperty>, DispatchError> {494 let key_prefix = rmrk_property!(Config=T, key: ThemeProperty(&RmrkString::default()))?;495496 let properties = <PalletNft<T>>::token_properties((collection_id, token_id))497 .into_iter()498 .filter_map(move |(key, value)| {499 let key = key.as_slice().strip_prefix(key_prefix.as_slice())?;500501 let key: RmrkString = key.to_vec().try_into().ok()?;502 let value: RmrkString = value.decode_or_default();503504 let property = RmrkThemeProperty {505 key,506 value507 };508509 Some(property)510 });511512 Ok(properties)513 }514515 pub fn get_typed_nft_collection(516 collection_id: CollectionId,517 collection_type: CollectionType518 ) -> Result<NonfungibleHandle<T>, DispatchError> {519 Self::ensure_collection_type(collection_id, collection_type)?;520521 Self::get_nft_collection(collection_id)522 }523524 fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {525 map_common_err_to_proxy! {526 match err {527 NoPermission => NoPermission,528 CollectionTokenLimitExceeded => CollectionFullOrLocked,529 PublicMintingNotAllowed => NoPermission,530 TokenNotFound => NoAvailableNftId531 }532 }533 }534}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::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};25use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle, TokenData};26use pallet_evm::account::CrossAccountId;2728pub use pallet::*;2930pub mod misc;31pub mod property;3233use misc::*;34pub use property::*;3536use RmrkProperty::*;3738#[frame_support::pallet]39pub mod pallet {40 use super::*;41 use pallet_evm::account;4243 #[pallet::config]44 pub trait Config: frame_system::Config45 + pallet_common::Config46 + pallet_nonfungible::Config47 + account::Config {48 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;49 }5051 #[pallet::storage]52 #[pallet::getter(fn collection_index)]53 pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;5455 #[pallet::pallet]56 #[pallet::generate_store(pub(super) trait Store)]57 pub struct Pallet<T>(_);5859 #[pallet::event]60 #[pallet::generate_deposit(pub(super) fn deposit_event)]61 pub enum Event<T: Config> {62 CollectionCreated {63 issuer: T::AccountId,64 collection_id: RmrkCollectionId,65 },66 CollectionDestroyed {67 issuer: T::AccountId,68 collection_id: RmrkCollectionId,69 },70 IssuerChanged {71 old_issuer: T::AccountId,72 new_issuer: T::AccountId,73 collection_id: RmrkCollectionId,74 },75 CollectionLocked {76 issuer: T::AccountId,77 collection_id: RmrkCollectionId,78 },79 NftMinted {80 owner: T::AccountId,81 collection_id: RmrkCollectionId,82 nft_id: RmrkNftId,83 },84 NFTBurned {85 owner: T::AccountId,86 nft_id: RmrkNftId,87 },88 }8990 #[pallet::error]91 pub enum Error<T> {92 /* Unique-specific events */93 CorruptedCollectionType,94 NftTypeEncodeError,95 RmrkPropertyKeyIsTooLong,96 RmrkPropertyValueIsTooLong,9798 /* RMRK compatible events */99 CollectionNotEmpty,100 NoAvailableCollectionId,101 NoAvailableNftId,102 CollectionUnknown,103 NoPermission,104 CollectionFullOrLocked,105 }106107 #[pallet::call]108 impl<T: Config> Pallet<T> {109 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]110 #[transactional]111 pub fn create_collection(112 origin: OriginFor<T>,113 metadata: RmrkString,114 max: Option<u32>,115 symbol: RmrkCollectionSymbol,116 ) -> DispatchResult {117 let sender = ensure_signed(origin)?;118119 let limits = CollectionLimits {120 owner_can_transfer: Some(false),121 token_limit: max,122 ..Default::default()123 };124125 let data = CreateCollectionData {126 limits: Some(limits),127 token_prefix: symbol.into_inner()128 .try_into()129 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,130 ..Default::default()131 };132133 let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);134135 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {136 return Err(<Error<T>>::NoAvailableCollectionId.into());137 }138139 let collection_id = collection_id_res?;140141 <PalletCommon<T>>::set_scoped_collection_properties(142 collection_id,143 PropertyScope::Rmrk,144 [145 Self::rmrk_property(Metadata, &metadata)?,146 Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,147 ].into_iter()148 )?;149150 <CollectionIndex<T>>::mutate(|n| *n += 1);151152 Self::deposit_event(Event::CollectionCreated {153 issuer: sender,154 collection_id: collection_id.0155 });156157 Ok(())158 }159160 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]161 #[transactional]162 pub fn destroy_collection(163 origin: OriginFor<T>,164 collection_id: RmrkCollectionId,165 ) -> DispatchResult {166 let sender = ensure_signed(origin)?;167 let cross_sender = T::CrossAccountId::from_sub(sender.clone());168169 let unique_collection_id = collection_id.into();170171 let collection = Self::get_typed_nft_collection(unique_collection_id, misc::CollectionType::Regular)?;172173 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);174175 <PalletNft<T>>::destroy_collection(collection, &cross_sender)176 .map_err(Self::map_common_err_to_proxy)?;177178 Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });179180 Ok(())181 }182183 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]184 #[transactional]185 pub fn change_collection_issuer(186 origin: OriginFor<T>,187 collection_id: RmrkCollectionId,188 new_issuer: <T::Lookup as StaticLookup>::Source,189 ) -> DispatchResult {190 let sender = ensure_signed(origin)?;191192 let new_issuer = T::Lookup::lookup(new_issuer)?;193194 Self::change_collection_owner(195 collection_id.into(),196 misc::CollectionType::Regular,197 sender.clone(),198 new_issuer.clone()199 )?;200201 Self::deposit_event(Event::IssuerChanged {202 old_issuer: sender,203 new_issuer,204 collection_id,205 });206207 Ok(())208 }209210 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]211 #[transactional]212 pub fn lock_collection(213 origin: OriginFor<T>,214 collection_id: RmrkCollectionId,215 ) -> DispatchResult {216 let sender = ensure_signed(origin)?;217 let cross_sender = T::CrossAccountId::from_sub(sender.clone());218219 let collection = Self::get_typed_nft_collection(220 collection_id.into(),221 misc::CollectionType::Regular222 )?;223224 Self::check_collection_owner(&collection, &cross_sender)?;225226 let token_count = collection.total_supply();227228 let mut collection = collection.into_inner();229 collection.limits.token_limit = Some(token_count);230 collection.save()?;231232 Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });233234 Ok(())235 }236237 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]238 #[transactional]239 pub fn mint_nft(240 origin: OriginFor<T>,241 owner: T::AccountId,242 collection_id: RmrkCollectionId,243 recipient: Option<T::AccountId>,244 royalty_amount: Option<Permill>,245 metadata: RmrkString,246 ) -> DispatchResult {247 let sender = ensure_signed(origin)?;248 let sender = T::CrossAccountId::from_sub(sender);249 let cross_owner = T::CrossAccountId::from_sub(owner.clone());250251 let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {252 recipient: recipient.unwrap_or_else(|| owner.clone()),253 amount254 });255256 let collection = Self::get_typed_nft_collection(257 collection_id.into(),258 misc::CollectionType::Regular,259 )?;260261 let nft_id = Self::create_nft(262 &sender,263 &cross_owner,264 &collection,265 NftType::Regular,266 [267 Self::rmrk_property(RoyaltyInfo, &royalty_info)?,268 Self::rmrk_property(Metadata, &metadata)?,269 Self::rmrk_property(Equipped, &false)?,270 Self::rmrk_property(ResourceCollection, &None::<CollectionId>)?,271 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,272 ].into_iter()273 ).map_err(|err| match err {274 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailableNftId.into(),275 err => Self::map_common_err_to_proxy(err)276 })?;277278 Self::deposit_event(Event::NftMinted {279 owner,280 collection_id,281 nft_id: nft_id.0282 });283284 Ok(())285 }286287 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]288 #[transactional]289 pub fn burn_nft(290 origin: OriginFor<T>,291 collection_id: RmrkCollectionId,292 nft_id: RmrkNftId,293 ) -> DispatchResult {294 let sender = ensure_signed(origin.clone())?;295 let cross_sender = T::CrossAccountId::from_sub(sender.clone());296297 Self::destroy_nft(298 cross_sender,299 collection_id.into(),300 misc::CollectionType::Regular,301 nft_id.into()302 )?;303304 Self::deposit_event(Event::NFTBurned { owner: sender, nft_id });305306 Ok(())307 }308 }309}310311impl<T: Config> Pallet<T> {312 pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result<PropertyKey, DispatchError> {313 let key = rmrk_key.to_key::<T>()?;314315 let scoped_key = PropertyScope::Rmrk.apply(key)316 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)?;317318 Ok(scoped_key)319 }320321 pub fn rmrk_property<E: Encode>(rmrk_key: RmrkProperty, value: &E) -> Result<Property, DispatchError> {322 let key = rmrk_key.to_key::<T>()?;323324 let value = value.encode()325 .try_into()326 .map_err(|_| <Error<T>>::RmrkPropertyValueIsTooLong)?;327328 let property = Property {329 key,330 value,331 };332333 Ok(property)334 }335336 pub fn create_nft(337 sender: &T::CrossAccountId,338 owner: &T::CrossAccountId,339 collection: &NonfungibleHandle<T>,340 nft_type: NftType,341 properties: impl Iterator<Item=Property>342 ) -> Result<TokenId, DispatchError> {343 let data = CreateNftExData {344 const_data: nft_type.encode()345 .try_into()346 .map_err(|_| <Error<T>>::NftTypeEncodeError)?,347 properties: BoundedVec::default(),348 owner: owner.clone(),349 };350351 let budget = budget::Value::new(2);352353 <PalletNft<T>>::create_item(354 collection,355 sender,356 data,357 &budget,358 )?;359360 let nft_id = <PalletNft<T>>::current_token_id(collection.id);361362 <PalletNft<T>>::set_scoped_token_properties(363 collection.id,364 nft_id,365 PropertyScope::Rmrk,366 properties367 )?;368369 Ok(nft_id)370 }371372 fn destroy_nft(373 sender: T::CrossAccountId,374 collection_id: CollectionId,375 collection_type: misc::CollectionType,376 token_id: TokenId377 ) -> DispatchResult {378 let collection = Self::get_typed_nft_collection(379 collection_id,380 collection_type381 )?;382383 <PalletNft<T>>::burn(&collection, &sender, token_id)384 .map_err(Self::map_common_err_to_proxy)?;385386 Ok(())387 }388389 fn change_collection_owner(390 collection_id: CollectionId,391 collection_type: misc::CollectionType,392 sender: T::AccountId,393 new_owner: T::AccountId,394 ) -> DispatchResult {395 let collection = Self::get_typed_nft_collection(396 collection_id,397 collection_type398 )?;399 Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?;400401 let mut collection = collection.into_inner();402403 collection.owner = new_owner;404 collection.save()405 }406407 fn check_collection_owner(collection: &NonfungibleHandle<T>, account: &T::CrossAccountId) -> DispatchResult {408 collection.check_is_owner(account)409 .map_err(Self::map_common_err_to_proxy)410 }411412 pub fn last_collection_idx() -> RmrkCollectionId {413 <CollectionIndex<T>>::get()414 }415416 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {417 let collection = <CollectionHandle<T>>::try_get(collection_id)418 .map_err(|_| <Error<T>>::CollectionUnknown)?;419420 match collection.mode {421 CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)),422 _ => Err(<Error<T>>::CollectionUnknown.into())423 }424 }425426 // should this even be here, might displace it to common/nonfungible -- but they did not need it, only rmrk does427 pub fn collection_exists(collection_id: CollectionId) -> bool {428 <pallet_common::CollectionById<T>>::contains_key(collection_id)429 }430431 pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool {432 <TokenData<T>>::contains_key((collection_id, nft_id))433 }434435 pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {436 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)437 .get(&Self::rmrk_property_key(key)?)438 .ok_or(<Error<T>>::CollectionUnknown)?439 .clone();440441 Ok(collection_property)442 }443444 pub fn get_collection_type(collection_id: CollectionId) -> Result<misc::CollectionType, DispatchError> {445 let value = Self::get_collection_property(collection_id, CollectionType)?;446447 let mut value = value.as_slice();448449 misc::CollectionType::decode(&mut value)450 .map_err(|_| <Error<T>>::CorruptedCollectionType.into())451 }452453 pub fn ensure_collection_type(collection_id: CollectionId, collection_type: misc::CollectionType) -> DispatchResult {454 let actual_type = Self::get_collection_type(collection_id)?;455 ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);456457 Ok(())458 }459460 pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {461 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))462 .get(&Self::rmrk_property_key(key)?)463 .ok_or(<Error<T>>::NoAvailableNftId)?464 .clone();465466 Ok(nft_property)467 }468469 pub fn get_nft_type(collection_id: CollectionId, token_id: TokenId) -> Result<NftType, DispatchError> {470 let token_data = <TokenData<T>>::get((collection_id, token_id))471 .ok_or(<Error<T>>::NoAvailableNftId)?;472473 let mut const_data = token_data.const_data.as_slice();474475 NftType::decode(&mut const_data).map_err(|_| <Error<T>>::NoAvailableNftId.into())476 }477478 pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult {479 let actual_type = Self::get_nft_type(collection_id, token_id)?;480 ensure!(actual_type == nft_type, <CommonError<T>>::NoPermission);481482 Ok(())483 }484485 pub fn filter_theme_properties(486 collection_id: CollectionId,487 token_id: TokenId,488 filter_keys: Option<Vec<RmrkPropertyKey>>489 ) -> Result<Vec<RmrkThemeProperty>, DispatchError> {490 filter_keys.map(|keys| {491 let properties = keys.into_iter()492 .filter_map(|key| {493 let key: RmrkString = key.try_into().ok()?;494495 let value = Self::get_nft_property(496 collection_id,497 token_id,498 ThemeProperty(&key)499 ).ok()?.decode_or_default();500501 let property = RmrkThemeProperty {502 key,503 value504 };505506 Some(property)507 })508 .collect();509510 Ok(properties)511 }).unwrap_or_else(|| {512 let properties = Self::iterate_theme_properties(collection_id, token_id)?513 .collect();514515 Ok(properties)516 })517 }518519 pub fn iterate_theme_properties(520 collection_id: CollectionId,521 token_id: TokenId522 ) -> Result<impl Iterator<Item=RmrkThemeProperty>, DispatchError> {523 let key_prefix = Self::rmrk_property_key(ThemeProperty(&RmrkString::default()))?;524525 let properties = <PalletNft<T>>::token_properties((collection_id, token_id))526 .into_iter()527 .filter_map(move |(key, value)| {528 let key = key.as_slice().strip_prefix(key_prefix.as_slice())?;529530 let key: RmrkString = key.to_vec().try_into().ok()?;531 let value: RmrkString = value.decode_or_default();532533 let property = RmrkThemeProperty {534 key,535 value536 };537538 Some(property)539 });540541 Ok(properties)542 }543544 pub fn get_typed_nft_collection(545 collection_id: CollectionId,546 collection_type: misc::CollectionType547 ) -> Result<NonfungibleHandle<T>, DispatchError> {548 Self::ensure_collection_type(collection_id, collection_type)?;549550 Self::get_nft_collection(collection_id)551 }552553 fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {554 map_common_err_to_proxy! {555 match err {556 NoPermission => NoPermission,557 CollectionTokenLimitExceeded => CollectionFullOrLocked,558 PublicMintingNotAllowed => NoPermission,559 TokenNotFound => NoAvailableNftId560 }561 }562 }563}pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -1,23 +1,6 @@
use super::*;
use codec::{Encode, Decode};
-use pallet_nonfungible::{NonfungibleHandle, ItemData};
-
-macro_rules! impl_rmrk_value {
- ($enum_name:path, decode_error: $error:ident) => {
- impl TryFrom<&PropertyValue> for $enum_name {
- type Error = MiscError;
-
- fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {
- let mut value = value.as_slice();
- <$enum_name>::decode(&mut value)
- .map_err(|_| MiscError::$error)
- }
- }
-
- };
-}
-
#[macro_export]
macro_rules! map_common_err_to_proxy {
(match $err:ident { $($common_err:ident => $proxy_err:ident),+ }) => {
@@ -29,59 +12,8 @@
$err
}
};
-}
-
-pub enum MiscError {
- RmrkPropertyValueIsTooLong,
- CorruptedCollectionType,
-}
-
-impl<T: Config> From<MiscError> for Error<T> {
- fn from(error: MiscError) -> Self {
- match error {
- MiscError::RmrkPropertyValueIsTooLong => Self::RmrkPropertyValueIsTooLong,
- MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,
- }
- }
-}
-
-pub trait IntoNftCollection<T: Config> {
- fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;
}
-impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {
- fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {
- match self.mode {
- CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),
- _ => Err(<Error<T>>::CollectionUnknown)
- }
- }
-}
-
-pub trait IntoPropertyValue {
- fn into_property_value(self) -> Result<PropertyValue, MiscError>;
-}
-
-impl<T: Encode> IntoPropertyValue for T {
- fn into_property_value(self) -> Result<PropertyValue, MiscError> {
- self.encode()
- .try_into()
- .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)
- }
-}
-
-pub trait RmrkNft {
- fn rmrk_nft_type(&self) -> Option<NftType>;
-}
-
-impl<CrossAccountId> RmrkNft for ItemData<CrossAccountId> {
- fn rmrk_nft_type(&self) -> Option<NftType> {
- let mut value = self.const_data.as_slice();
-
- NftType::decode(&mut value).ok()
- }
-}
-
pub trait RmrkDecode<T: Decode + Default, S> {
fn decode_or_default(&self) -> T;
}
@@ -121,5 +53,3 @@
SlotPart,
Theme
}
-
-impl_rmrk_value!(CollectionType, decode_error: CorruptedCollectionType);
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/property.rs
+++ b/pallets/proxy-rmrk-core/src/property.rs
@@ -71,31 +71,3 @@
}
}
}
-
-#[macro_export]
-macro_rules! rmrk_property {
- (Config=$cfg:ty, key: $key:ident $(($key_ext:expr))?) => {
- rmrk_property!(Config=$cfg, $crate::RmrkProperty::$key $(($key_ext))?)
- };
-
- (Config=$cfg:ty, $key:ident $(($key_ext:expr))?: $value:expr) => {{
- let key = rmrk_property!(@$cfg, $crate::RmrkProperty::$key $(($key_ext))?)?;
-
- let value = $value.into_property_value()
- .map_err(<$crate::Error<$cfg>>::from)?;
-
- Ok::<_, $crate::Error<$cfg>>(Property {
- key,
- value,
- })
- }};
-
- (@$cfg:ty, $key_enum:expr) => {
- $key_enum.to_key::<$cfg>()
- };
-
- (Config=$cfg:ty, $key_enum:expr) => {
- PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key_enum)?)
- .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)
- };
-}
pallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -20,9 +20,9 @@
use frame_system::{pallet_prelude::*, ensure_signed};
use sp_runtime::DispatchError;
use up_data_structs::*;
-use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle};
-use pallet_rmrk_core::{Pallet as PalletCore, rmrk_property, misc::*};
-use pallet_nonfungible::{Pallet as PalletNft};
+use pallet_common::{Pallet as PalletCommon, Error as CommonError};
+use pallet_rmrk_core::{Pallet as PalletCore, misc::{self, *}, property::RmrkProperty::*};
+use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};
use pallet_evm::account::CrossAccountId;
pub use pallet::*;
@@ -48,6 +48,16 @@
TokenId
>;
+ #[pallet::storage]
+ #[pallet::getter(fn base_has_default_theme)]
+ pub type BaseHasDefaultTheme<T: Config> = StorageMap<
+ _,
+ Twox64Concat,
+ CollectionId,
+ bool,
+ ValueQuery
+ >;
+
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
@@ -63,7 +73,11 @@
#[pallet::error]
pub enum Error<T> {
+ PermissionError,
NoAvailableBaseId,
+ NoAvailablePartId,
+ BaseDoesntExist,
+ NeedsDefaultThemeFirst,
}
#[pallet::call]
@@ -95,17 +109,17 @@
let collection_id = collection_id_res?;
- let collection = <PalletCore<T>>::get_nft_collection(collection_id)?.into_inner();
-
<PalletCommon<T>>::set_scoped_collection_properties(
- &collection,
+ collection_id,
PropertyScope::Rmrk,
[
- rmrk_property!(Config=T, CollectionType: CollectionType::Base)?,
- rmrk_property!(Config=T, BaseType: base_type)?,
+ <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)?;
+
for part in parts {
let part_id = part.id();
let part_token_id = Self::create_part(
@@ -117,10 +131,10 @@
<InernalPartId<T>>::insert(collection_id, part_id, part_token_id);
<PalletNft<T>>::set_scoped_token_property(
- &collection,
+ collection_id,
part_token_id,
PropertyScope::Rmrk,
- rmrk_property!(Config=T, ExternalPartId: part_id)?
+ <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?
)?;
}
@@ -128,13 +142,64 @@
Ok(())
}
+
+ #[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 = T::CrossAccountId::from_sub(sender);
+ let owner = &sender;
+
+ 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)?;
+
+ 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)?;
+
+ for property in theme.properties {
+ <PalletNft<T>>::set_scoped_token_property(
+ collection_id,
+ token_id,
+ PropertyScope::Rmrk,
+ <PalletCore<T>>::rmrk_property(
+ ThemeProperty(&property.key),
+ &property.value
+ )?
+ )?;
+ }
+
+ Ok(())
+ }
}
}
impl<T: Config> Pallet<T> {
fn create_part(
sender: &T::CrossAccountId,
- collection: &CollectionHandle<T>,
+ collection: &NonfungibleHandle<T>,
part: RmrkPartType
) -> Result<TokenId, DispatchError> {
let owner = sender;
@@ -150,21 +215,23 @@
let token_id = <PalletCore<T>>::create_nft(
sender,
owner,
- collection.id,
- CollectionType::Base,
+ collection,
nft_type,
[
- rmrk_property!(Config=T, Src: src)?,
- rmrk_property!(Config=T, ZIndex: z_index)?
+ <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,
+ collection.id,
token_id,
PropertyScope::Rmrk,
- rmrk_property!(Config=T, EquippableList: part.equippable)?
+ <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?
)?;
}
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -347,7 +347,7 @@
fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {
use frame_support::BoundedVec;
- use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkNft, RmrkDecode}};
+ use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};
let collection_id = CollectionId(base_id);
if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() { return Ok(Vec::new()); }
@@ -379,7 +379,7 @@
fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {
use frame_support::BoundedVec;
- use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkNft, RmrkDecode}};
+ use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode}};
let collection_id = CollectionId(base_id);
if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() {
@@ -407,7 +407,7 @@
use frame_support::BoundedVec;
use pallet_proxy_rmrk_core::{
RmrkProperty,
- misc::{CollectionType, NftType, RmrkNft, RmrkDecode}
+ misc::{CollectionType, NftType, RmrkDecode}
};
let collection_id = CollectionId(base_id);