55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
|
|
"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
|
|
}
|
|
|
|
// UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method
|
|
func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
consState, err := k.GetUpgradedConsensusState(ctx, req.LastHeight)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cs, err := clienttypes.PackConsensusState(consState)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.QueryUpgradedConsensusStateResponse{
|
|
UpgradedConsensusState: cs,
|
|
}, nil
|
|
}
|