From 2159e4dda8594b80c21432ff52eb952eb5ac9c5e Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Wed, 20 Apr 2022 13:29:53 +0100 Subject: [PATCH] refactor: pattern match replace status Signed-off-by: Gregory Hill --- crates/replace/src/lib.rs | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/crates/replace/src/lib.rs b/crates/replace/src/lib.rs index a121206037..f527f78e5e 100644 --- a/crates/replace/src/lib.rs +++ b/crates/replace/src/lib.rs @@ -501,24 +501,28 @@ impl Pallet { )?; // 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::::ReplaceCompleted.into()); + } }; // decrease old-vault's issued & to-be-redeemed tokens, and