fn compute_reward(config: &Config, state: &mut State, block_time: u64) {
    if state.total_bond_amount.is_zero() {
        state.last_distributed = block_time;
        return;
    }

    let mut distributed_amount: Uint128 = Uint128::zero();
    for s in config.distribution_schedule.iter() {
        if s.0 > block_time || s.1 < state.last_distributed {
            continue;
        }

        // min(s.1, block_time) - max(s.0, last_distributed)
        let elapsed_time =
            std::cmp::min(s.1, block_time) - std::cmp::max(s.0, state.last_distributed);

        let total_time = s.1 - s.0;
        let distribution_amount_per_second: Decimal = Decimal::from_ratio(s.2, total_time);
        distributed_amount += distribution_amount_per_second * Uint128::from(elapsed_time as u128);
    }

    state.last_distributed = block_time;
    state.global_reward_index = state.global_reward_index
        + Decimal::from_ratio(distributed_amount, state.total_bond_amount);
}
// compute distributed rewards and update global reward index
compute distributed rewards and update global reward index
compute distributed rewards and update global reward index
fn compute_reward(config: &Config, state: &mut State, block_time: u64) {
    if state.total_bond_amount.is_zero() {
        state.last_distributed = block_time;
        return;
    }
    let mut distributed_amount: Uint128 = Uint128::zero();
    for s in config.distribution_schedule.iter() {
        if s.0 > block_time || s.1 < state.last_distributed {
            continue;
        }
        // min(s.1, block_time) - max(s.0, last_distributed)
        let elapsed_time =
            std::cmp::min(s.1, block_time) - std::cmp::max(s.0, state.last_distributed);
        let total_time = s.1 - s.0;
        let distribution_amount_per_second: Decimal = Decimal::from_ratio(s.2, total_time);
        distributed_amount += distribution_amount_per_second * Uint128::from(elapsed_time as u128);
    }
    state.last_distributed = block_time;
    state.global_reward_index = state.global_reward_index
        + Decimal::from_ratio(distributed_amount, state.total_bond_amount);
}
fn compute_reward ( config : & Config , state : & mut State , block_time : u64 ) { if state . total_bond_amount . is_zero ( ) { state . last_distributed = block_time ; return ; } let mut distributed_amount : Uint128 = Uint128 :: zero ( ) ; for s in config . distribution_schedule . iter ( ) { if s . 0 > block_time || s . 1 < state . last_distributed { continue ; } // min(s.1, block_time) - max(s.0, last_distributed) let elapsed_time = std :: cmp :: min ( s . 1 , block_time ) - std :: cmp :: max ( s . 0 , state . last_distributed ) ; let total_time = s . 1 - s . 0 ; let distribution_amount_per_second : Decimal = Decimal :: from_ratio ( s . 2 , total_time ) ; distributed_amount += distribution_amount_per_second * Uint128 :: from ( elapsed_time as u128 ) ; } state . last_distributed = block_time ; state . global_reward_index = state . global_reward_index + Decimal :: from_ratio ( distributed_amount , state . total_bond_amount ) ; }
compute distributed rewards and update global reward index
compute distributed rewards and update global reward index
config
&Config
state
&mut State
block_time
u64
config
&Config
state
&mut State
block_time
u64