Skip to content

Commit

Permalink
refactor: pattern match replace status
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
gregdhill committed Apr 20, 2022
1 parent 8f6f705 commit 2159e4d
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions crates/replace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,24 +501,28 @@ impl<T: Config> Pallet<T> {
)?;

// only return griefing collateral if not already slashed
let collateral = if replace.status == ReplaceRequestStatus::Pending {
// give old-vault the griefing collateral
ext::vault_registry::transfer_funds(
CurrencySource::ActiveReplaceCollateral(old_vault_id.clone()),
CurrencySource::FreeBalance(old_vault_id.account_id.clone()),
&griefing_collateral,
)?;
// NOTE: this is just the additional collateral already locked on accept
// it is only used in the ReplaceTokens event
collateral
} else if replace.status == ReplaceRequestStatus::Cancelled {
// we need to re-accept first, this will check that the vault is over the secure threshold
Self::accept_replace_tokens(&old_vault_id, &new_vault_id, &amount)?;
// no additional collateral locked for this
Amount::zero(collateral.currency())
} else {
// we never enter this branch as completed requests are filtered
Amount::zero(collateral.currency())
let collateral = match replace.status {
ReplaceRequestStatus::Pending => {
// give old-vault the griefing collateral
ext::vault_registry::transfer_funds(
CurrencySource::ActiveReplaceCollateral(old_vault_id.clone()),
CurrencySource::FreeBalance(old_vault_id.account_id.clone()),
&griefing_collateral,
)?;
// NOTE: this is just the additional collateral already locked on accept
// it is only used in the ReplaceTokens event
collateral
}
ReplaceRequestStatus::Cancelled => {
// we need to re-accept first, this will check that the vault is over the secure threshold
Self::accept_replace_tokens(&old_vault_id, &new_vault_id, &amount)?;
// no additional collateral locked for this
Amount::zero(collateral.currency())
}
ReplaceRequestStatus::Completed => {
// we never enter this branch as completed requests are filtered
return Err(Error::<T>::ReplaceCompleted.into());
}
};

// decrease old-vault's issued & to-be-redeemed tokens, and
Expand Down

0 comments on commit 2159e4d

Please sign in to comment.