virto-network / virto-node

Virto Network blockchain node.
GNU General Public License v3.0
21 stars 10 forks source link

Make fee handlers composable #386

Open olanod opened 4 months ago

olanod commented 4 months ago

Instead of "the fee handler" we should be able to define several fee handlers that each focus on different things and can later be composed together with a tuple similar to how other Substrate traits allow composition.

Changing the FeeHandler trait to receive a mutable Fees object would make it easier for implementers.

pub trait FeeHandler<T: Config> {
    fn apply_fees(
        fees: &mut Fees<T>,
        amount: (&BalanceOf<T>, &AssetIdOf<T>),
        sender: &T::AccountId,
        beneficiary: &T::AccountId,
        detail: Option<&T::PaymentDetail>,
    ) ;
}
struct FeeA;
impl FeeHandler<Runtime> for FeeA {...}
struct FeeB;
impl FeeHandler<Runtime> for FeeB {...}
struct FeeC;
impl FeeHandler<Runtime> for FeeC {...}

impl pallet_payments::Config for Runtime {
    // ...
    type FeeHandler = (FeeA, FeeB, FeeC,),
    // ...
}