Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] make fee handler generic #17

Closed
wants to merge 1 commit into from

Conversation

stanly-johnson
Copy link
Member

Expands the FeeHandler trait to make it more generic, the trait is now

pub trait FeeHandler<T: pallet::Config> {
	/// Get the amount of fee to charge user
	fn get_fee_amount(
		from: &T::AccountId,
		to: &T::AccountId,
		detail: &PaymentDetail<T>,
		remark: Option<&[u8]>,
	) -> BalanceOf<T>;

	/// Deduct the fee from the user transaction
	fn apply_fees(from: &T::AccountId, to: &T::AccountId, detail: &PaymentDetail<T>) -> DispatchResult;
}

During the initial creation of the payment, the get_fee_amount is called to store the fee_amount, when the payment is settled, the apply_fees function is called, depending on the implementation it may deduct fee from user and transfer to fee recipients.

The previous logic of transferring to recipients can be achieved by implementing apply_fees like this

	fn apply_fees(from: &AccountId, _to: &AccountId, detail: &PaymentDetail<Test>) -> DispatchResult {
		// transfer the fee amount to fee recipient account
		<Tokens as MultiCurrency<AccountId>>::transfer(
			detail.asset,
			from,                   // fee is paid by payment creator
			&FEE_RECIPIENT_ACCOUNT, // account of fee recipient
			detail.fee_amount,      // amount of fee
		)
	}

Every runtime will have to benchmark the pallet based on their implementation of apply_fees.

Closes #10 since any complex logic can be written in apply_fees.

@stanly-johnson stanly-johnson requested a review from olanod May 8, 2022 19:59
@stanly-johnson stanly-johnson linked an issue May 9, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multiple fee recipients
1 participant