66
77use codec:: { Decode , Encode , MaxEncodedLen } ;
88use frame_support:: {
9- dispatch:: DispatchInfo ,
109 traits:: { ConstU32 , IsSubType , StorageVersion } ,
1110 BoundedVec ,
1211} ;
@@ -15,7 +14,7 @@ use scale_info::TypeInfo;
1514#[ cfg( feature = "std" ) ]
1615use serde:: { Deserialize , Serialize } ;
1716use sp_runtime:: {
18- traits:: { DispatchInfoOf , Dispatchable , SignedExtension } ,
17+ traits:: { DispatchInfoOf , SignedExtension } ,
1918 transaction_validity:: { TransactionValidity , TransactionValidityError } ,
2019} ;
2120use sp_std:: { fmt:: Debug , marker:: PhantomData , prelude:: * } ;
@@ -612,17 +611,9 @@ pub mod pallet {
612611 Ok ( auth_ticket)
613612 }
614613
615- pub fn check_tx ( call : & Call < T > ) -> TransactionValidity {
616- let transaction = match call {
617- Call :: authenticate { req : transaction } => transaction,
618- // Deny all unknown transactions.
619- _ => {
620- // The only supported transaction by this pallet is `authenticate`, so anything
621- // else is illegal.
622- return Err ( TransactionValidityError :: Invalid ( InvalidTransaction :: Call ) ) ;
623- }
624- } ;
625-
614+ pub fn check_tx (
615+ transaction : & Authenticate < T :: OpaqueAuthTicket , T :: RobonodeSignature > ,
616+ ) -> TransactionValidity {
626617 let auth_ticket =
627618 Self :: extract_auth_ticket_checked ( transaction. clone ( ) ) . map_err ( |error| {
628619 log:: error!( "Auth Ticket could not be extracted: {error:?}" ) ;
@@ -745,7 +736,6 @@ impl<T: Config + Send + Sync> Debug for CheckBioauthTx<T> {
745736
746737impl < T : Config + Send + Sync > SignedExtension for CheckBioauthTx < T >
747738where
748- T :: RuntimeCall : Dispatchable < Info = DispatchInfo > ,
749739 <T as frame_system:: Config >:: RuntimeCall : IsSubType < Call < T > > ,
750740{
751741 type AccountId = T :: AccountId ;
@@ -770,26 +760,43 @@ where
770760
771761 fn validate (
772762 & self ,
773- who : & Self :: AccountId ,
763+ _who : & Self :: AccountId ,
774764 call : & Self :: Call ,
775765 _info : & DispatchInfoOf < Self :: Call > ,
776766 _len : usize ,
777767 ) -> TransactionValidity {
778- let _account_id = who;
779- match call. is_sub_type ( ) {
780- Some ( call) => Pallet :: < T > :: check_tx ( call) ,
781- _ => Ok ( Default :: default ( ) ) ,
782- }
768+ Self :: do_validate ( call)
783769 }
784770
785771 fn validate_unsigned (
786772 call : & Self :: Call ,
787773 _info : & DispatchInfoOf < Self :: Call > ,
788774 _len : usize ,
789775 ) -> TransactionValidity {
790- match call. is_sub_type ( ) {
791- Some ( call) => Pallet :: < T > :: check_tx ( call) ,
792- _ => Ok ( Default :: default ( ) ) ,
793- }
776+ Self :: do_validate ( call)
777+ }
778+ }
779+
780+ impl < T : Config + Send + Sync > CheckBioauthTx < T >
781+ where
782+ <T as frame_system:: Config >:: RuntimeCall : IsSubType < Call < T > > ,
783+ {
784+ /// Perform the call validation.
785+ ///
786+ /// For the `authenticate` call checks the validity and correctness and lets everything else
787+ /// through.
788+ fn do_validate ( call : & T :: RuntimeCall ) -> TransactionValidity {
789+ // Reduce to calls from this pallet.
790+ let Some ( call) = call. is_sub_type ( ) else {
791+ return Ok ( Default :: default ( ) ) ;
792+ } ;
793+
794+ // Reduce to `authenticate` call.
795+ let Call :: authenticate { req : transaction } = call else {
796+ return Ok ( Default :: default ( ) ) ;
797+ } ;
798+
799+ // Check the `authenticate` transaction.
800+ Pallet :: < T > :: check_tx ( transaction)
794801 }
795802}
0 commit comments