/
tx.go
75 lines (61 loc) · 2.27 KB
/
tx.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
_ sdk.Msg = &MsgCreateSchedule{}
_ sdk.Msg = &MsgTerminateSchedules{}
)
//------------------------------------------------------------------------------
// MsgCreateSchedule
//------------------------------------------------------------------------------
// ValidateBasic does a sanity check on the provided data
func (m *MsgCreateSchedule) ValidateBasic() error {
// the authority address must be valid
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return ErrInvalidProposalAuthority.Wrap(err.Error())
}
// The start time must be earlier (strictly less than) the end time
if !m.StartTime.Before(m.EndTime) {
return ErrInvalidProposalStartEndTimes
}
// amount cannot be empty
if m.Amount.Empty() {
return ErrInvalidProposalAmount.Wrap("amount cannot be empty")
}
// the coins must be valid (unique denoms, non-zero amount, and sorted
// alphabetically)
if err := m.Amount.Validate(); err != nil {
return ErrInvalidProposalAmount.Wrap(err.Error())
}
return nil
}
// GetSigners returns the expected signers for the message
func (m *MsgCreateSchedule) GetSigners() []sdk.AccAddress {
// we have already asserted that the authority address is valid in
// ValidateBasic, so can ignore the error here
addr, _ := sdk.AccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}
//------------------------------------------------------------------------------
// MsgTerminateSchedules
//------------------------------------------------------------------------------
// ValidateBasic does a sanity check on the provided data
func (m *MsgTerminateSchedules) ValidateBasic() error {
// the authority address must be valid
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return ErrInvalidProposalAuthority.Wrap(err.Error())
}
// there must be at least one schedule id to be terminated
if len(m.Ids) == 0 {
return ErrInvalidProposalIds
}
return nil
}
// GetSigners returns the expected signers for the message
func (m *MsgTerminateSchedules) GetSigners() []sdk.AccAddress {
// we have already asserted that the authority address is valid in
// ValidateBasic, so can ignore the error here
addr, _ := sdk.AccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}