-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan.go
50 lines (42 loc) · 1.3 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
48
49
50
package types
import (
"fmt"
sdk "github.com/blockgenx/blockgen-sdk/types"
sdkerrors "github.com/blockgenx/blockgen-sdk/types/errors"
)
// UpgradeInfoFileName file to store upgrade information
const UpgradeInfoFilename = "upgrade-info.json"
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)
}