@@ -76,6 +76,10 @@ pub mod pallet {
76
76
ParentNotFound ,
77
77
// The frunique doesn't exist
78
78
FruniqueNotFound ,
79
+ // Collection already exists
80
+ CollectionAlreadyExists ,
81
+ // Frunique already exists
82
+ FruniqueAlreadyExists ,
79
83
}
80
84
81
85
#[ pallet:: storage]
@@ -142,10 +146,17 @@ pub mod pallet {
142
146
Ok ( ( ) )
143
147
}
144
148
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.
145
156
#[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
146
157
pub fn create_collection (
147
158
origin : OriginFor < T > ,
148
- metadata : Option < StringLimit < T > > ,
159
+ metadata : Option < CollectionDescription < T > > ,
149
160
) -> DispatchResult {
150
161
let admin: T :: AccountId = ensure_signed ( origin. clone ( ) ) ?;
151
162
@@ -182,14 +193,10 @@ pub mod pallet {
182
193
}
183
194
184
195
/// ## 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.
186
197
/// - `class_id` must be a valid class of the asset class.
187
198
/// - `instance_id` must be a valid instance of the asset class.
188
199
/// - `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
-
193
200
#[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
194
201
pub fn set_attributes (
195
202
origin : OriginFor < T > ,
@@ -218,22 +225,12 @@ pub mod pallet {
218
225
Ok ( ( ) )
219
226
}
220
227
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.
237
234
#[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 4 ) ) ]
238
235
pub fn spawn (
239
236
origin : OriginFor < T > ,
@@ -279,6 +276,61 @@ pub mod pallet {
279
276
Ok ( ( ) )
280
277
}
281
278
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
+
282
334
/// Kill all the stored data.
283
335
///
284
336
/// This function is used to kill ALL the stored data.
0 commit comments