@@ -17,10 +17,12 @@ mod test_util;
1717
1818mod functions;
1919pub mod types;
20-
20+ pub mod weights;
21+ use weights:: WeightInfo ;
2122#[ frame_support:: pallet]
2223pub mod pallet {
2324 //! Provides the backend services and metadata storage for the confidential docs solution
25+ use super :: * ;
2426 use crate :: types:: * ;
2527 use frame_support:: pallet_prelude:: * ;
2628 use frame_system:: pallet_prelude:: * ;
@@ -63,6 +65,9 @@ pub mod pallet {
6365 /// Maximum groups a user can belong to
6466 #[ pallet:: constant]
6567 type MaxMemberGroups : Get < u32 > ;
68+
69+ /// Weight information for extrinsics in this pallet.
70+ type WeightInfo : WeightInfo ;
6671 }
6772
6873 #[ pallet:: pallet]
@@ -246,7 +251,7 @@ pub mod pallet {
246251 /// - `public key`: The users cipher public key
247252 /// - `cid`: The IPFS CID that contains the vaults data
248253 #[ pallet:: call_index( 1 ) ]
249- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get ( ) . writes ( 1 ) ) ]
254+ #[ pallet:: weight( < T as Config > :: WeightInfo :: set_vault ( cid . len ( ) as u32 ) ) ]
250255 pub fn set_vault (
251256 origin : OriginFor < T > ,
252257 user_id : UserId ,
@@ -265,7 +270,7 @@ pub mod pallet {
265270 /// - `origin`: The user that is creating/updating an owned document
266271 /// - `owned_doc`: Metadata related to the owned document
267272 #[ pallet:: call_index( 2 ) ]
268- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get( ) . writes ( 1 ) ) ]
273+ #[ pallet:: weight( < T as Config > :: WeightInfo :: set_owned_document ( owned_doc . cid . len ( ) as u32 , owned_doc . name . len ( ) as u32 , owned_doc . description . len ( ) as u32 , T :: MaxOwnedDocs :: get( ) ) ) ]
269274 pub fn set_owned_document ( origin : OriginFor < T > , owned_doc : OwnedDoc < T > ) -> DispatchResult {
270275 let who = ensure_signed ( origin) ?;
271276 Self :: do_set_owned_document ( who, owned_doc)
@@ -279,7 +284,7 @@ pub mod pallet {
279284 /// - `origin`: The owner of the document
280285 /// - `cid`: of the document to be removed
281286 #[ pallet:: call_index( 3 ) ]
282- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get( ) . writes ( 1 ) ) ]
287+ #[ pallet:: weight( < T as Config > :: WeightInfo :: remove_owned_document ( cid . len ( ) as u32 , T :: DocNameMaxLen :: get( ) , T :: DocDescMaxLen :: get ( ) , T :: MaxOwnedDocs :: get ( ) ) ) ]
283288 pub fn remove_owned_document ( origin : OriginFor < T > , cid : CID ) -> DispatchResult {
284289 let who = ensure_signed ( origin) ?;
285290 Self :: do_remove_owned_document ( who, cid)
@@ -293,7 +298,7 @@ pub mod pallet {
293298 /// - `origin`: The user that is creating the shared document
294299 /// - `shared_doc`: Metadata related to the shared document
295300 #[ pallet:: call_index( 4 ) ]
296- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get( ) . writes ( 1 ) ) ]
301+ #[ pallet:: weight( < T as Config > :: WeightInfo :: share_document ( shared_doc . cid . len ( ) as u32 , shared_doc . name . len ( ) as u32 , shared_doc . description . len ( ) as u32 , T :: MaxSharedFromDocs :: get( ) ) ) ]
297302 pub fn share_document ( origin : OriginFor < T > , shared_doc : SharedDoc < T > ) -> DispatchResult {
298303 let who = ensure_signed ( origin) ?;
299304 Self :: do_share_document ( who, shared_doc)
@@ -308,7 +313,7 @@ pub mod pallet {
308313 /// - `origin`: The "to" user of the shared document
309314 /// - `shared_doc`: Metadata related to the shared document
310315 #[ pallet:: call_index( 5 ) ]
311- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get ( ) . writes ( 1 ) ) ]
316+ #[ pallet:: weight( < T as Config > :: WeightInfo :: update_shared_document_metadata ( shared_doc . cid . len ( ) as u32 , shared_doc . name . len ( ) as u32 , shared_doc . description . len ( ) as u32 ) ) ]
312317 pub fn update_shared_document_metadata (
313318 origin : OriginFor < T > ,
314319 shared_doc : SharedDoc < T > ,
@@ -326,7 +331,7 @@ pub mod pallet {
326331 /// - `origin`: The "to" user of the shared document
327332 /// - `cid`: of the document to be removed
328333 #[ pallet:: call_index( 6 ) ]
329- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get( ) . writes ( 1 ) ) ]
334+ #[ pallet:: weight( < T as Config > :: WeightInfo :: remove_shared_document ( cid . len ( ) as u32 , T :: DocNameMaxLen :: get( ) , T :: DocDescMaxLen :: get ( ) , T :: MaxSharedFromDocs :: get ( ) ) ) ]
330335 pub fn remove_shared_document ( origin : OriginFor < T > , cid : CID ) -> DispatchResult {
331336 let who = ensure_signed ( origin) ?;
332337 Self :: do_remove_shared_document ( who, cid)
@@ -343,7 +348,7 @@ pub mod pallet {
343348 /// - `public_key`: Public key of the group
344349 /// - `cid`: cid of the document containing the private key of the group
345350 #[ pallet:: call_index( 7 ) ]
346- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get ( ) . writes ( 1 ) ) ]
351+ #[ pallet:: weight( < T as Config > :: WeightInfo :: create_group ( cid . len ( ) as u32 , name . len ( ) as u32 ) ) ]
347352 pub fn create_group (
348353 origin : OriginFor < T > ,
349354 group : T :: AccountId ,
@@ -363,7 +368,7 @@ pub mod pallet {
363368 /// - `origin`: The user that is adding the member to the group
364369 /// - `group_member`: GroupMember object containg the details of the member
365370 #[ pallet:: call_index( 8 ) ]
366- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get( ) . writes ( 1 ) ) ]
371+ #[ pallet:: weight( < T as Config > :: WeightInfo :: add_group_member ( group_member . cid . len ( ) as u32 , T :: GroupNameMaxLen :: get( ) , T :: MaxMemberGroups :: get ( ) ) ) ]
367372 pub fn add_group_member (
368373 origin : OriginFor < T > ,
369374 group_member : GroupMember < T > ,
@@ -382,7 +387,7 @@ pub mod pallet {
382387 /// - `group`: AccountId of the group
383388 /// - `member`: AccountId of the user to remove from the group
384389 #[ pallet:: call_index( 9 ) ]
385- #[ pallet:: weight( Weight :: from_parts ( 10_000 , 0 ) + T :: DbWeight :: get( ) . writes ( 1 ) ) ]
390+ #[ pallet:: weight( < T as Config > :: WeightInfo :: add_group_member ( < CIDSize as frame_support :: traits :: TypedGet > :: get ( ) , T :: GroupNameMaxLen :: get( ) , T :: MaxMemberGroups :: get ( ) ) ) ]
386391 pub fn remove_group_member (
387392 origin : OriginFor < T > ,
388393 group : T :: AccountId ,
0 commit comments