Skip to content
Snippets Groups Projects
Unverified Commit 432ebafe authored by wangjj9219's avatar wangjj9219 Committed by GitHub
Browse files

update RewardHandler trait (#274)

parent 07db8580
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ pub type Balance = u64; ...@@ -14,6 +14,7 @@ pub type Balance = u64;
pub type Share = u64; pub type Share = u64;
pub type PoolId = u32; pub type PoolId = u32;
pub type BlockNumber = u64; pub type BlockNumber = u64;
pub type CurrencyId = u32;
pub const ALICE: AccountId = 1; pub const ALICE: AccountId = 1;
pub const BOB: AccountId = 2; pub const BOB: AccountId = 2;
...@@ -74,8 +75,12 @@ impl RewardHandler<AccountId, BlockNumber> for Handler { ...@@ -74,8 +75,12 @@ impl RewardHandler<AccountId, BlockNumber> for Handler {
type Share = Share; type Share = Share;
type Balance = Balance; type Balance = Balance;
type PoolId = PoolId; type PoolId = PoolId;
type CurrencyId = CurrencyId;
fn accumulate_reward(now: BlockNumber, callback: impl Fn(Self::PoolId, Self::Balance)) -> Self::Balance { fn accumulate_reward(
now: BlockNumber,
callback: impl Fn(Self::PoolId, Self::Balance),
) -> Vec<(Self::CurrencyId, Self::Balance)> {
if now % 2 == 0 { if now % 2 == 0 {
let mut total_accumulated_rewards = 0; let mut total_accumulated_rewards = 0;
let valid_pool_ids = vec![DOT_POOL, BTC_POOL]; let valid_pool_ids = vec![DOT_POOL, BTC_POOL];
...@@ -88,9 +93,9 @@ impl RewardHandler<AccountId, BlockNumber> for Handler { ...@@ -88,9 +93,9 @@ impl RewardHandler<AccountId, BlockNumber> for Handler {
} }
} }
total_accumulated_rewards vec![(1, total_accumulated_rewards)]
} else { } else {
0 vec![]
} }
} }
......
use codec::FullCodec; use codec::FullCodec;
use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize}; use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize};
use sp_std::fmt::Debug; use sp_std::{fmt::Debug, vec::Vec};
/// Hooks to manage reward pool /// Hooks to manage reward pool
pub trait RewardHandler<AccountId, BlockNumber> { pub trait RewardHandler<AccountId, BlockNumber> {
...@@ -13,8 +13,14 @@ pub trait RewardHandler<AccountId, BlockNumber> { ...@@ -13,8 +13,14 @@ pub trait RewardHandler<AccountId, BlockNumber> {
/// The reward pool ID type /// The reward pool ID type
type PoolId: Copy + FullCodec; type PoolId: Copy + FullCodec;
/// The currency type
type CurrencyId: FullCodec + Eq + PartialEq + Copy + MaybeSerializeDeserialize + Debug;
/// Accumulate rewards /// Accumulate rewards
fn accumulate_reward(now: BlockNumber, callback: impl Fn(Self::PoolId, Self::Balance)) -> Self::Balance; fn accumulate_reward(
now: BlockNumber,
callback: impl Fn(Self::PoolId, Self::Balance),
) -> Vec<(Self::CurrencyId, Self::Balance)>;
/// Payout the reward to `who` /// Payout the reward to `who`
fn payout(who: &AccountId, pool: Self::PoolId, amount: Self::Balance); fn payout(who: &AccountId, pool: Self::PoolId, amount: Self::Balance);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment