Skip to content

Commit

Permalink
Simplify ensure_running check
Browse files Browse the repository at this point in the history
  • Loading branch information
deuszx committed Oct 13, 2023
1 parent ddc8676 commit 18a0dd9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions farm/contracts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod farm {
/// 2. Farm's `end` timestamp is still in the future.
#[ink(message)]
pub fn stop(&mut self) -> Result<(), FarmError> {
self.ensure_running(true)?;
self.ensure_running()?;
let mut running = self.get_state()?;

// We allow owner of the farm to stop it prematurely
Expand Down Expand Up @@ -251,7 +251,7 @@ mod farm {
#[ink(message)]
pub fn deposit(&mut self, amount: u128) -> Result<(), FarmError> {
Self::assert_non_zero_amount(amount)?;
self.ensure_running(true)?;
self.ensure_running()?;
self.update_reward_index()?;
self.add_shares(amount)
}
Expand All @@ -260,7 +260,7 @@ mod farm {
/// NOTE: Requires that the caller has approved the farm to spend their tokens.
#[ink(message)]
pub fn deposit_all(&mut self) -> Result<(), FarmError> {
self.ensure_running(true)?;
self.ensure_running()?;
self.update_reward_index()?;
let token_balance = safe_balance_of(&self.pool.into(), self.env().caller());
Self::assert_non_zero_amount(token_balance)?;
Expand Down Expand Up @@ -447,9 +447,9 @@ mod farm {
self.state.get().ok_or(FarmError::StateMissing)
}

fn ensure_running(&self, should_be_running: bool) -> Result<(), FarmError> {
if !should_be_running && self.is_running {
return Err(FarmError::StillRunning)
fn ensure_running(&self) -> Result<(), FarmError> {
if !self.is_running {
return Err(FarmError::NotRunning)
}
Ok(())
}
Expand Down

0 comments on commit 18a0dd9

Please sign in to comment.