From 9887f4877e8c8e5e6799899757049042ebb138f7 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 11:25:42 +0200 Subject: [PATCH] feat: add vesting util functions (backport #11652) (#11667) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add vesting util functions (#11652) * feat: add vesting util functions * changelog * revert string deletion * fix build * Update x/auth/vesting/types/period.go Co-authored-by: Aleksandr Bezobchuk Co-authored-by: Aleksandr Bezobchuk Co-authored-by: Marko (cherry picked from commit c6769522789b62908fbe6b918da9aff53fb2f6d7) # Conflicts: # CHANGELOG.md # x/auth/vesting/types/period.go * changelog * Update x/auth/vesting/types/period.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer --- CHANGELOG.md | 4 ++++ x/auth/vesting/types/period.go | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 175522a367d5..c4a1b017fe18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/x/auth/vesting/types/period.go b/x/auth/vesting/types/period.go index a83608f146ca..4afffe0e9da7 100644 --- a/x/auth/vesting/types/period.go +++ b/x/auth/vesting/types/period.go @@ -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 @@ -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 @@ -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 {