Skip to content
Merged
Changes from all commits
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
23 changes: 7 additions & 16 deletions pallets/crowdloans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,11 @@ pub mod pallet {
.checked_sub(amount)
.ok_or(ArithmeticError::Underflow)?
};
Self::contribution_put(vault.trie_index, who, &new_pending, true);
if new_pending.is_zero() {
Self::contribution_kill(vault.trie_index, who, true);
} else {
Self::contribution_put(vault.trie_index, who, &new_pending, true);
}
Ok(())
}

Expand All @@ -754,25 +758,12 @@ pub mod pallet {
vault: &mut Vault<T>,
amount: BalanceOf<T>,
) -> DispatchResult {
vault.pending = vault
.pending
.checked_sub(amount)
.ok_or(ArithmeticError::Underflow)?;
Self::do_update_pending(who, vault, amount, false)?;

vault.contributed = vault
.contributed
.checked_add(amount)
.ok_or(ArithmeticError::Overflow)?;

let (pending, _) = Self::contribution_get(vault.trie_index, who, true);
let new_pending = pending
.checked_sub(amount)
.ok_or(ArithmeticError::Underflow)?;
if new_pending.is_zero() {
Self::contribution_kill(vault.trie_index, who, true);
} else {
Self::contribution_put(vault.trie_index, who, &new_pending, true);
}

let (contributed, _) = Self::contribution_get(vault.trie_index, who, false);
let new_contributed = contributed
.checked_add(amount)
Expand Down