forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_query.go
36 lines (27 loc) · 994 Bytes
/
grpc_query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package keeper
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
sdk "github.com/eligion/cosmos-sdk/types"
sdkerrors "github.com/eligion/cosmos-sdk/types/errors"
"github.com/eligion/cosmos-sdk/x/params/types/proposal"
)
var _ proposal.QueryServer = Keeper{}
// Params returns subspace params
func (k Keeper) Params(c context.Context, req *proposal.QueryParamsRequest) (*proposal.QueryParamsResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
if req.Subspace == "" || req.Key == "" {
return nil, status.Errorf(codes.InvalidArgument, "invalid request")
}
ss, ok := k.GetSubspace(req.Subspace)
if !ok {
return nil, sdkerrors.Wrap(proposal.ErrUnknownSubspace, req.Subspace)
}
ctx := sdk.UnwrapSDKContext(c)
rawValue := ss.GetRaw(ctx, []byte(req.Key))
param := proposal.NewParamChange(req.Subspace, req.Key, string(rawValue))
return &proposal.QueryParamsResponse{Param: param}, nil
}