-
Notifications
You must be signed in to change notification settings - Fork 6
/
message_split_vesting.go
78 lines (64 loc) · 2.19 KB
/
message_split_vesting.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
67
68
69
70
71
72
73
74
75
76
77
78
package types
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const TypeMsgSplitVesting = "split_vesting"
var _ sdk.Msg = &MsgSplitVesting{}
func NewMsgSplitVesting(fromAddress string, toAddress string, amount sdk.Coins) *MsgSplitVesting {
return &MsgSplitVesting{
FromAddress: fromAddress,
ToAddress: toAddress,
Amount: amount,
}
}
func (msg *MsgSplitVesting) Route() string {
return RouterKey
}
func (msg *MsgSplitVesting) Type() string {
return TypeMsgSplitVesting
}
func (msg *MsgSplitVesting) GetSigners() []sdk.AccAddress {
fromAddress, err := sdk.AccAddressFromBech32(msg.FromAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{fromAddress}
}
func (msg *MsgSplitVesting) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgSplitVesting) ValidateBasic() error {
_, _, err := ValidateMsgSplitVesting(msg.FromAddress, msg.ToAddress, msg.Amount)
return err
}
func ValidateMsgSplitVesting(fromAddress string, toAddress string,
amount sdk.Coins) (fromAccAddress sdk.AccAddress, toAccAddress sdk.AccAddress, error error) {
if amount == nil {
return nil, nil, errors.Wrapf(ErrParam, "split vesting - amount cannot be nil")
}
if amount.IsAnyNil() {
return nil, nil, errors.Wrapf(ErrParam, "split vesting - amount cannot be nil")
}
err := amount.Validate()
if err != nil {
return nil, nil, errors.Wrapf(ErrParam, "split vesting - invalid amount (%s)", err)
}
fromAccAddress, toAccAddress, err = ValidateAccountAddresses(fromAddress, toAddress)
if err != nil {
return nil, nil, errors.Wrap(err, "split vesting")
}
return fromAccAddress, toAccAddress, nil
}
func ValidateAccountAddresses(fromAddress string, toAddress string) (fromAccAddress sdk.AccAddress, toAccAddress sdk.AccAddress, error error) {
fromAccAddress, err := sdk.AccAddressFromBech32(fromAddress)
if err != nil {
return nil, nil, errors.Wrap(ErrParsing, errors.Wrap(err, "from acc address error").Error())
}
toAccAddress, err = sdk.AccAddressFromBech32(toAddress)
if err != nil {
return nil, nil, errors.Wrap(ErrParsing, errors.Wrap(err, "to acc address error").Error())
}
return fromAccAddress, toAccAddress, nil
}