forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflection.go
45 lines (33 loc) · 1.48 KB
/
reflection.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
package reflection
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/JaTochNietDan/cosmos-sdk/codec/types"
)
type reflectionServiceServer struct {
interfaceRegistry types.InterfaceRegistry
}
// NewReflectionServiceServer creates a new reflectionServiceServer.
func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) ReflectionServiceServer {
return &reflectionServiceServer{interfaceRegistry: interfaceRegistry}
}
var _ ReflectionServiceServer = (*reflectionServiceServer)(nil)
// ListAllInterfaces implements the ListAllInterfaces method of the
// ReflectionServiceServer interface.
func (r reflectionServiceServer) ListAllInterfaces(_ context.Context, _ *ListAllInterfacesRequest) (*ListAllInterfacesResponse, error) {
ifaces := r.interfaceRegistry.ListAllInterfaces()
return &ListAllInterfacesResponse{InterfaceNames: ifaces}, nil
}
// ListImplementations implements the ListImplementations method of the
// ReflectionServiceServer interface.
func (r reflectionServiceServer) ListImplementations(_ context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if req.InterfaceName == "" {
return nil, status.Error(codes.InvalidArgument, "invalid interface name")
}
impls := r.interfaceRegistry.ListImplementations(req.InterfaceName)
return &ListImplementationsResponse{ImplementationMessageNames: impls}, nil
}