/
vesting_options.go
50 lines (43 loc) · 1.22 KB
/
vesting_options.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
package types
import (
"errors"
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func NewDelayedVesting(totalBalance, vesting sdk.Coins, endTime time.Time) *VestingOptions {
return &VestingOptions{
Options: &VestingOptions_DelayedVesting{
DelayedVesting: &DelayedVesting{
TotalBalance: totalBalance,
Vesting: vesting,
EndTime: endTime,
},
},
}
}
// Validate check the DelayedVesting object
func (m VestingOptions) Validate() error {
switch vestionOptions := m.Options.(type) {
case *VestingOptions_DelayedVesting:
dv := vestionOptions.DelayedVesting
if dv.Vesting.Empty() {
return errors.New("empty vesting coins for DelayedVesting")
}
if !dv.Vesting.IsValid() {
return fmt.Errorf("invalid vesting coins for DelayedVesting: %s", dv.Vesting.String())
}
if !dv.TotalBalance.IsValid() {
return fmt.Errorf("invalid total balance for DelayedVesting: %s", dv.TotalBalance.String())
}
if !dv.Vesting.IsAllLTE(dv.TotalBalance) {
return errors.New("vesting is not a subset of the total balance")
}
if dv.EndTime.IsZero() {
return errors.New("end time for DelayedVesting cannot be 0")
}
default:
return errors.New("unrecognized vesting options")
}
return nil
}