github.com/Finschia/finschia-sdk@v0.48.1/x/distribution/types/msg.go (about) 1 package types 2 3 import ( 4 sdk "github.com/Finschia/finschia-sdk/types" 5 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 6 ) 7 8 // distribution message types 9 const ( 10 TypeMsgSetWithdrawAddress = "set_withdraw_address" 11 TypeMsgWithdrawDelegatorReward = "withdraw_delegator_reward" 12 TypeMsgWithdrawValidatorCommission = "withdraw_validator_commission" 13 TypeMsgFundCommunityPool = "fund_community_pool" 14 ) 15 16 // Verify interface at compile time 17 var _, _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorCommission{} 18 19 func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { 20 return &MsgSetWithdrawAddress{ 21 DelegatorAddress: delAddr.String(), 22 WithdrawAddress: withdrawAddr.String(), 23 } 24 } 25 26 func (msg MsgSetWithdrawAddress) Route() string { return ModuleName } 27 func (msg MsgSetWithdrawAddress) Type() string { return TypeMsgSetWithdrawAddress } 28 29 // Return address that must sign over msg.GetSignBytes() 30 func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress { 31 delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) 32 if err != nil { 33 panic(err) 34 } 35 return []sdk.AccAddress{delAddr} 36 } 37 38 // get the bytes for the message signer to sign on 39 func (msg MsgSetWithdrawAddress) GetSignBytes() []byte { 40 bz := ModuleCdc.MustMarshalJSON(&msg) 41 return sdk.MustSortJSON(bz) 42 } 43 44 // quick validity check 45 func (msg MsgSetWithdrawAddress) ValidateBasic() error { 46 if msg.DelegatorAddress == "" { 47 return ErrEmptyDelegatorAddr 48 } 49 if msg.WithdrawAddress == "" { 50 return ErrEmptyWithdrawAddr 51 } 52 53 return nil 54 } 55 56 func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) *MsgWithdrawDelegatorReward { 57 return &MsgWithdrawDelegatorReward{ 58 DelegatorAddress: delAddr.String(), 59 ValidatorAddress: valAddr.String(), 60 } 61 } 62 63 func (msg MsgWithdrawDelegatorReward) Route() string { return ModuleName } 64 func (msg MsgWithdrawDelegatorReward) Type() string { return TypeMsgWithdrawDelegatorReward } 65 66 // Return address that must sign over msg.GetSignBytes() 67 func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress { 68 delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) 69 if err != nil { 70 panic(err) 71 } 72 return []sdk.AccAddress{delAddr} 73 } 74 75 // get the bytes for the message signer to sign on 76 func (msg MsgWithdrawDelegatorReward) GetSignBytes() []byte { 77 bz := ModuleCdc.MustMarshalJSON(&msg) 78 return sdk.MustSortJSON(bz) 79 } 80 81 // quick validity check 82 func (msg MsgWithdrawDelegatorReward) ValidateBasic() error { 83 if msg.DelegatorAddress == "" { 84 return ErrEmptyDelegatorAddr 85 } 86 if msg.ValidatorAddress == "" { 87 return ErrEmptyValidatorAddr 88 } 89 return nil 90 } 91 92 func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) *MsgWithdrawValidatorCommission { 93 return &MsgWithdrawValidatorCommission{ 94 ValidatorAddress: valAddr.String(), 95 } 96 } 97 98 func (msg MsgWithdrawValidatorCommission) Route() string { return ModuleName } 99 func (msg MsgWithdrawValidatorCommission) Type() string { return TypeMsgWithdrawValidatorCommission } 100 101 // Return address that must sign over msg.GetSignBytes() 102 func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress { 103 valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) 104 if err != nil { 105 panic(err) 106 } 107 return []sdk.AccAddress{valAddr.Bytes()} 108 } 109 110 // get the bytes for the message signer to sign on 111 func (msg MsgWithdrawValidatorCommission) GetSignBytes() []byte { 112 bz := ModuleCdc.MustMarshalJSON(&msg) 113 return sdk.MustSortJSON(bz) 114 } 115 116 // quick validity check 117 func (msg MsgWithdrawValidatorCommission) ValidateBasic() error { 118 if msg.ValidatorAddress == "" { 119 return ErrEmptyValidatorAddr 120 } 121 return nil 122 } 123 124 // NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and 125 // a funding amount. 126 func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFundCommunityPool { 127 return &MsgFundCommunityPool{ 128 Amount: amount, 129 Depositor: depositor.String(), 130 } 131 } 132 133 // Route returns the MsgFundCommunityPool message route. 134 func (msg MsgFundCommunityPool) Route() string { return ModuleName } 135 136 // Type returns the MsgFundCommunityPool message type. 137 func (msg MsgFundCommunityPool) Type() string { return TypeMsgFundCommunityPool } 138 139 // GetSigners returns the signer addresses that are expected to sign the result 140 // of GetSignBytes. 141 func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress { 142 depoAddr, err := sdk.AccAddressFromBech32(msg.Depositor) 143 if err != nil { 144 panic(err) 145 } 146 return []sdk.AccAddress{depoAddr} 147 } 148 149 // GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that 150 // the expected signer needs to sign. 151 func (msg MsgFundCommunityPool) GetSignBytes() []byte { 152 bz := ModuleCdc.MustMarshalJSON(&msg) 153 return sdk.MustSortJSON(bz) 154 } 155 156 // ValidateBasic performs basic MsgFundCommunityPool message validation. 157 func (msg MsgFundCommunityPool) ValidateBasic() error { 158 if !msg.Amount.IsValid() { 159 return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String()) 160 } 161 if msg.Depositor == "" { 162 return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Depositor) 163 } 164 165 return nil 166 }