github.com/Finschia/finschia-sdk@v0.48.1/x/upgrade/keeper/grpc_query.go (about)

     1  package keeper
     2  
     3  import (
     4  	"context"
     5  
     6  	sdk "github.com/Finschia/finschia-sdk/types"
     7  	"github.com/Finschia/finschia-sdk/types/errors"
     8  	"github.com/Finschia/finschia-sdk/x/upgrade/types"
     9  )
    10  
    11  var _ types.QueryServer = Keeper{}
    12  
    13  // CurrentPlan implements the Query/CurrentPlan gRPC method
    14  func (k Keeper) CurrentPlan(c context.Context, req *types.QueryCurrentPlanRequest) (*types.QueryCurrentPlanResponse, error) {
    15  	ctx := sdk.UnwrapSDKContext(c)
    16  
    17  	plan, found := k.GetUpgradePlan(ctx)
    18  	if !found {
    19  		return &types.QueryCurrentPlanResponse{}, nil
    20  	}
    21  
    22  	return &types.QueryCurrentPlanResponse{Plan: &plan}, nil
    23  }
    24  
    25  // AppliedPlan implements the Query/AppliedPlan gRPC method
    26  func (k Keeper) AppliedPlan(c context.Context, req *types.QueryAppliedPlanRequest) (*types.QueryAppliedPlanResponse, error) {
    27  	ctx := sdk.UnwrapSDKContext(c)
    28  
    29  	applied := k.GetDoneHeight(ctx, req.Name)
    30  	if applied == 0 {
    31  		return &types.QueryAppliedPlanResponse{}, nil
    32  	}
    33  
    34  	return &types.QueryAppliedPlanResponse{Height: applied}, nil
    35  }
    36  
    37  // UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method
    38  // nolint: staticcheck
    39  func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) {
    40  	ctx := sdk.UnwrapSDKContext(c)
    41  
    42  	consState, found := k.GetUpgradedConsensusState(ctx, req.LastHeight)
    43  	if !found {
    44  		return &types.QueryUpgradedConsensusStateResponse{}, nil
    45  	}
    46  
    47  	return &types.QueryUpgradedConsensusStateResponse{
    48  		UpgradedConsensusState: consState,
    49  	}, nil
    50  }
    51  
    52  // ModuleVersions implements the Query/QueryModuleVersions gRPC method
    53  func (k Keeper) ModuleVersions(c context.Context, req *types.QueryModuleVersionsRequest) (*types.QueryModuleVersionsResponse, error) {
    54  	ctx := sdk.UnwrapSDKContext(c)
    55  
    56  	// check if a specific module was requested
    57  	if len(req.ModuleName) > 0 {
    58  		if version, ok := k.getModuleVersion(ctx, req.ModuleName); ok {
    59  			// return the requested module
    60  			res := []*types.ModuleVersion{{Name: req.ModuleName, Version: version}}
    61  			return &types.QueryModuleVersionsResponse{ModuleVersions: res}, nil
    62  		}
    63  		// module requested, but not found
    64  		return nil, errors.Wrapf(errors.ErrNotFound, "x/upgrade: QueryModuleVersions module %s not found", req.ModuleName)
    65  	}
    66  
    67  	// if no module requested return all module versions from state
    68  	mv := k.GetModuleVersions(ctx)
    69  	return &types.QueryModuleVersionsResponse{
    70  		ModuleVersions: mv,
    71  	}, nil
    72  }