From bfdfaa5dea684e61078c4f1419ce030a3fbd9934 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Fri, 10 Nov 2023 17:09:13 +0100 Subject: [PATCH] make eligibility more explicit --- pallets/quota/src/lib.rs | 21 +++++++++++++++------ pallets/quota/src/traits.rs | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pallets/quota/src/lib.rs b/pallets/quota/src/lib.rs index f72ac44b9..eff611f21 100644 --- a/pallets/quota/src/lib.rs +++ b/pallets/quota/src/lib.rs @@ -318,15 +318,24 @@ pub mod pallet { // implement quota traits impl<T: Config> RefundFee<T> for Pallet<T> { fn request_refund(account: T::AccountId, identity: IdtyId<T>, amount: BalanceOf<T>) { - // TODO only queue refund if identity is eligible for refund - Self::queue_refund(Refund { - account, - identity, - amount, - }) + if is_eligible_for_refund::<T>(identity) { + Self::queue_refund(Refund { + account, + identity, + amount, + }) + } } } +/// tells whether an identity is eligible for refund +fn is_eligible_for_refund<T: pallet_identity::Config>(_identity: IdtyId<T>) -> bool { + // all identities are eligible for refund, no matter their status + // if the identity has no quotas or has been deleted, the refund request is still queued + // but when handeled, no refund will be issued (and `NoQuotaForIdty` may be raised) + true +} + // implement identity event handler impl<T: Config> pallet_identity::traits::OnIdtyChange<T> for Pallet<T> { fn on_idty_change(idty_id: IdtyId<T>, idty_event: &IdtyEvent<T>) -> Weight { diff --git a/pallets/quota/src/traits.rs b/pallets/quota/src/traits.rs index 53259cb67..fb2e377fd 100644 --- a/pallets/quota/src/traits.rs +++ b/pallets/quota/src/traits.rs @@ -18,7 +18,7 @@ use crate::*; /// trait used to request refund of a fee pub trait RefundFee<T: Config> { - /// request refund + /// request refund for the account `account` using the quotas of identity `identity` fn request_refund(account: T::AccountId, identity: IdtyId<T>, amount: BalanceOf<T>); } // dummy impl -- GitLab