cosmos-sdk/x/distribution/types/msg.go

122 lines
3.8 KiB
Go

//nolint
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// name to identify transaction types
const MsgRoute = "distr"
// 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"`
WithdrawAddress sdk.AccAddress `json:"withdraw_address"`
}
func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdrawAddress {
return MsgSetWithdrawAddress{
DelegatorAddress: delAddr,
WithdrawAddress: withdrawAddr,
}
}
func (msg MsgSetWithdrawAddress) Route() string { return MsgRoute }
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 := MsgCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// quick validity check
func (msg MsgSetWithdrawAddress) ValidateBasic() sdk.Error {
if msg.DelegatorAddress.Empty() {
return ErrNilDelegatorAddr(DefaultCodespace)
}
if msg.WithdrawAddress.Empty() {
return ErrNilWithdrawAddr(DefaultCodespace)
}
return nil
}
// msg struct for delegation withdraw from a single validator
type MsgWithdrawDelegatorReward struct {
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
ValidatorAddress sdk.ValAddress `json:"validator_address"`
}
func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegatorReward {
return MsgWithdrawDelegatorReward{
DelegatorAddress: delAddr,
ValidatorAddress: valAddr,
}
}
func (msg MsgWithdrawDelegatorReward) Route() string { return MsgRoute }
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 := MsgCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// quick validity check
func (msg MsgWithdrawDelegatorReward) ValidateBasic() sdk.Error {
if msg.DelegatorAddress.Empty() {
return ErrNilDelegatorAddr(DefaultCodespace)
}
if msg.ValidatorAddress.Empty() {
return ErrNilValidatorAddr(DefaultCodespace)
}
return nil
}
// msg struct for validator withdraw
type MsgWithdrawValidatorCommission struct {
ValidatorAddress sdk.ValAddress `json:"validator_address"`
}
func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) MsgWithdrawValidatorCommission {
return MsgWithdrawValidatorCommission{
ValidatorAddress: valAddr,
}
}
func (msg MsgWithdrawValidatorCommission) Route() string { return MsgRoute }
func (msg MsgWithdrawValidatorCommission) Type() string { return "withdraw_validator_rewards_all" }
// 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 := MsgCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// quick validity check
func (msg MsgWithdrawValidatorCommission) ValidateBasic() sdk.Error {
if msg.ValidatorAddress.Empty() {
return ErrNilValidatorAddr(DefaultCodespace)
}
return nil
}