forked from strangelove-ventures/poa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
79 lines (64 loc) · 1.73 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
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 poa
import (
"encoding/json"
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
// DefaultParams returns default module parameters.
func DefaultParams() Params {
govModuleAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String()
return Params{
Admins: []string{govModuleAddress},
AllowValidatorSelfExit: true,
}
}
// NewParams returns a new POA Params.
func NewParams(admins []string, allowValSelfExit bool) (Params, error) {
p := Params{
Admins: admins,
AllowValidatorSelfExit: allowValSelfExit,
}
return p, p.Validate()
}
// DefaultParams returns the default x/staking parameters.
func DefaultStakingParams() StakingParams {
sp := stakingtypes.DefaultParams()
return StakingParams{
UnbondingTime: sp.UnbondingTime,
MaxValidators: sp.MaxValidators,
MaxEntries: sp.MaxEntries,
HistoricalEntries: sp.HistoricalEntries,
BondDenom: sp.BondDenom,
MinCommissionRate: sp.MinCommissionRate,
}
}
// Stringer method for Params.
func (p Params) String() string {
bz, err := json.Marshal(p)
if err != nil {
panic(err)
}
return string(bz)
}
// Validate does the sanity check on the params.
func (p Params) Validate() error {
return validateAdmins(p.Admins)
}
func validateAdmins(i interface{}) error {
admins, ok := i.([]string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if len(admins) == 0 {
return ErrMustProvideAtLeastOneAddress
}
for _, auth := range admins {
if _, err := sdk.AccAddressFromBech32(auth); err != nil {
return err
}
}
return nil
}