/
messages.go
244 lines (207 loc) · 7.04 KB
/
messages.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const RouterKey = ModuleName // this was defined in your key.go file
// MsgIssueToken defines a IssueToken message
type MsgIssueToken struct {
SourceAddress sdk.AccAddress `json:"source_address"`
Name string `json:"name"`
Symbol string `json:"symbol"`
OriginalSymbol string `json:"original_symbol"`
TotalSupply int64 `json:"total_supply"`
Mintable bool `json:"mintable"`
}
// NewMsgIssueToken is a constructor function for MsgIssueToken
func NewMsgIssueToken(sourceAddress sdk.AccAddress, name, symbol string, originalSymbol string,
totalSupply int64, mintable bool) MsgIssueToken {
return MsgIssueToken{
SourceAddress: sourceAddress,
Name: name,
Symbol: symbol,
OriginalSymbol: originalSymbol,
TotalSupply: totalSupply,
Mintable: mintable,
}
}
// Route should return the name of the module
func (msg MsgIssueToken) Route() string { return RouterKey }
// Type should return the action
func (msg MsgIssueToken) Type() string { return "issue_token" }
// ValidateBasic runs stateless checks on the message
func (msg MsgIssueToken) ValidateBasic() sdk.Error {
if msg.SourceAddress.Empty() {
return sdk.ErrInvalidAddress(msg.SourceAddress.String())
}
if len(msg.Name) == 0 || len(msg.Symbol) == 0 || len(msg.OriginalSymbol) == 0 {
return sdk.ErrUnknownRequest("Name and/or Symbols cannot be empty")
}
if msg.TotalSupply < 1 {
return sdk.ErrUnknownRequest("TotalSupply cannot be less than 1")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgIssueToken) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgIssueToken) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.SourceAddress}
}
// MsgMintCoins defines the MintCoins message
type MsgMintCoins struct {
Amount int64 `json:"amount"`
Symbol string `json:"symbol"`
Owner sdk.AccAddress `json:"owner"`
}
// NewMsgMintCoins is the constructor function for MsgMintCoins
func NewMsgMintCoins(amount int64, symbol string, owner sdk.AccAddress) MsgMintCoins {
return MsgMintCoins{
Amount: amount,
Symbol: symbol,
Owner: owner,
}
}
// Route should return the name of the module
func (msg MsgMintCoins) Route() string { return RouterKey }
// Type should return the action
func (msg MsgMintCoins) Type() string { return "mint_coins" }
// ValidateBasic runs stateless checks on the message
func (msg MsgMintCoins) ValidateBasic() sdk.Error {
if msg.Owner.Empty() {
return sdk.ErrInvalidAddress(msg.Owner.String())
}
if len(msg.Symbol) == 0 {
return sdk.ErrUnknownRequest("Symbol cannot be empty")
}
if msg.Amount < 1 {
return sdk.ErrUnknownRequest("Amount cannot be less than 1")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgMintCoins) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgMintCoins) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Owner}
}
// MsgBurnCoins defines the BurnCoins message
type MsgBurnCoins struct {
Amount int64 `json:"amount"`
Symbol string `json:"symbol"`
Owner sdk.AccAddress `json:"owner"`
}
// NewMsgBurnCoins is the constructor function for MsgBurnCoins
func NewMsgBurnCoins(amount int64, symbol string, owner sdk.AccAddress) MsgBurnCoins {
return MsgBurnCoins{
Amount: amount,
Symbol: symbol,
Owner: owner,
}
}
// Route should return the name of the module
func (msg MsgBurnCoins) Route() string { return RouterKey }
// Type should return the action
func (msg MsgBurnCoins) Type() string { return "burn_coins" }
// ValidateBasic runs stateless checks on the message
func (msg MsgBurnCoins) ValidateBasic() sdk.Error {
if msg.Owner.Empty() {
return sdk.ErrInvalidAddress(msg.Owner.String())
}
if len(msg.Symbol) == 0 {
return sdk.ErrUnknownRequest("Symbol cannot be empty")
}
if msg.Amount < 1 {
return sdk.ErrUnknownRequest("Amount cannot be less than 1")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgBurnCoins) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgBurnCoins) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Owner}
}
// MsgFreezeCoins defines the FreezeCoins message
type MsgFreezeCoins struct {
Amount int64 `json:"amount"`
Symbol string `json:"symbol"`
Owner sdk.AccAddress `json:"owner"`
}
// NewMsgFreezeCoins is the constructor function for MsgFreezeCoins
func NewMsgFreezeCoins(amount int64, symbol string, owner sdk.AccAddress) MsgFreezeCoins {
return MsgFreezeCoins{
Amount: amount,
Symbol: symbol,
Owner: owner,
}
}
// Route should return the name of the module
func (msg MsgFreezeCoins) Route() string { return RouterKey }
// Type should return the action
func (msg MsgFreezeCoins) Type() string { return "freeze_coins" }
// ValidateBasic runs stateless checks on the message
func (msg MsgFreezeCoins) ValidateBasic() sdk.Error {
if msg.Owner.Empty() {
return sdk.ErrInvalidAddress(msg.Owner.String())
}
if len(msg.Symbol) == 0 {
return sdk.ErrUnknownRequest("Symbol cannot be empty")
}
if msg.Amount < 1 {
return sdk.ErrUnknownRequest("Amount cannot be less than 1")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgFreezeCoins) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgFreezeCoins) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Owner}
}
// MsgUnfreezeCoins defines the UnfreezeCoins message
type MsgUnfreezeCoins struct {
Amount int64 `json:"amount"`
Symbol string `json:"symbol"`
Owner sdk.AccAddress `json:"owner"`
}
// NewMsgUnfreezeCoins is the constructor function for MsgUnfreezeCoins
func NewMsgUnfreezeCoins(amount int64, symbol string, owner sdk.AccAddress) MsgUnfreezeCoins {
return MsgUnfreezeCoins{
Amount: amount,
Symbol: symbol,
Owner: owner,
}
}
// Route should return the name of the module
func (msg MsgUnfreezeCoins) Route() string { return RouterKey }
// Type should return the action
func (msg MsgUnfreezeCoins) Type() string { return "unfreeze_coins" }
// ValidateBasic runs stateless checks on the message
func (msg MsgUnfreezeCoins) ValidateBasic() sdk.Error {
if msg.Owner.Empty() {
return sdk.ErrInvalidAddress(msg.Owner.String())
}
if len(msg.Symbol) == 0 {
return sdk.ErrUnknownRequest("Symbol cannot be empty")
}
if msg.Amount < 1 {
return sdk.ErrUnknownRequest("Amount cannot be less than 1")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgUnfreezeCoins) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgUnfreezeCoins) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Owner}
}