github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/types/msg.go (about)

     1  // nolint
     2  package types
     3  
     4  import (
     5  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     6  )
     7  
     8  // Verify interface at compile time
     9  var _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawValidatorCommission{}
    10  
    11  // msg struct for changing the withdraw address for a delegator (or validator self-delegation)
    12  type MsgSetWithdrawAddress struct {
    13  	DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
    14  	WithdrawAddress  sdk.AccAddress `json:"withdraw_address" yaml:"withdraw_address"`
    15  }
    16  
    17  func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdrawAddress {
    18  	return MsgSetWithdrawAddress{
    19  		DelegatorAddress: delAddr,
    20  		WithdrawAddress:  withdrawAddr,
    21  	}
    22  }
    23  
    24  func (msg MsgSetWithdrawAddress) Route() string { return ModuleName }
    25  func (msg MsgSetWithdrawAddress) Type() string  { return "set_withdraw_address" }
    26  
    27  // Return address that must sign over msg.GetSignBytes()
    28  func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress {
    29  	return []sdk.AccAddress{sdk.AccAddress(msg.DelegatorAddress)}
    30  }
    31  
    32  // get the bytes for the message signer to sign on
    33  func (msg MsgSetWithdrawAddress) GetSignBytes() []byte {
    34  	bz := ModuleCdc.MustMarshalJSON(msg)
    35  	return sdk.MustSortJSON(bz)
    36  }
    37  
    38  // quick validity check
    39  func (msg MsgSetWithdrawAddress) ValidateBasic() sdk.Error {
    40  	if msg.DelegatorAddress.Empty() {
    41  		return ErrNilDelegatorAddr()
    42  	}
    43  	if msg.WithdrawAddress.Empty() {
    44  		return ErrNilWithdrawAddr()
    45  	}
    46  	return nil
    47  }
    48  
    49  // msg struct for validator withdraw
    50  type MsgWithdrawValidatorCommission struct {
    51  	ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
    52  }
    53  
    54  func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) MsgWithdrawValidatorCommission {
    55  	return MsgWithdrawValidatorCommission{
    56  		ValidatorAddress: valAddr,
    57  	}
    58  }
    59  
    60  func (msg MsgWithdrawValidatorCommission) Route() string { return ModuleName }
    61  func (msg MsgWithdrawValidatorCommission) Type() string  { return "withdraw_validator_commission" }
    62  
    63  // Return address that must sign over msg.GetSignBytes()
    64  func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress {
    65  	return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddress.Bytes())}
    66  }
    67  
    68  // get the bytes for the message signer to sign on
    69  func (msg MsgWithdrawValidatorCommission) GetSignBytes() []byte {
    70  	bz := ModuleCdc.MustMarshalJSON(msg)
    71  	return sdk.MustSortJSON(bz)
    72  }
    73  
    74  // quick validity check
    75  func (msg MsgWithdrawValidatorCommission) ValidateBasic() sdk.Error {
    76  	if msg.ValidatorAddress.Empty() {
    77  		return ErrNilValidatorAddr()
    78  	}
    79  	return nil
    80  }