difftreelog
fix use rmrk type in proxy
in: master
4 files changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -16,9 +16,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
-use frame_support::{pallet_prelude::*, transactional, BoundedVec, traits::ConstU32, dispatch::DispatchResult};
+use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};
use frame_system::{pallet_prelude::*, ensure_signed};
-use sp_runtime::DispatchError;
+use sp_runtime::{DispatchError, traits::StaticLookup};
use up_data_structs::*;
use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};
use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};
@@ -54,15 +54,20 @@
pub enum Event<T: Config> {
CollectionCreated {
issuer: T::AccountId,
- collection_id: CollectionId,
+ collection_id: RmrkCollectionId,
},
CollectionDestroyed {
issuer: T::AccountId,
- collection_id: CollectionId,
+ collection_id: RmrkCollectionId,
+ },
+ IssuerChanged {
+ old_issuer: T::AccountId,
+ new_issuer: T::AccountId,
+ collection_id: RmrkCollectionId,
},
CollectionLocked {
issuer: T::AccountId,
- collection_id: CollectionId,
+ collection_id: RmrkCollectionId,
},
}
@@ -71,7 +76,8 @@
/* Unique-specific events */
CorruptedCollectionType,
NotRmrkCollection,
- RmrkPropertyIsTooLong,
+ RmrkPropertyKeyIsTooLong,
+ RmrkPropertyValueIsTooLong,
/* RMRK compatible events */
CollectionNotEmpty,
@@ -85,9 +91,9 @@
#[transactional]
pub fn create_collection(
origin: OriginFor<T>,
- metadata: PropertyValue,
+ metadata: RmrkString,
max: Option<u32>,
- symbol: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
+ symbol: RmrkCollectionSymbol,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -98,7 +104,9 @@
let data = CreateCollectionData {
limits,
- token_prefix: symbol,
+ token_prefix: symbol.into_inner()
+ .try_into()
+ .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
..Default::default()
};
@@ -121,7 +129,10 @@
].into_iter()
)?;
- Self::deposit_event(Event::CollectionCreated { issuer: sender, collection_id });
+ Self::deposit_event(Event::CollectionCreated {
+ issuer: sender,
+ collection_id: collection_id.0
+ });
Ok(())
}
@@ -130,14 +141,16 @@
#[transactional]
pub fn destroy_collection(
origin: OriginFor<T>,
- collection_id: CollectionId,
+ collection_id: RmrkCollectionId,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
let cross_sender = T::CrossAccountId::from_sub(sender.clone());
- let collection = Self::get_nft_collection(collection_id)?;
+ let unique_collection_id = collection_id.into();
+
+ let collection = Self::get_nft_collection(unique_collection_id)?;
- Self::check_collection_type(collection_id, CollectionType::Regular)?;
+ Self::check_collection_type(unique_collection_id, CollectionType::Regular)?;
ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
@@ -152,18 +165,26 @@
#[transactional]
pub fn change_collection_issuer(
origin: OriginFor<T>,
- collection_id: CollectionId,
- new_issuer: T::AccountId,
+ collection_id: RmrkCollectionId,
+ new_issuer: <T::Lookup as StaticLookup>::Source,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
+ let new_issuer = T::Lookup::lookup(new_issuer)?;
+
Self::change_collection_owner(
- collection_id,
+ collection_id.into(),
CollectionType::Regular,
- sender,
- new_issuer
+ sender.clone(),
+ new_issuer.clone()
)?;
+ Self::deposit_event(Event::IssuerChanged {
+ old_issuer: sender,
+ new_issuer,
+ collection_id,
+ });
+
Ok(())
}
@@ -171,12 +192,12 @@
#[transactional]
pub fn lock_collection(
origin: OriginFor<T>,
- collection_id: CollectionId,
+ collection_id: RmrkCollectionId,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
let cross_sender = T::CrossAccountId::from_sub(sender.clone());
- let collection = Self::get_nft_collection(collection_id)?;
+ let collection = Self::get_nft_collection(collection_id.into())?;
collection.check_is_owner(&cross_sender)?;
let token_count = collection.total_supply();
pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth1use super::*;2use codec::{Encode, Decode};3use pallet_nonfungible::NonfungibleHandle;45macro_rules! impl_rmrk_value {6 ($enum_name:path, decode_error: $error:ident) => {7 impl From<$enum_name> for PropertyValue {8 fn from(e: $enum_name) -> Self {9 e.encode().try_into().unwrap()10 }11 }1213 impl TryFrom<&PropertyValue> for $enum_name {14 type Error = MiscError;1516 fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {17 let mut value = value.as_slice();1819 <$enum_name>::decode(&mut value)20 .map_err(|_| MiscError::$error)21 }22 }2324 };25}2627pub enum MiscError {28 CorruptedCollectionType,29}3031impl<T: Config> From<MiscError> for Error<T> {32 fn from(error: MiscError) -> Self {33 match error {34 MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,35 }36 }37}3839pub trait IntoNftCollection<T: Config> {40 fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;41}4243impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {44 fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {45 match self.mode {46 CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),47 _ => Err(<Error<T>>::NotRmrkCollection)48 }49 }50}5152#[derive(Encode, Decode, PartialEq, Eq)]53pub enum CollectionType {54 Regular,55 Resource,56 Base,57}5859impl_rmrk_value!(CollectionType, decode_error: CorruptedCollectionType);1use super::*;2use codec::{Encode, Decode};3use pallet_nonfungible::NonfungibleHandle;45macro_rules! impl_rmrk_value {6 ($enum_name:path, decode_error: $error:ident) => {7 impl IntoPropertyValue for $enum_name {8 fn into_property_value(self) -> Result<PropertyValue, MiscError> {9 self.encode()10 .try_into()11 .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)12 }13 }1415 impl TryFrom<&PropertyValue> for $enum_name {16 type Error = MiscError;1718 fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {19 let mut value = value.as_slice();2021 <$enum_name>::decode(&mut value)22 .map_err(|_| MiscError::$error)23 }24 }2526 };27}2829pub enum MiscError {30 RmrkPropertyValueIsTooLong,31 CorruptedCollectionType,32}3334impl<T: Config> From<MiscError> for Error<T> {35 fn from(error: MiscError) -> Self {36 match error {37 MiscError::RmrkPropertyValueIsTooLong => Self::RmrkPropertyValueIsTooLong,38 MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,39 }40 }41}4243pub trait IntoNftCollection<T: Config> {44 fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;45}4647impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {48 fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {49 match self.mode {50 CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),51 _ => Err(<Error<T>>::NotRmrkCollection)52 }53 }54}5556pub trait IntoPropertyValue {57 fn into_property_value(self) -> Result<PropertyValue, MiscError>;58}5960impl<L: Get<u32>> IntoPropertyValue for BoundedVec<u8, L> {61 fn into_property_value(self) -> Result<PropertyValue, MiscError> {62 self.into_inner()63 .try_into()64 .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)65 }66}6768#[derive(Encode, Decode, PartialEq, Eq)]69pub enum CollectionType {70 Regular,71 Resource,72 Base,73}7475impl_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
@@ -36,7 +36,7 @@
macro_rules! key {
($($component:expr),+) => {
PropertyKey::try_from([$(key!(@ &$component)),+].concat())
- .map_err(|_| <Error<T>>::RmrkPropertyIsTooLong)
+ .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)
};
(@ $key:expr) => {
@@ -75,12 +75,17 @@
#[macro_export]
macro_rules! rmrk_property {
- (Config=$cfg:ty, $key:ident: $value:expr) => {
- rmrk_property!(@$cfg, $key).map(|key| Property {
+ (Config=$cfg:ty, $key:ident: $value:expr) => {{
+ let key = rmrk_property!(@$cfg, $key)?;
+
+ let value = $value.into_property_value()
+ .map_err(<$crate::Error<$cfg>>::from)?;
+
+ Ok::<_, $crate::Error<$cfg>>(Property {
key,
- value: $value.into()
+ value,
})
- };
+ }};
(@$cfg:ty, $key:ident) => {
$crate::RmrkProperty::$key.to_key::<$cfg>()
@@ -88,6 +93,6 @@
(Config=$cfg:ty, $key:ident) => {
PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key)?)
- .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyIsTooLong)
+ .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)
};
}
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -905,8 +905,20 @@
pub const RmrkPartsLimit: u32 = 3;
}
-pub type RmrkCollectionInfo<AccountId> =
- CollectionInfo<RmrkString, BoundedVec<u8, RmrkCollectionSymbolLimit>, AccountId>;
+impl From<RmrkCollectionId> for CollectionId {
+ fn from(id: RmrkCollectionId) -> Self {
+ Self(id)
+ }
+}
+
+impl From<RmrkNftId> for TokenId {
+ fn from(id: RmrkNftId) -> Self {
+ Self(id)
+ }
+}
+
+pub type RmrkCollectionSymbol = BoundedVec<u8, RmrkCollectionSymbolLimit>;
+pub type RmrkCollectionInfo<AccountId> = CollectionInfo<RmrkString, RmrkCollectionSymbol, AccountId>;
pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;
pub type RmrkResourceInfo = ResourceInfo<
BoundedVec<u8, RmrkResourceSymbolLimit>,