-
Notifications
You must be signed in to change notification settings - Fork 8
/
msg.go
161 lines (135 loc) · 4.38 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
_ sdk.Msg = &MsgCreateBond{}
_ sdk.Msg = &MsgRefillBond{}
_ sdk.Msg = &MsgWithdrawBond{}
_ sdk.Msg = &MsgCancelBond{}
)
// NewMsgCreateBond is the constructor function for MsgCreateBond.
func NewMsgCreateBond(coins sdk.Coins, signer sdk.AccAddress) MsgCreateBond {
return MsgCreateBond{
Coins: coins,
Signer: signer.String(),
}
}
// Route Implements Msg.
func (msg MsgCreateBond) Route() string { return RouterKey }
// Type Implements Msg.
func (msg MsgCreateBond) Type() string { return "create" }
func (msg MsgCreateBond) ValidateBasic() error {
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
func (msg MsgCreateBond) GetSigners() []sdk.AccAddress {
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
return []sdk.AccAddress{accAddr}
}
// GetSignBytes gets the sign bytes for the msg MsgCreateBond
func (msg MsgCreateBond) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// NewMsgRefillBond is the constructor function for MsgRefillBond.
func NewMsgRefillBond(id string, amount sdk.Coin, signer sdk.AccAddress) MsgRefillBond {
return MsgRefillBond{
Id: id,
Coins: sdk.NewCoins(amount),
Signer: signer.String(),
}
}
// Route Implements Msg.
func (msg MsgRefillBond) Route() string { return RouterKey }
// Type Implements Msg.
func (msg MsgRefillBond) Type() string { return "refill" }
func (msg MsgRefillBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
func (msg MsgRefillBond) GetSigners() []sdk.AccAddress {
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
return []sdk.AccAddress{accAddr}
}
// GetSignBytes gets the sign bytes for the msg MsgCreateBond
func (msg MsgRefillBond) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// NewMsgWithdrawBond is the constructor function for NewMsgWithdrawBond.
func NewMsgWithdrawBond(id string, amount sdk.Coin, signer sdk.AccAddress) MsgWithdrawBond {
return MsgWithdrawBond{
Id: id,
Coins: sdk.NewCoins(amount),
Signer: signer.String(),
}
}
// Route Implements Msg.
func (msg MsgWithdrawBond) Route() string { return RouterKey }
// Type Implements Msg.
func (msg MsgWithdrawBond) Type() string { return "withdraw" }
func (msg MsgWithdrawBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
func (msg MsgWithdrawBond) GetSigners() []sdk.AccAddress {
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
return []sdk.AccAddress{accAddr}
}
// GetSignBytes gets the sign bytes for the msg MsgCreateBond
func (msg MsgWithdrawBond) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// NewMsgCancelBond is the constructor function for CalcelBond.
func NewMsgCancelBond(id string, signer sdk.AccAddress) MsgCancelBond {
return MsgCancelBond{
Id: id,
Signer: signer.String(),
}
}
// Route Implements Msg.
func (msg MsgCancelBond) Route() string { return RouterKey }
// Type Implements Msg.
func (msg MsgCancelBond) Type() string { return "cancel" }
func (msg MsgCancelBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
return nil
}
func (msg MsgCancelBond) GetSigners() []sdk.AccAddress {
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
return []sdk.AccAddress{accAddr}
}
// GetSignBytes gets the sign bytes for the msg MsgCreateBond
func (msg MsgCancelBond) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}