Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {

fn on_initialize(now: T::BlockNumber) -> Weight {
let mut count = 0;
T::Handler::accumulate_reward(now, | pool, reward_to_accumulate | {
if !reward_to_accumulate.is_zero() {
count += 1;
Pools::<T>::mutate(pool, | pool_info | pool_info.total_rewards = pool_info.total_rewards.saturating_add(reward_to_accumulate));
}
});
T::WeightInfo::on_initialize(Pools::<T>::iter().count() as u32)
T::WeightInfo::on_initialize(count)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rewards/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl RewardHandler<AccountId, BlockNumber> for Handler {

fn accumulate_reward(
now: BlockNumber,
callback: impl Fn(Self::PoolId, Self::Balance),
mut callback: impl FnMut(Self::PoolId, Self::Balance),
) -> Vec<(Self::CurrencyId, Self::Balance)> {
if now % 2 == 0 {
let mut total_accumulated_rewards = 0;
Expand Down
2 changes: 1 addition & 1 deletion traits/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait RewardHandler<AccountId, BlockNumber> {
/// Accumulate rewards
fn accumulate_reward(
now: BlockNumber,
callback: impl Fn(Self::PoolId, Self::Balance),
callback: impl FnMut(Self::PoolId, Self::Balance),
) -> Vec<(Self::CurrencyId, Self::Balance)>;

/// Payout the reward to `who`
Expand Down