@@ -101,6 +101,14 @@ pub mod pallet {
101101 + IsType < <Self as frame_system:: Config >:: RuntimeEvent > ;
102102
103103 /// Identifier for the collection of item.
104+ ///
105+ /// SAFETY: The functions in the `Incrementable` trait are fallible. If the functions
106+ /// of the implementation both return `None`, the automatic CollectionId generation
107+ /// should not be used. So the `create` and `force_create` extrinsics and the
108+ /// `create_collection` function will return an `UnknownCollection` Error. Instead use
109+ /// the `create_collection_with_id` function. However, if the `Incrementable` trait
110+ /// implementation has an incremental order, the `create_collection_with_id` function
111+ /// should not be used as it can claim a value in the ID sequence.
104112 type CollectionId : Member + Parameter + MaxEncodedLen + Copy + Incrementable ;
105113
106114 /// The type used to identify a unique item within a collection.
@@ -476,7 +484,7 @@ pub mod pallet {
476484 /// Mint settings for a collection had changed.
477485 CollectionMintSettingsUpdated { collection : T :: CollectionId } ,
478486 /// Event gets emitted when the `NextCollectionId` gets incremented.
479- NextCollectionIdIncremented { next_id : T :: CollectionId } ,
487+ NextCollectionIdIncremented { next_id : Option < T :: CollectionId > } ,
480488 /// The price was set for the item.
481489 ItemPriceSet {
482490 collection : T :: CollectionId ,
@@ -665,8 +673,9 @@ pub mod pallet {
665673 admin : AccountIdLookupOf < T > ,
666674 config : CollectionConfigFor < T , I > ,
667675 ) -> DispatchResult {
668- let collection =
669- NextCollectionId :: < T , I > :: get ( ) . unwrap_or ( T :: CollectionId :: initial_value ( ) ) ;
676+ let collection = NextCollectionId :: < T , I > :: get ( )
677+ . or ( T :: CollectionId :: initial_value ( ) )
678+ . ok_or ( Error :: < T , I > :: UnknownCollection ) ?;
670679
671680 let owner = T :: CreateOrigin :: ensure_origin ( origin, & collection) ?;
672681 let admin = T :: Lookup :: lookup ( admin) ?;
@@ -684,7 +693,10 @@ pub mod pallet {
684693 config,
685694 T :: CollectionDeposit :: get ( ) ,
686695 Event :: Created { collection, creator : owner, owner : admin } ,
687- )
696+ ) ?;
697+
698+ Self :: set_next_collection_id ( collection) ;
699+ Ok ( ( ) )
688700 }
689701
690702 /// Issue a new collection of non-fungible items from a privileged origin.
@@ -712,8 +724,9 @@ pub mod pallet {
712724 T :: ForceOrigin :: ensure_origin ( origin) ?;
713725 let owner = T :: Lookup :: lookup ( owner) ?;
714726
715- let collection =
716- NextCollectionId :: < T , I > :: get ( ) . unwrap_or ( T :: CollectionId :: initial_value ( ) ) ;
727+ let collection = NextCollectionId :: < T , I > :: get ( )
728+ . or ( T :: CollectionId :: initial_value ( ) )
729+ . ok_or ( Error :: < T , I > :: UnknownCollection ) ?;
717730
718731 Self :: do_create_collection (
719732 collection,
@@ -722,7 +735,10 @@ pub mod pallet {
722735 config,
723736 Zero :: zero ( ) ,
724737 Event :: ForceCreated { collection, owner } ,
725- )
738+ ) ?;
739+
740+ Self :: set_next_collection_id ( collection) ;
741+ Ok ( ( ) )
726742 }
727743
728744 /// Destroy a collection of fungible items.
0 commit comments