Skip to content

Commit

Permalink
change(fc-pallet-pass): authenticate should be free if it's a valid a…
Browse files Browse the repository at this point in the history
…uthentication
  • Loading branch information
pandres95 committed Oct 9, 2024
1 parent 21c6dd6 commit ba8c15e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pallets/pass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ pub mod benchmarking;
mod mock;
#[cfg(test)]
mod tests;

mod extension;
mod types;

pub mod weights;
pub use extension::*;
pub use pallet::*;
pub use types::*;
pub use weights::*;
Expand Down Expand Up @@ -149,6 +152,15 @@ pub mod pallet {
Self::do_add_device(&account_id, attestation)
}

#[pallet::feeless_if(
|_: &OriginFor<T>, device_id: &DeviceId, _: &CredentialOf<T, I>, _: &Option<BlockNumberFor<T>>| -> bool {
if let Some(account_id) = Pallet::<T, I>::account_id_for(credential.user_id()).ok() {

Check warning on line 157 in pallets/pass/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

matching on `Some` with `ok()` is redundant

warning: matching on `Some` with `ok()` is redundant --> pallets/pass/src/lib.rs:157:17 | 157 | if let Some(account_id) = Pallet::<T, I>::account_id_for(credential.user_id()).ok() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_result_ok = note: `#[warn(clippy::match_result_ok)]` on by default help: consider matching on `Ok(account_id)` and removing the call to `ok` instead | 157 | if let Ok(account_id) = Pallet::<T, I>::account_id_for(credential.user_id()) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pallet::<T, I>::account_exists(&account_id)
} else {
false
}
}
)]
#[pallet::call_index(3)]
pub fn authenticate(
origin: OriginFor<T>,
Expand Down Expand Up @@ -222,7 +234,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(account_id)
}

pub(crate) fn account_exists(who: &T::AccountId) -> bool {
pub fn account_exists(who: &T::AccountId) -> bool {
frame_system::Pallet::<T>::account_exists(who)
}

Expand Down Expand Up @@ -279,6 +291,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(account_id)
}

pub(crate) fn signer_from_session_key(who: &T::AccountId) -> Option<T::AccountId> {
let (account_id, until) = Sessions::<T, I>::get(&who)?;

Check warning on line 295 in pallets/pass/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/pass/src/lib.rs:295:57 | 295 | let (account_id, until) = Sessions::<T, I>::get(&who)?; | ^^^^ help: change this to: `who` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
if frame_system::Pallet::<T>::block_number() <= until {
Some(account_id)
} else {
None
}
}

pub(crate) fn do_authenticate(
credential: CredentialOf<T, I>,
device_id: DeviceId,
Expand Down

0 comments on commit ba8c15e

Please sign in to comment.