-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_query.go
64 lines (53 loc) · 1.55 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/furya-official/fury-blockchain/x/iid/types"
)
var _ types.QueryServer = Keeper{}
// DidDocuments implements the DidDocuments gRPC method
func (k Keeper) IidDocuments(
c context.Context,
req *types.QueryIidDocumentsRequest,
) (*types.QueryIidDocumentsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
dids := k.GetAllDidDocuments(ctx)
return &types.QueryIidDocumentsResponse{
IidDocuments: dids,
}, nil
}
// DidDocument implements the DidDocument gRPC method
func (k Keeper) IidDocument(
c context.Context,
req *types.QueryIidDocumentRequest,
) (*types.QueryIidDocumentResponse, error) {
if req.Id == "" {
return nil, status.Error(codes.InvalidArgument, "verifiable credential id cannot be empty")
}
ctx := sdk.UnwrapSDKContext(c)
doc, _, err := k.ResolveDid(ctx, types.DID(req.Id))
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}
return &types.QueryIidDocumentResponse{
IidDocument: doc,
}, nil
}
func (k Keeper) MetaData(
c context.Context,
req *types.QueryIidMetaDataRequest,
) (*types.QueryIidMetaDataResponse, error) {
if req.Id == "" {
return nil, status.Error(codes.InvalidArgument, "verifiable credential id cannot be empty")
}
ctx := sdk.UnwrapSDKContext(c)
_, meta, err := k.ResolveDid(ctx, types.DID(req.Id))
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}
return &types.QueryIidMetaDataResponse{
DidMetadata: meta,
}, nil
}