42 lines
956 B
Go
42 lines
956 B
Go
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 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)
|
|
}
|