This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 372
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
make ToStakingPot and DealWithFees structs generic over account formats #2910
Copy link
Copy link
Open
Labels
J0-enhancementAn additional feature request.An additional feature request.
Description
I'm working on a project where we're using AccountId20 instead of AccountId32
I was having a hard time getting parachains_common::impls::DealWithFees and parachains_common::impls::ToStakingPot to compile with this account format.
so my workaround was to copy the parachains_common implementations of ToStakingPot and DealWithFees structs into my own codebase, with the basic modification of:
/// Implementation of `OnUnbalanced` that deals with the fees by combining tip and fee and passing
/// the result on to `ToStakingPot`.
pub struct DealWithFees<R>(PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R>
where
R: pallet_balances::Config + pallet_collator_selection::Config,
- AccountIdOf<R>: From<polkadot_primitives::AccountId> + Into<polkadot_primitives::AccountId>,
+ AccountIdOf<R>: From<fp_account::AccountId20> + Into<fp_account::AccountId20>,
<R as frame_system::Config>::RuntimeEvent: From<pallet_balances::Event<R>>,
{
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) {
if let Some(mut fees) = fees_then_tips.next() {
if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut fees);
}
<ToStakingPot<R> as OnUnbalanced<_>>::on_unbalanced(fees);
}
}
}
/// Implementation of `OnUnbalanced` that deposits the fees into a staking pot for later payout.
pub struct ToStakingPot<R>(PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for ToStakingPot<R>
where
R: pallet_balances::Config + pallet_collator_selection::Config,
- AccountIdOf<R>: From<polkadot_primitives::AccountId> + Into<polkadot_primitives::AccountId>,
+ AccountIdOf<R>: From<fp_account::AccountId20> + Into<fp_account::AccountId20>,
<R as frame_system::Config>::RuntimeEvent: From<pallet_balances::Event<R>>,
{
fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
let staking_pot = <pallet_collator_selection::Pallet<R>>::account_id();
<pallet_balances::Pallet<R>>::resolve_creating(&staking_pot, amount);
}
}but that feels quite dirty.
wouldn't it make sense to make ToStakingPot and DealWithFees structs generic over account formats, so that runtimes could import them from parachains_common::impls without having to re-implement them?
Metadata
Metadata
Assignees
Labels
J0-enhancementAn additional feature request.An additional feature request.