From eb685d6767ce8105a2f01aa4220c744642a307e4 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 15 Feb 2023 10:06:48 +0000 Subject: [PATCH] refac(app-promo): `unstake_partial` optimize code. --- --- a/pallets/app-promotion/src/lib.rs +++ b/pallets/app-promotion/src/lib.rs @@ -807,7 +807,7 @@ let mut pendings = >::get(unpending_block); - // checks that we can do unreserve stakes in the block + // checks that we can do unstake in the block ensure!(!pendings.is_full(), Error::::PendingForBlockOverflow); let mut stakes = Staked::::iter_prefix((&staker_id,)).collect::>(); @@ -836,18 +836,18 @@ let changed_stakes = stakes .into_iter() - .map_while(|(block, (balance_per_block, recalc_block))| { + .map_while(|(block, (balance_per_block, _))| { if acc_amount == >::default() { return None; } if acc_amount < balance_per_block { - let res = (block, (balance_per_block - acc_amount, recalc_block)); + let res = (block, balance_per_block - acc_amount); acc_amount = >::default(); return Some(res); } else { acc_amount -= balance_per_block; will_deleted_stakes_count += 1; - return Some((block, (>::default(), recalc_block))); + return Some((block, >::default())); } }) .collect::>(); @@ -864,13 +864,13 @@ })?; changed_stakes - .iter() - .for_each(|(staked_block, (current_stake_state, _))| { - if current_stake_state == &Default::default() { + .into_iter() + .for_each(|(staked_block, current_stake_state)| { + if current_stake_state == Default::default() { >::remove((&staker_id, staked_block)); } else { >::mutate((&staker_id, staked_block), |(old_stake_state, _)| { - *old_stake_state = *current_stake_state + *old_stake_state = current_stake_state }); } }); @@ -1087,7 +1087,7 @@ let mut pendings = >::get(block); - // checks that we can do unreserve stakes in the block + // checks that we can do unstake in the block ensure!(!pendings.is_full(), Error::::PendingForBlockOverflow); let mut total_stakes = 0u64; -- gitstuff