Skip to content

Commit

Permalink
stake-contract: FIXUP
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leegwater Simões committed Jul 18, 2024
1 parent 7fd9343 commit fec7061
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions contracts/stake/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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",
Expand Down

0 comments on commit fec7061

Please sign in to comment.