-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan.go
executable file
·47 lines (40 loc) · 1.19 KB
/
plan.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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
func (p Plan) String() string {
due := p.DueAt()
return fmt.Sprintf(`Upgrade Plan
Name: %s
%s
Info: %s.`, p.Name, due, p.Info)
}
// ValidateBasic does basic validation of a Plan
func (p Plan) ValidateBasic() error {
if !p.Time.IsZero() {
return sdkerrors.ErrInvalidRequest.Wrap("time-based upgrades have been deprecated in the SDK")
}
if p.UpgradedClientState != nil {
return sdkerrors.ErrInvalidRequest.Wrap("upgrade logic for IBC has been moved to the IBC module")
}
if len(p.Name) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name cannot be empty")
}
if p.Height <= 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height must be greater than 0")
}
return nil
}
// ShouldExecute returns true if the Plan is ready to execute given the current context
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
if p.Height > 0 {
return p.Height <= ctx.BlockHeight()
}
return false
}
// DueAt is a string representation of when this plan is due to be executed
func (p Plan) DueAt() string {
return fmt.Sprintf("height: %d", p.Height)
}