Skip to content

Commit 0136de3

Browse files
authored
Merge pull request #234 from hashed-io/develop
Release 122
2 parents 4f4d75b + 07d504c commit 0136de3

File tree

8 files changed

+210
-145
lines changed

8 files changed

+210
-145
lines changed

pallets/fruniques/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<T: Config> Pallet<T> {
145145
pub fn do_create_collection(
146146
origin: OriginFor<T>,
147147
class_id: T::CollectionId,
148-
metadata: Option<StringLimit<T>>,
148+
metadata: Option<CollectionDescription<T>>,
149149
admin: <T::Lookup as sp_runtime::traits::StaticLookup>::Source,
150150
) -> DispatchResult {
151151
pallet_uniques::Pallet::<T>::create(

pallets/fruniques/src/lib.rs

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ pub mod pallet {
7676
ParentNotFound,
7777
// The frunique doesn't exist
7878
FruniqueNotFound,
79+
// Collection already exists
80+
CollectionAlreadyExists,
81+
// Frunique already exists
82+
FruniqueAlreadyExists,
7983
}
8084

8185
#[pallet::storage]
@@ -142,10 +146,17 @@ pub mod pallet {
142146
Ok(())
143147
}
144148

149+
/// # Creation of a collection
150+
/// This function creates a collection and an asset class.
151+
/// The collection is a unique identifier for a set of fruniques.
152+
///
153+
/// ## Parameters
154+
/// - `origin`: The origin of the transaction.
155+
/// - `Metadata`: The title of the collection.
145156
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
146157
pub fn create_collection(
147158
origin: OriginFor<T>,
148-
metadata: Option<StringLimit<T>>,
159+
metadata: Option<CollectionDescription<T>>,
149160
) -> DispatchResult {
150161
let admin: T::AccountId = ensure_signed(origin.clone())?;
151162

@@ -182,14 +193,10 @@ pub mod pallet {
182193
}
183194

184195
/// ## Set multiple attributes to a frunique.
185-
/// `origin` must be signed by the owner of the frunique.
196+
/// - `origin` must be signed by the owner of the frunique.
186197
/// - `class_id` must be a valid class of the asset class.
187198
/// - `instance_id` must be a valid instance of the asset class.
188199
/// - `attributes` must be a list of pairs of `key` and `value`.
189-
/// `key` must be a valid key for the asset class.
190-
/// `value` must be a valid value for the asset class.
191-
/// `attributes` must not be empty.
192-
193200
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
194201
pub fn set_attributes(
195202
origin: OriginFor<T>,
@@ -218,22 +225,12 @@ pub mod pallet {
218225
Ok(())
219226
}
220227

221-
/// ## NFT Division
222-
///
223-
/// PD: the Key/value length limits are inherited from the uniques pallet,
224-
/// so they're not explicitly declared on this pallet
225-
///
226-
///
227-
/// ### Boilerplate parameters:
228-
///
229-
/// - `admin`: The admin of this class of assets. The admin is the initial address of each
230-
/// member of the asset class's admin team.
231-
///
232-
/// ### Parameters needed in order to divide a unique:
233-
/// - `class_id`: The type of NFT that the function will create, categorized by numbers.
234-
/// - `parent_info`: Information of the parent NFT and a flag to indicate the child would inherit their attributes.
235-
/// - `attributes`: Generates a list of attributes for the new NFT.
236-
///
228+
/// ## NFT creation
229+
/// ### Parameters:
230+
/// - `origin` must be signed by the owner of the frunique.
231+
/// - `class_id` must be a valid class of the asset class.
232+
/// - `parent_info` Optional value needed for the NFT division.
233+
/// - `attributes` An array of attributes (key, value) to be added to the NFT.
237234
#[pallet::weight(10_000 + T::DbWeight::get().writes(4))]
238235
pub fn spawn(
239236
origin: OriginFor<T>,
@@ -279,6 +276,61 @@ pub mod pallet {
279276
Ok(())
280277
}
281278

279+
/// ## Force set counter
280+
/// ### Parameters:
281+
/// `origin` must be signed by the Root origin.
282+
/// - `class_id` must be a valid class of the asset class.
283+
/// - `instance_id` must be a valid instance of the asset class.
284+
///
285+
/// ### Considerations:
286+
/// This function is only used for testing purposes. Or in case someone calls uniques pallet directly.
287+
/// This function it's not expected to be used in production as it can lead to unexpected results.
288+
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
289+
pub fn force_set_counter(
290+
origin: OriginFor<T>,
291+
class_id: T::CollectionId,
292+
instance_id: Option<T::ItemId>,
293+
) -> DispatchResult {
294+
T::RemoveOrigin::ensure_origin(origin.clone())?;
295+
296+
if let Some(instance_id) = instance_id {
297+
ensure!(!Self::item_exists(&class_id, &instance_id), <Error<T>>::FruniqueAlreadyExists);
298+
<NextFrunique<T>>::insert(class_id, instance_id);
299+
} else {
300+
ensure!(!Self::collection_exists(&class_id), <Error<T>>::CollectionAlreadyExists);
301+
<NextCollection<T>>::set(class_id);
302+
}
303+
304+
Ok(())
305+
}
306+
307+
/// ## Force destroy collection
308+
/// ### Parameters:
309+
/// - `origin` must be signed by the Root origin.
310+
/// - `class_id` must be a valid class of the asset class.
311+
/// - `witness` the witness data to destroy the collection. This is used to prevent accidental destruction of the collection. The witness data is retrieved from the `class` storage.
312+
/// - `maybe_check_owner` Optional value to check if the owner of the collection is the same as the signer.
313+
/// ### Considerations:
314+
/// This function is only used for testing purposes. Or in case someone calls uniques pallet directly.
315+
/// This function it's not expected to be used in production as it can lead to unexpected results.
316+
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
317+
pub fn force_destroy_collection(
318+
origin: OriginFor<T>,
319+
class_id: T::CollectionId,
320+
witness: pallet_uniques::DestroyWitness,
321+
maybe_check_owner: Option<T::AccountId>,
322+
) -> DispatchResult {
323+
T::RemoveOrigin::ensure_origin(origin.clone())?;
324+
325+
ensure!(Self::collection_exists(&class_id), <Error<T>>::CollectionNotFound);
326+
pallet_uniques::Pallet::<T>::do_destroy_collection(
327+
class_id,
328+
witness,
329+
maybe_check_owner,
330+
)?;
331+
Ok(())
332+
}
333+
282334
/// Kill all the stored data.
283335
///
284336
/// This function is used to kill ALL the stored data.

pallets/fruniques/src/types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ pub type AttributeKey<T> = BoundedVec<u8, <T as pallet_uniques::Config>::KeyLimi
1010
pub type AttributeValue<T> = BoundedVec<u8, <T as pallet_uniques::Config>::ValueLimit>;
1111
pub type Attributes<T> = Vec<(AttributeKey<T>, AttributeValue<T>)>;
1212

13-
pub type CollectionDescription = [u8; 32];
13+
// pub type CollectionDescription = [u8; 32];
1414
pub type StringLimit<T> = BoundedVec<u8, <T as pallet_uniques::Config>::StringLimit>;
1515

1616
pub type CollectionId = u32;
1717
pub type ItemId = u32;
1818

19-
// (ParentId, Heirarchical)
19+
pub type CollectionDescription<T> = BoundedVec<u8, <T as pallet_uniques::Config>::StringLimit>;
20+
// (ParentId, Hierarchical, Percentage)
2021
pub type HierarchicalInfo = (ItemId, bool, u8);
2122

2223
#[derive(CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen)]

0 commit comments

Comments
 (0)