-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
period.go
60 lines (49 loc) · 1.39 KB
/
period.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 types
import (
"fmt"
"strings"
"time"
"sigs.k8s.io/yaml"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Periods stores all vesting periods passed as part of a PeriodicVestingAccount
type Periods []Period
// Duration is converts the period Length from seconds to a time.Duration
func (p Period) Duration() time.Duration {
return time.Duration(p.Length) * time.Second
}
// String implements the fmt.Stringer interface
func (p Period) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
// TotalLength return the total length in seconds for a period
func (p Periods) TotalLength() int64 {
var total int64
for _, period := range p {
total += period.Length
}
return total
}
// TotalDuration returns the total duration of the period
func (p Periods) TotalDuration() time.Duration {
len := p.TotalLength()
return time.Duration(len) * time.Second
}
// TotalDuration returns the sum of coins for the period
func (p Periods) TotalAmount() sdk.Coins {
total := sdk.Coins{}
for _, period := range p {
total = total.Add(period.Amount...)
}
return total
}
// String implements the fmt.Stringer interface
func (p Periods) String() string {
periodsListString := make([]string, len(p))
for _, period := range p {
periodsListString = append(periodsListString, period.String())
}
return strings.TrimSpace(fmt.Sprintf(`Vesting Periods:
%s`, strings.Join(periodsListString, ", ")))
}