pub fn reward_per_share(
        &self,
        current_block_number: BlockNumber,
        amount_per_share: BalanceOf,
    ) -> Result<BalanceOf, ArithmeticError> {
        if self.total_supply.is_zero() {
            Ok(self.reward_per_share_stored)
        } else {
            let last_reward_block = self.last_reward_block_applicable(current_block_number);
            let block_diff =
                Self::block_to_balance(last_reward_block.saturating_sub(self.last_update_block));
            let reward_per_share_add = block_diff
                .checked_mul(&self.reward_rate)
                .and_then(|r| r.checked_mul(&amount_per_share))
                .and_then(|r| r.checked_div(&self.total_supply))
                .ok_or(ArithmeticError::Overflow)?;

            let ret = self
                .reward_per_share_stored
                .checked_add(&reward_per_share_add)
                .ok_or(ArithmeticError::Overflow)?;
            Ok(ret)
        }
    }
/// Calculate reward amount for one share of staking token.
/// Return ArithmeticError if it encounter an arithmetic error.
Calculate reward amount for one share of staking token.
Return ArithmeticError if it encounter an arithmetic error.
Calculate reward amount for one share of staking token . Return ArithmeticError if it encounter an arithmetic error .
pub fn reward_per_share(
        &self,
        current_block_number: BlockNumber,
        amount_per_share: BalanceOf,
    ) -> Result<BalanceOf, ArithmeticError> {
        if self.total_supply.is_zero() {
            Ok(self.reward_per_share_stored)
        } else {
            let last_reward_block = self.last_reward_block_applicable(current_block_number);
            let block_diff =
                Self::block_to_balance(last_reward_block.saturating_sub(self.last_update_block));
            let reward_per_share_add = block_diff
                .checked_mul(&self.reward_rate)
                .and_then(|r| r.checked_mul(&amount_per_share))
                .and_then(|r| r.checked_div(&self.total_supply))
                .ok_or(ArithmeticError::Overflow)?;
            let ret = self
                .reward_per_share_stored
                .checked_add(&reward_per_share_add)
                .ok_or(ArithmeticError::Overflow)?;
            Ok(ret)
        }
    }
pub fn reward_per_share ( & self , current_block_number : BlockNumber , amount_per_share : BalanceOf , ) -> Result < BalanceOf , ArithmeticError > { if self . total_supply . is_zero ( ) { Ok ( self . reward_per_share_stored ) } else { let last_reward_block = self . last_reward_block_applicable ( current_block_number ) ; let block_diff = Self :: block_to_balance ( last_reward_block . saturating_sub ( self . last_update_block ) ) ; let reward_per_share_add = block_diff . checked_mul ( & self . reward_rate ) . and_then ( | r | r . checked_mul ( & amount_per_share ) ) . and_then ( | r | r . checked_div ( & self . total_supply ) ) . ok_or ( ArithmeticError :: Overflow ) ? ; let ret = self . reward_per_share_stored . checked_add ( & reward_per_share_add ) . ok_or ( ArithmeticError :: Overflow ) ? ; Ok ( ret ) } }
Calculate reward amount for one share of staking token.
Calculate reward amount for one share of staking token .
&self
current_block_number
BlockNumber
amount_per_share
BalanceOf
&self
current_block_number
BlockNumber
amount_per_share
BalanceOf