-
Notifications
You must be signed in to change notification settings - Fork 4
/
msg.go
80 lines (66 loc) · 2.47 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
//nolint
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Verify interface at compile time
var _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &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() sdk.Error {
if msg.DelegatorAddress.Empty() {
return ErrNilDelegatorAddr()
}
if msg.WithdrawAddress.Empty() {
return ErrNilWithdrawAddr()
}
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() sdk.Error {
if msg.ValidatorAddress.Empty() {
return ErrNilValidatorAddr()
}
return nil
}