diff --git a/contracts/stake/src/state.rs b/contracts/stake/src/state.rs index af8dfedb4e..b106c80166 100644 --- a/contracts/stake/src/state.rs +++ b/contracts/stake/src/state.rs @@ -175,8 +175,6 @@ impl StakeState { } pub fn withdraw(&mut self, withdraw: Withdraw) { - self.check_new_block(); - let transfer_withdraw = withdraw.transfer_withdraw(); let account = *withdraw.account(); let value = transfer_withdraw.value(); @@ -186,10 +184,14 @@ impl StakeState { .get_stake_mut(&account) .expect("A stake should exist in the map to be unstaked!"); - // ensure there is a reward, and that the withdrawal is not more than - // that - if value > loaded_stake.reward { - panic!("Value withdrawn larger than available reward"); + // ensure there is a non-zero reward, and that the withdrawal is exactly + // the same amount + if loaded_stake.reward == 0 { + panic!("There is no reward available to withdraw"); + } + + if value != loaded_stake.reward { + panic!("Value withdrawn different from available reward"); } // check signature is correct @@ -205,7 +207,7 @@ impl StakeState { .expect("Withdrawing reward should succeed"); // update the state accordingly - loaded_stake.reward -= value; + loaded_stake.reward = 0; rusk_abi::emit( "withdraw",