Skip to content
Snippets Groups Projects
Unverified Commit 40404150 authored by bgallois's avatar bgallois
Browse files

move handle dust

parent db052be7
No related branches found
No related tags found
1 merge request!286Refactore Runtime handlers and providers
Pipeline #38569 passed
......@@ -15,7 +15,10 @@
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use super::{entities::*, AccountId, IdtyIndex};
use frame_support::{pallet_prelude::Weight, traits::UnfilteredDispatchable};
use frame_support::{
pallet_prelude::Weight,
traits::{Imbalance, UnfilteredDispatchable},
};
use pallet_smith_members::SmithRemovalReason;
use sp_core::Get;
......@@ -178,3 +181,25 @@ impl<
!pallet_authority_members::Pallet::<Runtime>::online().contains(idty_index)
}
}
type CreditOf<Runtime, Balances> =
frame_support::traits::tokens::fungible::Credit<Runtime, Balances>;
pub struct HandleFees<Runtime, Balances>(
frame_support::pallet_prelude::PhantomData<Runtime>,
frame_support::pallet_prelude::PhantomData<Balances>,
);
impl<Runtime, Balances> frame_support::traits::OnUnbalanced<CreditOf<Runtime::AccountId, Balances>>
for HandleFees<Runtime, Balances>
where
Runtime: pallet_treasury::Config,
Balances: frame_support::traits::fungible::Balanced<Runtime::AccountId>,
{
fn on_nonzero_unbalanced(amount: CreditOf<Runtime::AccountId, Balances>) {
// fee is moved to treasury
let _ = Balances::deposit(
&pallet_treasury::Pallet::<Runtime>::account_id(),
amount.peek(),
frame_support::traits::tokens::Precision::Exact,
);
}
}
......@@ -104,7 +104,8 @@ 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>;
type InnerOnChargeTransaction =
FungibleAdapter<Balances, HandleFees<Runtime, Balances>>;
type Refund = Quota;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_duniter_account::WeightInfo<Runtime>;
......@@ -162,7 +163,7 @@ macro_rules! pallets_config {
impl pallet_balances::Config for Runtime {
type AccountStore = Account;
type Balance = Balance;
type DustRemoval = HandleFees;
type DustRemoval = HandleFees<Runtime, Balances>;
type ExistentialDeposit = ExistentialDeposit;
type FreezeIdentifier = ();
type MaxFreezes = frame_support::pallet_prelude::ConstU32<0>;
......@@ -175,18 +176,6 @@ macro_rules! pallets_config {
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
}
type CreditOf = frame_support::traits::tokens::fungible::Credit<AccountId, Balances>;
pub struct HandleFees;
impl frame_support::traits::OnUnbalanced<CreditOf> for HandleFees {
fn on_nonzero_unbalanced(amount: CreditOf) {
// fee is moved to treasury
let _ = Balances::deposit(
&Treasury::account_id(),
amount.peek(),
frame_support::traits::tokens::Precision::Exact,
);
}
}
pub struct OnChargeTransaction;
parameter_types! {
......@@ -336,7 +325,7 @@ macro_rules! pallets_config {
type GetCurrentEpochIndex = GetCurrentEpochIndex<Self>;
type MaxRequests = frame_support::traits::ConstU32<100>;
type OnFilledRandomness = ();
type OnUnbalanced = HandleFees;
type OnUnbalanced = HandleFees<Runtime, Balances>;
type ParentBlockRandomness = pallet_babe::ParentBlockRandomness<Self>;
type RandomnessFromOneEpochAgo = pallet_babe::RandomnessFromOneEpochAgo<Self>;
type RequestPrice = frame_support::traits::ConstU64<2_000>;
......@@ -518,7 +507,7 @@ macro_rules! pallets_config {
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MaxRefereeDistance = MaxRefereeDistance;
type MinAccessibleReferees = MinAccessibleReferees;
type OnUnbalanced = HandleFees;
type OnUnbalanced = HandleFees<Runtime, Balances>;
type OnValidDistanceStatus = Wot;
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
......
......@@ -35,10 +35,7 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
use frame_support::{
traits::{fungible::Balanced, Contains, Imbalance},
PalletId,
};
use frame_support::{traits::Contains, PalletId};
pub use frame_system::Call as SystemCall;
use frame_system::EnsureRoot;
pub use pallet_balances::Call as BalancesCall;
......
......@@ -35,10 +35,7 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
use frame_support::{
traits::{fungible::Balanced, Contains, Imbalance},
PalletId,
};
use frame_support::{traits::Contains, PalletId};
pub use frame_system::Call as SystemCall;
use frame_system::EnsureRoot;
pub use pallet_balances::Call as BalancesCall;
......
......@@ -35,10 +35,7 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
use frame_support::{
traits::{fungible::Balanced, Contains, Imbalance},
PalletId,
};
use frame_support::{traits::Contains, PalletId};
pub use frame_system::Call as SystemCall;
use frame_system::EnsureRoot;
pub use pallet_balances::Call as BalancesCall;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment