-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgs.go
56 lines (45 loc) · 1.42 KB
/
msgs.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"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
vetypes "github.com/petri-labs/warmage/x/ve/types"
)
const (
TypeMsgVeDelegate = "ve_delegate"
)
// Route implements the sdk.Msg interface.
func (m MsgVeDelegate) Route() string { return stakingtypes.RouterKey }
// Type implements the sdk.Msg interface.
func (m MsgVeDelegate) Type() string { return TypeMsgVeDelegate }
// GetSigners implements the sdk.Msg interface.
func (m MsgVeDelegate) GetSigners() []sdk.AccAddress {
delAddr, err := sdk.AccAddressFromBech32(m.DelegatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{delAddr}
}
// GetSignBytes implements the sdk.Msg interface.
func (m MsgVeDelegate) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// ValidateBasic implements the sdk.Msg interface.
func (m MsgVeDelegate) ValidateBasic() error {
if m.DelegatorAddress == "" {
return stakingtypes.ErrEmptyDelegatorAddr
}
if m.ValidatorAddress == "" {
return stakingtypes.ErrEmptyValidatorAddr
}
if vetypes.Uint64FromVeID(m.VeId) == vetypes.EmptyVeID {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid ve id")
}
if !m.Amount.IsValid() || !m.Amount.Amount.IsPositive() {
return sdkerrors.Wrap(
sdkerrors.ErrInvalidRequest,
"invalid delegation amount",
)
}
return nil
}