Trust Anchor state query (#85)

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-09-21 14:02:32 +02:00 committed by GitHub
parent c05797333d
commit b215f7a5db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 739 additions and 27 deletions

View File

@ -46583,6 +46583,45 @@ paths:
type: string
tags:
- Query
/planetmint-go/machine/get_trust_anchor_status/{machineid}:
get:
summary: Queries a list of GetTrustAnchorStatus items.
operationId: PlanetmintgoMachineGetTrustAnchorStatus
responses:
'200':
description: A successful response.
schema:
type: object
properties:
machineid:
type: string
isactivated:
type: boolean
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: machineid
in: path
required: true
type: string
tags:
- Query
/planetmint-go/machine/params:
get:
summary: Parameters queries the parameters of the module.
@ -75479,6 +75518,13 @@ definitions:
format: int64
machineIdSignature:
type: string
planetmintgo.machine.QueryGetTrustAnchorStatusResponse:
type: object
properties:
machineid:
type: string
isactivated:
type: boolean
planetmintgo.machine.QueryParamsResponse:
type: object
properties:

View File

@ -24,6 +24,12 @@ service Query {
option (google.api.http).get = "/planetmint-go/machine/get_machine_by_public_key/{publicKey}";
}
// Queries a list of GetTrustAnchorStatus items.
rpc GetTrustAnchorStatus (QueryGetTrustAnchorStatusRequest) returns (QueryGetTrustAnchorStatusResponse) {
option (google.api.http).get = "/planetmint-go/machine/get_trust_anchor_status/{machineid}";
}
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}
@ -43,3 +49,12 @@ message QueryGetMachineByPublicKeyResponse {
Machine machine = 1;
}
message QueryGetTrustAnchorStatusRequest {
string machineid = 1;
}
message QueryGetTrustAnchorStatusResponse {
string machineid = 1;
bool isactivated = 2;
}

View File

@ -27,6 +27,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdGetMachineByPublicKey())
cmd.AddCommand(CmdGetTrustAnchorStatus())
// this line is used by starport scaffolding # 1
return cmd

View File

