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

add certification count check

parent c17639d5
No related branches found
No related tags found
No related merge requests found
Pipeline #34959 failed
This commit is part of merge request !219. Comments created here will be created in the context of that merge request.
......@@ -87,6 +87,8 @@ pub mod pallet {
type WeightInfo: WeightInfo;
/// Handler for successful distance evaluation
type OnValidDistanceStatus: OnValidDistanceStatus<Self>;
/// Trait to check that distance evaluation request is allowed
type CheckRequestDistanceEvaluation: CheckRequestDistanceEvaluation<Self>;
}
// STORAGE //
......@@ -255,7 +257,7 @@ pub mod pallet {
}
/// Request target identity to be evaluated
/// only possible for unconfirmed identity
/// only possible for unvalidated identity
#[pallet::call_index(4)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::request_distance_evaluation())]
pub fn request_distance_evaluation_for(
......@@ -398,7 +400,6 @@ pub mod pallet {
// caller has an identity
let idty_index = pallet_identity::IdentityIndexOf::<T>::get(who)
.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)?;
Ok(idty_index)
}
......@@ -411,8 +412,6 @@ pub mod pallet {
// caller has an identity
let caller_idty_index = pallet_identity::IdentityIndexOf::<T>::get(who)
.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)
.ok_or(Error::<T>::CallerIdentityNotFound)?;
// caller is member
......@@ -446,7 +445,9 @@ pub mod pallet {
ValidEvaluationResult::<T>::get(target).is_none(),
Error::<T>::ValidDistanceResultAlreadyAvailable
);
Ok(())
// external validation
// target has received enough certifications
T::CheckRequestDistanceEvaluation::check_request_distance_evaluation(target)
}
/// request distance evaluation in current pool
......
......@@ -260,6 +260,7 @@ impl pallet_distance::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type OnValidDistanceStatus = ();
type CheckRequestDistanceEvaluation = ();
}
// Build genesis storage according to the mock runtime.
......
......@@ -15,6 +15,7 @@
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use frame_support::pallet_prelude::*;
pub trait OnValidDistanceStatus<T: Config> {
/// Handler for valid distance evaluation
......@@ -24,3 +25,13 @@ pub trait OnValidDistanceStatus<T: Config> {
impl<T: Config> OnValidDistanceStatus<T> for () {
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 {
CertToRevoked,
/// Issuer or receiver not found.
IdtyNotFound,
/// Not enough certs received to request distance evaluation.
NotEnoughCertsReceivedToRequestDistanceEvaluation,
}
}
......@@ -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 {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_distance::WeightInfo<Runtime>;
type OnValidDistanceStatus = Wot;
type CheckRequestDistanceEvaluation = Wot;
}
// SMITHS SUB-WOT //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment