diff --git a/proto/babylon/btclightclient/query.proto b/proto/babylon/btclightclient/query.proto index dfd4d7a94..b1f175ea1 100644 --- a/proto/babylon/btclightclient/query.proto +++ b/proto/babylon/btclightclient/query.proto @@ -31,10 +31,14 @@ service Query { option (google.api.http).get = "/babylon/btclightclient/v1/mainchain"; } - // BestHeader return best header on canonical chain + // Tip return best header on canonical chain rpc Tip(QueryTipRequest) returns (QueryTipResponse) { option (google.api.http).get = "/babylon/btclightclient/v1/tip"; } + + rpc BaseHeader(QueryBaseHeaderRequest) returns (QueryBaseHeaderResponse) { + option (google.api.http).get = "/babylon/btclightclient/v1/baseheader"; + } } // QueryParamsRequest is request type for the Query/Params RPC method. @@ -91,3 +95,10 @@ message QueryTipRequest { message QueryTipResponse { BTCHeaderInfo header = 1; } + +message QueryBaseHeaderRequest { +} + +message QueryBaseHeaderResponse { + BTCHeaderInfo header = 1; +} diff --git a/x/btclightclient/client/cli/query.go b/x/btclightclient/client/cli/query.go index f6274f6fe..0cb3e0622 100644 --- a/x/btclightclient/client/cli/query.go +++ b/x/btclightclient/client/cli/query.go @@ -26,6 +26,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdContains()) cmd.AddCommand(CmdMainChain()) cmd.AddCommand(CmdTip()) + cmd.AddCommand(CmdBaseHeader()) return cmd } @@ -146,7 +147,7 @@ func CmdMainChain() *cobra.Command { func CmdTip() *cobra.Command { cmd := &cobra.Command{ Use: "tip", - Short: "retrieve tip of btc blockchain", + Short: "retrieve tip of the bitcoin blockchain", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) @@ -167,3 +168,28 @@ func CmdTip() *cobra.Command { return cmd } + +func CmdBaseHeader() *cobra.Command { + cmd := &cobra.Command{ + Use: "base-header", + Short: "retrieve base header of the bitcoin blockchain", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + params := types.NewQueryBaseHeaderRequest() + res, err := queryClient.BaseHeader(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/btclightclient/keeper/grpc_query.go b/x/btclightclient/keeper/grpc_query.go index b01fdab7c..78e93e270 100644 --- a/x/btclightclient/keeper/grpc_query.go +++ b/x/btclightclient/keeper/grpc_query.go @@ -160,3 +160,15 @@ func (k Keeper) Tip(ctx context.Context, req *types.QueryTipRequest) (*types.Que return &types.QueryTipResponse{Header: tip}, nil } + +func (k Keeper) BaseHeader(ctx context.Context, req *types.QueryBaseHeaderRequest) (*types.QueryBaseHeaderResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + baseHeader := k.headersState(sdkCtx).GetBaseBTCHeader() + + return &types.QueryBaseHeaderResponse{Header: baseHeader}, nil +} diff --git a/x/btclightclient/keeper/grpc_query_test.go b/x/btclightclient/keeper/grpc_query_test.go index 026a8297f..89195435d 100644 --- a/x/btclightclient/keeper/grpc_query_test.go +++ b/x/btclightclient/keeper/grpc_query_test.go @@ -318,6 +318,86 @@ func FuzzMainChainQuery(f *testing.F) { }) } +func FuzzTipQuery(f *testing.F) { + /* + Checks: + 1. If the request is nil, (nil, error) is returned + 2. The query returns the tip BTC header + + Data generation: + - Generate a random tree of headers and insert into storage + */ + datagen.AddRandomSeedsToFuzzer(f, 100) + f.Fuzz(func(t *testing.T, seed int64) { + rand.Seed(seed) + blcKeeper, ctx := testkeeper.BTCLightClientKeeper(t) + sdkCtx := sdk.WrapSDKContext(ctx) + + // Test nil input + resp, err := blcKeeper.Tip(sdkCtx, nil) + if resp != nil { + t.Errorf("Nil input led to a non-nil response") + } + if err == nil { + t.Errorf("Nil input led to a nil error") + } + + tree := genRandomTree(blcKeeper, ctx, 1, 10) + + query := types.NewQueryTipRequest() + resp, err = blcKeeper.Tip(sdkCtx, query) + if err != nil { + t.Errorf("valid input led to an error: %s", err) + } + if resp == nil { + t.Errorf("Valid input led to nil response") + } + if !resp.Header.Eq(tree.GetTip()) { + t.Errorf("Invalid header returned. Expected %s, got %s", tree.GetTip().Hash, resp.Header.Hash) + } + }) +} + +func FuzzBaseHeaderQuery(f *testing.F) { + /* + Checks: + 1. If the request is nil, (nil, error) is returned + 2. The query returns the base BTC header + + Data generation: + - Generate a random tree of headers and insert into storage. + */ + datagen.AddRandomSeedsToFuzzer(f, 100) + f.Fuzz(func(t *testing.T, seed int64) { + rand.Seed(seed) + blcKeeper, ctx := testkeeper.BTCLightClientKeeper(t) + sdkCtx := sdk.WrapSDKContext(ctx) + + // Test nil input + resp, err := blcKeeper.BaseHeader(sdkCtx, nil) + if resp != nil { + t.Errorf("Nil input led to a non-nil response") + } + if err == nil { + t.Errorf("Nil input led to a nil error") + } + + tree := genRandomTree(blcKeeper, ctx, 1, 10) + + query := types.NewQueryBaseHeaderRequest() + resp, err = blcKeeper.BaseHeader(sdkCtx, query) + if err != nil { + t.Errorf("valid input led to an error: %s", err) + } + if resp == nil { + t.Errorf("Valid input led to nil response") + } + if !resp.Header.Eq(tree.GetRoot()) { + t.Errorf("Invalid header returned. Expected %s, got %s", tree.GetRoot().Hash, resp.Header.Hash) + } + }) +} + // Constructors for PageRequest objects func constructRequestWithKeyAndLimit(key []byte, limit uint64) *query.PageRequest { // If limit is 0, set one randomly diff --git a/x/btclightclient/types/querier.go b/x/btclightclient/types/querier.go index b6ba85091..57065a3cb 100644 --- a/x/btclightclient/types/querier.go +++ b/x/btclightclient/types/querier.go @@ -32,3 +32,7 @@ func NewQueryMainChainRequest(req *query.PageRequest) *QueryMainChainRequest { func NewQueryTipRequest() *QueryTipRequest { return &QueryTipRequest{} } + +func NewQueryBaseHeaderRequest() *QueryBaseHeaderRequest { + return &QueryBaseHeaderRequest{} +} diff --git a/x/btclightclient/types/query.pb.go b/x/btclightclient/types/query.pb.go index 17a30200a..2d2664f1e 100644 --- a/x/btclightclient/types/query.pb.go +++ b/x/btclightclient/types/query.pb.go @@ -469,6 +469,86 @@ func (m *QueryTipResponse) GetHeader() *BTCHeaderInfo { return nil } +type QueryBaseHeaderRequest struct { +} + +func (m *QueryBaseHeaderRequest) Reset() { *m = QueryBaseHeaderRequest{} } +func (m *QueryBaseHeaderRequest) String() string { return proto.CompactTextString(m) } +func (*QueryBaseHeaderRequest) ProtoMessage() {} +func (*QueryBaseHeaderRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_6293be71fb7ba6c4, []int{10} +} +func (m *QueryBaseHeaderRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBaseHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBaseHeaderRequest.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 *QueryBaseHeaderRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBaseHeaderRequest.Merge(m, src) +} +func (m *QueryBaseHeaderRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryBaseHeaderRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBaseHeaderRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBaseHeaderRequest proto.InternalMessageInfo + +type QueryBaseHeaderResponse struct { + Header *BTCHeaderInfo `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` +} + +func (m *QueryBaseHeaderResponse) Reset() { *m = QueryBaseHeaderResponse{} } +func (m *QueryBaseHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*QueryBaseHeaderResponse) ProtoMessage() {} +func (*QueryBaseHeaderResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6293be71fb7ba6c4, []int{11} +} +func (m *QueryBaseHeaderResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBaseHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBaseHeaderResponse.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 *QueryBaseHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBaseHeaderResponse.Merge(m, src) +} +func (m *QueryBaseHeaderResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryBaseHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBaseHeaderResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBaseHeaderResponse proto.InternalMessageInfo + +func (m *QueryBaseHeaderResponse) GetHeader() *BTCHeaderInfo { + if m != nil { + return m.Header + } + return nil +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "babylon.btclightclient.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "babylon.btclightclient.v1.QueryParamsResponse") @@ -480,6 +560,8 @@ func init() { proto.RegisterType((*QueryMainChainResponse)(nil), "babylon.btclightclient.v1.QueryMainChainResponse") proto.RegisterType((*QueryTipRequest)(nil), "babylon.btclightclient.v1.QueryTipRequest") proto.RegisterType((*QueryTipResponse)(nil), "babylon.btclightclient.v1.QueryTipResponse") + proto.RegisterType((*QueryBaseHeaderRequest)(nil), "babylon.btclightclient.v1.QueryBaseHeaderRequest") + proto.RegisterType((*QueryBaseHeaderResponse)(nil), "babylon.btclightclient.v1.QueryBaseHeaderResponse") } func init() { @@ -487,49 +569,52 @@ func init() { } var fileDescriptor_6293be71fb7ba6c4 = []byte{ - // 660 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x4f, 0x6b, 0x13, 0x4f, - 0x18, 0xc7, 0x33, 0xfd, 0x93, 0x5f, 0x7f, 0x53, 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eb, 0x96, 0x6f, 0x89, 0x5c, 0x1e, 0xc2, 0xd7, - 0xe2, 0xd2, 0xdd, 0x1f, 0xe4, 0x0d, 0xc2, 0xe3, 0x0d, 0x99, 0x90, 0x95, 0x22, 0xa3, 0xe3, 0xb3, - 0xef, 0xad, 0x8e, 0x54, 0x0b, 0x38, 0x4b, 0x16, 0x67, 0x9e, 0xf8, 0x43, 0x70, 0x8c, 0x4c, 0xaa, - 0xb5, 0xbd, 0x43, 0x1f, 0xed, 0x1f, 0xfa, 0xe8, 0xfb, 0xa1, 0x8f, 0xde, 0x1e, 0xf9, 0xa5, 0xfd, - 0x23, 0xbf, 0xf4, 0xf5, 0xc8, 0x2f, 0x3d, 0xbd, 0x55, 0x74, 0xf7, 0xbd, 0xea, 0x97, 0xb4, 0x97, - 0x61, 0x58, 0xb6, 0xff, 0x73, 0xeb, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0xd4, 0x5b, 0x97, 0xa6, - 0xda, 0x07, 0x00, 0x00, + // 709 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0x4f, 0x6b, 0x13, 0x4f, + 0x18, 0xc7, 0x33, 0x6d, 0x7f, 0x69, 0x7f, 0x4f, 0x05, 0x75, 0xac, 0x5a, 0x17, 0xd9, 0xb6, 0x5b, + 0xfb, 0xc7, 0xd6, 0xee, 0x9a, 0x14, 0xc4, 0x83, 0xa0, 0x6c, 0x41, 0xeb, 0x41, 0x88, 0x21, 0x78, + 0x50, 0x41, 0x66, 0xe3, 0xb8, 0xbb, 0xd0, 0xec, 0x6c, 0xb3, 0xd3, 0x62, 0xae, 0x1e, 0x3c, 0x8b, + 0xde, 0x04, 0x3d, 0x08, 0xbe, 0x03, 0x5f, 0x44, 0x8f, 0x05, 0x2f, 0xe2, 0xa1, 0x48, 0xeb, 0x0b, + 0x91, 0x9d, 0x79, 0x36, 0x31, 0x29, 0xc9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0x53, 0x34, 0xf7, 0xe0, 0xc7, 0x9c, 0x69, 0x94, + 0x4f, 0x92, 0x82, 0x74, 0x6b, 0x8a, 0x6e, 0x89, 0x2e, 0x0c, 0xa0, 0x4b, 0x07, 0x94, 0xf6, 0xa7, + 0x5b, 0xd9, 0x3b, 0x34, 0xc9, 0xfe, 0xa1, 0x49, 0x7e, 0x1d, 0x9a, 0xe4, 0xdd, 0x91, 0x59, 0xd8, + 0x3f, 0x32, 0x0b, 0x3f, 0x8e, 0xcc, 0xc2, 0xd3, 0x5b, 0x79, 0xef, 0x85, 0xd7, 0xbd, 0x95, 0xd5, + 0x8b, 0xc2, 0x2b, 0xaa, 0xff, 0x00, 0xeb, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x71, 0xd0, 0x1d, + 0x22, 0xf6, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -552,8 +637,9 @@ type QueryClient interface { Contains(ctx context.Context, in *QueryContainsRequest, opts ...grpc.CallOption) (*QueryContainsResponse, error) // MainChain returns the canonical chain MainChain(ctx context.Context, in *QueryMainChainRequest, opts ...grpc.CallOption) (*QueryMainChainResponse, error) - // BestHeader return best header on canonical chain + // Tip return best header on canonical chain Tip(ctx context.Context, in *QueryTipRequest, opts ...grpc.CallOption) (*QueryTipResponse, error) + BaseHeader(ctx context.Context, in *QueryBaseHeaderRequest, opts ...grpc.CallOption) (*QueryBaseHeaderResponse, error) } type queryClient struct { @@ -609,6 +695,15 @@ func (c *queryClient) Tip(ctx context.Context, in *QueryTipRequest, opts ...grpc return out, nil } +func (c *queryClient) BaseHeader(ctx context.Context, in *QueryBaseHeaderRequest, opts ...grpc.CallOption) (*QueryBaseHeaderResponse, error) { + out := new(QueryBaseHeaderResponse) + err := c.cc.Invoke(ctx, "/babylon.btclightclient.v1.Query/BaseHeader", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Parameters queries the parameters of the module. @@ -619,8 +714,9 @@ type QueryServer interface { Contains(context.Context, *QueryContainsRequest) (*QueryContainsResponse, error) // MainChain returns the canonical chain MainChain(context.Context, *QueryMainChainRequest) (*QueryMainChainResponse, error) - // BestHeader return best header on canonical chain + // Tip return best header on canonical chain Tip(context.Context, *QueryTipRequest) (*QueryTipResponse, error) + BaseHeader(context.Context, *QueryBaseHeaderRequest) (*QueryBaseHeaderResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -642,6 +738,9 @@ func (*UnimplementedQueryServer) MainChain(ctx context.Context, req *QueryMainCh func (*UnimplementedQueryServer) Tip(ctx context.Context, req *QueryTipRequest) (*QueryTipResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Tip not implemented") } +func (*UnimplementedQueryServer) BaseHeader(ctx context.Context, req *QueryBaseHeaderRequest) (*QueryBaseHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BaseHeader not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -737,6 +836,24 @@ func _Query_Tip_Handler(srv interface{}, ctx context.Context, dec func(interface return interceptor(ctx, in, info, handler) } +func _Query_BaseHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryBaseHeaderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).BaseHeader(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/babylon.btclightclient.v1.Query/BaseHeader", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).BaseHeader(ctx, req.(*QueryBaseHeaderRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "babylon.btclightclient.v1.Query", HandlerType: (*QueryServer)(nil), @@ -761,6 +878,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Tip", Handler: _Query_Tip_Handler, }, + { + MethodName: "BaseHeader", + Handler: _Query_BaseHeader_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "babylon/btclightclient/query.proto", @@ -1116,6 +1237,64 @@ func (m *QueryTipResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryBaseHeaderRequest) 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 *QueryBaseHeaderRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBaseHeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryBaseHeaderResponse) 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 *QueryBaseHeaderResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBaseHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -1258,6 +1437,28 @@ func (m *QueryTipResponse) Size() (n int) { return n } +func (m *QueryBaseHeaderRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryBaseHeaderResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2101,6 +2302,142 @@ func (m *QueryTipResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryBaseHeaderRequest) 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 ErrIntOverflowQuery + } + 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: QueryBaseHeaderRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBaseHeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryBaseHeaderResponse) 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 ErrIntOverflowQuery + } + 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: QueryBaseHeaderResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBaseHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Header == nil { + m.Header = &BTCHeaderInfo{} + } + if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/btclightclient/types/query.pb.gw.go b/x/btclightclient/types/query.pb.gw.go index 7811e6661..0ca05598d 100644 --- a/x/btclightclient/types/query.pb.gw.go +++ b/x/btclightclient/types/query.pb.gw.go @@ -175,6 +175,24 @@ func local_request_Query_Tip_0(ctx context.Context, marshaler runtime.Marshaler, } +func request_Query_BaseHeader_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBaseHeaderRequest + var metadata runtime.ServerMetadata + + msg, err := client.BaseHeader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_BaseHeader_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBaseHeaderRequest + var metadata runtime.ServerMetadata + + msg, err := server.BaseHeader(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -281,6 +299,26 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_BaseHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_BaseHeader_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_BaseHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -422,6 +460,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_BaseHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_BaseHeader_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_BaseHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -435,6 +493,8 @@ var ( pattern_Query_MainChain_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "mainchain"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Tip_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "tip"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_BaseHeader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"babylon", "btclightclient", "v1", "baseheader"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -447,4 +507,6 @@ var ( forward_Query_MainChain_0 = runtime.ForwardResponseMessage forward_Query_Tip_0 = runtime.ForwardResponseMessage + + forward_Query_BaseHeader_0 = runtime.ForwardResponseMessage )