-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg.go
62 lines (51 loc) · 1.61 KB
/
msg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/coinexchain/cet-sdk/types"
)
// RouterKey is the name of the bankx module
const (
ModuleName = "distrx"
RouterKey = ModuleName
)
var _ sdk.Msg = MsgDonateToCommunityPool{}
// msg struct for validator withdraw
type MsgDonateToCommunityPool struct {
FromAddr sdk.AccAddress `json:"from_addr"`
Amount sdk.Coins `json:"amount"`
}
func NewMsgDonateToCommunityPool(addr sdk.AccAddress, amt sdk.Coins) MsgDonateToCommunityPool {
return MsgDonateToCommunityPool{
FromAddr: addr,
Amount: amt,
}
}
func (msg *MsgDonateToCommunityPool) SetAccAddress(address sdk.AccAddress) {
msg.FromAddr = address
}
func (msg MsgDonateToCommunityPool) Route() string { return ModuleName }
func (msg MsgDonateToCommunityPool) Type() string { return "donate_to_community_pool" }
// Return address that must sign over msg.GetSignBytes()
func (msg MsgDonateToCommunityPool) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.FromAddr}
}
// get the bytes for the message signer to sign on
func (msg MsgDonateToCommunityPool) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// quick validity check
func (msg MsgDonateToCommunityPool) ValidateBasic() sdk.Error {
if msg.FromAddr.Empty() {
return ErrorInvalidFromAddr()
}
if msg.Amount.Len() != 1 {
return ErrorInvalidDonation("invalid donation length")
}
if msg.Amount[0].Denom != types.DefaultBondDenom {
return ErrorInvalidDonation("donation's denom must be cet")
}
if !msg.Amount.IsValid() {
return ErrorInvalidDonation("invalid donation")
}
return nil
}