-
Notifications
You must be signed in to change notification settings - Fork 364
/
msg.go
56 lines (46 loc) · 1.76 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)
// ensure Msg interface compliance at compile time
var (
_ sdk.Msg = &MsgFundCommunityPool{}
_ legacytx.LegacyMsg = &MsgFundCommunityPool{}
)
// NewMsgFundCommunityPool returns a new MsgFundCommunityPool
func NewMsgFundCommunityPool(depositor sdk.AccAddress, amount sdk.Coins) MsgFundCommunityPool {
return MsgFundCommunityPool{
Depositor: depositor.String(),
Amount: amount,
}
}
// Route return the message type used for routing the message.
func (msg MsgFundCommunityPool) Route() string { return ModuleName }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgFundCommunityPool) Type() string { return sdk.MsgTypeURL(&msg) }
// ValidateBasic does a simple validation check that doesn't require access to any other information.
func (msg MsgFundCommunityPool) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Depositor)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, err.Error())
}
if msg.Amount.IsAnyNil() || !msg.Amount.IsValid() || msg.Amount.IsZero() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "'%s'", msg.Amount)
}
return nil
}
// GetSignBytes gets the canonical byte representation of the Msg.
func (msg MsgFundCommunityPool) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign.
func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress {
depositor, err := sdk.AccAddressFromBech32(msg.Depositor)
if err != nil {
panic(err)
}
return []sdk.AccAddress{depositor}
}