forked from evmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.go
74 lines (62 loc) · 2.23 KB
/
validator.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
package types
import (
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// historical rewards for a validator
// TODO add reference counter, ref https://github.com/cosmos/cosmos-sdk/pull/3099#discussion_r245747051
// height is implicit within the store key
type ValidatorHistoricalRewards = sdk.DecCoins
// current rewards and current period for a validator
// kept as a running counter and incremented each block
// as long as the validator's tokens remain constant
type ValidatorCurrentRewards struct {
Rewards sdk.DecCoins `json:"rewards"` // current rewards
Period uint64 `json:"period"` // current period
}
// create a new ValidatorCurrentRewards
func NewValidatorCurrentRewards(rewards sdk.DecCoins, period uint64) ValidatorCurrentRewards {
return ValidatorCurrentRewards{
Rewards: rewards,
Period: period,
}
}
// accumulated commission for a validator
// kept as a running counter, can be withdrawn at any time
type ValidatorAccumulatedCommission = sdk.DecCoins
// return the initial accumulated commission (zero)
func InitialValidatorAccumulatedCommission() ValidatorAccumulatedCommission {
return ValidatorAccumulatedCommission{}
}
// validator slash event
// height is implicit within the store key
// needed to calculate appropriate amounts of staking token
// for delegations which withdraw after a slash has occurred
type ValidatorSlashEvent struct {
ValidatorPeriod uint64 `json:"validator_period"` // period when the slash occurred
Fraction sdk.Dec `json:"fraction"` // slash fraction
}
// create a new ValidatorSlashEvent
func NewValidatorSlashEvent(validatorPeriod uint64, fraction sdk.Dec) ValidatorSlashEvent {
return ValidatorSlashEvent{
ValidatorPeriod: validatorPeriod,
Fraction: fraction,
}
}
func (vs ValidatorSlashEvent) String() string {
return fmt.Sprintf(`Period: %d
Fraction: %s`, vs.ValidatorPeriod, vs.Fraction)
}
// ValidatorSlashEvents is a collection of ValidatorSlashEvent
type ValidatorSlashEvents []ValidatorSlashEvent
func (vs ValidatorSlashEvents) String() string {
out := "Validator Slash Events:\n"
for i, sl := range vs {
out += fmt.Sprintf(` Slash %d:
Period: %d
Fraction: %s
`, i, sl.ValidatorPeriod, sl.Fraction)
}
return strings.TrimSpace(out)
}