/
msg.go
169 lines (139 loc) · 5.45 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
//nolint
package types
import (
sdk "github.com/FiboChain/fbc/libs/cosmos-sdk/types"
sdkerrors "github.com/FiboChain/fbc/libs/cosmos-sdk/types/errors"
)
// Verify interface at compile time
var _, _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorCommission{}
// msg struct for changing the withdraw address for a delegator (or validator self-delegation)
type MsgSetWithdrawAddress struct {
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
WithdrawAddress sdk.AccAddress `json:"withdraw_address" yaml:"withdraw_address"`
}
func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdrawAddress {
return MsgSetWithdrawAddress{
DelegatorAddress: delAddr,
WithdrawAddress: withdrawAddr,
}
}
func (msg MsgSetWithdrawAddress) Route() string { return ModuleName }
func (msg MsgSetWithdrawAddress) Type() string { return "set_withdraw_address" }
// Return address that must sign over msg.GetSignBytes()
func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.DelegatorAddress)}
}
// get the bytes for the message signer to sign on
func (msg MsgSetWithdrawAddress) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// quick validity check
func (msg MsgSetWithdrawAddress) ValidateBasic() error {
if msg.DelegatorAddress.Empty() {
return ErrEmptyDelegatorAddr
}
if msg.WithdrawAddress.Empty() {
return ErrEmptyWithdrawAddr
}
return nil
}
// msg struct for delegation withdraw from a single validator
type MsgWithdrawDelegatorReward struct {
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
}
func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegatorReward {
return MsgWithdrawDelegatorReward{
DelegatorAddress: delAddr,
ValidatorAddress: valAddr,
}
}
func (msg MsgWithdrawDelegatorReward) Route() string { return ModuleName }
func (msg MsgWithdrawDelegatorReward) Type() string { return "withdraw_delegator_reward" }
// Return address that must sign over msg.GetSignBytes()
func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.DelegatorAddress)}
}
// get the bytes for the message signer to sign on
func (msg MsgWithdrawDelegatorReward) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// quick validity check
func (msg MsgWithdrawDelegatorReward) ValidateBasic() error {
if msg.DelegatorAddress.Empty() {
return ErrEmptyDelegatorAddr
}
if msg.ValidatorAddress.Empty() {
return ErrEmptyValidatorAddr
}
return nil
}
// msg struct for validator withdraw
type MsgWithdrawValidatorCommission struct {
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
}
func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) MsgWithdrawValidatorCommission {
return MsgWithdrawValidatorCommission{
ValidatorAddress: valAddr,
}
}
func (msg MsgWithdrawValidatorCommission) Route() string { return ModuleName }
func (msg MsgWithdrawValidatorCommission) Type() string { return "withdraw_validator_commission" }
// Return address that must sign over msg.GetSignBytes()
func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddress.Bytes())}
}
// get the bytes for the message signer to sign on
func (msg MsgWithdrawValidatorCommission) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// quick validity check
func (msg MsgWithdrawValidatorCommission) ValidateBasic() error {
if msg.ValidatorAddress.Empty() {
return ErrEmptyValidatorAddr
}
return nil
}
const TypeMsgFundCommunityPool = "fund_community_pool"
// MsgFundCommunityPool defines a Msg type that allows an account to directly
// fund the community pool.
type MsgFundCommunityPool struct {
Amount sdk.Coins `json:"amount" yaml:"amount"`
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
}
// NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and
// a funding amount.
func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) MsgFundCommunityPool {
return MsgFundCommunityPool{
Amount: amount,
Depositor: depositor,
}
}
// Route returns the MsgFundCommunityPool message route.
func (msg MsgFundCommunityPool) Route() string { return ModuleName }
// Type returns the MsgFundCommunityPool message type.
func (msg MsgFundCommunityPool) Type() string { return TypeMsgFundCommunityPool }
// GetSigners returns the signer addresses that are expected to sign the result
// of GetSignBytes.
func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Depositor}
}
// GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that
// the expected signer needs to sign.
func (msg MsgFundCommunityPool) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// ValidateBasic performs basic MsgFundCommunityPool message validation.
func (msg MsgFundCommunityPool) ValidateBasic() error {
if !msg.Amount.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String())
}
if msg.Depositor.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Depositor.String())
}
return nil
}