2018-10-05 03:41:38 -07:00
|
|
|
//nolint
|
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-12-27 09:57:54 -08:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
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-07-05 16:25:56 -07:00
|
|
|
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
|
|
WithdrawAddress sdk.AccAddress `json:"withdraw_address" yaml:"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-03-28 16:27:47 -07:00
|
|
|
func (msg MsgSetWithdrawAddress) Route() string { return ModuleName }
|
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-05-16 08:25:32 -07:00
|
|
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
2019-01-23 00:46:41 -08:00
|
|
|
return sdk.MustSortJSON(bz)
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// quick validity check
|
2019-12-27 09:57:54 -08:00
|
|
|
func (msg MsgSetWithdrawAddress) ValidateBasic() error {
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.DelegatorAddress.Empty() {
|
2019-12-27 09:57:54 -08:00
|
|
|
return ErrEmptyDelegatorAddr
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.WithdrawAddress.Empty() {
|
2019-12-27 09:57:54 -08:00
|
|
|
return ErrEmptyWithdrawAddr
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
2019-12-27 09:57:54 -08:00
|
|
|
|
2018-10-05 03:41:38 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// msg struct for delegation withdraw from a single validator
|
|
|
|
type MsgWithdrawDelegatorReward struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"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-03-28 16:27:47 -07:00
|
|
|
func (msg MsgWithdrawDelegatorReward) Route() string { return ModuleName }
|
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-05-16 08:25:32 -07:00
|
|
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
2019-01-23 00:46:41 -08:00
|
|
|
return sdk.MustSortJSON(bz)
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// quick validity check
|
2019-12-27 09:57:54 -08:00
|
|
|
func (msg MsgWithdrawDelegatorReward) ValidateBasic() error {
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.DelegatorAddress.Empty() {
|
2019-12-27 09:57:54 -08:00
|
|
|
return ErrEmptyDelegatorAddr
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.ValidatorAddress.Empty() {
|
2019-12-27 09:57:54 -08:00
|
|
|
return ErrEmptyValidatorAddr
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// msg struct for validator withdraw
|
2019-01-16 13:38:05 -08:00
|
|
|
type MsgWithdrawValidatorCommission struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"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-03-28 16:27:47 -07:00
|
|
|
func (msg MsgWithdrawValidatorCommission) Route() string { return ModuleName }
|
2019-04-09 05:55:01 -07:00
|
|
|
func (msg MsgWithdrawValidatorCommission) Type() string { return "withdraw_validator_commission" }
|
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-05-16 08:25:32 -07:00
|
|
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
2019-01-23 00:46:41 -08:00
|
|
|
return sdk.MustSortJSON(bz)
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// quick validity check
|
2019-12-27 09:57:54 -08:00
|
|
|
func (msg MsgWithdrawValidatorCommission) ValidateBasic() error {
|
2019-02-25 07:16:52 -08:00
|
|
|
if msg.ValidatorAddress.Empty() {
|
2019-12-27 09:57:54 -08:00
|
|
|
return ErrEmptyValidatorAddr
|
2018-10-05 03:41:38 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-12-10 11:09:22 -08:00
|
|
|
|
2019-12-10 20:02:15 -08:00
|
|
|
const TypeMsgFundCommunityPool = "fund_community_pool"
|
|
|
|
|
|
|
|
// MsgFundCommunityPool defines a Msg type that allows an account to directly
|
|
|
|
// fund the community pool.
|
|
|
|
type MsgFundCommunityPool struct {
|
2019-12-10 11:09:22 -08:00
|
|
|
Amount sdk.Coins `json:"amount" yaml:"amount"`
|
|
|
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
|
|
|
}
|
|
|
|
|
2019-12-10 20:02:15 -08:00
|
|
|
// NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and
|
|
|
|
// a funding amount.
|
|
|
|
func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) MsgFundCommunityPool {
|
|
|
|
return MsgFundCommunityPool{
|
2019-12-10 11:09:22 -08:00
|
|
|
Amount: amount,
|
|
|
|
Depositor: depositor,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 20:02:15 -08:00
|
|
|
// Route returns the MsgFundCommunityPool message route.
|
|
|
|
func (msg MsgFundCommunityPool) Route() string { return ModuleName }
|
2019-12-10 11:09:22 -08:00
|
|
|
|
2019-12-10 20:02:15 -08:00
|
|
|
// 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 {
|
2019-12-10 11:09:22 -08:00
|
|
|
return []sdk.AccAddress{msg.Depositor}
|
|
|
|
}
|
|
|
|
|
2019-12-10 20:02:15 -08:00
|
|
|
// GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that
|
|
|
|
// the expected signer needs to sign.
|
|
|
|
func (msg MsgFundCommunityPool) GetSignBytes() []byte {
|
2019-12-10 11:09:22 -08:00
|
|
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
|
|
|
return sdk.MustSortJSON(bz)
|
|
|
|
}
|
|
|
|
|
2019-12-10 20:02:15 -08:00
|
|
|
// ValidateBasic performs basic MsgFundCommunityPool message validation.
|
2019-12-27 09:57:54 -08:00
|
|
|
func (msg MsgFundCommunityPool) ValidateBasic() error {
|
2019-12-10 11:09:22 -08:00
|
|
|
if !msg.Amount.IsValid() {
|
2019-12-27 09:57:54 -08:00
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String())
|
2019-12-10 11:09:22 -08:00
|
|
|
}
|
|
|
|
if msg.Depositor.Empty() {
|
2019-12-27 09:57:54 -08:00
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Depositor.String())
|
2019-12-10 11:09:22 -08:00
|
|
|
}
|
2019-12-10 20:02:15 -08:00
|
|
|
|
2019-12-10 11:09:22 -08:00
|
|
|
return nil
|
|
|
|
}
|