-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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>
- Loading branch information
1 parent
c25b3b9
commit 3f81c0a
Showing
10 changed files
with
1,139 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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 | ||
} |
Oops, something went wrong.