Skip to content
Snippets Groups Projects
Commit 6ea902a7 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

fix :)

- use treasury account
- compare weight in the good way
- actually mutate refuynd queue
parent 83542d27
No related branches found
No related tags found
No related merge requests found
Pipeline #33590 waiting for manual action
......@@ -260,12 +260,12 @@ pub mod pallet {
if !amount.is_zero() {
// take money from treasury
let res = <T as pallet::Config>::Currency::withdraw(
&queud_refund.account,
// TODO optimize: avoid calling treasury account_id which requires computation
&pallet_treasury::Pallet::<T>::account_id(),
amount,
frame_support::traits::WithdrawReasons::FEE, // a fee but in reverse
ExistenceRequirement::KeepAlive,
);
// if success
if let Ok(imbalance) = res {
// perform refund
......@@ -282,12 +282,12 @@ pub mod pallet {
/// perform as many refunds as possible within the supplied weight limit
pub fn process_refund_queue(weight_limit: Weight) -> Weight {
let mut queue = RefundQueue::<T>::get();
RefundQueue::<T>::mutate(|mut queue| {
if queue.is_empty() {
return Weight::zero();
}
let mut total_weight = Weight::zero();
while total_weight.any_gt(weight_limit) {
while total_weight.any_lt(weight_limit) {
// TODO take into account maximum weight
// - <T as pallet::Config>::WeightInfo::try_refund()
let Some(queued_refund) = queue.pop() else {
......@@ -297,6 +297,7 @@ pub mod pallet {
total_weight = total_weight.saturating_add(consumed_weight);
}
total_weight
})
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment