@@ -8,28 +8,30 @@ mod mock;
88#[ cfg( test) ]
99mod tests;
1010
11- #[ cfg( feature = "runtime-benchmarks" ) ]
12- mod benchmarking;
11+ // #[cfg(feature = "runtime-benchmarks")]
12+ // mod benchmarking;
1313
14- pub mod types;
1514mod functions;
15+ pub mod types;
1616
1717#[ frame_support:: pallet]
1818pub mod pallet {
1919 use super :: * ;
20- use frame_support:: { pallet_prelude:: * , BoundedVec , transactional} ;
20+ use crate :: types:: * ;
21+ use frame_support:: { pallet_prelude:: * , transactional, BoundedVec } ;
2122 use frame_system:: pallet_prelude:: * ;
2223 use scale_info:: prelude:: vec:: Vec ;
23- use sp_runtime:: { Permill } ;
24- use crate :: types:: * ;
24+ use sp_runtime:: Permill ;
2525 /// Configure the pallet by specifying the parameters and types on which it depends.
2626 #[ pallet:: config]
2727 pub trait Config : frame_system:: Config + pallet_uniques:: Config {
28-
2928 type Event : From < Event < Self > > + IsType < <Self as frame_system:: Config >:: Event > ;
3029
3130 type RemoveOrigin : EnsureOrigin < Self :: Origin > ;
3231
32+ /// Maximum number of children a Frunique can have
33+ #[ pallet:: constant]
34+ type ChildMaxLen : Get < u32 > ;
3335 }
3436
3537 #[ pallet:: pallet]
@@ -66,26 +68,22 @@ pub mod pallet {
6668 ValueTooLong ,
6769 // Calling set on a non-existing attributes
6870 AttributesEmpty ,
69- // The collection doenst exist
71+ // The collection doesn't exist
7072 CollectionNotFound ,
7173 }
7274
7375 #[ pallet:: storage]
7476 #[ pallet:: getter( fn frunique_cnt) ]
7577 /// Keeps track of the number of Kitties in existence.
76- pub ( super ) type FruniqueCnt < T : Config > = StorageValue <
77- _ ,
78- ItemId ,
79- ValueQuery
80- > ;
78+ pub ( super ) type FruniqueCnt < T : Config > = StorageValue < _ , ItemId , ValueQuery > ;
8179
8280 #[ pallet:: storage]
8381 #[ pallet:: getter( fn next_collection) ]
8482 /// Keeps track of the number of collections in existence.
8583 pub ( super ) type NextCollection < T : Config > = StorageValue <
8684 _ ,
8785 CollectionId , // Next collection id.
88- ValueQuery
86+ ValueQuery ,
8987 > ;
9088
9189 #[ pallet:: storage]
@@ -95,8 +93,8 @@ pub mod pallet {
9593 _ ,
9694 Blake2_128Concat ,
9795 CollectionId ,
98- ItemId , // The next frunique id for a collection.
99- ValueQuery
96+ ItemId , // The next frunique id for a collection.
97+ ValueQuery ,
10098 > ;
10199
102100 #[ pallet:: storage]
@@ -107,9 +105,9 @@ pub mod pallet {
107105 Blake2_128Concat ,
108106 CollectionId ,
109107 Blake2_128Concat ,
110- ItemId , // FruniqueId
108+ ItemId , // FruniqueId
111109 Option < HierarchicalInfo > , // ParentId and flag if it inherit attributes
112- ValueQuery
110+ ValueQuery ,
113111 > ;
114112
115113 #[ pallet:: storage]
@@ -120,22 +118,19 @@ pub mod pallet {
120118 Blake2_128Concat ,
121119 CollectionId ,
122120 Blake2_128Concat ,
123- ItemId , // FruniqueId
121+ ItemId , // FruniqueId
124122 Option < HierarchicalInfo > , // ParentId and flag if it inherit attributes
125- ValueQuery
123+ ValueQuery ,
126124 > ;
127125
128-
129126 #[ pallet:: call]
130127 impl < T : Config > Pallet < T >
131128 where
132129 T : pallet_uniques:: Config < CollectionId = CollectionId , ItemId = ItemId > ,
133130 {
134131 #[ transactional]
135132 #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 10 ) ) ]
136- pub fn initial_setup (
137- origin : OriginFor < T > ,
138- ) -> DispatchResult {
133+ pub fn initial_setup ( origin : OriginFor < T > ) -> DispatchResult {
139134 T :: RemoveOrigin :: ensure_origin ( origin. clone ( ) ) ?;
140135 // Self::do_initial_setup()?;
141136 Ok ( ( ) )
@@ -146,7 +141,6 @@ pub mod pallet {
146141 origin : OriginFor < T > ,
147142 metadata : Option < StringLimit < T > > ,
148143 ) -> DispatchResult {
149-
150144 let admin: T :: AccountId = ensure_signed ( origin. clone ( ) ) ?;
151145
152146 let new_collection_id: u32 = Self :: next_collection ( ) . try_into ( ) . unwrap ( ) ;
@@ -158,12 +152,9 @@ pub mod pallet {
158152 Self :: account_id_to_lookup_source ( & admin) ,
159153 ) ?;
160154
161- Self :: deposit_event ( Event :: FruniqueCollectionCreated (
162- admin,
163- new_collection_id,
164- ) ) ;
155+ Self :: deposit_event ( Event :: FruniqueCollectionCreated ( admin, new_collection_id) ) ;
165156
166- <NextCollection < T > >:: put ( Self :: next_collection ( ) + 1 ) ;
157+ <NextCollection < T > >:: put ( Self :: next_collection ( ) + 1 ) ;
167158
168159 Ok ( ( ) )
169160 }
@@ -244,7 +235,6 @@ pub mod pallet {
244235 parent_info : Option < HierarchicalInfo > ,
245236 attributes : Option < Vec < ( BoundedVec < u8 , T :: KeyLimit > , BoundedVec < u8 , T :: ValueLimit > ) > > ,
246237 ) -> DispatchResult {
247-
248238 let owner: T :: AccountId = ensure_signed ( origin. clone ( ) ) ?;
249239 let account_id = Self :: account_id_to_lookup_source ( & owner) ;
250240
@@ -257,14 +247,22 @@ pub mod pallet {
257247 instance_id,
258248 account_id,
259249 numeric_value,
260- attributes
250+ attributes,
261251 ) ?;
262252
263- Self :: deposit_event ( Event :: FruniqueCreated ( owner. clone ( ) , owner, class_id, instance_id) ) ;
253+ Self :: deposit_event ( Event :: FruniqueCreated (
254+ owner. clone ( ) ,
255+ owner,
256+ class_id,
257+ instance_id,
258+ ) ) ;
264259
265260 if let Some ( parent_info) = parent_info {
266261 // ! check if parent exists
267- ensure ! ( Self :: item_exists( & class_id, & parent_info. 0 ) , <Error <T >>:: CollectionNotFound ) ;
262+ ensure ! (
263+ Self :: item_exists( & class_id, & parent_info. 0 ) ,
264+ <Error <T >>:: CollectionNotFound
265+ ) ;
268266 <FruniqueParent < T > >:: insert ( class_id, instance_id, Some ( parent_info) ) ;
269267 // Self::do_hierarchical_division(origin.clone(), class_id, instance_id, parent_info)?;
270268 }
@@ -284,15 +282,12 @@ pub mod pallet {
284282 /// - This function is only available to the `admin` with sudo access.
285283 #[ transactional]
286284 #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
287- pub fn kill_storage (
288- origin : OriginFor < T > ,
289- ) -> DispatchResult {
285+ pub fn kill_storage ( origin : OriginFor < T > ) -> DispatchResult {
290286 T :: RemoveOrigin :: ensure_origin ( origin. clone ( ) ) ?;
291287 let _ = <FruniqueCnt < T > >:: put ( 0 ) ;
292288 let _ = <NextCollection < T > >:: put ( 0 ) ;
293289 let _ = <NextFrunique < T > >:: clear ( 1000 , None ) ;
294290 Ok ( ( ) )
295291 }
296-
297292 }
298293}
0 commit comments