-
Notifications
You must be signed in to change notification settings - Fork 10
/
validator_reward_api.go
79 lines (67 loc) · 1.75 KB
/
validator_reward_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package consensus
import (
"fmt"
"math/big"
"strings"
)
const (
STAKING_MAX_VALIDATOR_REWARDS = 1200
)
type ValidatorReward struct {
Epoch uint32
BaseReward *big.Int
ExpectDistribute *big.Int
ActualDistribute *big.Int
}
func (v *ValidatorReward) ToString() string {
return fmt.Sprintf("ValidatorReward(Epoch %v): BasedReward=%v ExpectDistribute=%v, ActualDistribute=%v",
v.Epoch, v.BaseReward.String(), v.ExpectDistribute.String(), v.ActualDistribute.String())
}
type ValidatorRewardList struct {
rewards []*ValidatorReward
}
func (v *ValidatorRewardList) String() string {
s := make([]string, 0)
for _, reward := range v.rewards {
s = append(s, reward.ToString())
}
return strings.Join(s, ", ")
}
func NewValidatorRewardList(rewards []*ValidatorReward) *ValidatorRewardList {
if rewards == nil {
rewards = make([]*ValidatorReward, 0)
}
return &ValidatorRewardList{rewards: rewards}
}
func (v *ValidatorRewardList) Get(epoch uint32) *ValidatorReward {
for _, reward := range v.rewards {
if reward.Epoch == epoch {
return reward
}
}
return nil
}
func (v *ValidatorRewardList) Count() int {
return len(v.rewards)
}
func (v *ValidatorRewardList) GetList() []*ValidatorReward {
return v.rewards
}
func (v *ValidatorRewardList) ToString() string {
if v == nil || len(v.rewards) == 0 {
return "ValidatorRewardList (size:0)"
}
s := []string{fmt.Sprintf("ValidatorRewardList (size:%v) {", len(v.rewards))}
for i, c := range v.rewards {
s = append(s, fmt.Sprintf(" %d.%v", i, c.ToString()))
}
s = append(s, "}")
return strings.Join(s, "\n")
}
func (v *ValidatorRewardList) ToList() []*ValidatorReward {
result := make([]*ValidatorReward, 0)
for _, s := range v.rewards {
result = append(result, s)
}
return result
}