-
Notifications
You must be signed in to change notification settings - Fork 368
/
msg.go
251 lines (218 loc) · 8.18 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
TypeMsgIssueTokens = "issue_tokens"
TypeMsgRedeemTokens = "redeem_tokens"
TypeMsgBlockAddress = "block_address"
TypeMsgUnBlockAddress = "unblock_address"
TypeMsgSetPauseStatus = "change_pause_status"
)
// ensure Msg interface compliance at compile time
var (
_ sdk.Msg = &MsgIssueTokens{}
_ sdk.Msg = &MsgRedeemTokens{}
_ sdk.Msg = &MsgBlockAddress{}
_ sdk.Msg = &MsgUnblockAddress{}
_ sdk.Msg = &MsgSetPauseStatus{}
)
// NewMsgIssueTokens returns a new MsgIssueTokens
func NewMsgIssueTokens(sender string, tokens sdk.Coin, receiver string) *MsgIssueTokens {
return &MsgIssueTokens{
Sender: sender,
Tokens: tokens,
Receiver: receiver,
}
}
// Route return the message type used for routing the message.
func (msg MsgIssueTokens) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgIssueTokens) Type() string { return TypeMsgIssueTokens }
// ValidateBasic does a simple validation check that doesn't require access to state.
func (msg MsgIssueTokens) ValidateBasic() error {
if len(msg.Sender) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
}
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid sender bech32 address")
}
if msg.Tokens.IsZero() || !msg.Tokens.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid tokens %s", msg.Tokens)
}
if len(msg.Receiver) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "receiver address cannot be empty")
}
_, err = sdk.AccAddressFromBech32(msg.Receiver)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid receiver bech32 address")
}
return nil
}
// GetSignBytes gets the canonical byte representation of the Msg
func (msg MsgIssueTokens) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign
func (msg MsgIssueTokens) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
// NewMsgRedeemTokens returns a new MsgRedeemTokens
func NewMsgRedeemTokens(sender string, tokens sdk.Coin) *MsgRedeemTokens {
return &MsgRedeemTokens{
Sender: sender,
Tokens: tokens,
}
}
// Route return the message type used for routing the message.
func (msg MsgRedeemTokens) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgRedeemTokens) Type() string { return TypeMsgRedeemTokens }
// ValidateBasic does a simple validation check that doesn't require access to state.
func (msg MsgRedeemTokens) ValidateBasic() error {
if len(msg.Sender) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
}
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid sender bech32 address")
}
if msg.Tokens.IsZero() || !msg.Tokens.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid tokens %s", msg.Tokens)
}
return nil
}
// GetSignBytes gets the canonical byte representation of the Msg
func (msg MsgRedeemTokens) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign
func (msg MsgRedeemTokens) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
// NewMsgBlockAddress returns a new MsgBlockAddress
func NewMsgBlockAddress(sender string, denom string, addr string) *MsgBlockAddress {
return &MsgBlockAddress{
Sender: sender,
Denom: denom,
BlockedAddress: addr,
}
}
// Route return the message type used for routing the message.
func (msg MsgBlockAddress) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgBlockAddress) Type() string { return TypeMsgBlockAddress }
// ValidateBasic does a simple validation check that doesn't require access to state.
func (msg MsgBlockAddress) ValidateBasic() error {
if len(msg.Sender) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
}
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid sender bech32 address")
}
if len(msg.BlockedAddress) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "blocked address cannot be empty")
}
return sdk.ValidateDenom(msg.Denom)
}
// GetSignBytes gets the canonical byte representation of the Msg
func (msg MsgBlockAddress) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign
func (msg MsgBlockAddress) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
// NewMsgUnblockAddress returns a new MsgUnblockAddress
func NewMsgUnblockAddress(sender string, denom string, addr string) *MsgUnblockAddress {
return &MsgUnblockAddress{
Sender: sender,
Denom: denom,
BlockedAddress: addr,
}
}
// Route return the message type used for routing the message.
func (msg MsgUnblockAddress) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgUnblockAddress) Type() string { return TypeMsgUnBlockAddress }
// ValidateBasic does a simple validation check that doesn't require access to state.
func (msg MsgUnblockAddress) ValidateBasic() error {
if len(msg.Sender) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
}
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid sender bech32 address")
}
if len(msg.BlockedAddress) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "blocked address cannot be empty")
}
return sdk.ValidateDenom(msg.Denom)
}
// GetSignBytes gets the canonical byte representation of the Msg
func (msg MsgUnblockAddress) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign
func (msg MsgUnblockAddress) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
// NewMsgSetPauseStatus returns a new MsgSetPauseStatus
func NewMsgSetPauseStatus(sender string, denom string, status bool) *MsgSetPauseStatus {
return &MsgSetPauseStatus{
Sender: sender,
Denom: denom,
Status: status,
}
}
// Route return the message type used for routing the message.
func (msg MsgSetPauseStatus) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgSetPauseStatus) Type() string { return TypeMsgSetPauseStatus }
// ValidateBasic does a simple validation check that doesn't require access to state.
func (msg MsgSetPauseStatus) ValidateBasic() error {
if len(msg.Sender) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
}
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid sender bech32 address")
}
return sdk.ValidateDenom(msg.Denom)
}
// GetSignBytes gets the canonical byte representation of the Msg
func (msg MsgSetPauseStatus) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign
func (msg MsgSetPauseStatus) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}