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.rsdiffbeforeafterboth445macro_rules! impl_rmrk_value {5macro_rules! impl_rmrk_value {6 ($enum_name:path, decode_error: $error:ident) => {6 ($enum_name:path, decode_error: $error:ident) => {7 impl From<$enum_name> for PropertyValue {7 impl IntoPropertyValue for $enum_name {8 fn from(e: $enum_name) -> Self {8 fn into_property_value(self) -> Result<PropertyValue, MiscError> {9 e.encode().try_into().unwrap()9 self.encode()10 .try_into()11 .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)10 }12 }11 }13 }121425}27}262827pub enum MiscError {29pub enum MiscError {30 RmrkPropertyValueIsTooLong,28 CorruptedCollectionType,31 CorruptedCollectionType,29}32}303331impl<T: Config> From<MiscError> for Error<T> {34impl<T: Config> From<MiscError> for Error<T> {32 fn from(error: MiscError) -> Self {35 fn from(error: MiscError) -> Self {33 match error {36 match error {37 MiscError::RmrkPropertyValueIsTooLong => Self::RmrkPropertyValueIsTooLong,34 MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,38 MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,35 }39 }36 }40 }49 }53 }50}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}516752#[derive(Encode, Decode, PartialEq, Eq)]68#[derive(Encode, Decode, PartialEq, Eq)]53pub enum CollectionType {69pub enum CollectionType {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>,