-
Notifications
You must be signed in to change notification settings - Fork 8
/
grpc_query.go
36 lines (27 loc) · 905 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"
"encoding/hex"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/bianjieai/iritamod/modules/identity/types"
)
var _ types.QueryServer = Keeper{}
// Identity queries an identity by id
func (k Keeper) Identity(c context.Context, req *types.QueryIdentityRequest) (*types.QueryIdentityResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
id, err := hex.DecodeString(req.Id)
if err != nil {
return nil, sdkerrors.Wrap(types.ErrInvalidID, req.Id)
}
identity, found := k.GetIdentity(ctx, id)
if !found {
return nil, status.Errorf(codes.NotFound, "identity %s not found", req.Id)
}
return &types.QueryIdentityResponse{Identity: &identity}, nil
}