-
Notifications
You must be signed in to change notification settings - Fork 6
/
message_move_available_vesting_by_denoms.go
68 lines (55 loc) · 2.06 KB
/
message_move_available_vesting_by_denoms.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
package types
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const TypeMsgMoveAvailableVestingByDenoms = "move_available_vesting_by_denoms"
var _ sdk.Msg = &MsgMoveAvailableVestingByDenoms{}
func NewMsgMoveAvailableVestingByDenoms(fromAddress string, toAddress string, denoms []string) *MsgMoveAvailableVestingByDenoms {
return &MsgMoveAvailableVestingByDenoms{
FromAddress: fromAddress,
ToAddress: toAddress,
Denoms: denoms,
}
}
func (msg *MsgMoveAvailableVestingByDenoms) Route() string {
return RouterKey
}
func (msg *MsgMoveAvailableVestingByDenoms) Type() string {
return TypeMsgMoveAvailableVestingByDenoms
}
func (msg *MsgMoveAvailableVestingByDenoms) GetSigners() []sdk.AccAddress {
fromAddress, err := sdk.AccAddressFromBech32(msg.FromAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{fromAddress}
}
func (msg *MsgMoveAvailableVestingByDenoms) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgMoveAvailableVestingByDenoms) ValidateBasic() error {
_, _, err := ValidateMsgMoveAvailableVestingByDenom(msg.FromAddress, msg.ToAddress, msg.Denoms)
return err
}
func ValidateMsgMoveAvailableVestingByDenom(fromAddress string, toAddress string, denoms []string) (fromAccAddress sdk.AccAddress, toAccAddress sdk.AccAddress, error error) {
fromAccAddress, toAccAddress, err := ValidateAccountAddresses(fromAddress, toAddress)
if err != nil {
return nil, nil, errors.Wrap(err, "move available vesting by denoms")
}
if len(denoms) == 0 {
return nil, nil, errors.Wrap(ErrParam, "move available vesting by denoms - no denominations")
}
seenDenoms := make(map[string]bool)
for i, denom := range denoms {
if len(denom) == 0 {
return nil, nil, errors.Wrapf(ErrParam, "move available vesting by denoms - empty denomination at position %d", i)
}
if seenDenoms[denom] {
return nil, nil, errors.Wrapf(ErrParam, "move available vesting by denoms - duplicate denomination %s", denom)
}
seenDenoms[denom] = true
}
return fromAccAddress, toAccAddress, nil
}