Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
open-runtime-module-library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noxim
open-runtime-module-library
Commits
432ebafe
Unverified
Commit
432ebafe
authored
4 years ago
by
wangjj9219
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
update RewardHandler trait (#274)
parent
07db8580
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rewards/src/mock.rs
+8
-3
8 additions, 3 deletions
rewards/src/mock.rs
traits/src/rewards.rs
+8
-2
8 additions, 2 deletions
traits/src/rewards.rs
with
16 additions
and
5 deletions
rewards/src/mock.rs
+
8
−
3
View file @
432ebafe
...
@@ -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!
[]
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
traits/src/rewards.rs
+
8
−
2
View file @
432ebafe
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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment