Skip to content
Snippets Groups Projects
Commit 9e804115 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

add certification count check

parent 22ad25c6
No related branches found
No related tags found
No related merge requests found
...@@ -87,6 +87,8 @@ pub mod pallet { ...@@ -87,6 +87,8 @@ pub mod pallet {
type WeightInfo: WeightInfo; type WeightInfo: WeightInfo;
/// Handler for successful distance evaluation /// Handler for successful distance evaluation
type OnValidDistanceStatus: OnValidDistanceStatus<Self>; type OnValidDistanceStatus: OnValidDistanceStatus<Self>;
/// Trait to check that distance evaluation request is allowed
type CheckRequestDistanceEvaluation: CheckRequestDistanceEvaluation<Self>;
} }
// STORAGE // // STORAGE //
...@@ -255,7 +257,7 @@ pub mod pallet { ...@@ -255,7 +257,7 @@ pub mod pallet {
} }
/// Request target identity to be evaluated /// Request target identity to be evaluated
/// only possible for unconfirmed identity /// only possible for unvalidated identity
#[pallet::call_index(4)] #[pallet::call_index(4)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::request_distance_evaluation())] #[pallet::weight(<T as pallet::Config>::WeightInfo::request_distance_evaluation())]
pub fn request_distance_evaluation_for( pub fn request_distance_evaluation_for(
...@@ -398,7 +400,6 @@ pub mod pallet { ...@@ -398,7 +400,6 @@ pub mod pallet {
// caller has an identity // caller has an identity
let idty_index = pallet_identity::IdentityIndexOf::<T>::get(who) let idty_index = pallet_identity::IdentityIndexOf::<T>::get(who)
.ok_or(Error::<T>::CallerHasNoIdentity)?; .ok_or(Error::<T>::CallerHasNoIdentity)?;
// TODO "check idty call allowed" managed by wot that checks received cert count
Self::check_request_distance_evaluation_common(idty_index)?; Self::check_request_distance_evaluation_common(idty_index)?;
Ok(idty_index) Ok(idty_index)
} }
...@@ -411,8 +412,6 @@ pub mod pallet { ...@@ -411,8 +412,6 @@ pub mod pallet {
// caller has an identity // caller has an identity
let caller_idty_index = pallet_identity::IdentityIndexOf::<T>::get(who) let caller_idty_index = pallet_identity::IdentityIndexOf::<T>::get(who)
.ok_or(Error::<T>::CallerHasNoIdentity)?; .ok_or(Error::<T>::CallerHasNoIdentity)?;
// TODO some of the following can be moved to a "check idty call allowed" managed by wot
// which also checks certification count
let caller_idty = pallet_identity::Identities::<T>::get(caller_idty_index) let caller_idty = pallet_identity::Identities::<T>::get(caller_idty_index)
.ok_or(Error::<T>::CallerIdentityNotFound)?; .ok_or(Error::<T>::CallerIdentityNotFound)?;
// caller is member // caller is member
...@@ -446,7 +445,9 @@ pub mod pallet { ...@@ -446,7 +445,9 @@ pub mod pallet {
ValidEvaluationResult::<T>::get(target).is_none(), ValidEvaluationResult::<T>::get(target).is_none(),
Error::<T>::ValidDistanceResultAlreadyAvailable Error::<T>::ValidDistanceResultAlreadyAvailable
); );
Ok(()) // external validation
// target has received enough certifications
T::CheckRequestDistanceEvaluation::check_request_distance_evaluation(target)
} }
/// request distance evaluation in current pool /// request distance evaluation in current pool
......
...@@ -258,6 +258,7 @@ impl pallet_distance::Config for Test { ...@@ -258,6 +258,7 @@ impl pallet_distance::Config for Test {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type WeightInfo = (); type WeightInfo = ();
type OnValidDistanceStatus = (); type OnValidDistanceStatus = ();
type CheckRequestDistanceEvaluation = ();
} }
// Build genesis storage according to the mock runtime. // Build genesis storage according to the mock runtime.
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. // along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::*; use crate::*;
use frame_support::pallet_prelude::*;
pub trait OnValidDistanceStatus<T: Config> { pub trait OnValidDistanceStatus<T: Config> {
/// Handler for valid distance evaluation /// Handler for valid distance evaluation
...@@ -24,3 +25,13 @@ pub trait OnValidDistanceStatus<T: Config> { ...@@ -24,3 +25,13 @@ pub trait OnValidDistanceStatus<T: Config> {
impl<T: Config> OnValidDistanceStatus<T> for () { impl<T: Config> OnValidDistanceStatus<T> for () {
fn on_valid_distance_status(_idty_index: T::IdtyIndex) {} fn on_valid_distance_status(_idty_index: T::IdtyIndex) {}
} }
pub trait CheckRequestDistanceEvaluation<T: Config> {
fn check_request_distance_evaluation(idty_index: T::IdtyIndex) -> Result<(), DispatchError>;
}
impl<T: Config> CheckRequestDistanceEvaluation<T> for () {
fn check_request_distance_evaluation(_idty_index: T::IdtyIndex) -> Result<(), DispatchError> {
Ok(())
}
}
...@@ -122,6 +122,8 @@ pub mod pallet { ...@@ -122,6 +122,8 @@ pub mod pallet {
CertToRevoked, CertToRevoked,
/// Issuer or receiver not found. /// Issuer or receiver not found.
IdtyNotFound, IdtyNotFound,
/// Not enough certs received to request distance evaluation.
NotEnoughCertsReceivedToRequestDistanceEvaluation,
} }
} }
...@@ -391,3 +393,19 @@ impl<T: Config<I> + pallet_distance::Config, I: 'static> ...@@ -391,3 +393,19 @@ impl<T: Config<I> + pallet_distance::Config, I: 'static>
} }
} }
} }
/// distance evaluation request allowed check
impl<T: Config<I> + pallet_distance::Config, I: 'static>
pallet_distance::traits::CheckRequestDistanceEvaluation<T> for Pallet<T, I>
{
fn check_request_distance_evaluation(idty_index: IdtyIndex) -> Result<(), DispatchError> {
// maybe check idty is not unconfirmed or revoked ?
// check cert count
let idty_cert_meta = pallet_certification::Pallet::<T, I>::idty_cert_meta(idty_index);
ensure!(
idty_cert_meta.received_count >= T::MinCertForMembership::get(),
Error::<T, I>::NotEnoughCertsReceivedToRequestDistanceEvaluation
);
Ok(())
}
}
...@@ -523,6 +523,7 @@ macro_rules! pallets_config { ...@@ -523,6 +523,7 @@ macro_rules! pallets_config {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_distance::WeightInfo<Runtime>; type WeightInfo = common_runtime::weights::pallet_distance::WeightInfo<Runtime>;
type OnValidDistanceStatus = Wot; type OnValidDistanceStatus = Wot;
type CheckRequestDistanceEvaluation = Wot;
} }
// SMITHS SUB-WOT // // SMITHS SUB-WOT //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment