pub(crate) fn add_reward(&mut self, amount: &Balance) -> Option<Balance> {

        match self.status {
            SimpleFarmStatus::Created => {
                // When a farm gots first deposit of reward, it turns to Running state,
                // but farming or not depends on `start_at` 
                self.status = SimpleFarmStatus::Running;
                if self.terms.start_at == 0 {
                    // for a farm without start time, the first deposit of reward 
                    // would trigger the farming
                    self.terms.start_at = to_sec(env::block_timestamp());
                }
                self.amount_of_reward += amount;
                self.last_distribution.undistributed += amount;
                Some(self.last_distribution.undistributed)
            },
            SimpleFarmStatus::Running => {
                if let Some(dis) = self.try_distribute(&DENOM) {
                    if dis.undistributed == 0 {
                        // farm has ended actually
                        return None;
                    }
                }
                // For a running farm, can add reward to extend duration
                self.amount_of_reward += amount;
                self.last_distribution.undistributed += amount;
                Some(self.last_distribution.undistributed)
            },
            _ => {None},
        }
        
    }
/// return None if the farm can not accept reward anymore
/// else return amount of undistributed reward 
return None if the farm can not accept reward anymore
else return amount of undistributed reward
return None if the farm can not accept reward anymore else return amount of undistributed reward
pub(crate) fn add_reward(&mut self, amount: &Balance) -> Option<Balance> {
        match self.status {
            SimpleFarmStatus::Created => {
                // When a farm gots first deposit of reward, it turns to Running state,
                // but farming or not depends on `start_at` 
                self.status = SimpleFarmStatus::Running;
                if self.terms.start_at == 0 {
                    // for a farm without start time, the first deposit of reward 
                    // would trigger the farming
                    self.terms.start_at = to_sec(env::block_timestamp());
                }
                self.amount_of_reward += amount;
                self.last_distribution.undistributed += amount;
                Some(self.last_distribution.undistributed)
            },
            SimpleFarmStatus::Running => {
                if let Some(dis) = self.try_distribute(&DENOM) {
                    if dis.undistributed == 0 {
                        // farm has ended actually
                        return None;
                    }
                }
                // For a running farm, can add reward to extend duration
                self.amount_of_reward += amount;
                self.last_distribution.undistributed += amount;
                Some(self.last_distribution.undistributed)
            },
            _ => {None},
        }
    }
pub ( crate ) fn add_reward ( & mut self , amount : & Balance ) -> Option < Balance > { match self . status { SimpleFarmStatus :: Created => { // When a farm gots first deposit of reward, it turns to Running state, // but farming or not depends on `start_at`  self . status = SimpleFarmStatus :: Running ; if self . terms . start_at == 0 { // for a farm without start time, the first deposit of reward  // would trigger the farming self . terms . start_at = to_sec ( env :: block_timestamp ( ) ) ; } self . amount_of_reward += amount ; self . last_distribution . undistributed += amount ; Some ( self . last_distribution . undistributed ) } , SimpleFarmStatus :: Running => { if let Some ( dis ) = self . try_distribute ( & DENOM ) { if dis . undistributed == 0 { // farm has ended actually return None ; } } // For a running farm, can add reward to extend duration self . amount_of_reward += amount ; self . last_distribution . undistributed += amount ; Some ( self . last_distribution . undistributed ) } , _ => { None } , } }
return None if the farm can not accept reward anymore
else return amount of undistributed reward
return None if the farm can not accept reward anymore else return amount of undistributed reward
&mut self
amount
&Balance
&mut self
amount
&Balance