@ -0,0 +1,46 @@
package cli
import (
"strconv"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
"planetmint-go/x/machine/types"
)
var _ = strconv.Itoa(0)
func CmdGetTrustAnchorStatus() *cobra.Command {
cmd := &cobra.Command{
Use: "get-trust-anchor-status [machineid]",
Short: "Query get_trust_anchor_status",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqMachineid := args[0]
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryGetTrustAnchorStatusRequest{
Machineid: reqMachineid,
}
res, err := queryClient.GetTrustAnchorStatus(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@ -0,0 +1,26 @@
package keeper
import (
"context"
"planetmint-go/x/machine/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) GetTrustAnchorStatus(goCtx context.Context, req *types.QueryGetTrustAnchorStatusRequest) (*types.QueryGetTrustAnchorStatusResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
_, activated, found := k.GetTrustAnchor(ctx, req.Machineid)
if !found {
return nil, status.Error(codes.NotFound, "trust anchor not found")
}
return &types.QueryGetTrustAnchorStatusResponse{Machineid: req.Machineid, Isactivated: activated}, nil
}

View File

@ -0,0 +1,50 @@
package keeper_test
import (
keepertest "planetmint-go/testutil/keeper"
"planetmint-go/x/machine/types"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func TestGetTrustAnchorQuery(t *testing.T) {
keeper, ctx := keepertest.MachineKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
msgs := createNTrustAnchor(t, keeper, ctx, 2)
for _, tc := range []struct {
desc string
request *types.QueryGetTrustAnchorStatusRequest
response *types.QueryGetTrustAnchorStatusResponse
err error
}{
{
desc: "GetByMachineId",
request: &types.QueryGetTrustAnchorStatusRequest{Machineid: msgs[0].Pubkey},
response: &types.QueryGetTrustAnchorStatusResponse{Machineid: msgs[0].Pubkey, Isactivated: false},
},
{
desc: "Not Activated",
request: &types.QueryGetTrustAnchorStatusRequest{Machineid: msgs[1].Pubkey},
response: &types.QueryGetTrustAnchorStatusResponse{Machineid: msgs[1].Pubkey, Isactivated: true},
},
{
desc: "NotFound",
request: &types.QueryGetTrustAnchorStatusRequest{Machineid: "invalid MachineID"},
err: status.Error(codes.NotFound, "trust anchor not found"),
},
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
response, err := keeper.GetTrustAnchorStatus(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.Equal(t, tc.response, response)
}
})
}
}

View File

@ -201,43 +201,148 @@ func (m *QueryGetMachineByPublicKeyResponse) GetMachine() *Machine {
return nil
}
type QueryGetTrustAnchorStatusRequest struct {
Machineid string `protobuf:"bytes,1,opt,name=machineid,proto3" json:"machineid,omitempty"`
}
func (m *QueryGetTrustAnchorStatusRequest) Reset() { *m = QueryGetTrustAnchorStatusRequest{} }
func (m *QueryGetTrustAnchorStatusRequest) String() string { return proto.CompactTextString(m) }
func (*QueryGetTrustAnchorStatusRequest) ProtoMessage() {}
func (*QueryGetTrustAnchorStatusRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_bf7841d43d757203, []int{4}
}
func (m *QueryGetTrustAnchorStatusRequest) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryGetTrustAnchorStatusRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryGetTrustAnchorStatusRequest.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 *QueryGetTrustAnchorStatusRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryGetTrustAnchorStatusRequest.Merge(m, src)
}
func (m *QueryGetTrustAnchorStatusRequest) XXX_Size() int {
return m.Size()
}
func (m *QueryGetTrustAnchorStatusRequest) XXX_DiscardUnknown() {
xxx_messageInfo_QueryGetTrustAnchorStatusRequest.DiscardUnknown(m)
}
var xxx_messageInfo_QueryGetTrustAnchorStatusRequest proto.InternalMessageInfo
func (m *QueryGetTrustAnchorStatusRequest) GetMachineid() string {
if m != nil {
return m.Machineid
}
return ""
}
type QueryGetTrustAnchorStatusResponse struct {
Machineid string `protobuf:"bytes,1,opt,name=machineid,proto3" json:"machineid,omitempty"`
Isactivated bool `protobuf:"varint,2,opt,name=isactivated,proto3" json:"isactivated,omitempty"`
}
func (m *QueryGetTrustAnchorStatusResponse) Reset() { *m = QueryGetTrustAnchorStatusResponse{} }
func (m *QueryGetTrustAnchorStatusResponse) String() string { return proto.CompactTextString(m) }
func (*QueryGetTrustAnchorStatusResponse) ProtoMessage() {}
func (*QueryGetTrustAnchorStatusResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_bf7841d43d757203, []int{5}
}
func (m *QueryGetTrustAnchorStatusResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *QueryGetTrustAnchorStatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_QueryGetTrustAnchorStatusResponse.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 *QueryGetTrustAnchorStatusResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_QueryGetTrustAnchorStatusResponse.Merge(m, src)
}
func (m *QueryGetTrustAnchorStatusResponse) XXX_Size() int {
return m.Size()
}
func (m *QueryGetTrustAnchorStatusResponse) XXX_DiscardUnknown() {
xxx_messageInfo_QueryGetTrustAnchorStatusResponse.DiscardUnknown(m)
}
var xxx_messageInfo_QueryGetTrustAnchorStatusResponse proto.InternalMessageInfo
func (m *QueryGetTrustAnchorStatusResponse) GetMachineid() string {
if m != nil {
return m.Machineid
}
return ""
}
func (m *QueryGetTrustAnchorStatusResponse) GetIsactivated() bool {
if m != nil {
return m.Isactivated
}
return false
}
func init() {
proto.RegisterType((*QueryParamsRequest)(nil), "planetmintgo.machine.QueryParamsRequest")
proto.RegisterType((*QueryParamsResponse)(nil), "planetmintgo.machine.QueryParamsResponse")
proto.RegisterType((*QueryGetMachineByPublicKeyRequest)(nil), "planetmintgo.machine.QueryGetMachineByPublicKeyRequest")
proto.RegisterType((*QueryGetMachineByPublicKeyResponse)(nil), "planetmintgo.machine.QueryGetMachineByPublicKeyResponse")
proto.RegisterType((*QueryGetTrustAnchorStatusRequest)(nil), "planetmintgo.machine.QueryGetTrustAnchorStatusRequest")
proto.RegisterType((*QueryGetTrustAnchorStatusResponse)(nil), "planetmintgo.machine.QueryGetTrustAnchorStatusResponse")
}
func init() { proto.RegisterFile("planetmintgo/machine/query.proto", fileDescriptor_bf7841d43d757203) }
var fileDescriptor_bf7841d43d757203 = []byte{
// 412 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xcf, 0x6a, 0x1a, 0x41,
0x1c, 0xc7, 0x77, 0xa5, 0xb5, 0x38, 0xbd, 0x4d, 0x2d, 0x94, 0x45, 0x57, 0x5d, 0x28, 0xd8, 0x42,
0x77, 0xd0, 0x1e, 0x2c, 0xa5, 0x14, 0x2a, 0x85, 0x1e, 0x4a, 0x41, 0xf7, 0x58, 0x28, 0xcb, 0xac,
0x0c, 0xdb, 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2, 0x89, 0x3a, 0x64, 0x61, 0x79, 0x72, 0x65, 0xd9, 0xd0, 0x18, 0xc0,
0x07, 0x95, 0x57, 0x82, 0xfa, 0x35, 0xbd, 0xea, 0xf6, 0xc0, 0x79, 0x7e, 0x7b, 0xa3, 0x65, 0x7e,
0x65, 0x98, 0x5f, 0xa0, 0xbd, 0x6b, 0x98, 0x63, 0xa6, 0x03, 0x7b, 0x0e, 0xc2, 0x3c, 0x28, 0x96,
0x2b, 0xf8, 0xc4, 0x72, 0x72, 0x36, 0x5f, 0xb4, 0x73, 0xf4, 0x13, 0xc0, 0x56, 0xd5, 0x25, 0xa2,
0x67, 0xf5, 0x60, 0xd7, 0xed, 0x8d, 0xd3, 0xbf, 0xb5, 0xcf, 0xce, 0x33, 0x30, 0xf3, 0xec, 0xa1,
0xdd, 0x9a, 0x79, 0xf4, 0xcc, 0x1d, 0x50, 0x63, 0x0f, 0x94, 0xf1, 0x93, 0xb3, 0xf9, 0x4a, 0x9d,
0x0f, 0xfa, 0x17, 0x13, 0x17, 0x8c, 0x27, 0x2e, 0xf8, 0x3b, 0x71, 0xc1, 0xb7, 0xa9, 0xdb, 0x18,
0x4f, 0xdd, 0xc6, 0xef, 0xa9, 0xdb, 0xf8, 0xd0, 0xb9, 0x1c, 0xfa, 0x79, 0x1e, 0xab, 0xf3, 0x84,
0xa9, 0xb0, 0x69, 0xfe, 0x11, 0x4f, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x5c, 0x61, 0xd3, 0x10,
0x04, 0x05, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@ -256,6 +361,8 @@ type QueryClient interface {
Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
// Queries a list of GetMachineByPublicKey items.
GetMachineByPublicKey(ctx context.Context, in *QueryGetMachineByPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetMachineByPublicKeyResponse, error)
// Queries a list of GetTrustAnchorStatus items.
GetTrustAnchorStatus(ctx context.Context, in *QueryGetTrustAnchorStatusRequest, opts ...grpc.CallOption) (*QueryGetTrustAnchorStatusResponse, error)
}
type queryClient struct {
@ -284,12 +391,23 @@ func (c *queryClient) GetMachineByPublicKey(ctx context.Context, in *QueryGetMac
return out, nil
}
func (c *queryClient) GetTrustAnchorStatus(ctx context.Context, in *QueryGetTrustAnchorStatusRequest, opts ...grpc.CallOption) (*QueryGetTrustAnchorStatusResponse, error) {
out := new(QueryGetTrustAnchorStatusResponse)
err := c.cc.Invoke(ctx, "/planetmintgo.machine.Query/GetTrustAnchorStatus", 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.
Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
// Queries a list of GetMachineByPublicKey items.
GetMachineByPublicKey(context.Context, *QueryGetMachineByPublicKeyRequest) (*QueryGetMachineByPublicKeyResponse, error)
// Queries a list of GetTrustAnchorStatus items.
GetTrustAnchorStatus(context.Context, *QueryGetTrustAnchorStatusRequest) (*QueryGetTrustAnchorStatusResponse, error)
}
// UnimplementedQueryServer can be embedded to have forward compatible implementations.
@ -302,6 +420,9 @@ func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsReq
func (*UnimplementedQueryServer) GetMachineByPublicKey(ctx context.Context, req *QueryGetMachineByPublicKeyRequest) (*QueryGetMachineByPublicKeyResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetMachineByPublicKey not implemented")
}
func (*UnimplementedQueryServer) GetTrustAnchorStatus(ctx context.Context, req *QueryGetTrustAnchorStatusRequest) (*QueryGetTrustAnchorStatusResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetTrustAnchorStatus not implemented")
}
func RegisterQueryServer(s grpc1.Server, srv QueryServer) {
s.RegisterService(&_Query_serviceDesc, srv)
@ -343,6 +464,24 @@ func _Query_GetMachineByPublicKey_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler)
}
func _Query_GetTrustAnchorStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryGetTrustAnchorStatusRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).GetTrustAnchorStatus(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/planetmintgo.machine.Query/GetTrustAnchorStatus",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).GetTrustAnchorStatus(ctx, req.(*QueryGetTrustAnchorStatusRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Query_serviceDesc = grpc.ServiceDesc{
ServiceName: "planetmintgo.machine.Query",
HandlerType: (*QueryServer)(nil),
@ -355,6 +494,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{
MethodName: "GetMachineByPublicKey",
Handler: _Query_GetMachineByPublicKey_Handler,
},
{
MethodName: "GetTrustAnchorStatus",
Handler: _Query_GetTrustAnchorStatus_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "planetmintgo/machine/query.proto",
@ -481,6 +624,76 @@ func (m *QueryGetMachineByPublicKeyResponse) MarshalToSizedBuffer(dAtA []byte) (
return len(dAtA) - i, nil
}
func (m *QueryGetTrustAnchorStatusRequest) 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 *QueryGetTrustAnchorStatusRequest) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryGetTrustAnchorStatusRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Machineid) > 0 {
i -= len(m.Machineid)
copy(dAtA[i:], m.Machineid)
i = encodeVarintQuery(dAtA, i, uint64(len(m.Machineid)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *QueryGetTrustAnchorStatusResponse) 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 *QueryGetTrustAnchorStatusResponse) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *QueryGetTrustAnchorStatusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.Isactivated {
i--
if m.Isactivated {
dAtA[i] = 1
} else {
dAtA[i] = 0
}
i--
dAtA[i] = 0x10
}
if len(m.Machineid) > 0 {
i -= len(m.Machineid)
copy(dAtA[i:], m.Machineid)
i = encodeVarintQuery(dAtA, i, uint64(len(m.Machineid)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintQuery(dAtA []byte, offset int, v uint64) int {
offset -= sovQuery(v)
base := offset
@ -538,6 +751,35 @@ func (m *QueryGetMachineByPublicKeyResponse) Size() (n int) {
return n
}
func (m *QueryGetTrustAnchorStatusRequest) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Machineid)
if l > 0 {
n += 1 + l + sovQuery(uint64(l))
}
return n
}
func (m *QueryGetTrustAnchorStatusResponse) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Machineid)
if l > 0 {
n += 1 + l + sovQuery(uint64(l))
}
if m.Isactivated {
n += 2
}
return n
}
func sovQuery(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@ -845,6 +1087,190 @@ func (m *QueryGetMachineByPublicKeyResponse) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *QueryGetTrustAnchorStatusRequest) 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: QueryGetTrustAnchorStatusRequest: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryGetTrustAnchorStatusRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Machineid", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
}
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 ErrInvalidLengthQuery
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthQuery
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Machineid = string(dAtA[iNdEx:postIndex])
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 (m *QueryGetTrustAnchorStatusResponse) 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: QueryGetTrustAnchorStatusResponse: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: QueryGetTrustAnchorStatusResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Machineid", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
}
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 ErrInvalidLengthQuery
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthQuery
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Machineid = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Isactivated", wireType)
}
var v int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
m.Isactivated = bool(v != 0)
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

View File

@ -105,6 +105,60 @@ func local_request_Query_GetMachineByPublicKey_0(ctx context.Context, marshaler
}
func request_Query_GetTrustAnchorStatus_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetTrustAnchorStatusRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["machineid"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "machineid")
}
protoReq.Machineid, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "machineid", err)
}
msg, err := client.GetTrustAnchorStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_GetTrustAnchorStatus_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetTrustAnchorStatusRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["machineid"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "machineid")
}
protoReq.Machineid, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "machineid", err)
}
msg, err := server.GetTrustAnchorStatus(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.
@ -157,6 +211,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
})
mux.Handle("GET", pattern_Query_GetTrustAnchorStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
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_GetTrustAnchorStatus_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_GetTrustAnchorStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -238,6 +315,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
})
mux.Handle("GET", pattern_Query_GetTrustAnchorStatus_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_GetTrustAnchorStatus_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_GetTrustAnchorStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -245,10 +342,14 @@ var (
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"planetmint-go", "machine", "params"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Query_GetMachineByPublicKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"planetmint-go", "machine", "get_machine_by_public_key", "publicKey"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Query_GetTrustAnchorStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"planetmint-go", "machine", "get_trust_anchor_status", "machineid"}, "", runtime.AssumeColonVerbOpt(true)))
)
var (
forward_Query_Params_0 = runtime.ForwardResponseMessage
forward_Query_GetMachineByPublicKey_0 = runtime.ForwardResponseMessage
forward_Query_GetTrustAnchorStatus_0 = runtime.ForwardResponseMessage
)