Function pallet_loans::types::policy::find_rule
source · pub fn find_rule<Rate: Ord>(
rules: impl Iterator<Item = WriteOffRule<Rate>>,
has_effect: impl Fn(&WriteOffTrigger) -> Result<bool, DispatchError>
) -> Result<Option<WriteOffRule<Rate>>, DispatchError>
Expand description
From all overdue write off rules, it returns the one with the highest percentage (or highest penalty, if same percentage) that can be applied.
Suppose a policy with the following rules:
- overdue_secs: 5, percentage 10%
- overdue_secs: 10, percentage 30%
- overdue_secs: 15, percentage 20%
If the loan is not overdue, it will not return any rule. If the loan is overdue by 4 days, it will not return any rule. If the loan is overdue by 9 days, it will return the first rule. If the loan is overdue by 60 days, it will return the second rule (because it has a higher percentage).