Skip to content

Commit f49547b

Browse files
committed
add validation to know if a collection exists
1 parent ce6abd1 commit f49547b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

pallets/fruniques/src/functions.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ impl<T: Config> Pallet<T> {
6060
pallet_uniques::Pallet::<T>::owner(*class_id, *instance_id)
6161
}
6262

63+
pub fn collection_exists(class_id: &T::CollectionId) -> bool {
64+
if let Some(_owner) = pallet_uniques::Pallet::<T>::collection_owner(*class_id) {
65+
return true;
66+
}
67+
false
68+
}
69+
6370
pub fn set_attribute(
6471
origin: OriginFor<T>,
6572
class_id: &T::CollectionId,
@@ -178,6 +185,7 @@ impl<T: Config> Pallet<T> {
178185
attributes: Option<Vec<(BoundedVec<u8, T::KeyLimit>, BoundedVec<u8, T::ValueLimit>)>>,
179186
) -> DispatchResult {
180187

188+
ensure!(Self::collection_exists(&collection), <Error<T>>::CollectionNotFound);
181189
pallet_uniques::Pallet::<T>::mint(
182190
origin.clone(),
183191
collection,
@@ -196,12 +204,6 @@ impl<T: Config> Pallet<T> {
196204
)?;
197205
}
198206
}
199-
// let instance_id: T::ItemId = Self::u32_to_instance_id(input);
200-
201-
// pallet_uniques::Pallet::<T>::mint(origin,
202-
// Self::u32_to_class_id(class_id),
203-
// Self::u32_to_instance_id(instance_id),
204-
// owner)?;
205207

206208
Ok(())
207209
}

pallets/fruniques/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pub mod pallet {
6666
ValueTooLong,
6767
// Calling set on a non-existing attributes
6868
AttributesEmpty,
69+
// The collection doenst exist
70+
CollectionNotFound,
6971
}
7072

7173
#[pallet::storage]
@@ -116,6 +118,15 @@ pub mod pallet {
116118
where
117119
T: pallet_uniques::Config<CollectionId = CollectionId, ItemId = ItemId>,
118120
{
121+
#[transactional]
122+
#[pallet::weight(10_000 + T::DbWeight::get().writes(10))]
123+
pub fn initial_setup(
124+
origin: OriginFor<T>,
125+
) -> DispatchResult {
126+
T::RemoveOrigin::ensure_origin(origin.clone())?;
127+
// Self::do_initial_setup()?;
128+
Ok(())
129+
}
119130

120131
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
121132
pub fn create_collection(

0 commit comments

Comments
 (0)