Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
treasury: use 'mutate' and 'retain' to avoid creating a new vec
  • Loading branch information
Guanqun Lu committed Sep 14, 2018
commit ecd909fd1b92a377e77bb1cac151e0594f968d15
47 changes: 24 additions & 23 deletions srml/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ decl_storage! {
/// proposal gets these back. A rejected proposal doesn't.
ProposalBond get(proposal_bond): required Permill;

/// Minimum amount of funds that should be placed ina deposit for making a proposal.
/// Minimum amount of funds that should be placed in a deposit for making a proposal.
ProposalBondMinimum get(proposal_bond_minimum): required T::Balance;

/// Period between successive spends.
Expand Down Expand Up @@ -227,30 +227,31 @@ impl<T: Trait> Module<T> {
Self::deposit_event(RawEvent::Spending(budget_remaining));

let mut missed_any = false;
let remaining_approvals: Vec<_> = <Approvals<T>>::get().into_iter().filter(|&index| {
// Should always be true, but shouldn't panic if false or we're screwed.
if let Some(p) = Self::proposals(index) {
if p.value <= budget_remaining {
budget_remaining -= p.value;
<Proposals<T>>::remove(index);

// return their deposit.
let _ = <balances::Module<T>>::unreserve(&p.proposer, p.bond);

// provide the allocation.
<balances::Module<T>>::increase_free_balance_creating(&p.beneficiary, p.value);

Self::deposit_event(RawEvent::Awarded(index, p.value, p.beneficiary));
false
<Approvals<T>>::mutate(|v| {
v.retain(|&index| {
// Should always be true, but shouldn't panic if false or we're screwed.
if let Some(p) = Self::proposals(index) {
if p.value <= budget_remaining {
budget_remaining -= p.value;
<Proposals<T>>::remove(index);

// return their deposit.
let _ = <balances::Module<T>>::unreserve(&p.proposer, p.bond);

// provide the allocation.
<balances::Module<T>>::increase_free_balance_creating(&p.beneficiary, p.value);

Self::deposit_event(RawEvent::Awarded(index, p.value, p.beneficiary));
false
} else {
missed_any = true;
true
}
} else {
missed_any = true;
true
false
}
} else {
false
}
}).collect();
<Approvals<T>>::put(remaining_approvals);
});
});

if !missed_any {
// burn some proportion of the remaining budget if we run a surplus.
Expand Down