2018-10-05 03:41:38 -07:00
|
|
|
//nolint
|
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// name to identify transaction types
|
|
|
|
const MsgRoute = "distr"
|
2018-10-05 03:41:38 -07:00
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// Verify interface at compile time
|
|
|
|
var _, _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorCommission{}
|
2018-10-05 03:41:38 -07:00
|
|
|
|
|
|
|
// msg struct for changing the withdraw address for a delegator (or validator self-delegation)
|
|
|
|
type MsgSetWithdrawAddress struct {
|
2019-02-25 07:16:52 -08:00
|
|
|
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
|
|
|
|
WithdrawAddress sdk.AccAddress `json:"withdraw_address"`
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdrawAddress {
|
|
|
|
return MsgSetWithdrawAddress{
|
2019-02-25 07:16:52 -08:00
|
|
|
DelegatorAddress: delAddr,
|
|
|
|
WithdrawAddress: withdrawAddr,
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
func (msg MsgSetWithdrawAddress) Route() string { return MsgRoute }
|
2018-10-23 12:23:55 -07:00
|
|
|
func (msg MsgSetWithdrawAddress) Type() string { return "set_withdraw_address" }
|
2018-10-05 03:41:38 -07:00
|
|
|
|
|
|
|
// Return address that must sign over msg.GetSignBytes()
|
|
|
|
func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress {
|
2019-02-25 07:16:52 -08:00
|
|
|
return []sdk.AccAddress{sdk.AccAddress(msg.DelegatorAddress)}
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the bytes for the message signer to sign on
|
|
|
|
func (msg MsgSetWithdrawAddress) GetSignBytes() []byte {
|
2019-01-23 00:46:41 -08:00
|
|
|
bz := MsgCdc.MustMarshalJSON(msg)
|
|
|
|
return sdk.MustSortJSON(bz)
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// quick validity check
|
|
|
|
func (msg MsgSetWithdrawAddress) ValidateBasic() sdk.Error {
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.DelegatorAddress.Empty() {
|
2018-10-05 03:41:38 -07:00
|
|
|
return ErrNilDelegatorAddr(DefaultCodespace)
|
|
|
|
}
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.WithdrawAddress.Empty() {
|
2018-10-05 03:41:38 -07:00
|
|
|
return ErrNilWithdrawAddr(DefaultCodespace)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// msg struct for delegation withdraw from a single validator
|
|
|
|
type MsgWithdrawDelegatorReward struct {
|
2019-02-25 07:16:52 -08:00
|
|
|
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
|
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegatorReward {
|
|
|
|
return MsgWithdrawDelegatorReward{
|
2019-02-25 07:16:52 -08:00
|
|
|
DelegatorAddress: delAddr,
|
|
|
|
ValidatorAddress: valAddr,
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
func (msg MsgWithdrawDelegatorReward) Route() string { return MsgRoute }
|
2019-03-01 11:15:53 -08:00
|
|
|
func (msg MsgWithdrawDelegatorReward) Type() string { return "withdraw_delegator_reward" }
|
2018-10-05 03:41:38 -07:00
|
|
|
|
|
|
|
// Return address that must sign over msg.GetSignBytes()
|
|
|
|
func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress {
|
2019-02-25 07:16:52 -08:00
|
|
|
return []sdk.AccAddress{sdk.AccAddress(msg.DelegatorAddress)}
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the bytes for the message signer to sign on
|
|
|
|
func (msg MsgWithdrawDelegatorReward) GetSignBytes() []byte {
|
2019-01-23 00:46:41 -08:00
|
|
|
bz := MsgCdc.MustMarshalJSON(msg)
|
|
|
|
return sdk.MustSortJSON(bz)
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// quick validity check
|
|
|
|
func (msg MsgWithdrawDelegatorReward) ValidateBasic() sdk.Error {
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.DelegatorAddress.Empty() {
|
2018-10-05 03:41:38 -07:00
|
|
|
return ErrNilDelegatorAddr(DefaultCodespace)
|
|
|
|
}
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.ValidatorAddress.Empty() {
|
2018-10-05 03:41:38 -07:00
|
|
|
return ErrNilValidatorAddr(DefaultCodespace)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// msg struct for validator withdraw
|
2019-01-16 13:38:05 -08:00
|
|
|
type MsgWithdrawValidatorCommission struct {
|
2019-02-25 07:16:52 -08:00
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) MsgWithdrawValidatorCommission {
|
|
|
|
return MsgWithdrawValidatorCommission{
|
2019-02-25 07:16:52 -08:00
|
|
|
ValidatorAddress: valAddr,
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
func (msg MsgWithdrawValidatorCommission) Route() string { return MsgRoute }
|
|
|
|
func (msg MsgWithdrawValidatorCommission) Type() string { return "withdraw_validator_rewards_all" }
|
2018-10-05 03:41:38 -07:00
|
|
|
|
|
|
|
// Return address that must sign over msg.GetSignBytes()
|
2019-01-16 13:38:05 -08:00
|
|
|
func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress {
|
2019-02-25 07:16:52 -08:00
|
|
|
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddress.Bytes())}
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the bytes for the message signer to sign on
|
2019-01-16 13:38:05 -08:00
|
|
|
func (msg MsgWithdrawValidatorCommission) GetSignBytes() []byte {
|
2019-01-23 00:46:41 -08:00
|
|
|
bz := MsgCdc.MustMarshalJSON(msg)
|
|
|
|
return sdk.MustSortJSON(bz)
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// quick validity check
|
2019-01-16 13:38:05 -08:00
|
|
|
func (msg MsgWithdrawValidatorCommission) ValidateBasic() sdk.Error {
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.ValidatorAddress.Empty() {
|
2018-10-05 03:41:38 -07:00
|
|
|
return ErrNilValidatorAddr(DefaultCodespace)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|