Skip to content

Commit

Permalink
feat: add vesting util functions (backport cosmos#11652) (cosmos#11667)
Browse files Browse the repository at this point in the history
* feat: add vesting util functions (cosmos#11652)

* feat: add vesting util functions

* changelog

* revert string deletion

* fix build

* Update x/auth/vesting/types/period.go

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Marko <[email protected]>
(cherry picked from commit c676952)

# Conflicts:
#	CHANGELOG.md
#	x/auth/vesting/types/period.go

* changelog

* Update x/auth/vesting/types/period.go

Co-authored-by: Federico Kunze Küllmer <[email protected]>
Co-authored-by: Federico Kunze Küllmer <[email protected]>
  • Loading branch information
3 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 42da3a0 commit 9887f48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Improvements

* (x/auth/vesting) [\#11652](https://github.com/cosmos/cosmos-sdk/pull/11652) Add util functions for `Period(s)`

## [v0.45.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.3) - 2022-04-12

### Improvements
Expand Down
10 changes: 9 additions & 1 deletion x/auth/vesting/types/period.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
yaml "gopkg.in/yaml.v2"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// Periods stores all vesting periods passed as part of a PeriodicVestingAccount
Expand All @@ -17,6 +19,12 @@ 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
Expand All @@ -32,7 +40,7 @@ func (p Periods) TotalDuration() time.Duration {
return time.Duration(len) * time.Second
}

// TotalAmount returns the sum of coins for the period
// TotalDuration returns the sum of coins for the period
func (p Periods) TotalAmount() sdk.Coins {
total := sdk.Coins{}
for _, period := range p {
Expand Down

0 comments on commit 9887f48

Please sign in to comment.