From 86cbe805c0384c810608d1063ec288b246f3861b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 14 Jul 2020 13:49:26 -0400 Subject: [PATCH 01/13] WIP on gRPC interface reflection. --- client/grpc/reflection/reflection.go | 39 + client/grpc/reflection/reflection.pb.go | 926 +++++++++++++++++++++++ codec/types/interface_registry.go | 34 + proto/cosmos/reflection/reflection.proto | 23 + 4 files changed, 1022 insertions(+) create mode 100644 client/grpc/reflection/reflection.go create mode 100644 client/grpc/reflection/reflection.pb.go create mode 100644 proto/cosmos/reflection/reflection.proto diff --git a/client/grpc/reflection/reflection.go b/client/grpc/reflection/reflection.go new file mode 100644 index 000000000000..d7a217b8719b --- /dev/null +++ b/client/grpc/reflection/reflection.go @@ -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{} + +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) { + if request == nil { + return nil, status.Errorf(codes.InvalidArgument, "empty request") + } + + if len(request.InterfaceName) == 0 { + return nil, status.Errorf(codes.InvalidArgument, "invalid interface name") + } + + impls := r.interfaceRegistry.ListImplementations(request.InterfaceName) + + return &ListImplementationsResponse{ImplementationMessageNames: impls}, nil +} diff --git a/client/grpc/reflection/reflection.pb.go b/client/grpc/reflection/reflection.pb.go new file mode 100644 index 000000000000..c996fef39e3c --- /dev/null +++ b/client/grpc/reflection/reflection.pb.go @@ -0,0 +1,926 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/reflection/reflection.proto + +package reflection + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type ListInterfacesRequest struct { +} + +func (m *ListInterfacesRequest) Reset() { *m = ListInterfacesRequest{} } +func (m *ListInterfacesRequest) String() string { return proto.CompactTextString(m) } +func (*ListInterfacesRequest) ProtoMessage() {} +func (*ListInterfacesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2bcf6a784c034e17, []int{0} +} +func (m *ListInterfacesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ListInterfacesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ListInterfacesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ListInterfacesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListInterfacesRequest.Merge(m, src) +} +func (m *ListInterfacesRequest) XXX_Size() int { + return m.Size() +} +func (m *ListInterfacesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListInterfacesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListInterfacesRequest proto.InternalMessageInfo + +type ListInterfacesResponse struct { + InterfaceNames []string `protobuf:"bytes,1,rep,name=interface_names,json=interfaceNames,proto3" json:"interface_names,omitempty"` +} + +func (m *ListInterfacesResponse) Reset() { *m = ListInterfacesResponse{} } +func (m *ListInterfacesResponse) String() string { return proto.CompactTextString(m) } +func (*ListInterfacesResponse) ProtoMessage() {} +func (*ListInterfacesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2bcf6a784c034e17, []int{1} +} +func (m *ListInterfacesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ListInterfacesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ListInterfacesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ListInterfacesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListInterfacesResponse.Merge(m, src) +} +func (m *ListInterfacesResponse) XXX_Size() int { + return m.Size() +} +func (m *ListInterfacesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListInterfacesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListInterfacesResponse proto.InternalMessageInfo + +func (m *ListInterfacesResponse) GetInterfaceNames() []string { + if m != nil { + return m.InterfaceNames + } + return nil +} + +type ListImplementationsRequest struct { + InterfaceName string `protobuf:"bytes,1,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"` +} + +func (m *ListImplementationsRequest) Reset() { *m = ListImplementationsRequest{} } +func (m *ListImplementationsRequest) String() string { return proto.CompactTextString(m) } +func (*ListImplementationsRequest) ProtoMessage() {} +func (*ListImplementationsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2bcf6a784c034e17, []int{2} +} +func (m *ListImplementationsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ListImplementationsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ListImplementationsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ListImplementationsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListImplementationsRequest.Merge(m, src) +} +func (m *ListImplementationsRequest) XXX_Size() int { + return m.Size() +} +func (m *ListImplementationsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListImplementationsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListImplementationsRequest proto.InternalMessageInfo + +func (m *ListImplementationsRequest) GetInterfaceName() string { + if m != nil { + return m.InterfaceName + } + return "" +} + +type ListImplementationsResponse struct { + ImplementationMessageNames []string `protobuf:"bytes,1,rep,name=implementation_message_names,json=implementationMessageNames,proto3" json:"implementation_message_names,omitempty"` +} + +func (m *ListImplementationsResponse) Reset() { *m = ListImplementationsResponse{} } +func (m *ListImplementationsResponse) String() string { return proto.CompactTextString(m) } +func (*ListImplementationsResponse) ProtoMessage() {} +func (*ListImplementationsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2bcf6a784c034e17, []int{3} +} +func (m *ListImplementationsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ListImplementationsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ListImplementationsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ListImplementationsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListImplementationsResponse.Merge(m, src) +} +func (m *ListImplementationsResponse) XXX_Size() int { + return m.Size() +} +func (m *ListImplementationsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListImplementationsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListImplementationsResponse proto.InternalMessageInfo + +func (m *ListImplementationsResponse) GetImplementationMessageNames() []string { + if m != nil { + return m.ImplementationMessageNames + } + return nil +} + +func init() { + proto.RegisterType((*ListInterfacesRequest)(nil), "cosmos.reflection.ListInterfacesRequest") + proto.RegisterType((*ListInterfacesResponse)(nil), "cosmos.reflection.ListInterfacesResponse") + proto.RegisterType((*ListImplementationsRequest)(nil), "cosmos.reflection.ListImplementationsRequest") + proto.RegisterType((*ListImplementationsResponse)(nil), "cosmos.reflection.ListImplementationsResponse") +} + +func init() { + proto.RegisterFile("cosmos/reflection/reflection.proto", fileDescriptor_2bcf6a784c034e17) +} + +var fileDescriptor_2bcf6a784c034e17 = []byte{ + // 317 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4a, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x2f, 0x4a, 0x4d, 0xcb, 0x49, 0x4d, 0x2e, 0xc9, 0xcc, 0xcf, 0x43, 0x62, 0xea, + 0x15, 0x14, 0xe5, 0x97, 0xe4, 0x0b, 0x09, 0x42, 0xd4, 0xe8, 0x21, 0x24, 0x94, 0xc4, 0xb9, 0x44, + 0x7d, 0x32, 0x8b, 0x4b, 0x3c, 0xf3, 0x4a, 0x52, 0x8b, 0xd2, 0x12, 0x93, 0x53, 0x8b, 0x83, 0x52, + 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x94, 0x1c, 0xb9, 0xc4, 0xd0, 0x25, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a, + 0x53, 0x85, 0xd4, 0xb9, 0xf8, 0x33, 0x61, 0xa2, 0xf1, 0x79, 0x89, 0xb9, 0xa9, 0xc5, 0x12, 0x8c, + 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x7c, 0x70, 0x61, 0x3f, 0x90, 0xa8, 0x92, 0x33, 0x97, 0x14, 0xd8, + 0x88, 0xdc, 0x82, 0x9c, 0xd4, 0xdc, 0xd4, 0xbc, 0x92, 0x44, 0x90, 0x8d, 0x30, 0x0b, 0x84, 0x54, + 0xb9, 0xf8, 0x50, 0x8d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0xe2, 0x45, 0x31, 0x45, 0x29, + 0x9e, 0x4b, 0x1a, 0xab, 0x21, 0x50, 0xc7, 0x38, 0x70, 0xc9, 0x64, 0xa2, 0x48, 0xc5, 0xe7, 0xa6, + 0x16, 0x17, 0x27, 0xa6, 0xa3, 0xba, 0x4c, 0x0a, 0x55, 0x8d, 0x2f, 0x44, 0x09, 0xd8, 0x95, 0x46, + 0x5f, 0x18, 0xb9, 0x04, 0x83, 0xe0, 0x01, 0x12, 0x9c, 0x5a, 0x54, 0x96, 0x99, 0x9c, 0x2a, 0x94, + 0xce, 0xc5, 0x87, 0xea, 0x7d, 0x21, 0x0d, 0x3d, 0x8c, 0xd0, 0xd3, 0xc3, 0x1a, 0x74, 0x52, 0x9a, + 0x44, 0xa8, 0x84, 0x38, 0x5f, 0x89, 0x41, 0xa8, 0x8c, 0x4b, 0x18, 0x8b, 0xff, 0x84, 0x74, 0x71, + 0x99, 0x81, 0x35, 0x30, 0xa5, 0xf4, 0x88, 0x55, 0x0e, 0xb3, 0xd7, 0xc9, 0xf7, 0xc4, 0x23, 0x39, + 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, + 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x8c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, + 0xf3, 0x73, 0xf5, 0xa1, 0x89, 0x0a, 0x42, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0x27, 0xe7, 0x64, 0xa6, + 0xe6, 0x95, 0xe8, 0xa7, 0x17, 0x15, 0x24, 0x23, 0x25, 0xb0, 0x24, 0x36, 0x70, 0x0a, 0x33, 0x06, + 0x04, 0x00, 0x00, 0xff, 0xff, 0xac, 0x67, 0x86, 0xe9, 0x87, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// ReflectionServiceClient is the client API for ReflectionService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ReflectionServiceClient interface { + ListInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) + ListImplementations(ctx context.Context, in *ListImplementationsRequest, opts ...grpc.CallOption) (*ListImplementationsResponse, error) +} + +type reflectionServiceClient struct { + cc grpc1.ClientConn +} + +func NewReflectionServiceClient(cc grpc1.ClientConn) ReflectionServiceClient { + return &reflectionServiceClient{cc} +} + +func (c *reflectionServiceClient) ListInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) { + out := new(ListInterfacesResponse) + err := c.cc.Invoke(ctx, "/cosmos.reflection.ReflectionService/ListInterfaces", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *reflectionServiceClient) ListImplementations(ctx context.Context, in *ListImplementationsRequest, opts ...grpc.CallOption) (*ListImplementationsResponse, error) { + out := new(ListImplementationsResponse) + err := c.cc.Invoke(ctx, "/cosmos.reflection.ReflectionService/ListImplementations", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ReflectionServiceServer is the server API for ReflectionService service. +type ReflectionServiceServer interface { + ListInterfaces(context.Context, *ListInterfacesRequest) (*ListInterfacesResponse, error) + ListImplementations(context.Context, *ListImplementationsRequest) (*ListImplementationsResponse, error) +} + +// UnimplementedReflectionServiceServer can be embedded to have forward compatible implementations. +type UnimplementedReflectionServiceServer struct { +} + +func (*UnimplementedReflectionServiceServer) ListInterfaces(ctx context.Context, req *ListInterfacesRequest) (*ListInterfacesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListInterfaces not implemented") +} +func (*UnimplementedReflectionServiceServer) ListImplementations(ctx context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListImplementations not implemented") +} + +func RegisterReflectionServiceServer(s grpc1.Server, srv ReflectionServiceServer) { + s.RegisterService(&_ReflectionService_serviceDesc, srv) +} + +func _ReflectionService_ListInterfaces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListInterfacesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ReflectionServiceServer).ListInterfaces(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.reflection.ReflectionService/ListInterfaces", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ReflectionServiceServer).ListInterfaces(ctx, req.(*ListInterfacesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ReflectionService_ListImplementations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListImplementationsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ReflectionServiceServer).ListImplementations(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.reflection.ReflectionService/ListImplementations", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ReflectionServiceServer).ListImplementations(ctx, req.(*ListImplementationsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _ReflectionService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.reflection.ReflectionService", + HandlerType: (*ReflectionServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ListInterfaces", + Handler: _ReflectionService_ListInterfaces_Handler, + }, + { + MethodName: "ListImplementations", + Handler: _ReflectionService_ListImplementations_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/reflection/reflection.proto", +} + +func (m *ListInterfacesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ListInterfacesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ListInterfacesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *ListInterfacesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ListInterfacesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ListInterfacesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.InterfaceNames) > 0 { + for iNdEx := len(m.InterfaceNames) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.InterfaceNames[iNdEx]) + copy(dAtA[i:], m.InterfaceNames[iNdEx]) + i = encodeVarintReflection(dAtA, i, uint64(len(m.InterfaceNames[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ListImplementationsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ListImplementationsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ListImplementationsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.InterfaceName) > 0 { + i -= len(m.InterfaceName) + copy(dAtA[i:], m.InterfaceName) + i = encodeVarintReflection(dAtA, i, uint64(len(m.InterfaceName))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ListImplementationsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ListImplementationsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ListImplementationsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ImplementationMessageNames) > 0 { + for iNdEx := len(m.ImplementationMessageNames) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ImplementationMessageNames[iNdEx]) + copy(dAtA[i:], m.ImplementationMessageNames[iNdEx]) + i = encodeVarintReflection(dAtA, i, uint64(len(m.ImplementationMessageNames[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintReflection(dAtA []byte, offset int, v uint64) int { + offset -= sovReflection(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ListInterfacesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *ListInterfacesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.InterfaceNames) > 0 { + for _, s := range m.InterfaceNames { + l = len(s) + n += 1 + l + sovReflection(uint64(l)) + } + } + return n +} + +func (m *ListImplementationsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.InterfaceName) + if l > 0 { + n += 1 + l + sovReflection(uint64(l)) + } + return n +} + +func (m *ListImplementationsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ImplementationMessageNames) > 0 { + for _, s := range m.ImplementationMessageNames { + l = len(s) + n += 1 + l + sovReflection(uint64(l)) + } + } + return n +} + +func sovReflection(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozReflection(x uint64) (n int) { + return sovReflection(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ListInterfacesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReflection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ListInterfacesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ListInterfacesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipReflection(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ListInterfacesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReflection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ListInterfacesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ListInterfacesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InterfaceNames", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReflection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthReflection + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReflection + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InterfaceNames = append(m.InterfaceNames, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipReflection(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ListImplementationsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReflection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ListImplementationsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ListImplementationsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InterfaceName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReflection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthReflection + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReflection + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InterfaceName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipReflection(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ListImplementationsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReflection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ListImplementationsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ListImplementationsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplementationMessageNames", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReflection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthReflection + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReflection + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ImplementationMessageNames = append(m.ImplementationMessageNames, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipReflection(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthReflection + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipReflection(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowReflection + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowReflection + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowReflection + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthReflection + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupReflection + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthReflection + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthReflection = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowReflection = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupReflection = fmt.Errorf("proto: unexpected end of group") +) diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 01df46834c55..9133ac438e80 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -42,6 +42,13 @@ type InterfaceRegistry interface { // Ex: // registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{}) RegisterImplementations(iface interface{}, impls ...proto.Message) + + // ListInterfaces list the type URLs of all registered interfaces + ListInterfaces() []string + + // ListImplementations lists the valid type URLs for the given interface name that can be used + // for the provided interface type URL + ListImplementations(ifaceTypeURL string) []string } // UnpackInterfacesMessage is meant to extend protobuf types (which implement @@ -111,6 +118,33 @@ func (registry *interfaceRegistry) RegisterImplementations(iface interface{}, im registry.interfaceImpls[ityp] = imap } +func (registry *interfaceRegistry) ListInterfaces() []string { + interfaceNames := registry.interfaceNames + keys := make([]string, 0, len(interfaceNames)) + for key := range interfaceNames { + keys = append(keys, key) + } + return keys +} + +func (registry *interfaceRegistry) ListImplementations(ifaceName string) []string { + typ, ok := registry.interfaceNames[ifaceName] + if !ok { + return []string{} + } + + impls, ok := registry.interfaceImpls[typ] + if !ok { + return []string{} + } + + keys := make([]string, 0, len(impls)) + for key := range impls { + keys = append(keys, key) + } + return keys +} + func (registry *interfaceRegistry) UnpackAny(any *Any, iface interface{}) error { if any.TypeUrl == "" { // if TypeUrl is empty return nil because without it we can't actually unpack anything diff --git a/proto/cosmos/reflection/reflection.proto b/proto/cosmos/reflection/reflection.proto new file mode 100644 index 000000000000..1aefe340b64f --- /dev/null +++ b/proto/cosmos/reflection/reflection.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; +package cosmos.reflection; + +option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/reflection"; + +service ReflectionService { + rpc ListInterfaces(ListInterfacesRequest) returns (ListInterfacesResponse) {}; + rpc ListImplementations(ListImplementationsRequest) returns (ListImplementationsResponse) {}; +} + +message ListInterfacesRequest { } + +message ListInterfacesResponse { + repeated string interface_names = 1; +} + +message ListImplementationsRequest { + string interface_name = 1; +} + +message ListImplementationsResponse { + repeated string implementation_message_names = 1; +} \ No newline at end of file From 70b1a2b482b88ca96242c4ed5e87e699e3ba1a7b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 13 Aug 2020 12:10:03 +0200 Subject: [PATCH 02/13] Update docs in proto --- client/grpc/reflection/reflection.go | 6 +- client/grpc/reflection/reflection.pb.go | 95 +++++++++++-------- client/grpc/reflection/reflection_test.go | 0 .../base/reflection/v1beta1/reflection.proto | 34 +++++++ proto/cosmos/reflection/reflection.proto | 23 ----- x/distribution/types/genesis.pb.go | 3 +- x/evidence/types/genesis.pb.go | 2 +- 7 files changed, 96 insertions(+), 67 deletions(-) create mode 100644 client/grpc/reflection/reflection_test.go create mode 100644 proto/cosmos/base/reflection/v1beta1/reflection.proto delete mode 100644 proto/cosmos/reflection/reflection.proto diff --git a/client/grpc/reflection/reflection.go b/client/grpc/reflection/reflection.go index d7a217b8719b..b757ded17d24 100644 --- a/client/grpc/reflection/reflection.go +++ b/client/grpc/reflection/reflection.go @@ -13,6 +13,7 @@ type reflectionServiceServer struct { interfaceRegistry types.InterfaceRegistry } +// NewReflectionServiceServer creates a new reflectionServiceServer. func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) ReflectionServiceServer { return &reflectionServiceServer{interfaceRegistry: interfaceRegistry} } @@ -21,16 +22,17 @@ var _ ReflectionServiceServer = &reflectionServiceServer{} 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) { if request == nil { - return nil, status.Errorf(codes.InvalidArgument, "empty request") + return nil, status.Error(codes.InvalidArgument, "empty request") } if len(request.InterfaceName) == 0 { - return nil, status.Errorf(codes.InvalidArgument, "invalid interface name") + return nil, status.Error(codes.InvalidArgument, "invalid interface name") } impls := r.interfaceRegistry.ListImplementations(request.InterfaceName) diff --git a/client/grpc/reflection/reflection.pb.go b/client/grpc/reflection/reflection.pb.go index c996fef39e3c..2bcb40d05018 100644 --- a/client/grpc/reflection/reflection.pb.go +++ b/client/grpc/reflection/reflection.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: cosmos/reflection/reflection.proto +// source: cosmos/base/reflection/v1beta1/reflection.proto package reflection @@ -27,6 +27,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// ListInterfacesRequest is the request type of the ListInterfaces RPC. type ListInterfacesRequest struct { } @@ -34,7 +35,7 @@ func (m *ListInterfacesRequest) Reset() { *m = ListInterfacesRequest{} } func (m *ListInterfacesRequest) String() string { return proto.CompactTextString(m) } func (*ListInterfacesRequest) ProtoMessage() {} func (*ListInterfacesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2bcf6a784c034e17, []int{0} + return fileDescriptor_d48c054165687f5c, []int{0} } func (m *ListInterfacesRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -63,7 +64,9 @@ func (m *ListInterfacesRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ListInterfacesRequest proto.InternalMessageInfo +// ListInterfacesResponse is the response type of the ListInterfaces RPC. type ListInterfacesResponse struct { + // interface_names is an array of all the registered interfaces. InterfaceNames []string `protobuf:"bytes,1,rep,name=interface_names,json=interfaceNames,proto3" json:"interface_names,omitempty"` } @@ -71,7 +74,7 @@ func (m *ListInterfacesResponse) Reset() { *m = ListInterfacesResponse{} func (m *ListInterfacesResponse) String() string { return proto.CompactTextString(m) } func (*ListInterfacesResponse) ProtoMessage() {} func (*ListInterfacesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2bcf6a784c034e17, []int{1} + return fileDescriptor_d48c054165687f5c, []int{1} } func (m *ListInterfacesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -107,7 +110,9 @@ func (m *ListInterfacesResponse) GetInterfaceNames() []string { return nil } +// ListImplementationsRequest is the request type of the ListImplementations RPC. type ListImplementationsRequest struct { + // interface_name defines the interface to query the implementations for. InterfaceName string `protobuf:"bytes,1,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"` } @@ -115,7 +120,7 @@ func (m *ListImplementationsRequest) Reset() { *m = ListImplementationsR func (m *ListImplementationsRequest) String() string { return proto.CompactTextString(m) } func (*ListImplementationsRequest) ProtoMessage() {} func (*ListImplementationsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2bcf6a784c034e17, []int{2} + return fileDescriptor_d48c054165687f5c, []int{2} } func (m *ListImplementationsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -151,6 +156,7 @@ func (m *ListImplementationsRequest) GetInterfaceName() string { return "" } +// ListImplementationsResponse is the response type of the ListImplementations RPC. type ListImplementationsResponse struct { ImplementationMessageNames []string `protobuf:"bytes,1,rep,name=implementation_message_names,json=implementationMessageNames,proto3" json:"implementation_message_names,omitempty"` } @@ -159,7 +165,7 @@ func (m *ListImplementationsResponse) Reset() { *m = ListImplementations func (m *ListImplementationsResponse) String() string { return proto.CompactTextString(m) } func (*ListImplementationsResponse) ProtoMessage() {} func (*ListImplementationsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2bcf6a784c034e17, []int{3} + return fileDescriptor_d48c054165687f5c, []int{3} } func (m *ListImplementationsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -196,38 +202,39 @@ func (m *ListImplementationsResponse) GetImplementationMessageNames() []string { } func init() { - proto.RegisterType((*ListInterfacesRequest)(nil), "cosmos.reflection.ListInterfacesRequest") - proto.RegisterType((*ListInterfacesResponse)(nil), "cosmos.reflection.ListInterfacesResponse") - proto.RegisterType((*ListImplementationsRequest)(nil), "cosmos.reflection.ListImplementationsRequest") - proto.RegisterType((*ListImplementationsResponse)(nil), "cosmos.reflection.ListImplementationsResponse") + proto.RegisterType((*ListInterfacesRequest)(nil), "cosmos.base.reflection.v1beta1.ListInterfacesRequest") + proto.RegisterType((*ListInterfacesResponse)(nil), "cosmos.base.reflection.v1beta1.ListInterfacesResponse") + proto.RegisterType((*ListImplementationsRequest)(nil), "cosmos.base.reflection.v1beta1.ListImplementationsRequest") + proto.RegisterType((*ListImplementationsResponse)(nil), "cosmos.base.reflection.v1beta1.ListImplementationsResponse") } func init() { - proto.RegisterFile("cosmos/reflection/reflection.proto", fileDescriptor_2bcf6a784c034e17) -} - -var fileDescriptor_2bcf6a784c034e17 = []byte{ - // 317 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4a, 0xce, 0x2f, 0xce, - 0xcd, 0x2f, 0xd6, 0x2f, 0x4a, 0x4d, 0xcb, 0x49, 0x4d, 0x2e, 0xc9, 0xcc, 0xcf, 0x43, 0x62, 0xea, - 0x15, 0x14, 0xe5, 0x97, 0xe4, 0x0b, 0x09, 0x42, 0xd4, 0xe8, 0x21, 0x24, 0x94, 0xc4, 0xb9, 0x44, - 0x7d, 0x32, 0x8b, 0x4b, 0x3c, 0xf3, 0x4a, 0x52, 0x8b, 0xd2, 0x12, 0x93, 0x53, 0x8b, 0x83, 0x52, - 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x94, 0x1c, 0xb9, 0xc4, 0xd0, 0x25, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a, - 0x53, 0x85, 0xd4, 0xb9, 0xf8, 0x33, 0x61, 0xa2, 0xf1, 0x79, 0x89, 0xb9, 0xa9, 0xc5, 0x12, 0x8c, - 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x7c, 0x70, 0x61, 0x3f, 0x90, 0xa8, 0x92, 0x33, 0x97, 0x14, 0xd8, - 0x88, 0xdc, 0x82, 0x9c, 0xd4, 0xdc, 0xd4, 0xbc, 0x92, 0x44, 0x90, 0x8d, 0x30, 0x0b, 0x84, 0x54, - 0xb9, 0xf8, 0x50, 0x8d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0xe2, 0x45, 0x31, 0x45, 0x29, - 0x9e, 0x4b, 0x1a, 0xab, 0x21, 0x50, 0xc7, 0x38, 0x70, 0xc9, 0x64, 0xa2, 0x48, 0xc5, 0xe7, 0xa6, - 0x16, 0x17, 0x27, 0xa6, 0xa3, 0xba, 0x4c, 0x0a, 0x55, 0x8d, 0x2f, 0x44, 0x09, 0xd8, 0x95, 0x46, - 0x5f, 0x18, 0xb9, 0x04, 0x83, 0xe0, 0x01, 0x12, 0x9c, 0x5a, 0x54, 0x96, 0x99, 0x9c, 0x2a, 0x94, - 0xce, 0xc5, 0x87, 0xea, 0x7d, 0x21, 0x0d, 0x3d, 0x8c, 0xd0, 0xd3, 0xc3, 0x1a, 0x74, 0x52, 0x9a, - 0x44, 0xa8, 0x84, 0x38, 0x5f, 0x89, 0x41, 0xa8, 0x8c, 0x4b, 0x18, 0x8b, 0xff, 0x84, 0x74, 0x71, - 0x99, 0x81, 0x35, 0x30, 0xa5, 0xf4, 0x88, 0x55, 0x0e, 0xb3, 0xd7, 0xc9, 0xf7, 0xc4, 0x23, 0x39, - 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, - 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x8c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, - 0xf3, 0x73, 0xf5, 0xa1, 0x89, 0x0a, 0x42, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0x27, 0xe7, 0x64, 0xa6, - 0xe6, 0x95, 0xe8, 0xa7, 0x17, 0x15, 0x24, 0x23, 0x25, 0xb0, 0x24, 0x36, 0x70, 0x0a, 0x33, 0x06, - 0x04, 0x00, 0x00, 0xff, 0xff, 0xac, 0x67, 0x86, 0xe9, 0x87, 0x02, 0x00, 0x00, + proto.RegisterFile("cosmos/base/reflection/v1beta1/reflection.proto", fileDescriptor_d48c054165687f5c) +} + +var fileDescriptor_d48c054165687f5c = []byte{ + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x4d, 0x4b, 0xc3, 0x40, + 0x14, 0xcc, 0x2a, 0x08, 0x5d, 0xb0, 0xe2, 0x8a, 0x5a, 0xa2, 0x2c, 0x25, 0x20, 0xf6, 0x62, 0x42, + 0x2d, 0x7a, 0xd0, 0x8b, 0x1f, 0x27, 0xc1, 0x7a, 0x88, 0x37, 0x2f, 0x25, 0x59, 0x5f, 0xeb, 0x62, + 0x93, 0x8d, 0x79, 0xdb, 0xde, 0xfd, 0x07, 0xfd, 0x1d, 0xfe, 0x12, 0x8f, 0x3d, 0x7a, 0x94, 0xf6, + 0x8f, 0x48, 0x9b, 0xa6, 0x64, 0x25, 0x88, 0x7a, 0x5a, 0x98, 0xb7, 0x33, 0x6f, 0xde, 0x30, 0xd4, + 0x13, 0x0a, 0x23, 0x85, 0x5e, 0x18, 0x20, 0x78, 0x29, 0x74, 0xfb, 0x20, 0xb4, 0x54, 0xb1, 0x37, + 0x6c, 0x86, 0xa0, 0x83, 0x66, 0x01, 0x72, 0x93, 0x54, 0x69, 0xc5, 0x78, 0x46, 0x70, 0x67, 0x04, + 0xb7, 0x30, 0x5d, 0x10, 0x9c, 0x5d, 0xba, 0x7d, 0x2b, 0x51, 0xdf, 0xc4, 0x1a, 0xd2, 0x6e, 0x20, + 0x00, 0x7d, 0x78, 0x19, 0x00, 0x6a, 0xe7, 0x92, 0xee, 0x7c, 0x1f, 0x60, 0xa2, 0x62, 0x04, 0x76, + 0x48, 0x37, 0x64, 0x8e, 0x76, 0xe2, 0x20, 0x02, 0xac, 0x91, 0xfa, 0x6a, 0xa3, 0xe2, 0x57, 0x97, + 0xf0, 0xdd, 0x0c, 0x75, 0xae, 0xa9, 0x3d, 0x97, 0x88, 0x92, 0x3e, 0x44, 0x10, 0xeb, 0x60, 0xb6, + 0x39, 0x5f, 0xc0, 0x0e, 0x68, 0xd5, 0x94, 0xa9, 0x91, 0x3a, 0x69, 0x54, 0xfc, 0x75, 0x43, 0xc5, + 0xe9, 0xd0, 0xbd, 0x52, 0x91, 0x85, 0x99, 0x0b, 0xba, 0x2f, 0x8d, 0x51, 0x27, 0x02, 0xc4, 0xa0, + 0x67, 0x3a, 0xb3, 0xcd, 0x3f, 0xed, 0xec, 0xcb, 0xdc, 0xe5, 0xf1, 0xdb, 0x0a, 0xdd, 0xf4, 0x97, + 0xc1, 0xdc, 0x43, 0x3a, 0x94, 0x02, 0xd8, 0x2b, 0xa1, 0x55, 0xf3, 0x7e, 0x76, 0xe2, 0xfe, 0x9c, + 0xa5, 0x5b, 0x1a, 0xa4, 0x7d, 0xfa, 0x57, 0x5a, 0x76, 0x99, 0x63, 0xb1, 0x11, 0xa1, 0x5b, 0x25, + 0xb7, 0xb3, 0xb3, 0x5f, 0x29, 0x96, 0xa6, 0x6e, 0x9f, 0xff, 0x8b, 0x9b, 0x5b, 0xba, 0x6a, 0xbf, + 0x4f, 0x38, 0x19, 0x4f, 0x38, 0xf9, 0x9c, 0x70, 0x32, 0x9a, 0x72, 0x6b, 0x3c, 0xe5, 0xd6, 0xc7, + 0x94, 0x5b, 0x0f, 0xad, 0x9e, 0xd4, 0x4f, 0x83, 0xd0, 0x15, 0x2a, 0xca, 0x4b, 0x9a, 0x3d, 0x47, + 0xf8, 0xf8, 0xec, 0x89, 0xbe, 0x84, 0x58, 0x7b, 0xbd, 0x34, 0x11, 0x85, 0x8e, 0x86, 0x6b, 0xf3, + 0x92, 0xb6, 0xbe, 0x02, 0x00, 0x00, 0xff, 0xff, 0x54, 0x84, 0xe6, 0xb1, 0xd7, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -242,7 +249,11 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type ReflectionServiceClient interface { + // ListInterfaces lists all the interfaces registered in the interface + // registry. ListInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) + // ListImplementations list all the concrete types that implement a given + // interface. ListImplementations(ctx context.Context, in *ListImplementationsRequest, opts ...grpc.CallOption) (*ListImplementationsResponse, error) } @@ -256,7 +267,7 @@ func NewReflectionServiceClient(cc grpc1.ClientConn) ReflectionServiceClient { func (c *reflectionServiceClient) ListInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) { out := new(ListInterfacesResponse) - err := c.cc.Invoke(ctx, "/cosmos.reflection.ReflectionService/ListInterfaces", in, out, opts...) + err := c.cc.Invoke(ctx, "/cosmos.base.reflection.v1beta1.ReflectionService/ListInterfaces", in, out, opts...) if err != nil { return nil, err } @@ -265,7 +276,7 @@ func (c *reflectionServiceClient) ListInterfaces(ctx context.Context, in *ListIn func (c *reflectionServiceClient) ListImplementations(ctx context.Context, in *ListImplementationsRequest, opts ...grpc.CallOption) (*ListImplementationsResponse, error) { out := new(ListImplementationsResponse) - err := c.cc.Invoke(ctx, "/cosmos.reflection.ReflectionService/ListImplementations", in, out, opts...) + err := c.cc.Invoke(ctx, "/cosmos.base.reflection.v1beta1.ReflectionService/ListImplementations", in, out, opts...) if err != nil { return nil, err } @@ -274,7 +285,11 @@ func (c *reflectionServiceClient) ListImplementations(ctx context.Context, in *L // ReflectionServiceServer is the server API for ReflectionService service. type ReflectionServiceServer interface { + // ListInterfaces lists all the interfaces registered in the interface + // registry. ListInterfaces(context.Context, *ListInterfacesRequest) (*ListInterfacesResponse, error) + // ListImplementations list all the concrete types that implement a given + // interface. ListImplementations(context.Context, *ListImplementationsRequest) (*ListImplementationsResponse, error) } @@ -303,7 +318,7 @@ func _ReflectionService_ListInterfaces_Handler(srv interface{}, ctx context.Cont } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.reflection.ReflectionService/ListInterfaces", + FullMethod: "/cosmos.base.reflection.v1beta1.ReflectionService/ListInterfaces", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReflectionServiceServer).ListInterfaces(ctx, req.(*ListInterfacesRequest)) @@ -321,7 +336,7 @@ func _ReflectionService_ListImplementations_Handler(srv interface{}, ctx context } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.reflection.ReflectionService/ListImplementations", + FullMethod: "/cosmos.base.reflection.v1beta1.ReflectionService/ListImplementations", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReflectionServiceServer).ListImplementations(ctx, req.(*ListImplementationsRequest)) @@ -330,7 +345,7 @@ func _ReflectionService_ListImplementations_Handler(srv interface{}, ctx context } var _ReflectionService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "cosmos.reflection.ReflectionService", + ServiceName: "cosmos.base.reflection.v1beta1.ReflectionService", HandlerType: (*ReflectionServiceServer)(nil), Methods: []grpc.MethodDesc{ { @@ -343,7 +358,7 @@ var _ReflectionService_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "cosmos/reflection/reflection.proto", + Metadata: "cosmos/base/reflection/v1beta1/reflection.proto", } func (m *ListInterfacesRequest) Marshal() (dAtA []byte, err error) { diff --git a/client/grpc/reflection/reflection_test.go b/client/grpc/reflection/reflection_test.go new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/proto/cosmos/base/reflection/v1beta1/reflection.proto b/proto/cosmos/base/reflection/v1beta1/reflection.proto new file mode 100644 index 000000000000..2a79ae076169 --- /dev/null +++ b/proto/cosmos/base/reflection/v1beta1/reflection.proto @@ -0,0 +1,34 @@ +syntax = "proto3"; +package cosmos.base.reflection.v1beta1; + +option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/reflection"; + +// ReflectionService defines a service for interface reflection. +service ReflectionService { + // ListInterfaces lists all the interfaces registered in the interface + // registry. + rpc ListInterfaces(ListInterfacesRequest) returns (ListInterfacesResponse) {}; + // ListImplementations list all the concrete types that implement a given + // interface. + rpc ListImplementations(ListImplementationsRequest) returns (ListImplementationsResponse) {}; +} + +// ListInterfacesRequest is the request type of the ListInterfaces RPC. +message ListInterfacesRequest { } + +// ListInterfacesResponse is the response type of the ListInterfaces RPC. +message ListInterfacesResponse { + // interface_names is an array of all the registered interfaces. + repeated string interface_names = 1; +} + +// ListImplementationsRequest is the request type of the ListImplementations RPC. +message ListImplementationsRequest { + // interface_name defines the interface to query the implementations for. + string interface_name = 1; +} + +// ListImplementationsResponse is the response type of the ListImplementations RPC. +message ListImplementationsResponse { + repeated string implementation_message_names = 1; +} diff --git a/proto/cosmos/reflection/reflection.proto b/proto/cosmos/reflection/reflection.proto deleted file mode 100644 index 1aefe340b64f..000000000000 --- a/proto/cosmos/reflection/reflection.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; -package cosmos.reflection; - -option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/reflection"; - -service ReflectionService { - rpc ListInterfaces(ListInterfacesRequest) returns (ListInterfacesResponse) {}; - rpc ListImplementations(ListImplementationsRequest) returns (ListImplementationsResponse) {}; -} - -message ListInterfacesRequest { } - -message ListInterfacesResponse { - repeated string interface_names = 1; -} - -message ListImplementationsRequest { - string interface_name = 1; -} - -message ListImplementationsResponse { - repeated string implementation_message_names = 1; -} \ No newline at end of file diff --git a/x/distribution/types/genesis.pb.go b/x/distribution/types/genesis.pb.go index 8468ec9fe98c..e73cecfcaf7f 100644 --- a/x/distribution/types/genesis.pb.go +++ b/x/distribution/types/genesis.pb.go @@ -141,7 +141,8 @@ func (m *ValidatorOutstandingRewardsRecord) GetOutstandingRewards() github_com_c type ValidatorAccumulatedCommissionRecord struct { // validator_address is the address of the validator. ValidatorAddress github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"validator_address,omitempty" yaml:"validator_address"` - Accumulated ValidatorAccumulatedCommission `protobuf:"bytes,2,opt,name=accumulated,proto3" json:"accumulated" yaml:"accumulated"` + // accumulated is the accumulated commission of a validator. + Accumulated ValidatorAccumulatedCommission `protobuf:"bytes,2,opt,name=accumulated,proto3" json:"accumulated" yaml:"accumulated"` } func (m *ValidatorAccumulatedCommissionRecord) Reset() { *m = ValidatorAccumulatedCommissionRecord{} } diff --git a/x/evidence/types/genesis.pb.go b/x/evidence/types/genesis.pb.go index 1c63284e4e29..c40bb8a5290c 100644 --- a/x/evidence/types/genesis.pb.go +++ b/x/evidence/types/genesis.pb.go @@ -25,7 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the evidence module's genesis state. type GenesisState struct { - // evidence defines all the evidences at genesis. + // evidence defines all the evidence at genesis. Evidence []*types.Any `protobuf:"bytes,1,rep,name=evidence,proto3" json:"evidence,omitempty"` } From a990896d8595e6727336f208eb006b88d154d9cc Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 13 Aug 2020 16:45:53 +0200 Subject: [PATCH 03/13] Add tests --- client/grpc/reflection/reflection_test.go | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/client/grpc/reflection/reflection_test.go b/client/grpc/reflection/reflection_test.go index e69de29bb2d1..ac8639e34f48 100644 --- a/client/grpc/reflection/reflection_test.go +++ b/client/grpc/reflection/reflection_test.go @@ -0,0 +1,63 @@ +package reflection_test + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/grpc/reflection" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +type IntegrationTestSuite struct { + suite.Suite + + app *simapp.SimApp + clientCtx client.Context + queryClient reflection. + sdkCtx sdk.Context +} + +func (s *IntegrationTestSuite) SetupTest() { + app := simapp.Setup(false) + sdkCtx := app.BaseApp.NewContext(false, abci.Header{}) + + srv := + + queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry()) + reflection.RegisterSimulateServiceServer(queryHelper, srv) + queryClient := reflection.NewSimulateServiceClient(queryHelper) + + s.app = app + s.clientCtx = client.Context{}. + WithTxConfig(encodingConfig.TxConfig) + s.queryClient = queryClient + s.sdkCtx = sdkCtx +} + +func (s IntegrationTestSuite) TestSimulateService() { + + res, err := s.queryClient.Simulate( + context.Background(), + &reflection.SimulateRequest{Tx: txBuilder.GetProtoTx()}, + ) + s.Require().NoError(err) + + fmt.Println(res) +} + +func TestSimulateTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +} \ No newline at end of file From 8e6512fd8d39add12600ebcd89d459050fcdf65b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 17:03:13 +0200 Subject: [PATCH 04/13] Add test --- client/grpc/reflection/reflection_test.go | 53 +++++++++++------------ codec/types/interface_registry.go | 2 +- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/client/grpc/reflection/reflection_test.go b/client/grpc/reflection/reflection_test.go index ac8639e34f48..5a8071f83924 100644 --- a/client/grpc/reflection/reflection_test.go +++ b/client/grpc/reflection/reflection_test.go @@ -6,58 +6,57 @@ import ( "testing" "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/reflection" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) type IntegrationTestSuite struct { suite.Suite - app *simapp.SimApp - clientCtx client.Context - queryClient reflection. - sdkCtx sdk.Context + queryClient reflection.ReflectionServiceClient } -func (s *IntegrationTestSuite) SetupTest() { +func (s *IntegrationTestSuite) SetupSuite() { app := simapp.Setup(false) - sdkCtx := app.BaseApp.NewContext(false, abci.Header{}) - srv := + srv := reflection.NewReflectionServiceServer(app.InterfaceRegistry()) + sdkCtx := app.BaseApp.NewContext(false, tmproto.Header{}) queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry()) - reflection.RegisterSimulateServiceServer(queryHelper, srv) - queryClient := reflection.NewSimulateServiceClient(queryHelper) - s.app = app - s.clientCtx = client.Context{}. - WithTxConfig(encodingConfig.TxConfig) + reflection.RegisterReflectionServiceServer(queryHelper, srv) + queryClient := reflection.NewReflectionServiceClient(queryHelper) + s.queryClient = queryClient - s.sdkCtx = sdkCtx } func (s IntegrationTestSuite) TestSimulateService() { - - res, err := s.queryClient.Simulate( + // We will test the following interface for testing. + var iface = "cosmos.evidence.v1beta1.Evidence" + + // Test that "cosmos.evidence.v1beta1.Evidence" is included in the + // interfaces. + resIface, err := s.queryClient.ListInterfaces( context.Background(), - &reflection.SimulateRequest{Tx: txBuilder.GetProtoTx()}, + &reflection.ListInterfacesRequest{}, ) s.Require().NoError(err) + fmt.Println(resIface.GetInterfaceNames()) + s.Require().Contains(resIface.GetInterfaceNames(), iface) - fmt.Println(res) + // Test that "cosmos.evidence.v1beta1.Evidence" has at least the + // Equivocation implementations. + resImpl, err := s.queryClient.ListImplementations( + context.Background(), + &reflection.ListImplementationsRequest{InterfaceName: iface}, + ) + s.Require().NoError(err) + s.Require().Contains(resImpl.GetImplementationMessageNames(), "/cosmos.evidence.v1beta1.Equivocation") } func TestSimulateTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) -} \ No newline at end of file +} diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 7a49e2a3b2f9..182bb2fa0ac6 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -133,7 +133,7 @@ func (registry *interfaceRegistry) ListImplementations(ifaceName string) []strin return []string{} } - impls, ok := registry.interfaceImpls[typ] + impls, ok := registry.interfaceImpls[typ.Elem()] if !ok { return []string{} } From 1c7b9e4a6d868dc7f6cb12e7d4114be953dbff4b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:24:38 +0200 Subject: [PATCH 05/13] Add route inside router --- baseapp/grpcrouter.go | 29 ++++++++++++++++------------- baseapp/grpcrouter_helpers.go | 8 ++++---- baseapp/grpcrouter_test.go | 2 +- baseapp/grpcserver.go | 1 + simapp/app.go | 2 +- types/module/module.go | 1 + 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/baseapp/grpcrouter.go b/baseapp/grpcrouter.go index 632e34915070..45021a56ebbc 100644 --- a/baseapp/grpcrouter.go +++ b/baseapp/grpcrouter.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc/encoding" "google.golang.org/grpc/encoding/proto" + "github.com/cosmos/cosmos-sdk/client/grpc/reflection" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -17,9 +18,9 @@ var protoCodec = encoding.GetCodec(proto.Name) // GRPCQueryRouter routes ABCI Query requests to GRPC handlers type GRPCQueryRouter struct { - routes map[string]GRPCQueryHandler - anyUnpacker types.AnyUnpacker - serviceData []serviceData + routes map[string]GRPCQueryHandler + interfaceRegistry types.InterfaceRegistry + serviceData []serviceData } // serviceData represents a gRPC service, along with its handler. @@ -28,7 +29,7 @@ type serviceData struct { handler interface{} } -var _ gogogrpc.Server +var _ gogogrpc.Server = &GRPCQueryRouter{} // NewGRPCQueryRouter creates a new GRPCQueryRouter func NewGRPCQueryRouter() *GRPCQueryRouter { @@ -67,8 +68,8 @@ func (qrt *GRPCQueryRouter) RegisterService(sd *grpc.ServiceDesc, handler interf if err != nil { return err } - if qrt.anyUnpacker != nil { - return types.UnpackInterfaces(i, qrt.anyUnpacker) + if qrt.interfaceRegistry != nil { + return types.UnpackInterfaces(i, qrt.interfaceRegistry) } return nil }, nil) @@ -96,12 +97,14 @@ func (qrt *GRPCQueryRouter) RegisterService(sd *grpc.ServiceDesc, handler interf }) } -// AnyUnpacker returns the AnyUnpacker for the router -func (qrt *GRPCQueryRouter) AnyUnpacker() types.AnyUnpacker { - return qrt.anyUnpacker -} +// SetInterfaceRegistry sets the interface registry for the router. +func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry types.InterfaceRegistry) { + qrt.interfaceRegistry = interfaceRegistry -// SetAnyUnpacker sets the AnyUnpacker for the router -func (qrt *GRPCQueryRouter) SetAnyUnpacker(anyUnpacker types.AnyUnpacker) { - qrt.anyUnpacker = anyUnpacker + // Once we have an interface registry, we can register the interface + // registry reflection gRPC service. + reflection.RegisterReflectionServiceServer( + qrt, + reflection.NewReflectionServiceServer(qrt.interfaceRegistry), + ) } diff --git a/baseapp/grpcrouter_helpers.go b/baseapp/grpcrouter_helpers.go index c40f22648519..5d4048e0ed1f 100644 --- a/baseapp/grpcrouter_helpers.go +++ b/baseapp/grpcrouter_helpers.go @@ -24,9 +24,9 @@ type QueryServiceTestHelper struct { // NewQueryServerTestHelper creates a new QueryServiceTestHelper that wraps // the provided sdk.Context -func NewQueryServerTestHelper(ctx sdk.Context, anyUnpacker types.AnyUnpacker) *QueryServiceTestHelper { +func NewQueryServerTestHelper(ctx sdk.Context, interfaceRegistry types.InterfaceRegistry) *QueryServiceTestHelper { qrt := NewGRPCQueryRouter() - qrt.SetAnyUnpacker(anyUnpacker) + qrt.SetInterfaceRegistry(interfaceRegistry) return &QueryServiceTestHelper{GRPCQueryRouter: qrt, ctx: ctx} } @@ -51,8 +51,8 @@ func (q *QueryServiceTestHelper) Invoke(_ gocontext.Context, method string, args return err } - if q.anyUnpacker != nil { - return types.UnpackInterfaces(reply, q.anyUnpacker) + if q.interfaceRegistry != nil { + return types.UnpackInterfaces(reply, q.interfaceRegistry) } return nil diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index 13e839a23101..2e06ea7ae216 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -15,7 +15,7 @@ import ( func TestGRPCRouter(t *testing.T) { qr := NewGRPCQueryRouter() interfaceRegistry := testdata.NewTestInterfaceRegistry() - qr.SetAnyUnpacker(interfaceRegistry) + qr.SetInterfaceRegistry(interfaceRegistry) testdata.RegisterTestServiceServer(qr, testdata.TestServiceImpl{}) helper := &QueryServiceTestHelper{ GRPCQueryRouter: qr, diff --git a/baseapp/grpcserver.go b/baseapp/grpcserver.go index ab27685b1672..95a187e6beae 100644 --- a/baseapp/grpcserver.go +++ b/baseapp/grpcserver.go @@ -83,4 +83,5 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { server.RegisterService(newDesc, data.handler) } + } diff --git a/simapp/app.go b/simapp/app.go index 0dee68f023d3..fc6cda4c7282 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -181,7 +181,7 @@ func NewSimApp( bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) - bApp.GRPCQueryRouter().SetAnyUnpacker(interfaceRegistry) + bApp.GRPCQueryRouter().SetInterfaceRegistry(interfaceRegistry) keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, diff --git a/types/module/module.go b/types/module/module.go index 797c29cdb6a2..27401c64a525 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -195,6 +195,7 @@ func (GenesisOnlyAppModule) QuerierRoute() string { return "" } // LegacyQuerierHandler returns an empty module querier func (gam GenesisOnlyAppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return nil } +// RegisterQueryService registers all gRPC query services. func (gam GenesisOnlyAppModule) RegisterQueryService(grpc.Server) {} // BeginBlock returns an empty module begin-block From 52b47ad8208dd46fe5aa614b0b4dcbf68b56315b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:29:01 +0200 Subject: [PATCH 06/13] Address nits --- baseapp/grpcserver.go | 1 - client/grpc/reflection/reflection.go | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/baseapp/grpcserver.go b/baseapp/grpcserver.go index 95a187e6beae..ab27685b1672 100644 --- a/baseapp/grpcserver.go +++ b/baseapp/grpcserver.go @@ -83,5 +83,4 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { server.RegisterService(newDesc, data.handler) } - } diff --git a/client/grpc/reflection/reflection.go b/client/grpc/reflection/reflection.go index b757ded17d24..01f5e0381655 100644 --- a/client/grpc/reflection/reflection.go +++ b/client/grpc/reflection/reflection.go @@ -18,7 +18,7 @@ func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) Refle return &reflectionServiceServer{interfaceRegistry: interfaceRegistry} } -var _ ReflectionServiceServer = &reflectionServiceServer{} +var _ ReflectionServiceServer = (*reflectionServiceServer)(nil) func (r reflectionServiceServer) ListInterfaces(_ context.Context, _ *ListInterfacesRequest) (*ListInterfacesResponse, error) { ifaces := r.interfaceRegistry.ListInterfaces() @@ -26,16 +26,16 @@ func (r reflectionServiceServer) ListInterfaces(_ context.Context, _ *ListInterf return &ListInterfacesResponse{InterfaceNames: ifaces}, nil } -func (r reflectionServiceServer) ListImplementations(_ context.Context, request *ListImplementationsRequest) (*ListImplementationsResponse, error) { - if request == nil { +func (r reflectionServiceServer) ListImplementations(_ context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) { + if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - if len(request.InterfaceName) == 0 { + if req.InterfaceName == "" { return nil, status.Error(codes.InvalidArgument, "invalid interface name") } - impls := r.interfaceRegistry.ListImplementations(request.InterfaceName) + impls := r.interfaceRegistry.ListImplementations(req.InterfaceName) return &ListImplementationsResponse{ImplementationMessageNames: impls}, nil } From 861a4853c6ccf24442e63d18913cfdd5cdfc2691 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:32:51 +0200 Subject: [PATCH 07/13] ListInterfaces -> ListAllInterfaces --- client/grpc/reflection/reflection.go | 4 +- client/grpc/reflection/reflection.pb.go | 69 ++++++++++--------- client/grpc/reflection/reflection_test.go | 2 +- codec/types/interface_registry.go | 6 +- .../base/reflection/v1beta1/reflection.proto | 2 +- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/client/grpc/reflection/reflection.go b/client/grpc/reflection/reflection.go index 01f5e0381655..d478938d197a 100644 --- a/client/grpc/reflection/reflection.go +++ b/client/grpc/reflection/reflection.go @@ -20,8 +20,8 @@ func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) Refle var _ ReflectionServiceServer = (*reflectionServiceServer)(nil) -func (r reflectionServiceServer) ListInterfaces(_ context.Context, _ *ListInterfacesRequest) (*ListInterfacesResponse, error) { - ifaces := r.interfaceRegistry.ListInterfaces() +func (r reflectionServiceServer) ListAllInterfaces(_ context.Context, _ *ListInterfacesRequest) (*ListInterfacesResponse, error) { + ifaces := r.interfaceRegistry.ListAllInterfaces() return &ListInterfacesResponse{InterfaceNames: ifaces}, nil } diff --git a/client/grpc/reflection/reflection.pb.go b/client/grpc/reflection/reflection.pb.go index 2bcb40d05018..bac91674dd05 100644 --- a/client/grpc/reflection/reflection.pb.go +++ b/client/grpc/reflection/reflection.pb.go @@ -213,28 +213,29 @@ func init() { } var fileDescriptor_d48c054165687f5c = []byte{ - // 336 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x4d, 0x4b, 0xc3, 0x40, - 0x14, 0xcc, 0x2a, 0x08, 0x5d, 0xb0, 0xe2, 0x8a, 0x5a, 0xa2, 0x2c, 0x25, 0x20, 0xf6, 0x62, 0x42, - 0x2d, 0x7a, 0xd0, 0x8b, 0x1f, 0x27, 0xc1, 0x7a, 0x88, 0x37, 0x2f, 0x25, 0x59, 0x5f, 0xeb, 0x62, - 0x93, 0x8d, 0x79, 0xdb, 0xde, 0xfd, 0x07, 0xfd, 0x1d, 0xfe, 0x12, 0x8f, 0x3d, 0x7a, 0x94, 0xf6, - 0x8f, 0x48, 0x9b, 0xa6, 0x64, 0x25, 0x88, 0x7a, 0x5a, 0x98, 0xb7, 0x33, 0x6f, 0xde, 0x30, 0xd4, - 0x13, 0x0a, 0x23, 0x85, 0x5e, 0x18, 0x20, 0x78, 0x29, 0x74, 0xfb, 0x20, 0xb4, 0x54, 0xb1, 0x37, - 0x6c, 0x86, 0xa0, 0x83, 0x66, 0x01, 0x72, 0x93, 0x54, 0x69, 0xc5, 0x78, 0x46, 0x70, 0x67, 0x04, - 0xb7, 0x30, 0x5d, 0x10, 0x9c, 0x5d, 0xba, 0x7d, 0x2b, 0x51, 0xdf, 0xc4, 0x1a, 0xd2, 0x6e, 0x20, - 0x00, 0x7d, 0x78, 0x19, 0x00, 0x6a, 0xe7, 0x92, 0xee, 0x7c, 0x1f, 0x60, 0xa2, 0x62, 0x04, 0x76, - 0x48, 0x37, 0x64, 0x8e, 0x76, 0xe2, 0x20, 0x02, 0xac, 0x91, 0xfa, 0x6a, 0xa3, 0xe2, 0x57, 0x97, - 0xf0, 0xdd, 0x0c, 0x75, 0xae, 0xa9, 0x3d, 0x97, 0x88, 0x92, 0x3e, 0x44, 0x10, 0xeb, 0x60, 0xb6, - 0x39, 0x5f, 0xc0, 0x0e, 0x68, 0xd5, 0x94, 0xa9, 0x91, 0x3a, 0x69, 0x54, 0xfc, 0x75, 0x43, 0xc5, - 0xe9, 0xd0, 0xbd, 0x52, 0x91, 0x85, 0x99, 0x0b, 0xba, 0x2f, 0x8d, 0x51, 0x27, 0x02, 0xc4, 0xa0, - 0x67, 0x3a, 0xb3, 0xcd, 0x3f, 0xed, 0xec, 0xcb, 0xdc, 0xe5, 0xf1, 0xdb, 0x0a, 0xdd, 0xf4, 0x97, - 0xc1, 0xdc, 0x43, 0x3a, 0x94, 0x02, 0xd8, 0x2b, 0xa1, 0x55, 0xf3, 0x7e, 0x76, 0xe2, 0xfe, 0x9c, - 0xa5, 0x5b, 0x1a, 0xa4, 0x7d, 0xfa, 0x57, 0x5a, 0x76, 0x99, 0x63, 0xb1, 0x11, 0xa1, 0x5b, 0x25, - 0xb7, 0xb3, 0xb3, 0x5f, 0x29, 0x96, 0xa6, 0x6e, 0x9f, 0xff, 0x8b, 0x9b, 0x5b, 0xba, 0x6a, 0xbf, - 0x4f, 0x38, 0x19, 0x4f, 0x38, 0xf9, 0x9c, 0x70, 0x32, 0x9a, 0x72, 0x6b, 0x3c, 0xe5, 0xd6, 0xc7, - 0x94, 0x5b, 0x0f, 0xad, 0x9e, 0xd4, 0x4f, 0x83, 0xd0, 0x15, 0x2a, 0xca, 0x4b, 0x9a, 0x3d, 0x47, - 0xf8, 0xf8, 0xec, 0x89, 0xbe, 0x84, 0x58, 0x7b, 0xbd, 0x34, 0x11, 0x85, 0x8e, 0x86, 0x6b, 0xf3, - 0x92, 0xb6, 0xbe, 0x02, 0x00, 0x00, 0xff, 0xff, 0x54, 0x84, 0xe6, 0xb1, 0xd7, 0x02, 0x00, 0x00, + // 342 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4f, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0x2c, 0x4e, 0xd5, 0x2f, 0x4a, 0x4d, 0xcb, 0x49, 0x4d, 0x2e, 0xc9, + 0xcc, 0xcf, 0xd3, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x44, 0x12, 0xd2, 0x2b, 0x28, 0xca, + 0x2f, 0xc9, 0x17, 0x92, 0x83, 0x68, 0xd0, 0x03, 0x69, 0xd0, 0x43, 0x92, 0x85, 0x6a, 0x50, 0x12, + 0xe7, 0x12, 0xf5, 0xc9, 0x2c, 0x2e, 0xf1, 0xcc, 0x2b, 0x49, 0x2d, 0x4a, 0x4b, 0x4c, 0x4e, 0x2d, + 0x0e, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x51, 0x72, 0xe4, 0x12, 0x43, 0x97, 0x28, 0x2e, 0xc8, + 0xcf, 0x2b, 0x4e, 0x15, 0x52, 0xe7, 0xe2, 0xcf, 0x84, 0x89, 0xc6, 0xe7, 0x25, 0xe6, 0xa6, 0x16, + 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x06, 0xf1, 0xc1, 0x85, 0xfd, 0x40, 0xa2, 0x4a, 0xce, 0x5c, + 0x52, 0x60, 0x23, 0x72, 0x0b, 0x72, 0x52, 0x73, 0x53, 0xf3, 0x4a, 0x12, 0x41, 0x36, 0xc3, 0x2c, + 0x10, 0x52, 0xe5, 0xe2, 0x43, 0x35, 0x46, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x88, 0x17, 0xc5, + 0x14, 0xa5, 0x78, 0x2e, 0x69, 0xac, 0x86, 0x40, 0x1d, 0xe3, 0xc0, 0x25, 0x93, 0x89, 0x22, 0x15, + 0x9f, 0x9b, 0x5a, 0x5c, 0x9c, 0x98, 0x8e, 0xea, 0x32, 0x29, 0x54, 0x35, 0xbe, 0x10, 0x25, 0x60, + 0x57, 0x1a, 0xad, 0x65, 0xe2, 0x12, 0x0c, 0x82, 0x07, 0x4c, 0x70, 0x6a, 0x51, 0x59, 0x66, 0x72, + 0xaa, 0x50, 0x0b, 0x23, 0x97, 0x20, 0xc8, 0x5e, 0xc7, 0x9c, 0x1c, 0x44, 0x10, 0x08, 0x99, 0xea, + 0xe1, 0x0f, 0x4e, 0x3d, 0xac, 0x61, 0x29, 0x65, 0x46, 0xaa, 0x36, 0x88, 0xe7, 0x94, 0x18, 0x84, + 0x26, 0x30, 0x72, 0x09, 0x63, 0xf1, 0xbe, 0x90, 0x15, 0x51, 0x26, 0x62, 0x0d, 0x78, 0x29, 0x6b, + 0xb2, 0xf4, 0xc2, 0x9c, 0xe4, 0xe4, 0x7b, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, + 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, + 0x51, 0xc6, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xb0, 0x74, 0x0a, 0xa1, + 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x93, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0xf4, 0xd3, 0x8b, 0x0a, 0x92, + 0x91, 0x92, 0x69, 0x12, 0x1b, 0x38, 0x9d, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe3, 0xe3, + 0xd6, 0x27, 0xda, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -251,7 +252,7 @@ const _ = grpc.SupportPackageIsVersion4 type ReflectionServiceClient interface { // ListInterfaces lists all the interfaces registered in the interface // registry. - ListInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) + ListAllInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) // ListImplementations list all the concrete types that implement a given // interface. ListImplementations(ctx context.Context, in *ListImplementationsRequest, opts ...grpc.CallOption) (*ListImplementationsResponse, error) @@ -265,9 +266,9 @@ func NewReflectionServiceClient(cc grpc1.ClientConn) ReflectionServiceClient { return &reflectionServiceClient{cc} } -func (c *reflectionServiceClient) ListInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) { +func (c *reflectionServiceClient) ListAllInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) { out := new(ListInterfacesResponse) - err := c.cc.Invoke(ctx, "/cosmos.base.reflection.v1beta1.ReflectionService/ListInterfaces", in, out, opts...) + err := c.cc.Invoke(ctx, "/cosmos.base.reflection.v1beta1.ReflectionService/ListAllInterfaces", in, out, opts...) if err != nil { return nil, err } @@ -287,7 +288,7 @@ func (c *reflectionServiceClient) ListImplementations(ctx context.Context, in *L type ReflectionServiceServer interface { // ListInterfaces lists all the interfaces registered in the interface // registry. - ListInterfaces(context.Context, *ListInterfacesRequest) (*ListInterfacesResponse, error) + ListAllInterfaces(context.Context, *ListInterfacesRequest) (*ListInterfacesResponse, error) // ListImplementations list all the concrete types that implement a given // interface. ListImplementations(context.Context, *ListImplementationsRequest) (*ListImplementationsResponse, error) @@ -297,8 +298,8 @@ type ReflectionServiceServer interface { type UnimplementedReflectionServiceServer struct { } -func (*UnimplementedReflectionServiceServer) ListInterfaces(ctx context.Context, req *ListInterfacesRequest) (*ListInterfacesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListInterfaces not implemented") +func (*UnimplementedReflectionServiceServer) ListAllInterfaces(ctx context.Context, req *ListInterfacesRequest) (*ListInterfacesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListAllInterfaces not implemented") } func (*UnimplementedReflectionServiceServer) ListImplementations(ctx context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListImplementations not implemented") @@ -308,20 +309,20 @@ func RegisterReflectionServiceServer(s grpc1.Server, srv ReflectionServiceServer s.RegisterService(&_ReflectionService_serviceDesc, srv) } -func _ReflectionService_ListInterfaces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _ReflectionService_ListAllInterfaces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ListInterfacesRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(ReflectionServiceServer).ListInterfaces(ctx, in) + return srv.(ReflectionServiceServer).ListAllInterfaces(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.base.reflection.v1beta1.ReflectionService/ListInterfaces", + FullMethod: "/cosmos.base.reflection.v1beta1.ReflectionService/ListAllInterfaces", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ReflectionServiceServer).ListInterfaces(ctx, req.(*ListInterfacesRequest)) + return srv.(ReflectionServiceServer).ListAllInterfaces(ctx, req.(*ListInterfacesRequest)) } return interceptor(ctx, in, info, handler) } @@ -349,8 +350,8 @@ var _ReflectionService_serviceDesc = grpc.ServiceDesc{ HandlerType: (*ReflectionServiceServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "ListInterfaces", - Handler: _ReflectionService_ListInterfaces_Handler, + MethodName: "ListAllInterfaces", + Handler: _ReflectionService_ListAllInterfaces_Handler, }, { MethodName: "ListImplementations", diff --git a/client/grpc/reflection/reflection_test.go b/client/grpc/reflection/reflection_test.go index 5a8071f83924..8e1ceaacbb57 100644 --- a/client/grpc/reflection/reflection_test.go +++ b/client/grpc/reflection/reflection_test.go @@ -39,7 +39,7 @@ func (s IntegrationTestSuite) TestSimulateService() { // Test that "cosmos.evidence.v1beta1.Evidence" is included in the // interfaces. - resIface, err := s.queryClient.ListInterfaces( + resIface, err := s.queryClient.ListAllInterfaces( context.Background(), &reflection.ListInterfacesRequest{}, ) diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 182bb2fa0ac6..ba7df0ce0d3d 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -43,8 +43,8 @@ type InterfaceRegistry interface { // registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{}) RegisterImplementations(iface interface{}, impls ...proto.Message) - // ListInterfaces list the type URLs of all registered interfaces - ListInterfaces() []string + // ListAllInterfaces list the type URLs of all registered interfaces + ListAllInterfaces() []string // ListImplementations lists the valid type URLs for the given interface name that can be used // for the provided interface type URL @@ -118,7 +118,7 @@ func (registry *interfaceRegistry) RegisterImplementations(iface interface{}, im registry.interfaceImpls[ityp] = imap } -func (registry *interfaceRegistry) ListInterfaces() []string { +func (registry *interfaceRegistry) ListAllInterfaces() []string { interfaceNames := registry.interfaceNames keys := make([]string, 0, len(interfaceNames)) for key := range interfaceNames { diff --git a/proto/cosmos/base/reflection/v1beta1/reflection.proto b/proto/cosmos/base/reflection/v1beta1/reflection.proto index 2a79ae076169..574adb815f5f 100644 --- a/proto/cosmos/base/reflection/v1beta1/reflection.proto +++ b/proto/cosmos/base/reflection/v1beta1/reflection.proto @@ -7,7 +7,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/reflection"; service ReflectionService { // ListInterfaces lists all the interfaces registered in the interface // registry. - rpc ListInterfaces(ListInterfacesRequest) returns (ListInterfacesResponse) {}; + rpc ListAllInterfaces(ListInterfacesRequest) returns (ListInterfacesResponse) {}; // ListImplementations list all the concrete types that implement a given // interface. rpc ListImplementations(ListImplementationsRequest) returns (ListImplementationsResponse) {}; From 26d6907f75f197766b2ebce7d57fe6720b7a3c52 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:36:18 +0200 Subject: [PATCH 08/13] Fix proto lint --- client/grpc/reflection/reflection.go | 4 +- client/grpc/reflection/reflection.pb.go | 158 +++++++++--------- client/grpc/reflection/reflection_test.go | 2 +- .../base/reflection/v1beta1/reflection.proto | 12 +- 4 files changed, 88 insertions(+), 88 deletions(-) diff --git a/client/grpc/reflection/reflection.go b/client/grpc/reflection/reflection.go index d478938d197a..7a7010612c23 100644 --- a/client/grpc/reflection/reflection.go +++ b/client/grpc/reflection/reflection.go @@ -20,10 +20,10 @@ func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) Refle var _ ReflectionServiceServer = (*reflectionServiceServer)(nil) -func (r reflectionServiceServer) ListAllInterfaces(_ context.Context, _ *ListInterfacesRequest) (*ListInterfacesResponse, error) { +func (r reflectionServiceServer) ListAllInterfaces(_ context.Context, _ *ListAllInterfacesRequest) (*ListAllInterfacesResponse, error) { ifaces := r.interfaceRegistry.ListAllInterfaces() - return &ListInterfacesResponse{InterfaceNames: ifaces}, nil + return &ListAllInterfacesResponse{InterfaceNames: ifaces}, nil } func (r reflectionServiceServer) ListImplementations(_ context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) { diff --git a/client/grpc/reflection/reflection.pb.go b/client/grpc/reflection/reflection.pb.go index bac91674dd05..8b26ea90e263 100644 --- a/client/grpc/reflection/reflection.pb.go +++ b/client/grpc/reflection/reflection.pb.go @@ -27,22 +27,22 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// ListInterfacesRequest is the request type of the ListInterfaces RPC. -type ListInterfacesRequest struct { +// ListAllInterfacesRequest is the request type of the ListAllInterfaces RPC. +type ListAllInterfacesRequest struct { } -func (m *ListInterfacesRequest) Reset() { *m = ListInterfacesRequest{} } -func (m *ListInterfacesRequest) String() string { return proto.CompactTextString(m) } -func (*ListInterfacesRequest) ProtoMessage() {} -func (*ListInterfacesRequest) Descriptor() ([]byte, []int) { +func (m *ListAllInterfacesRequest) Reset() { *m = ListAllInterfacesRequest{} } +func (m *ListAllInterfacesRequest) String() string { return proto.CompactTextString(m) } +func (*ListAllInterfacesRequest) ProtoMessage() {} +func (*ListAllInterfacesRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d48c054165687f5c, []int{0} } -func (m *ListInterfacesRequest) XXX_Unmarshal(b []byte) error { +func (m *ListAllInterfacesRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *ListInterfacesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *ListAllInterfacesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_ListInterfacesRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_ListAllInterfacesRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -52,36 +52,36 @@ func (m *ListInterfacesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byt return b[:n], nil } } -func (m *ListInterfacesRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListInterfacesRequest.Merge(m, src) +func (m *ListAllInterfacesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListAllInterfacesRequest.Merge(m, src) } -func (m *ListInterfacesRequest) XXX_Size() int { +func (m *ListAllInterfacesRequest) XXX_Size() int { return m.Size() } -func (m *ListInterfacesRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ListInterfacesRequest.DiscardUnknown(m) +func (m *ListAllInterfacesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListAllInterfacesRequest.DiscardUnknown(m) } -var xxx_messageInfo_ListInterfacesRequest proto.InternalMessageInfo +var xxx_messageInfo_ListAllInterfacesRequest proto.InternalMessageInfo -// ListInterfacesResponse is the response type of the ListInterfaces RPC. -type ListInterfacesResponse struct { +// ListAllInterfacesResponse is the response type of the ListAllInterfaces RPC. +type ListAllInterfacesResponse struct { // interface_names is an array of all the registered interfaces. InterfaceNames []string `protobuf:"bytes,1,rep,name=interface_names,json=interfaceNames,proto3" json:"interface_names,omitempty"` } -func (m *ListInterfacesResponse) Reset() { *m = ListInterfacesResponse{} } -func (m *ListInterfacesResponse) String() string { return proto.CompactTextString(m) } -func (*ListInterfacesResponse) ProtoMessage() {} -func (*ListInterfacesResponse) Descriptor() ([]byte, []int) { +func (m *ListAllInterfacesResponse) Reset() { *m = ListAllInterfacesResponse{} } +func (m *ListAllInterfacesResponse) String() string { return proto.CompactTextString(m) } +func (*ListAllInterfacesResponse) ProtoMessage() {} +func (*ListAllInterfacesResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d48c054165687f5c, []int{1} } -func (m *ListInterfacesResponse) XXX_Unmarshal(b []byte) error { +func (m *ListAllInterfacesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *ListInterfacesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *ListAllInterfacesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_ListInterfacesResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_ListAllInterfacesResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -91,19 +91,19 @@ func (m *ListInterfacesResponse) XXX_Marshal(b []byte, deterministic bool) ([]by return b[:n], nil } } -func (m *ListInterfacesResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListInterfacesResponse.Merge(m, src) +func (m *ListAllInterfacesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListAllInterfacesResponse.Merge(m, src) } -func (m *ListInterfacesResponse) XXX_Size() int { +func (m *ListAllInterfacesResponse) XXX_Size() int { return m.Size() } -func (m *ListInterfacesResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ListInterfacesResponse.DiscardUnknown(m) +func (m *ListAllInterfacesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListAllInterfacesResponse.DiscardUnknown(m) } -var xxx_messageInfo_ListInterfacesResponse proto.InternalMessageInfo +var xxx_messageInfo_ListAllInterfacesResponse proto.InternalMessageInfo -func (m *ListInterfacesResponse) GetInterfaceNames() []string { +func (m *ListAllInterfacesResponse) GetInterfaceNames() []string { if m != nil { return m.InterfaceNames } @@ -202,8 +202,8 @@ func (m *ListImplementationsResponse) GetImplementationMessageNames() []string { } func init() { - proto.RegisterType((*ListInterfacesRequest)(nil), "cosmos.base.reflection.v1beta1.ListInterfacesRequest") - proto.RegisterType((*ListInterfacesResponse)(nil), "cosmos.base.reflection.v1beta1.ListInterfacesResponse") + proto.RegisterType((*ListAllInterfacesRequest)(nil), "cosmos.base.reflection.v1beta1.ListAllInterfacesRequest") + proto.RegisterType((*ListAllInterfacesResponse)(nil), "cosmos.base.reflection.v1beta1.ListAllInterfacesResponse") proto.RegisterType((*ListImplementationsRequest)(nil), "cosmos.base.reflection.v1beta1.ListImplementationsRequest") proto.RegisterType((*ListImplementationsResponse)(nil), "cosmos.base.reflection.v1beta1.ListImplementationsResponse") } @@ -213,29 +213,29 @@ func init() { } var fileDescriptor_d48c054165687f5c = []byte{ - // 342 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4f, 0xce, 0x2f, 0xce, - 0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0x2c, 0x4e, 0xd5, 0x2f, 0x4a, 0x4d, 0xcb, 0x49, 0x4d, 0x2e, 0xc9, - 0xcc, 0xcf, 0xd3, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0x44, 0x12, 0xd2, 0x2b, 0x28, 0xca, - 0x2f, 0xc9, 0x17, 0x92, 0x83, 0x68, 0xd0, 0x03, 0x69, 0xd0, 0x43, 0x92, 0x85, 0x6a, 0x50, 0x12, - 0xe7, 0x12, 0xf5, 0xc9, 0x2c, 0x2e, 0xf1, 0xcc, 0x2b, 0x49, 0x2d, 0x4a, 0x4b, 0x4c, 0x4e, 0x2d, - 0x0e, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x51, 0x72, 0xe4, 0x12, 0x43, 0x97, 0x28, 0x2e, 0xc8, - 0xcf, 0x2b, 0x4e, 0x15, 0x52, 0xe7, 0xe2, 0xcf, 0x84, 0x89, 0xc6, 0xe7, 0x25, 0xe6, 0xa6, 0x16, - 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x06, 0xf1, 0xc1, 0x85, 0xfd, 0x40, 0xa2, 0x4a, 0xce, 0x5c, - 0x52, 0x60, 0x23, 0x72, 0x0b, 0x72, 0x52, 0x73, 0x53, 0xf3, 0x4a, 0x12, 0x41, 0x36, 0xc3, 0x2c, - 0x10, 0x52, 0xe5, 0xe2, 0x43, 0x35, 0x46, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x88, 0x17, 0xc5, - 0x14, 0xa5, 0x78, 0x2e, 0x69, 0xac, 0x86, 0x40, 0x1d, 0xe3, 0xc0, 0x25, 0x93, 0x89, 0x22, 0x15, - 0x9f, 0x9b, 0x5a, 0x5c, 0x9c, 0x98, 0x8e, 0xea, 0x32, 0x29, 0x54, 0x35, 0xbe, 0x10, 0x25, 0x60, - 0x57, 0x1a, 0xad, 0x65, 0xe2, 0x12, 0x0c, 0x82, 0x07, 0x4c, 0x70, 0x6a, 0x51, 0x59, 0x66, 0x72, - 0xaa, 0x50, 0x0b, 0x23, 0x97, 0x20, 0xc8, 0x5e, 0xc7, 0x9c, 0x1c, 0x44, 0x10, 0x08, 0x99, 0xea, - 0xe1, 0x0f, 0x4e, 0x3d, 0xac, 0x61, 0x29, 0x65, 0x46, 0xaa, 0x36, 0x88, 0xe7, 0x94, 0x18, 0x84, - 0x26, 0x30, 0x72, 0x09, 0x63, 0xf1, 0xbe, 0x90, 0x15, 0x51, 0x26, 0x62, 0x0d, 0x78, 0x29, 0x6b, - 0xb2, 0xf4, 0xc2, 0x9c, 0xe4, 0xe4, 0x7b, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, - 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, - 0x51, 0xc6, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xb0, 0x74, 0x0a, 0xa1, - 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x93, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0xf4, 0xd3, 0x8b, 0x0a, 0x92, - 0x91, 0x92, 0x69, 0x12, 0x1b, 0x38, 0x9d, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe3, 0xe3, - 0xd6, 0x27, 0xda, 0x02, 0x00, 0x00, + // 339 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x4d, 0x4b, 0xc3, 0x40, + 0x14, 0xcc, 0x2a, 0x08, 0x5d, 0xb0, 0xd2, 0xf5, 0x52, 0xa3, 0x2c, 0x25, 0x20, 0xf6, 0x62, 0x42, + 0xed, 0xc5, 0x8f, 0x8b, 0x5f, 0x97, 0x82, 0xf5, 0x10, 0x6f, 0x5e, 0x4a, 0xb2, 0xbe, 0xd6, 0xc5, + 0x24, 0x1b, 0xf3, 0xb6, 0xfd, 0x11, 0x9e, 0xfa, 0x5f, 0xfc, 0x13, 0x1e, 0x7b, 0xf4, 0x28, 0xed, + 0x1f, 0x91, 0x34, 0x4d, 0x69, 0x30, 0x8a, 0xf4, 0xb4, 0x30, 0xef, 0xcd, 0xbc, 0xd9, 0x61, 0xa8, + 0x23, 0x14, 0x86, 0x0a, 0x1d, 0xdf, 0x43, 0x70, 0x12, 0xe8, 0x07, 0x20, 0xb4, 0x54, 0x91, 0x33, + 0x6a, 0xf9, 0xa0, 0xbd, 0xd6, 0x0a, 0x64, 0xc7, 0x89, 0xd2, 0x8a, 0xf1, 0x8c, 0x60, 0xa7, 0x04, + 0x7b, 0x65, 0xba, 0x20, 0x58, 0x26, 0xad, 0xdf, 0x49, 0xd4, 0x57, 0x41, 0xd0, 0x89, 0x34, 0x24, + 0x7d, 0x4f, 0x00, 0xba, 0xf0, 0x3a, 0x04, 0xd4, 0xd6, 0x2d, 0xdd, 0x2b, 0x99, 0x61, 0xac, 0x22, + 0x04, 0x76, 0x44, 0x77, 0x64, 0x8e, 0xf6, 0x22, 0x2f, 0x04, 0xac, 0x93, 0xc6, 0x66, 0xb3, 0xe2, + 0x56, 0x97, 0xf0, 0x7d, 0x8a, 0x5a, 0x37, 0xd4, 0x4c, 0x55, 0x3a, 0x61, 0x1c, 0x40, 0x08, 0x91, + 0xf6, 0xd2, 0xfb, 0xf9, 0x0d, 0x76, 0x48, 0xab, 0x45, 0x99, 0x3a, 0x69, 0x90, 0x66, 0xc5, 0xdd, + 0x2e, 0xa8, 0x58, 0x3d, 0xba, 0x5f, 0x2a, 0xb2, 0x30, 0x73, 0x49, 0x0f, 0x64, 0x61, 0xd4, 0x0b, + 0x01, 0xd1, 0x1b, 0x14, 0x9d, 0x99, 0xc5, 0x9d, 0x6e, 0xb6, 0x32, 0x77, 0x79, 0xf2, 0xbe, 0x41, + 0x6b, 0xee, 0x32, 0x9e, 0x07, 0x48, 0x46, 0x52, 0x00, 0x7b, 0x23, 0xb4, 0xf6, 0x23, 0x02, 0x76, + 0x6a, 0xff, 0x1d, 0xaa, 0xfd, 0x5b, 0xa2, 0xe6, 0xd9, 0x1a, 0xcc, 0xec, 0x8b, 0x96, 0xc1, 0xc6, + 0x84, 0xee, 0x96, 0x84, 0xc0, 0xce, 0xff, 0x23, 0x5a, 0x1e, 0xbf, 0x79, 0xb1, 0x16, 0x37, 0xb7, + 0x74, 0xdd, 0xfd, 0x98, 0x72, 0x32, 0x99, 0x72, 0xf2, 0x35, 0xe5, 0x64, 0x3c, 0xe3, 0xc6, 0x64, + 0xc6, 0x8d, 0xcf, 0x19, 0x37, 0x1e, 0xdb, 0x03, 0xa9, 0x9f, 0x87, 0xbe, 0x2d, 0x54, 0x98, 0x77, + 0x36, 0x7b, 0x8e, 0xf1, 0xe9, 0xc5, 0x11, 0x81, 0x84, 0x48, 0x3b, 0x83, 0x24, 0x16, 0x2b, 0x95, + 0xf5, 0xb7, 0xe6, 0x9d, 0x6d, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x2d, 0x13, 0x9d, 0x10, 0xe6, + 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -250,9 +250,9 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type ReflectionServiceClient interface { - // ListInterfaces lists all the interfaces registered in the interface + // ListAllInterfaces lists all the interfaces registered in the interface // registry. - ListAllInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) + ListAllInterfaces(ctx context.Context, in *ListAllInterfacesRequest, opts ...grpc.CallOption) (*ListAllInterfacesResponse, error) // ListImplementations list all the concrete types that implement a given // interface. ListImplementations(ctx context.Context, in *ListImplementationsRequest, opts ...grpc.CallOption) (*ListImplementationsResponse, error) @@ -266,8 +266,8 @@ func NewReflectionServiceClient(cc grpc1.ClientConn) ReflectionServiceClient { return &reflectionServiceClient{cc} } -func (c *reflectionServiceClient) ListAllInterfaces(ctx context.Context, in *ListInterfacesRequest, opts ...grpc.CallOption) (*ListInterfacesResponse, error) { - out := new(ListInterfacesResponse) +func (c *reflectionServiceClient) ListAllInterfaces(ctx context.Context, in *ListAllInterfacesRequest, opts ...grpc.CallOption) (*ListAllInterfacesResponse, error) { + out := new(ListAllInterfacesResponse) err := c.cc.Invoke(ctx, "/cosmos.base.reflection.v1beta1.ReflectionService/ListAllInterfaces", in, out, opts...) if err != nil { return nil, err @@ -286,9 +286,9 @@ func (c *reflectionServiceClient) ListImplementations(ctx context.Context, in *L // ReflectionServiceServer is the server API for ReflectionService service. type ReflectionServiceServer interface { - // ListInterfaces lists all the interfaces registered in the interface + // ListAllInterfaces lists all the interfaces registered in the interface // registry. - ListAllInterfaces(context.Context, *ListInterfacesRequest) (*ListInterfacesResponse, error) + ListAllInterfaces(context.Context, *ListAllInterfacesRequest) (*ListAllInterfacesResponse, error) // ListImplementations list all the concrete types that implement a given // interface. ListImplementations(context.Context, *ListImplementationsRequest) (*ListImplementationsResponse, error) @@ -298,7 +298,7 @@ type ReflectionServiceServer interface { type UnimplementedReflectionServiceServer struct { } -func (*UnimplementedReflectionServiceServer) ListAllInterfaces(ctx context.Context, req *ListInterfacesRequest) (*ListInterfacesResponse, error) { +func (*UnimplementedReflectionServiceServer) ListAllInterfaces(ctx context.Context, req *ListAllInterfacesRequest) (*ListAllInterfacesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListAllInterfaces not implemented") } func (*UnimplementedReflectionServiceServer) ListImplementations(ctx context.Context, req *ListImplementationsRequest) (*ListImplementationsResponse, error) { @@ -310,7 +310,7 @@ func RegisterReflectionServiceServer(s grpc1.Server, srv ReflectionServiceServer } func _ReflectionService_ListAllInterfaces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListInterfacesRequest) + in := new(ListAllInterfacesRequest) if err := dec(in); err != nil { return nil, err } @@ -322,7 +322,7 @@ func _ReflectionService_ListAllInterfaces_Handler(srv interface{}, ctx context.C FullMethod: "/cosmos.base.reflection.v1beta1.ReflectionService/ListAllInterfaces", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ReflectionServiceServer).ListAllInterfaces(ctx, req.(*ListInterfacesRequest)) + return srv.(ReflectionServiceServer).ListAllInterfaces(ctx, req.(*ListAllInterfacesRequest)) } return interceptor(ctx, in, info, handler) } @@ -362,7 +362,7 @@ var _ReflectionService_serviceDesc = grpc.ServiceDesc{ Metadata: "cosmos/base/reflection/v1beta1/reflection.proto", } -func (m *ListInterfacesRequest) Marshal() (dAtA []byte, err error) { +func (m *ListAllInterfacesRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -372,12 +372,12 @@ func (m *ListInterfacesRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ListInterfacesRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *ListAllInterfacesRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ListInterfacesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *ListAllInterfacesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -385,7 +385,7 @@ func (m *ListInterfacesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *ListInterfacesResponse) Marshal() (dAtA []byte, err error) { +func (m *ListAllInterfacesResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -395,12 +395,12 @@ func (m *ListInterfacesResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ListInterfacesResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *ListAllInterfacesResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ListInterfacesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *ListAllInterfacesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -490,7 +490,7 @@ func encodeVarintReflection(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *ListInterfacesRequest) Size() (n int) { +func (m *ListAllInterfacesRequest) Size() (n int) { if m == nil { return 0 } @@ -499,7 +499,7 @@ func (m *ListInterfacesRequest) Size() (n int) { return n } -func (m *ListInterfacesResponse) Size() (n int) { +func (m *ListAllInterfacesResponse) Size() (n int) { if m == nil { return 0 } @@ -548,7 +548,7 @@ func sovReflection(x uint64) (n int) { func sozReflection(x uint64) (n int) { return sovReflection(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *ListInterfacesRequest) Unmarshal(dAtA []byte) error { +func (m *ListAllInterfacesRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -571,10 +571,10 @@ func (m *ListInterfacesRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ListInterfacesRequest: wiretype end group for non-group") + return fmt.Errorf("proto: ListAllInterfacesRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ListInterfacesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ListAllInterfacesRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -601,7 +601,7 @@ func (m *ListInterfacesRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *ListInterfacesResponse) Unmarshal(dAtA []byte) error { +func (m *ListAllInterfacesResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -624,10 +624,10 @@ func (m *ListInterfacesResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ListInterfacesResponse: wiretype end group for non-group") + return fmt.Errorf("proto: ListAllInterfacesResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ListInterfacesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ListAllInterfacesResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/client/grpc/reflection/reflection_test.go b/client/grpc/reflection/reflection_test.go index 8e1ceaacbb57..f78c61e7e506 100644 --- a/client/grpc/reflection/reflection_test.go +++ b/client/grpc/reflection/reflection_test.go @@ -41,7 +41,7 @@ func (s IntegrationTestSuite) TestSimulateService() { // interfaces. resIface, err := s.queryClient.ListAllInterfaces( context.Background(), - &reflection.ListInterfacesRequest{}, + &reflection.ListAllInterfacesRequest{}, ) s.Require().NoError(err) fmt.Println(resIface.GetInterfaceNames()) diff --git a/proto/cosmos/base/reflection/v1beta1/reflection.proto b/proto/cosmos/base/reflection/v1beta1/reflection.proto index 574adb815f5f..a9cfa73dcd69 100644 --- a/proto/cosmos/base/reflection/v1beta1/reflection.proto +++ b/proto/cosmos/base/reflection/v1beta1/reflection.proto @@ -5,19 +5,19 @@ option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/reflection"; // ReflectionService defines a service for interface reflection. service ReflectionService { - // ListInterfaces lists all the interfaces registered in the interface + // ListAllInterfaces lists all the interfaces registered in the interface // registry. - rpc ListAllInterfaces(ListInterfacesRequest) returns (ListInterfacesResponse) {}; + rpc ListAllInterfaces(ListAllInterfacesRequest) returns (ListAllInterfacesResponse) {}; // ListImplementations list all the concrete types that implement a given // interface. rpc ListImplementations(ListImplementationsRequest) returns (ListImplementationsResponse) {}; } -// ListInterfacesRequest is the request type of the ListInterfaces RPC. -message ListInterfacesRequest { } +// ListAllInterfacesRequest is the request type of the ListAllInterfaces RPC. +message ListAllInterfacesRequest { } -// ListInterfacesResponse is the response type of the ListInterfaces RPC. -message ListInterfacesResponse { +// ListAllInterfacesResponse is the response type of the ListAllInterfaces RPC. +message ListAllInterfacesResponse { // interface_names is an array of all the registered interfaces. repeated string interface_names = 1; } From 3fe47f8bfa2906b78cf0fc0d24cfd135cdae5adb Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:50:36 +0200 Subject: [PATCH 09/13] Remove stray println --- client/grpc/reflection/reflection_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/grpc/reflection/reflection_test.go b/client/grpc/reflection/reflection_test.go index f78c61e7e506..037e7e06ae0b 100644 --- a/client/grpc/reflection/reflection_test.go +++ b/client/grpc/reflection/reflection_test.go @@ -2,7 +2,6 @@ package reflection_test import ( "context" - "fmt" "testing" "github.com/stretchr/testify/suite" @@ -44,7 +43,6 @@ func (s IntegrationTestSuite) TestSimulateService() { &reflection.ListAllInterfacesRequest{}, ) s.Require().NoError(err) - fmt.Println(resIface.GetInterfaceNames()) s.Require().Contains(resIface.GetInterfaceNames(), iface) // Test that "cosmos.evidence.v1beta1.Evidence" has at least the From d9e08a96befa60787f95a76d8d75ccd04ef2c862 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:52:07 +0200 Subject: [PATCH 10/13] Update proto/cosmos/base/reflection/v1beta1/reflection.proto Co-authored-by: Alexander Bezobchuk --- proto/cosmos/base/reflection/v1beta1/reflection.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/proto/cosmos/base/reflection/v1beta1/reflection.proto b/proto/cosmos/base/reflection/v1beta1/reflection.proto index a9cfa73dcd69..7e7a8d048361 100644 --- a/proto/cosmos/base/reflection/v1beta1/reflection.proto +++ b/proto/cosmos/base/reflection/v1beta1/reflection.proto @@ -8,6 +8,7 @@ service ReflectionService { // ListAllInterfaces lists all the interfaces registered in the interface // registry. rpc ListAllInterfaces(ListAllInterfacesRequest) returns (ListAllInterfacesResponse) {}; + // ListImplementations list all the concrete types that implement a given // interface. rpc ListImplementations(ListImplementationsRequest) returns (ListImplementationsResponse) {}; From f362809b41732d00fc9c12f1e6419c2d47ca27f8 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:52:17 +0200 Subject: [PATCH 11/13] Update codec/types/interface_registry.go Co-authored-by: Alexander Bezobchuk --- codec/types/interface_registry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index ba7df0ce0d3d..8d11032a83b9 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -47,7 +47,7 @@ type InterfaceRegistry interface { ListAllInterfaces() []string // ListImplementations lists the valid type URLs for the given interface name that can be used - // for the provided interface type URL + // for the provided interface type URL. ListImplementations(ifaceTypeURL string) []string } From 926b224b24ca47b26f78b51f9cb9e52188e65d78 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:52:24 +0200 Subject: [PATCH 12/13] Update codec/types/interface_registry.go Co-authored-by: Alexander Bezobchuk --- codec/types/interface_registry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 8d11032a83b9..0e59ea9694d3 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -43,7 +43,7 @@ type InterfaceRegistry interface { // registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{}) RegisterImplementations(iface interface{}, impls ...proto.Message) - // ListAllInterfaces list the type URLs of all registered interfaces + // ListAllInterfaces list the type URLs of all registered interfaces. ListAllInterfaces() []string // ListImplementations lists the valid type URLs for the given interface name that can be used From 99d5cce00f0d76b1ccc06311881a73f4358d90af Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 17 Aug 2020 18:54:00 +0200 Subject: [PATCH 13/13] Add godoc --- client/grpc/reflection/reflection.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/grpc/reflection/reflection.go b/client/grpc/reflection/reflection.go index 7a7010612c23..eb07ea86bd73 100644 --- a/client/grpc/reflection/reflection.go +++ b/client/grpc/reflection/reflection.go @@ -20,12 +20,16 @@ func NewReflectionServiceServer(interfaceRegistry types.InterfaceRegistry) Refle 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")