2020-07-04 10:30:17 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-05-19 10:04:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/errors"
|
2020-07-04 10:30:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ types.QueryServer = Keeper{}
|
|
|
|
|
|
|
|
// CurrentPlan implements the Query/CurrentPlan gRPC method
|
|
|
|
func (k Keeper) CurrentPlan(c context.Context, req *types.QueryCurrentPlanRequest) (*types.QueryCurrentPlanResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
plan, found := k.GetUpgradePlan(ctx)
|
|
|
|
if !found {
|
|
|
|
return &types.QueryCurrentPlanResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.QueryCurrentPlanResponse{Plan: &plan}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppliedPlan implements the Query/AppliedPlan gRPC method
|
|
|
|
func (k Keeper) AppliedPlan(c context.Context, req *types.QueryAppliedPlanRequest) (*types.QueryAppliedPlanResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
applied := k.GetDoneHeight(ctx, req.Name)
|
|
|
|
if applied == 0 {
|
|
|
|
return &types.QueryAppliedPlanResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.QueryAppliedPlanResponse{Height: applied}, nil
|
|
|
|
}
|
2020-11-24 03:45:33 -08:00
|
|
|
|
|
|
|
// UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method
|
|
|
|
func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
2021-03-01 08:28:54 -08:00
|
|
|
consState, found := k.GetUpgradedConsensusState(ctx, req.LastHeight)
|
|
|
|
if !found {
|
|
|
|
return &types.QueryUpgradedConsensusStateResponse{}, nil
|
2020-11-24 03:45:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return &types.QueryUpgradedConsensusStateResponse{
|
2021-03-01 08:28:54 -08:00
|
|
|
UpgradedConsensusState: consState,
|
2020-11-24 03:45:33 -08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-05-19 10:04:38 -07:00
|
|
|
|
|
|
|
// ModuleVersions implements the Query/QueryModuleVersions gRPC method
|
|
|
|
func (k Keeper) ModuleVersions(c context.Context, req *types.QueryModuleVersionsRequest) (*types.QueryModuleVersionsResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
// check if a specific module was requested
|
|
|
|
if len(req.ModuleName) > 0 {
|
|
|
|
if version, ok := k.getModuleVersion(ctx, req.ModuleName); ok {
|
|
|
|
// return the requested module
|
|
|
|
res := []*types.ModuleVersion{{Name: req.ModuleName, Version: version}}
|
|
|
|
return &types.QueryModuleVersionsResponse{ModuleVersions: res}, nil
|
|
|
|
}
|
|
|
|
// module requested, but not found
|
|
|
|
return nil, errors.Wrapf(errors.ErrNotFound, "x/upgrade: QueryModuleVersions module %s not found", req.ModuleName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no module requested return all module versions from state
|
|
|
|
mv := k.GetModuleVersions(ctx)
|
|
|
|
return &types.QueryModuleVersionsResponse{
|
|
|
|
ModuleVersions: mv,
|
|
|
|
}, nil
|
|
|
|
}
|