diff --git a/runtime/common/src/handlers.rs b/runtime/common/src/handlers.rs index 27200baecab1e63f4fe8401075b0cd999973e114..ff9aba8518717b9418d79b400f8baf7436c15219 100644 --- a/runtime/common/src/handlers.rs +++ b/runtime/common/src/handlers.rs @@ -100,7 +100,7 @@ impl< /// done at the handler level. pub struct OnRemoveMembershipHandler<Runtime>(core::marker::PhantomData<Runtime>); impl< - Runtime: frame_system::Config<AccountId = AccountId> + Runtime: frame_system::Config + pallet_identity::Config<IdtyData = IdtyData, IdtyIndex = IdtyIndex> + pallet_smith_members::Config<IdtyIndex = IdtyIndex> + pallet_duniter_wot::Config @@ -182,21 +182,19 @@ impl< } } -type CreditOf<T, Balances> = frame_support::traits::tokens::fungible::Credit<T, Balances>; -pub struct HandleFees<T, TreasuryAccount, Balances>( - frame_support::pallet_prelude::PhantomData<T>, +/// Runtime handler for managing fee handling by transferring unbalanced amounts to a treasury account. +pub struct HandleFees<TreasuryAccount, Balances>( frame_support::pallet_prelude::PhantomData<TreasuryAccount>, frame_support::pallet_prelude::PhantomData<Balances>, ); -impl<T, TreasuryAccount, Balances> - frame_support::traits::OnUnbalanced<CreditOf<T::AccountId, Balances>> - for HandleFees<T, TreasuryAccount, Balances> +type CreditOf<Balances> = frame_support::traits::tokens::fungible::Credit<AccountId, Balances>; +impl<TreasuryAccount, Balances> frame_support::traits::OnUnbalanced<CreditOf<Balances>> + for HandleFees<TreasuryAccount, Balances> where - T: frame_system::Config, - TreasuryAccount: Get<T::AccountId>, - Balances: frame_support::traits::fungible::Balanced<T::AccountId>, + TreasuryAccount: Get<AccountId>, + Balances: frame_support::traits::fungible::Balanced<AccountId>, { - fn on_nonzero_unbalanced(amount: CreditOf<T::AccountId, Balances>) { + fn on_nonzero_unbalanced(amount: CreditOf<Balances>) { // fee is moved to treasury let _ = Balances::deposit( &TreasuryAccount::get(), diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index a5d56933c9423d115e60f3c7ae9b293776da4f60..dd41a49edb909304350a9e8eca6faec32a4ecd51 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -105,7 +105,7 @@ macro_rules! pallets_config { impl pallet_duniter_account::Config for Runtime { // does currency adapter in any case, but adds "refund with quota" feature type InnerOnChargeTransaction = - FungibleAdapter<Balances, HandleFees<Runtime, TreasuryAccount, Balances>>; + FungibleAdapter<Balances, HandleFees<TreasuryAccount, Balances>>; type Refund = Quota; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_duniter_account::WeightInfo<Runtime>; @@ -154,7 +154,7 @@ macro_rules! pallets_config { impl pallet_balances::Config for Runtime { type AccountStore = Account; type Balance = Balance; - type DustRemoval = HandleFees<Runtime, TreasuryAccount, Balances>; + type DustRemoval = HandleFees<TreasuryAccount, Balances>; type ExistentialDeposit = ExistentialDeposit; type FreezeIdentifier = (); type MaxFreezes = frame_support::pallet_prelude::ConstU32<0>; @@ -314,7 +314,7 @@ macro_rules! pallets_config { type GetCurrentEpochIndex = GetCurrentEpochIndex<Self>; type MaxRequests = frame_support::traits::ConstU32<100>; type OnFilledRandomness = (); - type OnUnbalanced = HandleFees<Runtime, TreasuryAccount, Balances>; + type OnUnbalanced = HandleFees<TreasuryAccount, Balances>; type ParentBlockRandomness = pallet_babe::ParentBlockRandomness<Self>; type RandomnessFromOneEpochAgo = pallet_babe::RandomnessFromOneEpochAgo<Self>; type RequestPrice = frame_support::traits::ConstU64<2_000>; @@ -489,7 +489,7 @@ macro_rules! pallets_config { type EvaluationPrice = frame_support::traits::ConstU64<1000>; type MaxRefereeDistance = MaxRefereeDistance; type MinAccessibleReferees = MinAccessibleReferees; - type OnUnbalanced = HandleFees<Runtime, TreasuryAccount, Balances>; + type OnUnbalanced = HandleFees<TreasuryAccount, Balances>; type OnValidDistanceStatus = Wot; type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs index 848ebec9a072f4fdf28c393c267caa065b743285..015043f01480ff7b71ba9434ab4b3a4ab0b6b181 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -18,31 +18,32 @@ use crate::{entities::IdtyData, AccountId, Balance, IdtyIndex}; use core::marker::PhantomData; use pallet_universal_dividend::FirstEligibleUd; +/// A provider for converting IdtyIndex to associated AccountId. pub struct IdentityAccountIdProvider<Runtime>(PhantomData<Runtime>); - -impl< - Runtime: frame_system::Config<AccountId = AccountId> - + pallet_identity::Config<IdtyIndex = IdtyIndex>, - > sp_runtime::traits::Convert<IdtyIndex, Option<AccountId>> +impl<Runtime> sp_runtime::traits::Convert<IdtyIndex, Option<AccountId>> for IdentityAccountIdProvider<Runtime> +where + Runtime: frame_system::Config<AccountId = AccountId> + + pallet_identity::Config<IdtyIndex = IdtyIndex>, { fn convert(idty_index: IdtyIndex) -> Option<AccountId> { pallet_identity::Pallet::<Runtime>::identity(idty_index).map(|idty| idty.owner_key) } } +/// A provider for converting AccountId to their associated IdtyIndex. pub struct IdentityIndexOf<T: pallet_identity::Config>(PhantomData<T>); - -impl<T: pallet_identity::Config> sp_runtime::traits::Convert<T::AccountId, Option<T::IdtyIndex>> - for IdentityIndexOf<T> +impl<T> sp_runtime::traits::Convert<T::AccountId, Option<T::IdtyIndex>> for IdentityIndexOf<T> +where + T: pallet_identity::Config, { fn convert(account_id: T::AccountId) -> Option<T::IdtyIndex> { pallet_identity::Pallet::<T>::identity_index_of(account_id) } } +/// A provider associating an AccountId to their first eligible UD creation time. pub struct UdMembersStorage<T: pallet_identity::Config>(PhantomData<T>); - impl<T> frame_support::traits::StoredMap<AccountId, FirstEligibleUd> for UdMembersStorage<T> where T: frame_system::Config<AccountId = AccountId>, @@ -71,12 +72,12 @@ where } } +/// A provider to WoT membership status based on an IdtyIndex. pub struct IsWoTMemberProvider<T>(PhantomData<T>); -impl<T: pallet_smith_members::Config> - sp_runtime::traits::IsMember<<T as pallet_membership::Config>::IdtyId> +impl<T> sp_runtime::traits::IsMember<<T as pallet_membership::Config>::IdtyId> for IsWoTMemberProvider<T> where - T: pallet_distance::Config + pallet_membership::Config, + T: pallet_distance::Config + pallet_membership::Config + pallet_smith_members::Config, { fn is_member(idty_id: &T::IdtyId) -> bool { pallet_membership::Pallet::<T>::is_member(idty_id) @@ -117,6 +118,7 @@ macro_rules! impl_benchmark_setup_handler { #[cfg(feature = "runtime-benchmarks")] impl_benchmark_setup_handler!(pallet_membership::SetupBenchmark<<T as pallet_identity::Config>::IdtyIndex, T::AccountId>); +/// A provider for retrieving the number of accounts allowed to create the universal dividend. pub struct MembersCount<T>(PhantomData<T>); impl<T> frame_support::pallet_prelude::Get<Balance> for MembersCount<T> where