-
Notifications
You must be signed in to change notification settings - Fork 6
/
vesting_types_utils.go
60 lines (50 loc) · 1.77 KB
/
vesting_types_utils.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
package cfevesting
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"math/rand"
"strconv"
"time"
"github.com/chain4energy/c4e-chain/x/cfevesting/types"
)
func GenerateVestingTypes(numberOfVestingTypes int, startId int) []*types.VestingType {
return Generate10BasedVestingTypes(numberOfVestingTypes, 0, startId)
}
func Generate10BasedVestingTypes(numberOfVestingTypes int, amountOf10BasedVestingTypes int, startId int) []*types.VestingType {
vestingTypes := []*types.VestingType{}
rgen := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < numberOfVestingTypes; i++ {
if i < amountOf10BasedVestingTypes {
vestingType := types.VestingType{
Name: "test-vesting-type-" + strconv.Itoa(i+startId),
LockupPeriod: CreateDurationFromNumOfHours(1000),
VestingPeriod: CreateDurationFromNumOfHours(5000),
Free: sdk.MustNewDecFromStr("0.05"),
}
vestingTypes = append(vestingTypes, &vestingType)
} else {
vestingType := types.VestingType{
Name: "test-vesting-type-" + strconv.Itoa(i+startId),
LockupPeriod: CreateDurationFromNumOfHours(int64(rgen.Intn(100000))),
VestingPeriod: CreateDurationFromNumOfHours(int64(rgen.Intn(100000))),
Free: sdk.MustNewDecFromStr("0.05"),
}
vestingTypes = append(vestingTypes, &vestingType)
}
}
return vestingTypes
}
func GenerateVestingTypesForAccountVestingPools(accountVestingPools []types.AccountVestingPools) []*types.VestingType {
m := make(map[string]*types.VestingType)
result := []*types.VestingType{}
for _, av := range accountVestingPools {
for _, v := range av.VestingPools {
vt := GenerateVestingTypes(1, 1)[0]
vt.Name = v.VestingType
m[v.VestingType] = vt
}
}
for _, vt := range m {
result = append(result, vt)
}
return result
}