From 432ebafe52ea575d551956452ed4c2f61a16e33a Mon Sep 17 00:00:00 2001
From: wangjj9219 <183318287@qq.com>
Date: Sat, 5 Sep 2020 01:01:48 +0800
Subject: [PATCH] update RewardHandler trait (#274)

---
 rewards/src/mock.rs   | 11 ++++++++---
 traits/src/rewards.rs | 10 ++++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/rewards/src/mock.rs b/rewards/src/mock.rs
index f8fe43f..4954254 100644
--- a/rewards/src/mock.rs
+++ b/rewards/src/mock.rs
@@ -14,6 +14,7 @@ pub type Balance = u64;
 pub type Share = u64;
 pub type PoolId = u32;
 pub type BlockNumber = u64;
+pub type CurrencyId = u32;
 
 pub const ALICE: AccountId = 1;
 pub const BOB: AccountId = 2;
@@ -74,8 +75,12 @@ impl RewardHandler<AccountId, BlockNumber> for Handler {
 	type Share = Share;
 	type Balance = Balance;
 	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 {
 			let mut total_accumulated_rewards = 0;
 			let valid_pool_ids = vec![DOT_POOL, BTC_POOL];
@@ -88,9 +93,9 @@ impl RewardHandler<AccountId, BlockNumber> for Handler {
 				}
 			}
 
-			total_accumulated_rewards
+			vec![(1, total_accumulated_rewards)]
 		} else {
-			0
+			vec![]
 		}
 	}
 
diff --git a/traits/src/rewards.rs b/traits/src/rewards.rs
index e0909ce..7e545f2 100644
--- a/traits/src/rewards.rs
+++ b/traits/src/rewards.rs
@@ -1,6 +1,6 @@
 use codec::FullCodec;
 use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize};
-use sp_std::fmt::Debug;
+use sp_std::{fmt::Debug, vec::Vec};
 
 /// Hooks to manage reward pool
 pub trait RewardHandler<AccountId, BlockNumber> {
@@ -13,8 +13,14 @@ pub trait RewardHandler<AccountId, BlockNumber> {
 	/// The reward pool ID type
 	type PoolId: Copy + FullCodec;
 
+	/// The currency type
+	type CurrencyId: FullCodec + Eq + PartialEq + Copy + MaybeSerializeDeserialize + Debug;
+
 	/// 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`
 	fn payout(who: &AccountId, pool: Self::PoolId, amount: Self::Balance);
-- 
GitLab