/
msgs.go
194 lines (157 loc) · 5.73 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
package slashing
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// TypeMsgSlashArgument represents the type of the message for creating new community
TypeMsgSlashArgument = "slash_argument"
// 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"
)
// MsgSlashArgument defines the message to slash an argument
type MsgSlashArgument struct {
ArgumentID uint64 `json:"argument_id"`
SlashType SlashType `json:"slash_type"`
SlashReason SlashReason `json:"slash_reason"`
SlashDetailedReason string `json:"slash_detailed_reason,omitempty"`
Creator sdk.AccAddress `json:"creator"`
}
// NewMsgSlashArgument returns the messages to slash an argument
func NewMsgSlashArgument(argumentID uint64, slashType SlashType, slashReason SlashReason, slashDetailedReason string, creator sdk.AccAddress) MsgSlashArgument {
return MsgSlashArgument{
ArgumentID: argumentID,
SlashType: slashType,
SlashReason: slashReason,
SlashDetailedReason: slashDetailedReason,
Creator: creator,
}
}
// ValidateBasic implements Msg
func (msg MsgSlashArgument) ValidateBasic() sdk.Error {
if len(msg.Creator) == 0 {
return sdk.ErrInvalidAddress(fmt.Sprintf("Invalid address: %s", msg.Creator.String()))
}
if msg.SlashReason == SlashReasonOther && len(msg.SlashDetailedReason) == 0 {
return ErrInvalidSlashReason("Need to have detailed reason when chosen Others")
}
return nil
}
// Route implements Msg
func (msg MsgSlashArgument) Route() string { return RouterKey }
// Type implements Msg
func (msg MsgSlashArgument) Type() string { return TypeMsgSlashArgument }
// GetSignBytes implements Msg
func (msg MsgSlashArgument) GetSignBytes() []byte {
msgBytes := ModuleCodec.MustMarshalJSON(msg)
return sdk.MustSortJSON(msgBytes)
}
// GetSigners implements Msg. Returns the creator as the signer.
func (msg MsgSlashArgument) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.Creator)}
}
// 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)}
}