@@ -513,6 +513,51 @@ pub mod pallet {
513513 Self :: deposit_event ( Event :: ExpiredPreimageAuthorizationRemoved { hash } ) ;
514514 Ok ( ( ) )
515515 }
516+
517+ /// Refresh the expiration of an existing authorization for an account.
518+ ///
519+ /// If the account does not have an authorization, the call will fail.
520+ ///
521+ /// Parameters:
522+ ///
523+ /// - `who`: The account to be credited with an authorization to store data.
524+ ///
525+ /// The origin for this call must be the pallet's `Authorizer`. Emits
526+ /// [`AccountAuthorizationRefreshed`](Event::AccountAuthorizationRefreshed) when successful.
527+ #[ pallet:: call_index( 7 ) ]
528+ #[ pallet:: weight( T :: WeightInfo :: refresh_account_authorization( ) ) ]
529+ pub fn refresh_account_authorization (
530+ origin : OriginFor < T > ,
531+ who : T :: AccountId ,
532+ ) -> DispatchResult {
533+ T :: Authorizer :: ensure_origin ( origin) ?;
534+ Self :: refresh_authorization ( AuthorizationScope :: Account ( who. clone ( ) ) ) ?;
535+ Self :: deposit_event ( Event :: AccountAuthorizationRefreshed { who } ) ;
536+ Ok ( ( ) )
537+ }
538+
539+ /// Refresh the expiration of an existing authorization for a preimage of a BLAKE2b hash.
540+ ///
541+ /// If the preimage does not have an authorization, the call will fail.
542+ ///
543+ /// Parameters:
544+ ///
545+ /// - `hash`: The BLAKE2b hash of the data to be submitted.
546+ ///
547+ /// The origin for this call must be the pallet's `Authorizer`. Emits
548+ /// [`PreimageAuthorizationRefreshed`](Event::PreimageAuthorizationRefreshed) when
549+ /// successful.
550+ #[ pallet:: call_index( 8 ) ]
551+ #[ pallet:: weight( T :: WeightInfo :: refresh_preimage_authorization( ) ) ]
552+ pub fn refresh_preimage_authorization (
553+ origin : OriginFor < T > ,
554+ hash : ContentHash ,
555+ ) -> DispatchResult {
556+ T :: Authorizer :: ensure_origin ( origin) ?;
557+ Self :: refresh_authorization ( AuthorizationScope :: Preimage ( hash) ) ?;
558+ Self :: deposit_event ( Event :: PreimageAuthorizationRefreshed { hash } ) ;
559+ Ok ( ( ) )
560+ }
516561 }
517562
518563 #[ pallet:: event]
@@ -526,9 +571,13 @@ pub mod pallet {
526571 ProofChecked ,
527572 /// An account `who` was authorized to store `bytes` bytes in `transactions` transactions.
528573 AccountAuthorized { who : T :: AccountId , transactions : u32 , bytes : u64 } ,
574+ /// An authorization for account `who` was refreshed.
575+ AccountAuthorizationRefreshed { who : T :: AccountId } ,
529576 /// Authorization was given for a preimage of `hash` (not exceeding `max_size`) to be
530577 /// stored by anyone.
531578 PreimageAuthorized { hash : ContentHash , max_size : u64 } ,
579+ /// An authorization for a preimage of `hash` was refreshed.
580+ PreimageAuthorizationRefreshed { hash : ContentHash } ,
532581 /// An expired account authorization was removed.
533582 ExpiredAccountAuthorizationRemoved { who : T :: AccountId } ,
534583 /// An expired preimage authorization was removed.
@@ -678,6 +727,22 @@ pub mod pallet {
678727 } ) ;
679728 }
680729
730+ /// Authorize data storage.
731+ fn refresh_authorization ( scope : AuthorizationScopeFor < T > ) -> DispatchResult {
732+ let expiration = frame_system:: Pallet :: < T > :: block_number ( )
733+ . saturating_add ( T :: AuthorizationPeriod :: get ( ) ) ;
734+
735+ Authorizations :: < T > :: mutate ( & scope, |maybe_authorization| {
736+ if let Some ( authorization) = maybe_authorization {
737+ authorization. expiration = expiration;
738+ Ok ( ( ) )
739+ } else {
740+ // No previous authorization to refresh.
741+ return Err ( Error :: < T > :: AuthorizationNotFound . into ( ) )
742+ }
743+ } )
744+ }
745+
681746 /// Remove an expired authorization.
682747 fn remove_expired_authorization ( scope : AuthorizationScopeFor < T > ) -> DispatchResult {
683748 // In the case of a regular unsigned transaction, pre_dispatch should have checked that
0 commit comments