-
Notifications
You must be signed in to change notification settings - Fork 368
/
msg.go
201 lines (166 loc) · 7.49 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)
const (
// TypeMsgMintDeposit defines the type for MsgMintDeposit
TypeMsgMintDeposit = "mint_deposit"
// TypeMsgDelegateMintDeposit defines the type for MsgDelegateMintDeposit
TypeMsgDelegateMintDeposit = "delegate_mint_deposit"
// TypeMsgWithdrawBurn defines the type for MsgWithdrawBurn
TypeMsgWithdrawBurn = "withdraw_burn"
// TypeMsgWithdrawBurnUndelegate defines the type for MsgWithdrawBurnUndelegate
TypeMsgWithdrawBurnUndelegate = "withdraw_burn_undelegate"
)
var (
_ sdk.Msg = &MsgMintDeposit{}
_ legacytx.LegacyMsg = &MsgMintDeposit{}
_ sdk.Msg = &MsgDelegateMintDeposit{}
_ legacytx.LegacyMsg = &MsgDelegateMintDeposit{}
_ sdk.Msg = &MsgWithdrawBurn{}
_ legacytx.LegacyMsg = &MsgWithdrawBurn{}
_ sdk.Msg = &MsgWithdrawBurnUndelegate{}
_ legacytx.LegacyMsg = &MsgWithdrawBurnUndelegate{}
)
// NewMsgMintDeposit returns a new MsgMintDeposit.
func NewMsgMintDeposit(depositor sdk.AccAddress, validator sdk.ValAddress, amount sdk.Coin) *MsgMintDeposit {
return &MsgMintDeposit{
Depositor: depositor.String(),
Validator: validator.String(),
Amount: amount,
}
}
// Route return the message type used for routing the message.
func (msg MsgMintDeposit) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgMintDeposit) Type() string { return TypeMsgMintDeposit }
// ValidateBasic does a simple validation check that doesn't require access to any other information.
func (msg MsgMintDeposit) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid depositor address: %s", err)
}
if _, err := sdk.ValAddressFromBech32(msg.Validator); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address: %s", err)
}
if msg.Amount.IsNil() || !msg.Amount.IsValid() || msg.Amount.IsZero() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "'%s'", msg.Amount)
}
return nil
}
// GetSignBytes gets the canonical byte representation of the Msg.
func (msg MsgMintDeposit) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign.
func (msg MsgMintDeposit) GetSigners() []sdk.AccAddress {
depositor, _ := sdk.AccAddressFromBech32(msg.Depositor)
return []sdk.AccAddress{depositor}
}
// NewMsgDelegateMintDeposit returns a new MsgDelegateMintDeposit.
func NewMsgDelegateMintDeposit(depositor sdk.AccAddress, validator sdk.ValAddress, amount sdk.Coin) *MsgDelegateMintDeposit {
return &MsgDelegateMintDeposit{
Depositor: depositor.String(),
Validator: validator.String(),
Amount: amount,
}
}
// Route return the message type used for routing the message.
func (msg MsgDelegateMintDeposit) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgDelegateMintDeposit) Type() string { return TypeMsgDelegateMintDeposit }
// ValidateBasic does a simple validation check that doesn't require access to any other information.
func (msg MsgDelegateMintDeposit) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid depositor address: %s", err)
}
if _, err := sdk.ValAddressFromBech32(msg.Validator); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address: %s", err)
}
if msg.Amount.IsNil() || !msg.Amount.IsValid() || msg.Amount.IsZero() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "'%s'", msg.Amount)
}
return nil
}
// GetSignBytes gets the canonical byte representation of the Msg.
func (msg MsgDelegateMintDeposit) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign.
func (msg MsgDelegateMintDeposit) GetSigners() []sdk.AccAddress {
depositor, _ := sdk.AccAddressFromBech32(msg.Depositor)
return []sdk.AccAddress{depositor}
}
// NewMsgWithdrawBurn returns a new MsgWithdrawBurn.
func NewMsgWithdrawBurn(from sdk.AccAddress, validator sdk.ValAddress, amount sdk.Coin) *MsgWithdrawBurn {
return &MsgWithdrawBurn{
From: from.String(),
Validator: validator.String(),
Amount: amount,
}
}
// Route return the message type used for routing the message.
func (msg MsgWithdrawBurn) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgWithdrawBurn) Type() string { return TypeMsgWithdrawBurn }
// ValidateBasic does a simple validation check that doesn't require access to any other information.
func (msg MsgWithdrawBurn) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.From); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid from address: %s", err)
}
if _, err := sdk.ValAddressFromBech32(msg.Validator); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address: %s", err)
}
if msg.Amount.IsNil() || !msg.Amount.IsValid() || msg.Amount.IsZero() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "'%s'", msg.Amount)
}
return nil
}
// GetSignBytes gets the canonical byte representation of the Msg.
func (msg MsgWithdrawBurn) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign.
func (msg MsgWithdrawBurn) GetSigners() []sdk.AccAddress {
from, _ := sdk.AccAddressFromBech32(msg.From)
return []sdk.AccAddress{from}
}
// NewMsgWithdrawBurnUndelegate returns a new MsgWithdrawBurnUndelegate.
func NewMsgWithdrawBurnUndelegate(from sdk.AccAddress, validator sdk.ValAddress, amount sdk.Coin) *MsgWithdrawBurnUndelegate {
return &MsgWithdrawBurnUndelegate{
From: from.String(),
Validator: validator.String(),
Amount: amount,
}
}
// Route return the message type used for routing the message.
func (msg MsgWithdrawBurnUndelegate) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgWithdrawBurnUndelegate) Type() string { return TypeMsgWithdrawBurnUndelegate }
// ValidateBasic does a simple validation check that doesn't require access to any other information.
func (msg MsgWithdrawBurnUndelegate) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.From); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid from address: %s", err)
}
if _, err := sdk.ValAddressFromBech32(msg.Validator); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address: %s", err)
}
if msg.Amount.IsNil() || !msg.Amount.IsValid() || msg.Amount.IsZero() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "'%s'", msg.Amount)
}
return nil
}
// GetSignBytes gets the canonical byte representation of the Msg.
func (msg MsgWithdrawBurnUndelegate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign.
func (msg MsgWithdrawBurnUndelegate) GetSigners() []sdk.AccAddress {
from, _ := sdk.AccAddressFromBech32(msg.From)
return []sdk.AccAddress{from}
}