From 380f085ccc77a82728da06abd4129e5fd2245314 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Wed, 27 Dec 2023 13:00:02 +0100
Subject: [PATCH] refac(smith-members): remove IsSubWoT

---
 pallets/duniter-wot/src/lib.rs       | 59 +++++++++++-----------------
 pallets/duniter-wot/src/mock.rs      |  1 -
 runtime/common/src/pallets_config.rs |  1 -
 3 files changed, 24 insertions(+), 37 deletions(-)

diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs
index 7cf49c3a7..400a3d06c 100644
--- a/pallets/duniter-wot/src/lib.rs
+++ b/pallets/duniter-wot/src/lib.rs
@@ -66,8 +66,6 @@ pub mod pallet {
         #[pallet::constant]
         type FirstIssuableOn: Get<Self::BlockNumber>;
         #[pallet::constant]
-        type IsSubWot: Get<bool>;
-        #[pallet::constant]
         type MinCertForMembership: Get<u32>;
         #[pallet::constant]
         type MinCertForCreateIdtyRight: Get<u32>;
@@ -132,30 +130,25 @@ where
 {
     // identity creation checks
     fn check_create_identity(creator: IdtyIndex) -> Result<(), DispatchError> {
-        // main WoT constraints
-        if !T::IsSubWot::get() {
-            let cert_meta = pallet_certification::Pallet::<T, I>::idty_cert_meta(creator);
-            // perform all checks
-            // 1. check that identity has the right to create an identity
-            // identity can be member with 5 certifications and still not reach identity creation threshold which could be higher (6, 7...)
-            ensure!(
-                cert_meta.received_count >= T::MinCertForCreateIdtyRight::get(),
-                Error::<T, I>::NotEnoughReceivedCertsToCreateIdty
-            );
-            // 2. check that issuer can emit one more certification
-            // (this is only a partial check)
-            ensure!(
-                cert_meta.issued_count < T::MaxByIssuer::get(),
-                Error::<T, I>::MaxEmittedCertsReached
-            );
-            // 3. check that issuer respects certification creation period
-            ensure!(
-                cert_meta.next_issuable_on <= frame_system::pallet::Pallet::<T>::block_number(),
-                Error::<T, I>::IdtyCreationPeriodNotRespected
-            );
-        }
-        // TODO (#136) make these trait implementation work on instances rather than static to avoid checking IsSubWot
-        // smith subwot can never prevent from creating identity
+        let cert_meta = pallet_certification::Pallet::<T, I>::idty_cert_meta(creator);
+        // perform all checks
+        // 1. check that identity has the right to create an identity
+        // identity can be member with 5 certifications and still not reach identity creation threshold which could be higher (6, 7...)
+        ensure!(
+            cert_meta.received_count >= T::MinCertForCreateIdtyRight::get(),
+            Error::<T, I>::NotEnoughReceivedCertsToCreateIdty
+        );
+        // 2. check that issuer can emit one more certification
+        // (this is only a partial check)
+        ensure!(
+            cert_meta.issued_count < T::MaxByIssuer::get(),
+            Error::<T, I>::MaxEmittedCertsReached
+        );
+        // 3. check that issuer respects certification creation period
+        ensure!(
+            cert_meta.next_issuable_on <= frame_system::pallet::Pallet::<T>::block_number(),
+            Error::<T, I>::IdtyCreationPeriodNotRespected
+        );
         Ok(())
     }
 }
@@ -238,17 +231,13 @@ where
     fn on_event(membership_event: &sp_membership::Event<IdtyIndex>) {
         match membership_event {
             sp_membership::Event::<IdtyIndex>::MembershipAdded(idty_index) => {
-                if !T::IsSubWot::get() {
-                    // when main membership is acquired, tell identity
-                    // (only used on first membership acquiry)
-                    pallet_identity::Pallet::<T>::membership_added(*idty_index);
-                }
+                // when main membership is acquired, tell identity
+                // (only used on first membership acquiry)
+                pallet_identity::Pallet::<T>::membership_added(*idty_index);
             }
             sp_membership::Event::<IdtyIndex>::MembershipRemoved(idty_index) => {
-                if !T::IsSubWot::get() {
-                    // when main membership is lost, tell identity
-                    pallet_identity::Pallet::<T>::membership_removed(*idty_index);
-                }
+                // when main membership is lost, tell identity
+                pallet_identity::Pallet::<T>::membership_removed(*idty_index);
             }
             sp_membership::Event::<IdtyIndex>::MembershipRenewed(_) => {}
         }
diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs
index 33034b24c..1b501b409 100644
--- a/pallets/duniter-wot/src/mock.rs
+++ b/pallets/duniter-wot/src/mock.rs
@@ -94,7 +94,6 @@ parameter_types! {
 }
 
 impl pallet_duniter_wot::Config<Instance1> for Test {
-    type IsSubWot = frame_support::traits::ConstBool<false>;
     type MinCertForMembership = MinCertForMembership;
     type MinCertForCreateIdtyRight = MinCertForCreateIdtyRight;
     type FirstIssuableOn = FirstIssuableOn;
diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs
index 1c64d6bb8..6e1c717ba 100644
--- a/runtime/common/src/pallets_config.rs
+++ b/runtime/common/src/pallets_config.rs
@@ -458,7 +458,6 @@ macro_rules! pallets_config {
         impl pallet_duniter_wot::Config<Instance1> for Runtime {
             type FirstIssuableOn = WotFirstCertIssuableOn;
             type IsDistanceOk = common_runtime::providers::MainWotIsDistanceOk<Runtime>;
-            type IsSubWot = frame_support::traits::ConstBool<false>;
             type MinCertForMembership = WotMinCertForMembership;
             type MinCertForCreateIdtyRight = WotMinCertForCreateIdtyRight;
         }
-- 
GitLab