/
types.go
201 lines (164 loc) · 5.14 KB
/
types.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package v040
import (
"fmt"
"strings"
"time"
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Staking params default values
const (
// DefaultUnbondingTime reflects three weeks in seconds as the default
// unbonding time.
// TODO: Justify our choice of default here.
DefaultUnbondingTime time.Duration = time.Hour * 24 * 7 * 3
// Default maximum number of bonded validators
DefaultMaxValidators uint32 = 100
// Default maximum entries in a UBD/RED pair
DefaultMaxEntries uint32 = 7
// DefaultHistorical entries is 10000. Apps that don't use IBC can ignore this
// value by not adding the staking module to the application module manager's
// SetOrderBeginBlockers.
DefaultHistoricalEntries uint32 = 10000
)
// NewParams creates a new Params instance
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string) Params {
return Params{
UnbondingTime: unbondingTime,
MaxValidators: maxValidators,
MaxEntries: maxEntries,
HistoricalEntries: historicalEntries,
BondDenom: bondDenom,
}
}
// String returns a human readable string representation of the parameters.
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
func DefaultParams() Params {
return NewParams(
DefaultUnbondingTime,
DefaultMaxValidators,
DefaultMaxEntries,
DefaultHistoricalEntries,
sdk.DefaultBondDenom,
)
}
// String implements the Stringer interface for a Commission object.
func (c Commission) String() string {
out, _ := yaml.Marshal(c)
return string(out)
}
// String implements the Stringer interface for a CommissionRates object.
func (cr CommissionRates) String() string {
out, _ := yaml.Marshal(cr)
return string(out)
}
// String implements the Stringer interface for a DVPair object.
func (dv DVPair) String() string {
out, _ := yaml.Marshal(dv)
return string(out)
}
// String implements the Stringer interface for a DVVTriplet object.
func (dvv DVVTriplet) String() string {
out, _ := yaml.Marshal(dvv)
return string(out)
}
// String returns a human readable string representation of a Delegation.
func (d Delegation) String() string {
out, _ := yaml.Marshal(d)
return string(out)
}
// Delegations is a collection of delegations
type Delegations []Delegation
func (d Delegations) String() (out string) {
for _, del := range d {
out += del.String() + "\n"
}
return strings.TrimSpace(out)
}
// String implements the stringer interface for a UnbondingDelegationEntry.
func (e UnbondingDelegationEntry) String() string {
out, _ := yaml.Marshal(e)
return string(out)
}
// String returns a human readable string representation of an UnbondingDelegation.
func (ubd UnbondingDelegation) String() string {
out := fmt.Sprintf(`Unbonding Delegations between:
Delegator: %s
Validator: %s
Entries:`, ubd.DelegatorAddress, ubd.ValidatorAddress)
for i, entry := range ubd.Entries {
out += fmt.Sprintf(` Unbonding Delegation %d:
Creation Height: %v
Min time to unbond (unix): %v
Expected balance: %s`, i, entry.CreationHeight,
entry.CompletionTime, entry.Balance)
}
return out
}
// UnbondingDelegations is a collection of UnbondingDelegation
type UnbondingDelegations []UnbondingDelegation
func (ubds UnbondingDelegations) String() (out string) {
for _, u := range ubds {
out += u.String() + "\n"
}
return strings.TrimSpace(out)
}
// String implements the Stringer interface for a RedelegationEntry object.
func (e RedelegationEntry) String() string {
out, _ := yaml.Marshal(e)
return string(out)
}
// String returns a human readable string representation of a Redelegation.
func (red Redelegation) String() string {
out := fmt.Sprintf(`Redelegations between:
Delegator: %s
Source Validator: %s
Destination Validator: %s
Entries:
`,
red.DelegatorAddress, red.ValidatorSrcAddress, red.ValidatorDstAddress,
)
for i, entry := range red.Entries {
out += fmt.Sprintf(` Redelegation Entry #%d:
Creation height: %v
Min time to unbond (unix): %v
Dest Shares: %s
`,
i, entry.CreationHeight, entry.CompletionTime, entry.SharesDst,
)
}
return strings.TrimRight(out, "\n")
}
// Redelegations are a collection of Redelegation
type Redelegations []Redelegation
func (d Redelegations) String() (out string) {
for _, red := range d {
out += red.String() + "\n"
}
return strings.TrimSpace(out)
}
// String implements the Stringer interface for DelegationResponse.
func (d DelegationResponse) String() string {
return fmt.Sprintf("%s\n Balance: %s", d.Delegation.String(), d.Balance)
}
// String implements the Stringer interface for a Validator object.
func (v Validator) String() string {
out, _ := yaml.Marshal(v)
return string(out)
}
// Validators is a collection of Validator
type Validators []Validator
func (v Validators) String() (out string) {
for _, val := range v {
out += val.String() + "\n"
}
return strings.TrimSpace(out)
}
// String implements the Stringer interface for a Description object.
func (d Description) String() string {
out, _ := yaml.Marshal(d)
return string(out)
}