github.com/Finschia/finschia-sdk@v0.48.1/x/upgrade/types/plan.go (about) 1 package types 2 3 import ( 4 "fmt" 5 6 sdk "github.com/Finschia/finschia-sdk/types" 7 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 8 ) 9 10 func (p Plan) String() string { 11 due := p.DueAt() 12 return fmt.Sprintf(`Upgrade Plan 13 Name: %s 14 %s 15 Info: %s.`, p.Name, due, p.Info) 16 } 17 18 // ValidateBasic does basic validation of a Plan 19 func (p Plan) ValidateBasic() error { 20 if p.UpgradedClientState != nil { 21 return sdkerrors.ErrInvalidRequest.Wrap("upgrade logic for IBC has been moved to the IBC module") 22 } 23 if len(p.Name) == 0 { 24 return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name cannot be empty") 25 } 26 if p.Height <= 0 { 27 return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height must be greater than 0") 28 } 29 30 return nil 31 } 32 33 // ShouldExecute returns true if the Plan is ready to execute given the current context 34 func (p Plan) ShouldExecute(ctx sdk.Context) bool { 35 if p.Height > 0 { 36 return p.Height <= ctx.BlockHeight() 37 } 38 return false 39 } 40 41 // DueAt is a string representation of when this plan is due to be executed 42 func (p Plan) DueAt() string { 43 return fmt.Sprintf("Height: %d", p.Height) 44 }