github.com/cosmos/cosmos-sdk@v0.50.10/x/auth/vesting/types/period.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "strings" 6 "time" 7 8 sdk "github.com/cosmos/cosmos-sdk/types" 9 ) 10 11 // Periods stores all vesting periods passed as part of a PeriodicVestingAccount 12 type Periods []Period 13 14 // Duration is converts the period Length from seconds to a time.Duration 15 func (p Period) Duration() time.Duration { 16 return time.Duration(p.Length) * time.Second 17 } 18 19 // TotalLength return the total length in seconds for a period 20 func (p Periods) TotalLength() int64 { 21 var total int64 22 for _, period := range p { 23 total += period.Length 24 } 25 return total 26 } 27 28 // TotalDuration returns the total duration of the period 29 func (p Periods) TotalDuration() time.Duration { 30 len := p.TotalLength() 31 return time.Duration(len) * time.Second 32 } 33 34 // TotalDuration returns the sum of coins for the period 35 func (p Periods) TotalAmount() sdk.Coins { 36 total := sdk.Coins{} 37 for _, period := range p { 38 total = total.Add(period.Amount...) 39 } 40 return total 41 } 42 43 // String implements the fmt.Stringer interface 44 func (p Periods) String() string { 45 periodsListString := make([]string, len(p)) 46 for _, period := range p { 47 periodsListString = append(periodsListString, period.String()) 48 } 49 50 return strings.TrimSpace(fmt.Sprintf(`Vesting Periods: 51 %s`, strings.Join(periodsListString, ", "))) 52 }