/
msg.go
184 lines (147 loc) · 4.76 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
package types
import (
sdk "github.com/ci123chain/ci123chain/pkg/abci/types"
)
type MsgFundCommunityPool struct {
FromAddress sdk.AccAddress `json:"from_address"`
Amount sdk.Coin `json:"amount"`
Depositor sdk.AccAddress `json:"depositor"`
}
func NewMsgFundCommunityPool(from sdk.AccAddress,amount sdk.Coin, _, _ uint64, depositor sdk.AccAddress) *MsgFundCommunityPool {
return &MsgFundCommunityPool{
FromAddress: from,
Amount: amount,
Depositor: depositor,
}
}
// Route returns the MsgFundCommunityPool message route.
func (msg *MsgFundCommunityPool) Route() string { return RouteKey }
func (msg *MsgFundCommunityPool) MsgType() string { return "fund_community_pool" }
func (msg *MsgFundCommunityPool) Bytes() []byte{
bytes, err := DistributionCdc.MarshalBinaryLengthPrefixed(msg)
if err != nil {
panic(err)
}
return bytes
}
// ValidateBasic performs basic MsgFundCommunityPool message validation.
func (msg *MsgFundCommunityPool) ValidateBasic() error {
if !msg.Amount.IsValid() {
return ErrInvalidParams
}
if msg.Depositor.Empty() {
return ErrInvalidParams
}
if !msg.FromAddress.Equal(msg.Depositor) {
return ErrInvalidParams
}
return nil
}
func (msg *MsgFundCommunityPool) GetFromAddress() sdk.AccAddress { return msg.FromAddress}
type MsgSetWithdrawAddress struct {
FromAddress sdk.AccAddress `json:"from_address"`
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
WithdrawAddress sdk.AccAddress `json:"withdraw_address"`
}
func NewMsgSetWithdrawAddress(from, withdraw, del sdk.AccAddress) *MsgSetWithdrawAddress{
return &MsgSetWithdrawAddress{
FromAddress: from,
DelegatorAddress: del,
WithdrawAddress: withdraw,
}
}
func (msg *MsgSetWithdrawAddress) Route() string { return RouteKey}
func (msg *MsgSetWithdrawAddress) MsgType() string { return "set_withdraw_address"}
func (msg *MsgSetWithdrawAddress) ValidateBasic() error {
if msg.DelegatorAddress.Empty() {
return ErrInvalidParams
}
if msg.WithdrawAddress.Empty() {
return ErrInvalidParams
}
if msg.FromAddress.Empty() {
return ErrInvalidParams
}
//keep delegator address and from address the same.
if !msg.FromAddress.Equal(msg.DelegatorAddress) {
return ErrInvalidParams
}
return nil
}
func (msg *MsgSetWithdrawAddress) Bytes() []byte {
bytes, err := DistributionCdc.MarshalBinaryLengthPrefixed(msg)
if err != nil {
panic(err)
}
return bytes
}
func (msg *MsgSetWithdrawAddress) GetFromAddress() sdk.AccAddress { return msg.FromAddress}
type MsgWithdrawDelegatorReward struct {
FromAddress sdk.AccAddress `json:"from_address"`
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
ValidatorAddress sdk.AccAddress `json:"validator_address"`
}
func NewMsgWithdrawDelegatorReward(from, val, del sdk.AccAddress) *MsgWithdrawDelegatorReward {
return &MsgWithdrawDelegatorReward{
FromAddress: from,
DelegatorAddress:del,
ValidatorAddress:val,
}
}
func (msg *MsgWithdrawDelegatorReward) Route() string { return RouteKey}
func (msg *MsgWithdrawDelegatorReward) MsgType() string { return "withdraw_delegator_reward"}
func (msg *MsgWithdrawDelegatorReward) ValidateBasic() error {
if msg.ValidatorAddress.Empty() {
return ErrInvalidParams
}
if msg.DelegatorAddress.Empty() {
return ErrInvalidParams
}
if msg.FromAddress.Empty() {
return ErrInvalidParams
}
if !msg.FromAddress.Equal(msg.DelegatorAddress) {
return ErrInvalidParams
}
return nil
}
func (msg *MsgWithdrawDelegatorReward) Bytes() []byte {
bytes, err := DistributionCdc.MarshalBinaryLengthPrefixed(msg)
if err != nil {
panic(err)
}
return bytes
}
func (msg *MsgWithdrawDelegatorReward) GetFromAddress() sdk.AccAddress { return msg.FromAddress}
type MsgWithdrawValidatorCommission struct {
FromAddress sdk.AccAddress `json:"from_address"`
ValidatorAddress sdk.AccAddress `json:"validator_address"`
}
func NewMsgWithdrawValidatorCommission(from, val sdk.AccAddress) *MsgWithdrawValidatorCommission {
return &MsgWithdrawValidatorCommission{
FromAddress: from,
ValidatorAddress: val,
}
}
func (msg *MsgWithdrawValidatorCommission) Route() string { return RouteKey}
func (msg *MsgWithdrawValidatorCommission) MsgType() string { return "withdraw_validator_commission"}
func (msg *MsgWithdrawValidatorCommission) ValidateBasic() error {
if msg.ValidatorAddress.Empty() {
return ErrInvalidParams
}
if msg.FromAddress.Empty() {
return ErrInvalidParams
}
if !msg.FromAddress.Equal(msg.ValidatorAddress) {
return ErrInvalidParams
}
return nil
}
func (msg *MsgWithdrawValidatorCommission) Bytes() []byte {
bytes, err := DistributionCdc.MarshalBinaryLengthPrefixed(msg)
if err != nil {
panic(err)
}
return bytes
}
func (msg *MsgWithdrawValidatorCommission) GetFromAddress() sdk.AccAddress { return msg.FromAddress}