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 { ...@@ -260,12 +260,12 @@ pub mod pallet {
if !amount.is_zero() { if !amount.is_zero() {
// take money from treasury // take money from treasury
let res = <T as pallet::Config>::Currency::withdraw( 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, amount,
frame_support::traits::WithdrawReasons::FEE, // a fee but in reverse frame_support::traits::WithdrawReasons::FEE, // a fee but in reverse
ExistenceRequirement::KeepAlive, ExistenceRequirement::KeepAlive,
); );
// if success // if success
if let Ok(imbalance) = res { if let Ok(imbalance) = res {
// perform refund // perform refund
...@@ -282,12 +282,12 @@ pub mod pallet { ...@@ -282,12 +282,12 @@ pub mod pallet {
/// perform as many refunds as possible within the supplied weight limit /// perform as many refunds as possible within the supplied weight limit
pub fn process_refund_queue(weight_limit: Weight) -> Weight { pub fn process_refund_queue(weight_limit: Weight) -> Weight {
let mut queue = RefundQueue::<T>::get(); RefundQueue::<T>::mutate(|mut queue| {
if queue.is_empty() { if queue.is_empty() {
return Weight::zero(); return Weight::zero();
} }
let mut total_weight = 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 // TODO take into account maximum weight
// - <T as pallet::Config>::WeightInfo::try_refund() // - <T as pallet::Config>::WeightInfo::try_refund()
let Some(queued_refund) = queue.pop() else { let Some(queued_refund) = queue.pop() else {
...@@ -297,6 +297,7 @@ pub mod pallet { ...@@ -297,6 +297,7 @@ pub mod pallet {
total_weight = total_weight.saturating_add(consumed_weight); total_weight = total_weight.saturating_add(consumed_weight);
} }
total_weight total_weight
})
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment