difftreelog
feat add rmrk proxy nft minting
in: master
5 files changed
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -22,7 +22,7 @@
use up_data_structs::{
AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
- PropertyKey, PropertyKeyPermission, Properties, TrySetProperty,
+ PropertyKey, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty,
};
use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use pallet_common::{
@@ -193,6 +193,38 @@
pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {
<TokenData<T>>::contains_key((collection.id, token))
}
+
+ pub fn set_scoped_token_property(
+ collection: &CollectionHandle<T>,
+ token_id: TokenId,
+ scope: PropertyScope,
+ property: Property,
+ ) -> DispatchResult {
+ TokenProperties::<T>::try_mutate((collection.id, token_id), |properties| {
+ properties.try_scoped_set(scope, property.key, property.value)
+ })
+ .map_err(<CommonError<T>>::from)?;
+
+ Ok(())
+ }
+
+ pub fn set_scoped_token_properties(
+ collection: &CollectionHandle<T>,
+ token_id: TokenId,
+ scope: PropertyScope,
+ 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)
+ })
+ .map_err(<CommonError<T>>::from)?;
+
+ Ok(())
+ }
+
+ pub fn current_token_id(collection: &CollectionHandle<T>) -> TokenId {
+ TokenId(<TokensMinted<T>>::get(collection.id))
+ }
}
// unchecked calls skips any permission checks
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, traits::StaticLookup};22use up_data_structs::*;23use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};24use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};25use pallet_evm::account::CrossAccountId;2627pub use pallet::*;2829pub mod misc;30pub mod property;3132use misc::*;33pub use property::*;3435#[frame_support::pallet]36pub mod pallet {37 use super::*;38 use pallet_evm::account;3940 #[pallet::config]41 pub trait Config: frame_system::Config42 + pallet_common::Config43 + pallet_nonfungible::Config44 + account::Config {45 type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;46 }4748 #[pallet::pallet]49 #[pallet::generate_store(pub(super) trait Store)]50 pub struct Pallet<T>(_);5152 #[pallet::event]53 #[pallet::generate_deposit(pub(super) fn deposit_event)]54 pub enum Event<T: Config> {55 CollectionCreated {56 issuer: T::AccountId,57 collection_id: RmrkCollectionId,58 },59 CollectionDestroyed {60 issuer: T::AccountId,61 collection_id: RmrkCollectionId,62 },63 IssuerChanged {64 old_issuer: T::AccountId,65 new_issuer: T::AccountId,66 collection_id: RmrkCollectionId,67 },68 CollectionLocked {69 issuer: T::AccountId,70 collection_id: RmrkCollectionId,71 },72 }7374 #[pallet::error]75 pub enum Error<T> {76 /* Unique-specific events */77 CorruptedCollectionType,78 RmrkPropertyKeyIsTooLong,79 RmrkPropertyValueIsTooLong,8081 /* RMRK compatible events */82 CollectionNotEmpty,83 NoAvailableCollectionId,84 CollectionUnknown,85 }8687 #[pallet::call]88 impl<T: Config> Pallet<T> {89 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]90 #[transactional]91 pub fn create_collection(92 origin: OriginFor<T>,93 metadata: RmrkString,94 max: Option<u32>,95 symbol: RmrkCollectionSymbol,96 ) -> DispatchResult {97 let sender = ensure_signed(origin)?;9899 let limits = max.map(|max| CollectionLimits {100 token_limit: Some(max),101 ..Default::default()102 });103104 let data = CreateCollectionData {105 limits,106 token_prefix: symbol.into_inner()107 .try_into()108 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,109 ..Default::default()110 };111112 let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);113114 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {115 return Err(<Error<T>>::NoAvailableCollectionId.into());116 }117118 let collection_id = collection_id_res?;119120 let collection = Self::get_nft_collection(collection_id)?.into_inner();121122 <PalletCommon<T>>::set_scoped_collection_properties(123 &collection,124 PropertyScope::Rmrk,125 [126 rmrk_property!(Config=T, Metadata: metadata)?,127 rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,128 ].into_iter()129 )?;130131 Self::deposit_event(Event::CollectionCreated {132 issuer: sender,133 collection_id: collection_id.0134 });135136 Ok(())137 }138139 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]140 #[transactional]141 pub fn destroy_collection(142 origin: OriginFor<T>,143 collection_id: RmrkCollectionId,144 ) -> DispatchResult {145 let sender = ensure_signed(origin)?;146 let cross_sender = T::CrossAccountId::from_sub(sender.clone());147148 let unique_collection_id = collection_id.into();149150 let collection = Self::get_nft_collection(unique_collection_id)?;151152 Self::check_collection_type(unique_collection_id, CollectionType::Regular)?;153154 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);155156 <PalletNft<T>>::destroy_collection(collection, &cross_sender)?;157158 Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });159160 Ok(())161 }162163 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]164 #[transactional]165 pub fn change_collection_issuer(166 origin: OriginFor<T>,167 collection_id: RmrkCollectionId,168 new_issuer: <T::Lookup as StaticLookup>::Source,169 ) -> DispatchResult {170 let sender = ensure_signed(origin)?;171172 let new_issuer = T::Lookup::lookup(new_issuer)?;173174 Self::change_collection_owner(175 collection_id.into(),176 CollectionType::Regular,177 sender.clone(),178 new_issuer.clone()179 )?;180181 Self::deposit_event(Event::IssuerChanged {182 old_issuer: sender,183 new_issuer,184 collection_id,185 });186187 Ok(())188 }189190 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]191 #[transactional]192 pub fn lock_collection(193 origin: OriginFor<T>,194 collection_id: RmrkCollectionId,195 ) -> DispatchResult {196 let sender = ensure_signed(origin)?;197 let cross_sender = T::CrossAccountId::from_sub(sender.clone());198199 let collection = Self::get_nft_collection(collection_id.into())?;200 collection.check_is_owner(&cross_sender)?;201202 let token_count = collection.total_supply();203204 let mut collection = collection.into_inner();205 collection.limits.token_limit = Some(token_count);206 collection.save()?;207208 Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });209210 Ok(())211 }212 }213}214215impl<T: Config> Pallet<T> {216 fn change_collection_owner(217 collection_id: CollectionId,218 collection_type: CollectionType,219 sender: T::AccountId,220 new_owner: T::AccountId,221 ) -> DispatchResult {222 let mut collection = Self::get_nft_collection(collection_id)?.into_inner();223 collection.check_is_owner(&T::CrossAccountId::from_sub(sender))?;224225 Self::check_collection_type(collection_id, collection_type)?;226227 collection.owner = new_owner;228 collection.save()229 }230231 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {232 let collection = <CollectionHandle<T>>::try_get(collection_id)233 .map_err(|_| <Error<T>>::CollectionUnknown)?234 .into_nft_collection()?;235236 Ok(collection)237 }238239 pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {240 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)241 .get(&rmrk_property!(Config=T, key)?)242 .ok_or(<Error<T>>::CollectionUnknown)?243 .clone();244245 Ok(collection_property)246 }247248 pub fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {249 let value = Self::get_collection_property(collection_id, RmrkProperty::CollectionType)?;250 let collection_type: CollectionType = (&value)251 .try_into()252 .map_err(<Error<T>>::from)?;253254 Ok(collection_type)255 }256257 pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {258 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))259 .get(&rmrk_property!(Config=T, key)?)260 .ok_or(<Error<T>>::CollectionUnknown)? // todo is that right?261 .clone();262263 Ok(nft_property)264 }265266 pub fn check_collection_type(collection_id: CollectionId, collection_type: CollectionType) -> DispatchResult {267 let actual_type = Self::get_collection_type(collection_id)?;268 ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);269270 Ok(())271 }272}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};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::pallet]50 #[pallet::generate_store(pub(super) trait Store)]51 pub struct Pallet<T>(_);5253 #[pallet::event]54 #[pallet::generate_deposit(pub(super) fn deposit_event)]55 pub enum Event<T: Config> {56 CollectionCreated {57 issuer: T::AccountId,58 collection_id: RmrkCollectionId,59 },60 CollectionDestroyed {61 issuer: T::AccountId,62 collection_id: RmrkCollectionId,63 },64 IssuerChanged {65 old_issuer: T::AccountId,66 new_issuer: T::AccountId,67 collection_id: RmrkCollectionId,68 },69 CollectionLocked {70 issuer: T::AccountId,71 collection_id: RmrkCollectionId,72 },73 NftMinted {74 owner: T::AccountId,75 collection_id: RmrkCollectionId,76 nft_id: RmrkNftId,77 },78 }7980 #[pallet::error]81 pub enum Error<T> {82 /* Unique-specific events */83 CorruptedCollectionType,84 NftTypeEncodeError,85 RmrkPropertyKeyIsTooLong,86 RmrkPropertyValueIsTooLong,8788 /* RMRK compatible events */89 CollectionNotEmpty,90 NoAvailableCollectionId,91 NoAvailableNftId,92 CollectionUnknown,93 NoPermission,94 CollectionFullOrLocked,95 }9697 #[pallet::call]98 impl<T: Config> Pallet<T> {99 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]100 #[transactional]101 pub fn create_collection(102 origin: OriginFor<T>,103 metadata: RmrkString,104 max: Option<u32>,105 symbol: RmrkCollectionSymbol,106 ) -> DispatchResult {107 let sender = ensure_signed(origin)?;108109 let limits = max.map(|max| CollectionLimits {110 token_limit: Some(max),111 ..Default::default()112 });113114 let data = CreateCollectionData {115 limits,116 token_prefix: symbol.into_inner()117 .try_into()118 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,119 ..Default::default()120 };121122 let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);123124 if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {125 return Err(<Error<T>>::NoAvailableCollectionId.into());126 }127128 let collection_id = collection_id_res?;129130 let collection = Self::get_nft_collection(collection_id)?.into_inner();131132 <PalletCommon<T>>::set_scoped_collection_properties(133 &collection,134 PropertyScope::Rmrk,135 [136 rmrk_property!(Config=T, Metadata: metadata)?,137 rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,138 ].into_iter()139 )?;140141 Self::deposit_event(Event::CollectionCreated {142 issuer: sender,143 collection_id: collection_id.0144 });145146 Ok(())147 }148149 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]150 #[transactional]151 pub fn destroy_collection(152 origin: OriginFor<T>,153 collection_id: RmrkCollectionId,154 ) -> DispatchResult {155 let sender = ensure_signed(origin)?;156 let cross_sender = T::CrossAccountId::from_sub(sender.clone());157158 let unique_collection_id = collection_id.into();159160 let collection = Self::get_typed_nft_collection(unique_collection_id, CollectionType::Regular)?;161162 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);163164 <PalletNft<T>>::destroy_collection(collection, &cross_sender)?;165166 Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });167168 Ok(())169 }170171 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]172 #[transactional]173 pub fn change_collection_issuer(174 origin: OriginFor<T>,175 collection_id: RmrkCollectionId,176 new_issuer: <T::Lookup as StaticLookup>::Source,177 ) -> DispatchResult {178 let sender = ensure_signed(origin)?;179180 let new_issuer = T::Lookup::lookup(new_issuer)?;181182 Self::change_collection_owner(183 collection_id.into(),184 CollectionType::Regular,185 sender.clone(),186 new_issuer.clone()187 )?;188189 Self::deposit_event(Event::IssuerChanged {190 old_issuer: sender,191 new_issuer,192 collection_id,193 });194195 Ok(())196 }197198 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]199 #[transactional]200 pub fn lock_collection(201 origin: OriginFor<T>,202 collection_id: RmrkCollectionId,203 ) -> DispatchResult {204 let sender = ensure_signed(origin)?;205 let cross_sender = T::CrossAccountId::from_sub(sender.clone());206207 let collection = Self::get_typed_nft_collection(208 collection_id.into(),209 CollectionType::Regular210 )?;211 collection.check_is_owner(&cross_sender)?;212213 let token_count = collection.total_supply();214215 let mut collection = collection.into_inner();216 collection.limits.token_limit = Some(token_count);217 collection.save()?;218219 Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });220221 Ok(())222 }223224 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]225 #[transactional]226 pub fn mint_nft(227 origin: OriginFor<T>,228 owner: T::AccountId,229 collection_id: RmrkCollectionId,230 recipient: Option<T::AccountId>,231 royalty_amount: Option<Permill>,232 metadata: RmrkString,233 ) -> DispatchResult {234 let sender = ensure_signed(origin)?;235 let sender = T::CrossAccountId::from_sub(sender);236 let cross_owner = T::CrossAccountId::from_sub(owner.clone());237238 let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {239 recipient: recipient.unwrap_or_else(|| owner.clone()),240 amount241 });242243 let nft_id = Self::create_nft(244 sender,245 cross_owner,246 collection_id.into(),247 CollectionType::Regular,248 NftType::Regular,249 [250 rmrk_property!(Config=T, RoyaltyInfo: royalty_info)?,251 rmrk_property!(Config=T, Metadata: metadata)?,252 rmrk_property!(Config=T, Equipped: false)?,253 rmrk_property!(Config=T, ResourceCollection: None::<CollectionId>)?,254 rmrk_property!(Config=T, ResourcePriorities: <Vec<u8>>::new())?,255 ].into_iter()256 )?;257258 Self::deposit_event(Event::NftMinted {259 owner,260 collection_id,261 nft_id: nft_id.0262 });263264 Ok(())265 }266 }267}268269impl<T: Config> Pallet<T> {270 fn create_nft(271 sender: T::CrossAccountId,272 owner: T::CrossAccountId,273 collection_id: CollectionId,274 collection_type: CollectionType,275 nft_type: NftType,276 properties: impl Iterator<Item=Property>277 ) -> Result<TokenId, DispatchError> {278 let collection = Self::get_typed_nft_collection(279 collection_id,280 collection_type281 )?;282283 let data = CreateNftExData {284 const_data: nft_type.encode()285 .try_into()286 .map_err(|_| <Error<T>>::NftTypeEncodeError)?,287 properties: BoundedVec::default(),288 owner,289 };290291 let budget = budget::Value::new(2);292293 <PalletNft<T>>::create_item(294 &collection,295 &sender,296 data,297 &budget,298 ).map_err(|err| {299 map_common_err_to_proxy!(300 match err {301 NoPermission => NoPermission,302 CollectionTokenLimitExceeded => CollectionFullOrLocked303 }304 )305 })?;306307 let nft_id = <PalletNft<T>>::current_token_id(&collection);308309 <PalletNft<T>>::set_scoped_token_properties(310 &collection,311 nft_id,312 PropertyScope::Rmrk,313 properties314 )?;315316 Ok(nft_id)317 }318319 fn change_collection_owner(320 collection_id: CollectionId,321 collection_type: CollectionType,322 sender: T::AccountId,323 new_owner: T::AccountId,324 ) -> DispatchResult {325 let mut collection = Self::get_typed_nft_collection(326 collection_id,327 collection_type328 )?.into_inner();329 collection.check_is_owner(&T::CrossAccountId::from_sub(sender))?;330331 collection.owner = new_owner;332 collection.save()333 }334335 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {336 let collection = <CollectionHandle<T>>::try_get(collection_id)337 .map_err(|_| <Error<T>>::CollectionUnknown)?338 .into_nft_collection()?;339340 Ok(collection)341 }342343 pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {344 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)345 .get(&rmrk_property!(Config=T, key)?)346 .ok_or(<Error<T>>::CollectionUnknown)?347 .clone();348349 Ok(collection_property)350 }351352 pub fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {353 let value = Self::get_collection_property(collection_id, RmrkProperty::CollectionType)?;354 let collection_type: CollectionType = (&value)355 .try_into()356 .map_err(<Error<T>>::from)?;357358 Ok(collection_type)359 }360361 pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {362 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))363 .get(&rmrk_property!(Config=T, key)?)364 .ok_or(<Error<T>>::NoAvailableNftId)?365 .clone();366367 Ok(nft_property)368 }369370 pub fn check_collection_type(collection_id: CollectionId, collection_type: CollectionType) -> DispatchResult {371 let actual_type = Self::get_collection_type(collection_id)?;372 ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);373374 Ok(())375 }376377 fn get_typed_nft_collection(378 collection_id: CollectionId,379 collection_type: CollectionType380 ) -> Result<NonfungibleHandle<T>, DispatchError> {381 Self::check_collection_type(collection_id, collection_type)?;382383 Self::get_nft_collection(collection_id)384 }385}pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -1,17 +1,9 @@
use super::*;
use codec::{Encode, Decode};
-use pallet_nonfungible::NonfungibleHandle;
+use pallet_nonfungible::{NonfungibleHandle, ItemData};
macro_rules! impl_rmrk_value {
($enum_name:path, decode_error: $error:ident) => {
- impl IntoPropertyValue for $enum_name {
- fn into_property_value(self) -> Result<PropertyValue, MiscError> {
- self.encode()
- .try_into()
- .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)
- }
- }
-
impl TryFrom<&PropertyValue> for $enum_name {
type Error = MiscError;
@@ -26,6 +18,19 @@
};
}
+#[macro_export]
+macro_rules! map_common_err_to_proxy {
+ (match $err:ident { $($common_err:ident => $proxy_err:ident),+ }) => {
+ $(
+ if $err == <CommonError<T>>::$common_err.into() {
+ return <Error<T>>::$proxy_err.into()
+ } else
+ )+ {
+ $err
+ }
+ };
+}
+
pub enum MiscError {
RmrkPropertyValueIsTooLong,
CorruptedCollectionType,
@@ -57,14 +62,26 @@
fn into_property_value(self) -> Result<PropertyValue, MiscError>;
}
-impl<L: Get<u32>> IntoPropertyValue for BoundedVec<u8, L> {
+impl<T: Encode> IntoPropertyValue for T {
fn into_property_value(self) -> Result<PropertyValue, MiscError> {
- self.into_inner()
+ 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()
+ }
+}
+
#[derive(Encode, Decode, PartialEq, Eq)]
pub enum CollectionType {
Regular,
@@ -72,4 +89,13 @@
Base,
}
+#[derive(Encode, Decode, PartialEq, Eq)]
+pub enum NftType {
+ Regular,
+ Resource,
+ FixedPart,
+ 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
@@ -4,8 +4,7 @@
pub enum RmrkProperty {
Metadata,
CollectionType,
- Recipient,
- Royalty,
+ RoyaltyInfo,
Equipped,
ResourceCollection,
ResourcePriorities,
@@ -48,8 +47,7 @@
match self {
Self::Metadata => key!("metadata"),
Self::CollectionType => key!("collection-type"),
- Self::Recipient => key!("recipient"),
- Self::Royalty => key!("royalty"),
+ Self::RoyaltyInfo => key!("royalty-info"),
Self::Equipped => key!("equipped"),
Self::ResourceCollection => key!("resource-collection"),
Self::ResourcePriorities => key!("resource-priorities"),
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -188,10 +188,9 @@
};
let keys = [
- RmrkProperty::Royalty,
+ RmrkProperty::RoyaltyInfo,
RmrkProperty::Metadata,
RmrkProperty::Equipped,
- RmrkProperty::Pending,
// ?? "rmrk:recipient", "rmrk:nft-type", "rmrk:resource-collection", "rmrk:resource-priorities"
];
@@ -315,13 +314,13 @@
let collection_id = CollectionId(collection_id);
let nft_id = TokenId(nft_id);
- let keys = [
- RmrkProperty::Royalty,
- RmrkProperty::Metadata,
- RmrkProperty::Equipped,
- RmrkProperty::Pending,
- // ?? "rmrk:recipient", "rmrk:nft-type", "rmrk:resource-collection", "rmrk:resource-priorities"
- ];
+ // let keys = [
+ // RmrkProperty::Royalty,
+ // RmrkProperty::Metadata,
+ // RmrkProperty::Equipped,
+ // RmrkProperty::Pending,
+ // // ?? "rmrk:recipient", "rmrk:nft-type", "rmrk:resource-collection", "rmrk:resource-priorities"
+ // ];
/*let resources = keys.into_iter().map(
|key| BoundedVec::try_from(