diff --git a/crates/pallet-bioauth/src/lib.rs b/crates/pallet-bioauth/src/lib.rs index 65d661a68..fde432b05 100644 --- a/crates/pallet-bioauth/src/lib.rs +++ b/crates/pallet-bioauth/src/lib.rs @@ -6,7 +6,6 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ - dispatch::DispatchInfo, traits::{ConstU32, IsSubType, StorageVersion}, BoundedVec, }; @@ -15,7 +14,7 @@ use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; use sp_runtime::{ - traits::{DispatchInfoOf, Dispatchable, SignedExtension}, + traits::{DispatchInfoOf, SignedExtension}, transaction_validity::{TransactionValidity, TransactionValidityError}, }; use sp_std::{fmt::Debug, marker::PhantomData, prelude::*}; @@ -612,17 +611,9 @@ pub mod pallet { Ok(auth_ticket) } - pub fn check_tx(call: &Call) -> TransactionValidity { - let transaction = match call { - Call::authenticate { req: transaction } => transaction, - // Deny all unknown transactions. - _ => { - // The only supported transaction by this pallet is `authenticate`, so anything - // else is illegal. - return Err(TransactionValidityError::Invalid(InvalidTransaction::Call)); - } - }; - + pub fn check_tx( + transaction: &Authenticate, + ) -> TransactionValidity { let auth_ticket = Self::extract_auth_ticket_checked(transaction.clone()).map_err(|error| { log::error!("Auth Ticket could not be extracted: {error:?}"); @@ -745,7 +736,6 @@ impl Debug for CheckBioauthTx { impl SignedExtension for CheckBioauthTx where - T::RuntimeCall: Dispatchable, ::RuntimeCall: IsSubType>, { type AccountId = T::AccountId; @@ -770,16 +760,12 @@ where fn validate( &self, - who: &Self::AccountId, + _who: &Self::AccountId, call: &Self::Call, _info: &DispatchInfoOf, _len: usize, ) -> TransactionValidity { - let _account_id = who; - match call.is_sub_type() { - Some(call) => Pallet::::check_tx(call), - _ => Ok(Default::default()), - } + Self::do_validate(call) } fn validate_unsigned( @@ -787,9 +773,30 @@ where _info: &DispatchInfoOf, _len: usize, ) -> TransactionValidity { - match call.is_sub_type() { - Some(call) => Pallet::::check_tx(call), - _ => Ok(Default::default()), - } + Self::do_validate(call) + } +} + +impl CheckBioauthTx +where + ::RuntimeCall: IsSubType>, +{ + /// Perform the call validation. + /// + /// For the `authenticate` call checks the validity and correctness and lets everything else + /// through. + fn do_validate(call: &T::RuntimeCall) -> TransactionValidity { + // Reduce to calls from this pallet. + let Some(call) = call.is_sub_type() else { + return Ok(Default::default()); + }; + + // Reduce to `authenticate` call. + let Call::authenticate { req: transaction } = call else { + return Ok(Default::default()); + }; + + // Check the `authenticate` transaction. + Pallet::::check_tx(transaction) } } diff --git a/crates/pallet-bioauth/src/tests.rs b/crates/pallet-bioauth/src/tests.rs index 4ff8201b6..b3bf91030 100644 --- a/crates/pallet-bioauth/src/tests.rs +++ b/crates/pallet-bioauth/src/tests.rs @@ -4,8 +4,8 @@ use std::ops::Div; use frame_support::{ - assert_err, assert_noop, assert_ok, assert_storage_noop, pallet_prelude::*, traits::ConstU32, - BoundedVec, + assert_err, assert_noop, assert_ok, assert_storage_noop, dispatch::DispatchInfo, + pallet_prelude::*, traits::ConstU32, BoundedVec, }; use mockall::predicate;