-
Notifications
You must be signed in to change notification settings - Fork 15
/
msg.go
293 lines (241 loc) · 7.84 KB
/
msg.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
package claim
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// TypeMsgCreateClaim represents the type of the message for creating new claim
TypeMsgCreateClaim = "create_claim"
// TypeMsgAddAdmin represents the type of message for adding a new admin
TypeMsgAddAdmin = "add_admin"
// TypeMsgRemoveAdmin represents the type of message for removeing an admin
TypeMsgRemoveAdmin = "remove_admin"
// TypeMsgUpdateParams represents the type of
TypeMsgUpdateParams = "update_params"
)
// verify interface at compile time
var _ sdk.Msg = &MsgCreateClaim{}
var _ sdk.Msg = &MsgEditClaim{}
var _ sdk.Msg = &MsgAddAdmin{}
var _ sdk.Msg = &MsgRemoveAdmin{}
var _ sdk.Msg = &MsgUpdateParams{}
// MsgCreateClaim defines a message to submit a story
type MsgCreateClaim struct {
CommunityID string `json:"community_id"`
Body string `json:"body"`
Creator sdk.AccAddress `json:"creator"`
Source string `json:"source,omitempty"`
}
// NewMsgCreateClaim creates a new message to create a claim
func NewMsgCreateClaim(communityID, body string, creator sdk.AccAddress, source string) MsgCreateClaim {
return MsgCreateClaim{
CommunityID: communityID,
Body: body,
Creator: creator,
Source: source,
}
}
// Route is the name of the route for claim
func (msg MsgCreateClaim) Route() string {
return RouterKey
}
// Type is the name for the Msg
func (msg MsgCreateClaim) Type() string {
return TypeMsgCreateClaim
}
// ValidateBasic validates basic fields of the Msg
func (msg MsgCreateClaim) ValidateBasic() sdk.Error {
if len(msg.Body) == 0 {
return ErrInvalidBodyTooShort(msg.Body)
}
if len(msg.CommunityID) == 0 {
return ErrInvalidCommunityID(msg.CommunityID)
}
if len(msg.Creator) == 0 {
return sdk.ErrInvalidAddress("Invalid address: " + msg.Creator.String())
}
return nil
}
// GetSignBytes gets the bytes for Msg signer to sign on
func (msg MsgCreateClaim) GetSignBytes() []byte {
msgBytes := ModuleCodec.MustMarshalJSON(msg)
return sdk.MustSortJSON(msgBytes)
}
// GetSigners gets the signs of the Msg
func (msg MsgCreateClaim) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.Creator)}
}
// MsgDeleteClaim defines a message to submit a story
type MsgDeleteClaim struct {
ID uint64 `json:"id"`
Creator sdk.AccAddress `json:"creator"`
}
// Route is the name of the route for claim
func (msg MsgDeleteClaim) Route() string {
return RouterKey
}
// Type is the name for the Msg
func (msg MsgDeleteClaim) Type() string {
return ModuleName
}
// ValidateBasic validates basic fields of the Msg
func (msg MsgDeleteClaim) ValidateBasic() sdk.Error {
if msg.ID == 0 {
return ErrUnknownClaim(msg.ID)
}
if len(msg.Creator) == 0 {
return sdk.ErrInvalidAddress("Invalid address: " + msg.Creator.String())
}
return nil
}
// GetSignBytes gets the bytes for Msg signer to sign on
func (msg MsgDeleteClaim) GetSignBytes() []byte {
msgBytes := ModuleCodec.MustMarshalJSON(msg)
return sdk.MustSortJSON(msgBytes)
}
// GetSigners gets the signs of the Msg
func (msg MsgDeleteClaim) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.Creator)}
}
// MsgEditClaim defines a message to submit a story
type MsgEditClaim struct {
ID uint64 `json:"id"`
Body string `json:"body"`
Editor sdk.AccAddress `json:"editor"`
}
// NewMsgEditClaim creates a new message to edit a claim
func NewMsgEditClaim(id uint64, body string, editor sdk.AccAddress) MsgEditClaim {
return MsgEditClaim{
ID: id,
Body: body,
Editor: editor,
}
}
// Route is the name of the route for claim
func (msg MsgEditClaim) Route() string {
return RouterKey
}
// Type is the name for the Msg
func (msg MsgEditClaim) Type() string {
return ModuleName
}
// ValidateBasic validates basic fields of the Msg
func (msg MsgEditClaim) ValidateBasic() sdk.Error {
if msg.ID == 0 {
return ErrUnknownClaim(msg.ID)
}
if len(msg.Editor) == 0 {
return sdk.ErrInvalidAddress("Invalid address: " + msg.Editor.String())
}
return nil
}
// GetSignBytes gets the bytes for Msg signer to sign on
func (msg MsgEditClaim) GetSignBytes() []byte {
msgBytes := ModuleCodec.MustMarshalJSON(msg)
return sdk.MustSortJSON(msgBytes)
}
// GetSigners gets the signs of the Msg
func (msg MsgEditClaim) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.Editor)}
}
// MsgAddAdmin defines the message to add a new admin
type MsgAddAdmin struct {
Admin sdk.AccAddress `json:"admin"`
Creator sdk.AccAddress `json:"creator"`
}
// NewMsgAddAdmin returns the messages to add a new admin
func NewMsgAddAdmin(admin, creator sdk.AccAddress) MsgAddAdmin {
return MsgAddAdmin{
Admin: admin,
Creator: creator,
}
}
// ValidateBasic implements Msg
func (msg MsgAddAdmin) ValidateBasic() sdk.Error {
if len(msg.Admin) == 0 {
return sdk.ErrInvalidAddress(fmt.Sprintf("Invalid address: %s", msg.Admin.String()))
}
if len(msg.Creator) == 0 {
return sdk.ErrInvalidAddress(fmt.Sprintf("Invalid address: %s", msg.Creator.String()))
}
return nil
}
// Route implements Msg
func (msg MsgAddAdmin) Route() string { return RouterKey }
// Type implements Msg
func (msg MsgAddAdmin) Type() string { return TypeMsgAddAdmin }
// GetSignBytes implements Msg
func (msg MsgAddAdmin) GetSignBytes() []byte {
msgBytes := ModuleCodec.MustMarshalJSON(msg)
return sdk.MustSortJSON(msgBytes)
}
// GetSigners implements Msg. Returns the creator as the signer.
func (msg MsgAddAdmin) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.Creator)}
}
// MsgRemoveAdmin defines the message to remove an admin
type MsgRemoveAdmin struct {
Admin sdk.AccAddress `json:"admin"`
Remover sdk.AccAddress `json:"remover"`
}
// NewMsgRemoveAdmin returns the messages to remove an admin
func NewMsgRemoveAdmin(admin, remover sdk.AccAddress) MsgRemoveAdmin {
return MsgRemoveAdmin{
Admin: admin,
Remover: remover,
}
}
// ValidateBasic implements Msg
func (msg MsgRemoveAdmin) ValidateBasic() sdk.Error {
if len(msg.Admin) == 0 {
return sdk.ErrInvalidAddress(fmt.Sprintf("Invalid address: %s", msg.Admin.String()))
}
if len(msg.Remover) == 0 {
return sdk.ErrInvalidAddress(fmt.Sprintf("Invalid address: %s", msg.Remover.String()))
}
return nil
}
// Route implements Msg
func (msg MsgRemoveAdmin) Route() string { return RouterKey }
// Type implements Msg
func (msg MsgRemoveAdmin) Type() string { return TypeMsgRemoveAdmin }
// GetSignBytes implements Msg
func (msg MsgRemoveAdmin) GetSignBytes() []byte {
msgBytes := ModuleCodec.MustMarshalJSON(msg)
return sdk.MustSortJSON(msgBytes)
}
// GetSigners implements Msg. Returns the remover as the signer.
func (msg MsgRemoveAdmin) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.Remover)}
}
// MsgUpdateParams defines the message to remove an admin
type MsgUpdateParams struct {
Updates Params `json:"updates"`
UpdatedFields []string `json:"updated_fields"`
Updater sdk.AccAddress `json:"updater"`
}
// NewMsgUpdateParams returns the message to update the params
func NewMsgUpdateParams(updates Params, updatedFields []string, updater sdk.AccAddress) MsgUpdateParams {
return MsgUpdateParams{
Updates: updates,
UpdatedFields: updatedFields,
Updater: updater,
}
}
// ValidateBasic implements Msg
func (msg MsgUpdateParams) ValidateBasic() sdk.Error {
return nil
}
// Route implements Msg
func (msg MsgUpdateParams) Route() string { return RouterKey }
// Type implements Msg
func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams }
// GetSignBytes implements Msg
func (msg MsgUpdateParams) GetSignBytes() []byte {
msgBytes := ModuleCodec.MustMarshalJSON(msg)
return sdk.MustSortJSON(msgBytes)
}
// GetSigners implements Msg. Returns the remover as the signer.
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.Updater)}
}