From 37fec7e9cace46db0142113f66543e07b87222ff Mon Sep 17 00:00:00 2001
From: bgallois <benjamin@gallois.cc>
Date: Thu, 7 Mar 2024 14:00:39 +0100
Subject: [PATCH] unify handlers implementation in runtime

---
 runtime/common/src/handlers.rs       | 31 ++++++++++++++++++++++++++++
 runtime/common/src/pallets_config.rs |  4 ++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/runtime/common/src/handlers.rs b/runtime/common/src/handlers.rs
index 54eec5cb4..c12f6d3d5 100644
--- a/runtime/common/src/handlers.rs
+++ b/runtime/common/src/handlers.rs
@@ -33,6 +33,37 @@ where
     }
 }
 
+/// Runtime handler for OnNewIdty, calling all implementations of
+/// OnNewIdty and implementing logic at the runtime level.
+pub struct OnNewIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>);
+impl<Runtime: pallet_duniter_wot::Config + pallet_quota::Config>
+    pallet_identity::traits::OnNewIdty<Runtime> for OnNewIdtyHandler<Runtime>
+{
+    fn on_created(idty_index: &IdtyIndex, creator: &IdtyIndex) {
+        pallet_duniter_wot::Pallet::<Runtime>::on_created(idty_index, creator);
+        pallet_quota::Pallet::<Runtime>::on_created(idty_index, creator);
+    }
+}
+
+/// Runtime handler for OnRemoveIdty, calling all implementations of
+/// OnRemoveIdty and implementing logic at the runtime level.
+pub struct OnRemoveIdtyHandler<Runtime>(core::marker::PhantomData<Runtime>);
+impl<Runtime: pallet_duniter_wot::Config + pallet_quota::Config>
+    pallet_identity::traits::OnRemoveIdty<Runtime> for OnRemoveIdtyHandler<Runtime>
+{
+    fn on_removed(idty_index: &IdtyIndex) -> Weight {
+        let mut weight = pallet_duniter_wot::Pallet::<Runtime>::on_removed(idty_index);
+        weight += pallet_quota::Pallet::<Runtime>::on_removed(idty_index);
+        weight
+    }
+
+    fn on_revoked(idty_index: &IdtyIndex) -> Weight {
+        let mut weight = pallet_duniter_wot::Pallet::<Runtime>::on_revoked(idty_index);
+        weight += pallet_quota::Pallet::<Runtime>::on_revoked(idty_index);
+        weight
+    }
+}
+
 /// Runtime handler for OnNewMembership, calling all implementations of
 /// OnNewMembership and implementing logic at the runtime level.
 pub struct OnNewMembershipHandler<Runtime>(core::marker::PhantomData<Runtime>);
diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs
index 4ab357080..1c9d1e0c5 100644
--- a/runtime/common/src/pallets_config.rs
+++ b/runtime/common/src/pallets_config.rs
@@ -481,8 +481,8 @@ type RuntimeFreezeReason = ();
             type IdtyNameValidator = IdtyNameValidatorImpl;
             type Signer = <Signature as sp_runtime::traits::Verify>::Signer;
 			type Signature = Signature;
-            type OnNewIdty = (Wot, Quota);
-            type OnRemoveIdty = (Wot, Quota);
+            type OnNewIdty = OnNewIdtyHandler<Runtime>;
+            type OnRemoveIdty = OnRemoveIdtyHandler<Runtime>;
             type RuntimeEvent = RuntimeEvent;
             type WeightInfo = common_runtime::weights::pallet_identity::WeightInfo<Runtime>;
         }
-- 
GitLab