1

I would like to modify the substrate transaction-payment pallet's CurrencyAdapter without cloning the entire crate into the local pallets. What's the best practice to provide another implementation while keep all other functionality as is. Tried tight coupling but this only inherits the features that we want to use within new pallet.

Thanks!

1 Answer 1

2

CurrencyAdapter is passed as a value for OnChargeTransaction in pallet_transaction_payment::Config. And OnChargeTransaction has a trait bound OnChargeTransaction, i.e a type has to implement OnChargeTransaction trait.

To have a different implementation of OnChargeTransaction, create a new struct and manually implement the OnChargeTransaction trait. You can closely follow the implementation of the CurrencyAdapter:

/// Your implementation of `CurrencyAdapter`
pub struct CustomCurrencyAdapter<C, OU>(PhantomData<(C, OU)>);

impl<T, C, OU> OnChargeTransaction<T> for CustomCurrencyAdapter<C, OU>
where
...
{
    type LiquidityInfo = Option<NegativeImbalanceOf<C, T>>;
    type Balance = <C as Currency<<T as frame_system::Config>::AccountId>>::Balance;

    fn withdraw_fee(
        who: &T::AccountId,
        call: &T::RuntimeCall,
        dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
        fee: Self::Balance,
        tip: Self::Balance,
    ) -> Result<Self::LiquidityInfo, TransactionValidityError> {...}

    fn correct_and_deposit_fee(
        who: &T::AccountId,
        dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
        post_info: &PostDispatchInfoOf<T::RuntimeCall>,
        corrected_fee: Self::Balance,
        tip: Self::Balance,
        already_withdrawn: Self::LiquidityInfo,
    ) -> Result<(), TransactionValidityError> {...}
}


/// runtime.rs
impl pallet_transaction_payment::Config for Runtime {
    ...
    type OnChargeTransaction = CustomCurrencyAdapter<Balances, DealWithFees>;
    ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.