-
Notifications
You must be signed in to change notification settings - Fork 206
/
message_redelegate.go
66 lines (53 loc) · 1.64 KB
/
message_redelegate.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
63
64
65
66
package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
legacyerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgRedelegate = "redelegate"
var _ sdk.Msg = &MsgRedelegate{}
func NewMsgRedelegate(delegator string, from_provider string, from_chainID string, to_provider string, to_chainID string, amount sdk.Coin) *MsgRedelegate {
return &MsgRedelegate{
Creator: delegator,
FromProvider: from_provider,
FromChainID: from_chainID,
ToProvider: to_provider,
ToChainID: to_chainID,
Amount: amount,
}
}
func (msg *MsgRedelegate) Route() string {
return RouterKey
}
func (msg *MsgRedelegate) Type() string {
return TypeMsgRedelegate
}
func (msg *MsgRedelegate) GetSigners() []sdk.AccAddress {
delegator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{delegator}
}
func (msg *MsgRedelegate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgRedelegate) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(legacyerrors.ErrInvalidAddress, "invalid delegator address (%s)", err)
}
_, err = sdk.AccAddressFromBech32(msg.FromProvider)
if err != nil {
return sdkerrors.Wrapf(legacyerrors.ErrInvalidAddress, "invalid (from) provider address (%s)", err)
}
_, err = sdk.AccAddressFromBech32(msg.ToProvider)
if err != nil {
return sdkerrors.Wrapf(legacyerrors.ErrInvalidAddress, "invalid (to) provider address (%s)", err)
}
if !msg.Amount.IsValid() {
return legacyerrors.ErrInvalidCoins
}
return nil
}