forked from terra-money/classic-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
params.go
54 lines (46 loc) · 1.48 KB
/
params.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
package oracle
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Params oracle parameters
type Params struct {
VotePeriod sdk.Int `json:"vote_period"` // voting period; tallys and reward claim period
VoteThreshold sdk.Dec `json:"vote_threshold"` // minimum stake power threshold to clear vote
DropThreshold sdk.Int `json:"drop_threshold"` // tolerated drops before blacklist
}
// NewParams creates a new param instance
func NewParams(votePeriod sdk.Int, voteThreshold sdk.Dec, dropThreshold sdk.Int) Params {
return Params{
VotePeriod: votePeriod,
VoteThreshold: voteThreshold,
DropThreshold: dropThreshold,
}
}
// DefaultParams creates default oracle module parameters
func DefaultParams() Params {
return NewParams(
sdk.NewInt(1000000),
sdk.NewDecWithPrec(66, 2), // 66%
sdk.NewInt(10),
)
}
func validateParams(params Params) error {
if params.VotePeriod.LT(sdk.ZeroInt()) {
return fmt.Errorf("oracle parameter VotePeriod must be > 0, is %s", params.VotePeriod.String())
}
if params.VoteThreshold.LT(sdk.NewDecWithPrec(33, 2)) {
return fmt.Errorf("oracle parameter VoteThreshold must be greater than 33 percent")
}
if params.DropThreshold.LTE(sdk.NewInt(3)) {
return fmt.Errorf("oracle parameter DropThreshold must be greater than 3")
}
return nil
}
func (params Params) String() string {
return fmt.Sprintf(`Oracle Params:
VotePeriod: %s
VoteThreshold: %s
DropThresdhold: %s
`, params.VotePeriod, params.VoteThreshold, params.DropThreshold)
}