/
params.go
82 lines (70 loc) · 2.95 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
80
81
82
package keeper
import (
"fmt"
"regexp"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/provenance-io/provenance/x/marker/types"
)
// GetParams returns the total set of distribution parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return types.Params{
MaxTotalSupply: k.GetMaxTotalSupply(ctx),
EnableGovernance: k.GetEnableGovernance(ctx),
UnrestrictedDenomRegex: k.GetUnrestrictedDenomRegex(ctx),
MaxSupply: k.GetMaxSupply(ctx),
}
}
// SetParams sets the distribution parameters to the param space.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, ¶ms)
}
// GetMaxTotalSupply is deprecated.
// Deprecated: GetMaxTotalSupply is kept for backwards compatibility.
func (k Keeper) GetMaxTotalSupply(ctx sdk.Context) (max uint64) {
max = types.DefaultMaxTotalSupply
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxTotalSupply) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxTotalSupply, &max)
}
return
}
// GetMaxSupply return the current parameter value for the max allowed supply (or default if unset)
func (k Keeper) GetMaxSupply(ctx sdk.Context) (max math.Int) {
max = types.StringToBigInt(types.DefaultMaxSupply)
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxSupply) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxSupply, &max)
}
return
}
// GetEnableGovernance returns the current parameter value for enabling governance control (or default if unset)
func (k Keeper) GetEnableGovernance(ctx sdk.Context) (enabled bool) {
enabled = types.DefaultEnableGovernance
if k.paramSpace.Has(ctx, types.ParamStoreKeyEnableGovernance) {
k.paramSpace.Get(ctx, types.ParamStoreKeyEnableGovernance, &enabled)
}
return
}
// GetUnrestrictedDenomRegex returns the current parameter value for enabling governance control (or default if unset)
func (k Keeper) GetUnrestrictedDenomRegex(ctx sdk.Context) (regex string) {
regex = types.DefaultUnrestrictedDenomRegex
if k.paramSpace.Has(ctx, types.ParamStoreKeyUnrestrictedDenomRegex) {
k.paramSpace.Get(ctx, types.ParamStoreKeyUnrestrictedDenomRegex, ®ex)
// use the default value for empty regex expressions.
if len(regex) == 0 {
regex = types.DefaultUnrestrictedDenomRegex
}
}
return
}
// ValidateUnrestictedDenom checks if the supplied denom is valid based on the module params
func (k Keeper) ValidateUnrestictedDenom(ctx sdk.Context, denom string) error {
// Anchors are enforced on the denom validation expression. Similar to how the SDK does hits.
// https://github.com/cosmos/cosmos-sdk/blob/512b533242d34926972a8fc2f5639e8cf182f5bd/types/coin.go#L625
exp := k.GetUnrestrictedDenomRegex(ctx)
// Safe to use must compile here because the regular expression is validated on parameter set.
r := regexp.MustCompile(fmt.Sprintf(`^%s$`, exp))
if !r.MatchString(denom) {
return fmt.Errorf("invalid denom [%s] (fails unrestricted marker denom validation %s)", denom, exp)
}
return nil
}