/
msgs.go
309 lines (249 loc) · 8.03 KB
/
msgs.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
MsgTypeCreateDeployment = "create-deployment"
MsgTypeDepositDeployment = "deposit-deployment"
MsgTypeUpdateDeployment = "update-deployment"
MsgTypeCloseDeployment = "close-deployment"
MsgTypeCloseGroup = "close-group"
MsgTypePauseGroup = "pause-group"
MsgTypeStartGroup = "start-group"
)
var (
_, _, _, _ sdk.Msg = &MsgCreateDeployment{}, &MsgUpdateDeployment{}, &MsgCloseDeployment{}, &MsgCloseGroup{}
)
// NewMsgCreateDeployment creates a new MsgCreateDeployment instance
func NewMsgCreateDeployment(id DeploymentID, groups []GroupSpec, version []byte, deposit sdk.Coin) *MsgCreateDeployment {
return &MsgCreateDeployment{
ID: id,
Groups: groups,
Version: version,
Deposit: deposit,
}
}
// Route implements the sdk.Msg interface
func (msg MsgCreateDeployment) Route() string { return RouterKey }
// Type implements the sdk.Msg interface
func (msg MsgCreateDeployment) Type() string { return MsgTypeCreateDeployment }
// GetSignBytes encodes the message for signing
func (msg MsgCreateDeployment) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgCreateDeployment) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.ID.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// ValidateBasic does basic validation like check owner and groups length
func (msg MsgCreateDeployment) ValidateBasic() error {
if err := msg.ID.Validate(); err != nil {
return err
}
if len(msg.Groups) == 0 {
return ErrInvalidGroups
}
if len(msg.Version) == 0 {
return ErrEmptyVersion
}
if len(msg.Version) != ManifestVersionLength {
return ErrInvalidVersion
}
for _, gs := range msg.Groups {
err := gs.ValidateBasic()
if err != nil {
return err
}
}
return nil
}
// NewMsgDepositDeployment creates a new MsgDepositDeployment instance
func NewMsgDepositDeployment(id DeploymentID, amount sdk.Coin) *MsgDepositDeployment {
return &MsgDepositDeployment{
ID: id,
Amount: amount,
}
}
// Route implements the sdk.Msg interface
func (msg MsgDepositDeployment) Route() string { return RouterKey }
// Type implements the sdk.Msg interface
func (msg MsgDepositDeployment) Type() string { return MsgTypeDepositDeployment }
// GetSignBytes encodes the message for signing
func (msg MsgDepositDeployment) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgDepositDeployment) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.ID.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// ValidateBasic does basic validation like check owner and groups length
func (msg MsgDepositDeployment) ValidateBasic() error {
if err := msg.ID.Validate(); err != nil {
return err
}
if msg.Amount.IsZero() {
return ErrInvalidDeposit
}
return nil
}
// NewMsgUpdateDeployment creates a new MsgUpdateDeployment instance
func NewMsgUpdateDeployment(id DeploymentID, groups []GroupSpec, version []byte) *MsgUpdateDeployment {
return &MsgUpdateDeployment{
ID: id,
Groups: groups,
Version: version,
}
}
// Route implements the sdk.Msg interface
func (msg MsgUpdateDeployment) Route() string { return RouterKey }
// Type implements the sdk.Msg interface
func (msg MsgUpdateDeployment) Type() string { return MsgTypeUpdateDeployment }
// ValidateBasic does basic validation
func (msg MsgUpdateDeployment) ValidateBasic() error {
if err := msg.ID.Validate(); err != nil {
return err
}
if len(msg.Version) == 0 {
return ErrEmptyVersion
}
if len(msg.Version) != ManifestVersionLength {
return ErrInvalidVersion
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgUpdateDeployment) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgUpdateDeployment) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.ID.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// NewMsgCloseDeployment creates a new MsgCloseDeployment instance
func NewMsgCloseDeployment(id DeploymentID) *MsgCloseDeployment {
return &MsgCloseDeployment{
ID: id,
}
}
// Route implements the sdk.Msg interface
func (msg MsgCloseDeployment) Route() string { return RouterKey }
// Type implements the sdk.Msg interface
func (msg MsgCloseDeployment) Type() string { return MsgTypeCloseDeployment }
// ValidateBasic does basic validation with deployment details
func (msg MsgCloseDeployment) ValidateBasic() error {
if err := msg.ID.Validate(); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgCloseDeployment) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgCloseDeployment) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.ID.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// NewMsgCloseGroup creates a new MsgCloseGroup instance
func NewMsgCloseGroup(id GroupID) *MsgCloseGroup {
return &MsgCloseGroup{
ID: id,
}
}
// Route implements the sdk.Msg interface for routing
func (msg MsgCloseGroup) Route() string { return RouterKey }
// Type implements the sdk.Msg interface exposing message type
func (msg MsgCloseGroup) Type() string { return MsgTypeCloseGroup }
// ValidateBasic calls underlying GroupID.Validate() check and returns result
func (msg MsgCloseGroup) ValidateBasic() error {
if err := msg.ID.Validate(); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgCloseGroup) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgCloseGroup) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.ID.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// NewMsgPauseGroup creates a new MsgPauseGroup instance
func NewMsgPauseGroup(id GroupID) *MsgPauseGroup {
return &MsgPauseGroup{
ID: id,
}
}
// Route implements the sdk.Msg interface for routing
func (msg MsgPauseGroup) Route() string { return RouterKey }
// Type implements the sdk.Msg interface exposing message type
func (msg MsgPauseGroup) Type() string { return MsgTypePauseGroup }
// ValidateBasic calls underlying GroupID.Validate() check and returns result
func (msg MsgPauseGroup) ValidateBasic() error {
if err := msg.ID.Validate(); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgPauseGroup) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgPauseGroup) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.ID.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}
// NewMsgStartGroup creates a new MsgStartGroup instance
func NewMsgStartGroup(id GroupID) *MsgStartGroup {
return &MsgStartGroup{
ID: id,
}
}
// Route implements the sdk.Msg interface for routing
func (msg MsgStartGroup) Route() string { return RouterKey }
// Type implements the sdk.Msg interface exposing message type
func (msg MsgStartGroup) Type() string { return MsgTypeStartGroup }
// ValidateBasic calls underlying GroupID.Validate() check and returns result
func (msg MsgStartGroup) ValidateBasic() error {
if err := msg.ID.Validate(); err != nil {
return err
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgStartGroup) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners defines whose signature is required
func (msg MsgStartGroup) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.ID.Owner)
if err != nil {
panic(err)
}
return []sdk.AccAddress{owner}
}