2019-11-08 06:40:56 -08:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-12-27 09:57:54 -08:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2019-11-08 06:40:56 -08:00
|
|
|
)
|
|
|
|
|
2021-08-11 08:03:48 -07:00
|
|
|
// UpgradeInfoFileName file to store upgrade information
|
|
|
|
const UpgradeInfoFilename = "upgrade-info.json"
|
|
|
|
|
2019-11-08 06:40:56 -08:00
|
|
|
func (p Plan) String() string {
|
|
|
|
due := p.DueAt()
|
|
|
|
return fmt.Sprintf(`Upgrade Plan
|
|
|
|
Name: %s
|
|
|
|
%s
|
2021-03-13 17:03:01 -08:00
|
|
|
Info: %s.`, p.Name, due, p.Info)
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateBasic does basic validation of a Plan
|
2019-12-27 09:57:54 -08:00
|
|
|
func (p Plan) ValidateBasic() error {
|
2021-06-23 06:03:33 -07:00
|
|
|
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")
|
|
|
|
}
|
2019-11-08 06:40:56 -08:00
|
|
|
if len(p.Name) == 0 {
|
2019-12-27 09:57:54 -08:00
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name cannot be empty")
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
2021-03-13 17:03:01 -08:00
|
|
|
if p.Height <= 0 {
|
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height must be greater than 0")
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
2019-12-27 09:57:54 -08:00
|
|
|
|
2019-11-08 06:40:56 -08:00
|
|
|
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 {
|
2021-05-28 13:06:06 -07:00
|
|
|
return fmt.Sprintf("height: %d", p.Height)
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|