-
Notifications
You must be signed in to change notification settings - Fork 352
/
staking.go
51 lines (42 loc) · 1.29 KB
/
staking.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
package types
import (
"errors"
"time"
sdkmath "cosmossdk.io/math"
)
var (
// DefaultLastAccumulationTime is zero
DefaultLastAccumulationTime = time.Time{}
// DefaultLastTruncationError is zero
DefaultLastTruncationError = sdkmath.LegacyZeroDec()
)
// NewStakingRewardsState returns a new staking rewards state object
func NewStakingRewardsState(
lastAccumulationTime time.Time,
lastTruncationError sdkmath.LegacyDec,
) StakingRewardsState {
return StakingRewardsState{
LastAccumulationTime: lastAccumulationTime,
LastTruncationError: lastTruncationError,
}
}
// DefaultStakingRewardsState returns default params
func DefaultStakingRewardsState() StakingRewardsState {
return NewStakingRewardsState(
DefaultLastAccumulationTime,
DefaultLastTruncationError,
)
}
// Validate checks the params are valid
func (p StakingRewardsState) Validate() error {
if err := validateDecNotNilNonNegative(p.LastTruncationError, "LastTruncationError"); err != nil {
return err
}
if p.LastTruncationError.GTE(sdkmath.LegacyOneDec()) {
return errors.New("LastTruncationError should not be greater or equal to 1")
}
if p.LastAccumulationTime.IsZero() && !p.LastTruncationError.IsZero() {
return errors.New("LastTruncationError should be zero if last accumulation time is zero")
}
return nil
}