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.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -4,9 +4,11 @@
macro_rules! impl_rmrk_value {
($enum_name:path, decode_error: $error:ident) => {
- impl From<$enum_name> for PropertyValue {
- fn from(e: $enum_name) -> Self {
- e.encode().try_into().unwrap()
+ impl IntoPropertyValue for $enum_name {
+ fn into_property_value(self) -> Result<PropertyValue, MiscError> {
+ self.encode()
+ .try_into()
+ .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)
}
}
@@ -25,12 +27,14 @@
}
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,
}
}
@@ -49,6 +53,18 @@
}
}
+pub trait IntoPropertyValue {
+ fn into_property_value(self) -> Result<PropertyValue, MiscError>;
+}
+
+impl<L: Get<u32>> IntoPropertyValue for BoundedVec<u8, L> {
+ fn into_property_value(self) -> Result<PropertyValue, MiscError> {
+ self.into_inner()
+ .try_into()
+ .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)
+ }
+}
+
#[derive(Encode, Decode, PartialEq, Eq)]
pub enum CollectionType {
Regular,
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth36 macro_rules! key {36 macro_rules! key {37 ($($component:expr),+) => {37 ($($component:expr),+) => {38 PropertyKey::try_from([$(key!(@ &$component)),+].concat())38 PropertyKey::try_from([$(key!(@ &$component)),+].concat())39 .map_err(|_| <Error<T>>::RmrkPropertyIsTooLong)39 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)40 };40 };414142 (@ $key:expr) => {42 (@ $key:expr) => {757576#[macro_export]76#[macro_export]77macro_rules! rmrk_property {77macro_rules! rmrk_property {78 (Config=$cfg:ty, $key:ident: $value:expr) => {78 (Config=$cfg:ty, $key:ident: $value:expr) => {{79 rmrk_property!(@$cfg, $key).map(|key| Property {79 let key = rmrk_property!(@$cfg, $key)?;8081 let value = $value.into_property_value()82 .map_err(<$crate::Error<$cfg>>::from)?;8384 Ok::<_, $crate::Error<$cfg>>(Property {80 key,85 key,81 value: $value.into()86 value,82 })87 })83 };88 }};848985 (@$cfg:ty, $key:ident) => {90 (@$cfg:ty, $key:ident) => {86 $crate::RmrkProperty::$key.to_key::<$cfg>()91 $crate::RmrkProperty::$key.to_key::<$cfg>()87 };92 };889389 (Config=$cfg:ty, $key:ident) => {94 (Config=$cfg:ty, $key:ident) => {90 PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key)?)95 PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key)?)91 .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyIsTooLong)96 .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)92 };97 };93}98}9499primitives/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>,