This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
params.go
140 lines (128 loc) · 4.61 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package types
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/x/params"
)
const (
DefaultFeeForAliasLength2 = 10000e8
DefaultFeeForAliasLength3 = 5000e8
DefaultFeeForAliasLength4 = 2000e8
DefaultFeeForAliasLength5 = 1000e8
DefaultFeeForAliasLength6 = 100e8
DefaultFeeForAliasLength7OrHigher = 10e8
DefaultMaxAliasCount = 5
)
var (
KeyFeeForAliasLength2 = []byte("FeeForAliasLength2")
KeyFeeForAliasLength3 = []byte("FeeForAliasLength3")
KeyFeeForAliasLength4 = []byte("FeeForAliasLength4")
KeyFeeForAliasLength5 = []byte("FeeForAliasLength5")
KeyFeeForAliasLength6 = []byte("FeeForAliasLength6")
KeyFeeForAliasLength7OrHigher = []byte("FeeForAliasLength7OrHigher")
KeyMaxAliasCount = []byte("MaxAliasCount")
)
type Params struct {
FeeForAliasLength2 int64 `json:"fee_for_alias_length_2"`
FeeForAliasLength3 int64 `json:"fee_for_alias_length_3"`
FeeForAliasLength4 int64 `json:"fee_for_alias_length_4"`
FeeForAliasLength5 int64 `json:"fee_for_alias_length_5"`
FeeForAliasLength6 int64 `json:"fee_for_alias_length_6"`
FeeForAliasLength7OrHigher int64 `json:"fee_for_alias_length_7_or_higher"`
MaxAliasCount int `json:"max_alias_count"`
}
// ParamKeyTable for alias module
func ParamKeyTable() params.KeyTable {
return params.NewKeyTable().RegisterParamSet(&Params{})
}
// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return Params{
DefaultFeeForAliasLength2,
DefaultFeeForAliasLength3,
DefaultFeeForAliasLength4,
DefaultFeeForAliasLength5,
DefaultFeeForAliasLength6,
DefaultFeeForAliasLength7OrHigher,
DefaultMaxAliasCount,
}
}
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
// pairs of asset module's parameters.
// nolint
func (p *Params) ParamSetPairs() params.ParamSetPairs {
return params.ParamSetPairs{
{Key: KeyFeeForAliasLength2, Value: &p.FeeForAliasLength2},
{Key: KeyFeeForAliasLength3, Value: &p.FeeForAliasLength3},
{Key: KeyFeeForAliasLength4, Value: &p.FeeForAliasLength4},
{Key: KeyFeeForAliasLength5, Value: &p.FeeForAliasLength5},
{Key: KeyFeeForAliasLength6, Value: &p.FeeForAliasLength6},
{Key: KeyFeeForAliasLength7OrHigher, Value: &p.FeeForAliasLength7OrHigher},
{Key: KeyMaxAliasCount, Value: &p.MaxAliasCount},
}
}
func (p *Params) ValidateGenesis() error {
if p.FeeForAliasLength2 <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyFeeForAliasLength2, p.FeeForAliasLength2)
}
if p.FeeForAliasLength3 <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyFeeForAliasLength3, p.FeeForAliasLength3)
}
if p.FeeForAliasLength3 <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyFeeForAliasLength3, p.FeeForAliasLength3)
}
if p.FeeForAliasLength4 <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyFeeForAliasLength4, p.FeeForAliasLength4)
}
if p.FeeForAliasLength5 <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyFeeForAliasLength5, p.FeeForAliasLength5)
}
if p.FeeForAliasLength6 <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyFeeForAliasLength6, p.FeeForAliasLength6)
}
if p.FeeForAliasLength7OrHigher <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyFeeForAliasLength7OrHigher, p.FeeForAliasLength7OrHigher)
}
if p.MaxAliasCount <= 0 {
return fmt.Errorf("%s must be a positive number, is %d", KeyMaxAliasCount, p.MaxAliasCount)
}
return nil
}
func (p *Params) GetFeeForAlias(alias string) int64 {
if n := len(alias); n == 2 {
return p.FeeForAliasLength2
} else if n == 3 {
return p.FeeForAliasLength3
} else if n == 4 {
return p.FeeForAliasLength4
} else if n == 5 {
return p.FeeForAliasLength5
} else if n == 6 {
return p.FeeForAliasLength6
} else {
return p.FeeForAliasLength7OrHigher
}
}
// Equal returns a boolean determining if two Params types are identical.
func (p Params) Equal(p2 Params) bool {
bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p)
bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p2)
return bytes.Equal(bz1, bz2)
}
func (p Params) String() string {
return fmt.Sprintf(`Alias Params:
FeeForAliasLength2: %d
FeeForAliasLength3: %d
FeeForAliasLength4: %d
FeeForAliasLength5: %d
FeeForAliasLength6: %d
FeeForAliasLength7OrHigher: %d
MaxAliasCount: %d`,
p.FeeForAliasLength2,
p.FeeForAliasLength3,
p.FeeForAliasLength4,
p.FeeForAliasLength5,
p.FeeForAliasLength6,
p.FeeForAliasLength7OrHigher,
p.MaxAliasCount)
}