cosmos-sdk/client/grpc/reflection/reflection.go
Aaron Craelius 3f81c0a18d
gRPC interface reflection. (#6722)
* WIP on gRPC interface reflection.

* Update docs in proto

* Add tests

* Add test

* Add route inside router

* Address nits

* ListInterfaces -> ListAllInterfaces

* Fix proto lint

* Remove stray println

* Update proto/cosmos/base/reflection/v1beta1/reflection.proto

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Update codec/types/interface_registry.go

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Update codec/types/interface_registry.go

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* Add godoc

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
2020-08-17 17:02:13 +00:00

46 lines
1.5 KiB
Go

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
}
// 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
}