From 96f3b0c5d6f16d8311dffcdfd4efc3e40f08acf7 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Tue, 7 Nov 2023 15:49:20 +0530 Subject: [PATCH] wrap condition under ensure! --- pallets/roles/src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pallets/roles/src/lib.rs b/pallets/roles/src/lib.rs index f43e3618c..7ec48cb8f 100644 --- a/pallets/roles/src/lib.rs +++ b/pallets/roles/src/lib.rs @@ -195,15 +195,14 @@ pub mod pallet { !AccountRolesMapping::::contains_key(&stash_account), Error::::RoleAlreadyAssigned ); + // Check if stash account is already paired. - if >::contains_key(&stash_account) { - return Err(Error::::AlreadyPaired.into()) - } + ensure!(!>::contains_key(&stash_account), Error::::AlreadyPaired); + // Check if min active bond is met. let min_active_bond = MinActiveBond::::get(); - if bond_value < min_active_bond.into() { - return Err(Error::::InsufficientBond.into()) - } + ensure!(bond_value > min_active_bond.into(), Error::::InsufficientBond); + // Bond with stash account. let stash_balance = T::Currency::free_balance(&stash_account); let value = bond_value.min(stash_balance);