-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
params.go
75 lines (63 loc) · 1.94 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
package types
import (
"errors"
"fmt"
"sigs.k8s.io/yaml"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// DefaultDefaultSendEnabled is the value that DefaultSendEnabled will have from DefaultParams().
var DefaultDefaultSendEnabled = true
// NewParams creates a new parameter configuration for the bank module
func NewParams(defaultSendEnabled bool) Params {
return Params{
SendEnabled: nil,
DefaultSendEnabled: defaultSendEnabled,
}
}
// DefaultParams is the default parameter configuration for the bank module
func DefaultParams() Params {
return Params{
SendEnabled: nil,
DefaultSendEnabled: DefaultDefaultSendEnabled,
}
}
// Validate all bank module parameters
func (p Params) Validate() error {
if len(p.SendEnabled) > 0 {
return errors.New("use of send_enabled in params is no longer supported")
}
return validateIsBool(p.DefaultSendEnabled)
}
// String implements the Stringer interface.
func (p Params) String() string {
sendEnabled, _ := yaml.Marshal(p.SendEnabled)
d := " "
if len(sendEnabled) > 0 && sendEnabled[0] == '-' {
d = "\n"
}
return fmt.Sprintf("default_send_enabled: %t\nsend_enabled:%s%s", p.DefaultSendEnabled, d, sendEnabled)
}
// Validate gets any errors with this SendEnabled entry.
func (se SendEnabled) Validate() error {
return sdk.ValidateDenom(se.Denom)
}
// NewSendEnabled creates a new SendEnabled object
// The denom may be left empty to control the global default setting of send_enabled
func NewSendEnabled(denom string, sendEnabled bool) *SendEnabled {
return &SendEnabled{
Denom: denom,
Enabled: sendEnabled,
}
}
// String implements stringer interface
func (se SendEnabled) String() string {
return fmt.Sprintf("denom: %s\nenabled: %t\n", se.Denom, se.Enabled)
}
// validateIsBool is used by the x/params module to validate that a thing is a bool.
func validateIsBool(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}