Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC interface reflection. #6722

Merged
merged 18 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions client/grpc/reflection/reflection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package reflection

import (
"context"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cosmos/cosmos-sdk/codec/types"
)

type reflectionServiceServer struct {
interfaceRegistry types.InterfaceRegistry
}

func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) ReflectionServiceServer {
return &reflectionServiceServer{interfaceRegistry: interfaceRegistry}
}

var _ ReflectionServiceServer = &reflectionServiceServer{}
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

func (r reflectionServiceServer) ListInterfaces(_ context.Context, _ *ListInterfacesRequest) (*ListInterfacesResponse, error) {
ifaces := r.interfaceRegistry.ListInterfaces()
return &ListInterfacesResponse{InterfaceNames: ifaces}, nil
}

func (r reflectionServiceServer) ListImplementations(_ context.Context, request *ListImplementationsRequest) (*ListImplementationsResponse, error) {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

if len(request.InterfaceName) == 0 {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
return nil, status.Errorf(codes.InvalidArgument, "invalid interface name")
}

impls := r.interfaceRegistry.ListImplementations(request.InterfaceName)

return &ListImplementationsResponse{ImplementationMessageNames: impls}, nil
}
Loading