Eckelj/adding machine types (#67)

* added machine-type definition and checks
* fixed staticcheck issues

---------
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-08-31 10:04:07 +02:00 committed by GitHub
parent 9e5172583f
commit 5763bd6a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 27 deletions

View File

@ -46517,6 +46517,9 @@ paths:
type: string
additionalDataCID:
type: string
type:
type: integer
format: int64
default:
description: An unexpected error response.
schema:
@ -75363,6 +75366,9 @@ definitions:
type: string
additionalDataCID:
type: string
type:
type: integer
format: int64
planetmintgo.machine.Metadata:
type: object
properties:
@ -75416,6 +75422,9 @@ definitions:
type: string
additionalDataCID:
type: string
type:
type: integer
format: int64
planetmintgo.machine.QueryParamsResponse:
type: object
properties:

View File

@ -13,8 +13,9 @@ message Machine {
uint64 precision = 6;
string issuerPlanetmint = 7;
string issuerLiquid = 8;
string machineId = 9;
string machineId = 9;
Metadata metadata = 10;
uint32 type = 11;
}
message Metadata {

View File

@ -63,6 +63,7 @@ func Machine(name, pubKey string) machinetypes.Machine {
IssuerLiquid: liquidPubKey,
MachineId: pubKey,
Metadata: &metadata,
Type: 1,
}
return m
}

View File

@ -39,6 +39,10 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
}
}
if msg.Machine.GetType() == 0 { // 0 == RDDL_MACHINE_UNDEFINED
return nil, errors.New("the machine type has to be defined")
}
k.StoreMachine(ctx, *msg.Machine)
k.StoreMachineIndex(ctx, *msg.Machine)
@ -59,6 +63,7 @@ func (k msgServer) issueMachineNFT(machine *types.Machine) error {
client := osc.NewClient(conf.WatchmenEndpoint, conf.WatchmenPort)
machine_precision := strconv.FormatInt(int64(machine.Precision), 10)
machine_amount := strconv.FormatInt(int64(machine.Amount), 10)
machine_type := strconv.FormatUint(uint64(machine.GetType()), 10)
msg := osc.NewMessage("/rddl/issue")
msg.Append(machine.Name)
@ -69,6 +74,7 @@ func (k msgServer) issueMachineNFT(machine *types.Machine) error {
msg.Append(machine_precision)
msg.Append(machine.Metadata.GetAdditionalDataCID())
msg.Append(machine.GetIssuerPlanetmint())
msg.Append(machine_type)
err := client.Send(msg)
return err

View File

@ -33,6 +33,7 @@ type Machine struct {
IssuerLiquid string `protobuf:"bytes,8,opt,name=issuerLiquid,proto3" json:"issuerLiquid,omitempty"`
MachineId string `protobuf:"bytes,9,opt,name=machineId,proto3" json:"machineId,omitempty"`
Metadata *Metadata `protobuf:"bytes,10,opt,name=metadata,proto3" json:"metadata,omitempty"`
Type uint32 `protobuf:"varint,11,opt,name=type,proto3" json:"type,omitempty"`
}
func (m *Machine) Reset() { *m = Machine{} }
@ -138,6 +139,13 @@ func (m *Machine) GetMetadata() *Metadata {
return nil
}
func (m *Machine) GetType() uint32 {
if m != nil {
return m.Type
}
return 0
}
type Metadata struct {
Gps string `protobuf:"bytes,1,opt,name=gps,proto3" json:"gps,omitempty"`
Device string `protobuf:"bytes,2,opt,name=device,proto3" json:"device,omitempty"`
@ -277,32 +285,32 @@ func init() {
}
var fileDescriptor_1bb279745bef7c4b = []byte{
// 385 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x4a, 0xeb, 0x40,
0x14, 0x87, 0x3b, 0x6d, 0x6f, 0x9b, 0x9c, 0x5b, 0xb8, 0xbd, 0xc3, 0xe5, 0x32, 0x0b, 0x0d, 0x21,
0xab, 0x20, 0x9a, 0x82, 0x2e, 0x04, 0x97, 0xda, 0x4d, 0xc1, 0x82, 0x64, 0xe9, 0x6e, 0x4c, 0x8e,
0x75, 0xb0, 0x99, 0xc4, 0x64, 0x2a, 0x15, 0x7c, 0x04, 0x17, 0xbe, 0x95, 0x2e, 0xbb, 0x74, 0x29,
0xed, 0x8b, 0x48, 0x26, 0x49, 0x6b, 0xff, 0x2c, 0x5c, 0xf5, 0x9c, 0xef, 0xf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, 0xd4, 0xc2, 0xf0, 0x51, 0x04, 0x58, 0x89, 0x2c, 0x3a, 0xea,
0xc2, 0x1f, 0x9e, 0x65, 0xa8, 0xfa, 0x78, 0x2b, 0xa4, 0x50, 0xb9, 0x84, 0xc2, 0xe8, 0x26, 0xa6,
0x87, 0xf0, 0x97, 0x87, 0xa1, 0xae, 0xf9, 0xb8, 0xcf, 0x15, 0xbf, 0x18, 0xf4, 0xb5, 0x64, 0xd3,
0xdf, 0x1e, 0x38, 0xcf, 0xd0, 0x29, 0xbf, 0xeb, 0x40, 0x86, 0x38, 0x5d, 0x5f, 0x9c, 0x6c, 0x2e,
0xbe, 0x4b, 0x73, 0xfd, 0x87, 0x9a, 0x1b, 0xdb, 0x9a, 0xcf, 0x4f, 0xdf, 0xe7, 0x16, 0x99, 0xcd,
0x2d, 0xf2, 0x39, 0xb7, 0xc8, 0xeb, 0xc2, 0xaa, 0xcd, 0x16, 0x56, 0xed, 0x63, 0x61, 0xd5, 0xae,
0xf7, 0x57, 0x3e, 0x8f, 0x46, 0x71, 0x6f, 0xba, 0x7c, 0xad, 0xea, 0x29, 0xc1, 0xec, 0xa6, 0xa5,
0x1f, 0xeb, 0xc9, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x61, 0x27, 0xb2, 0x55, 0xd2, 0x02, 0x00,
0x00,
// 394 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x4a, 0xf3, 0x40,
0x14, 0xc5, 0x3b, 0x6d, 0xbf, 0x36, 0xb9, 0xed, 0x87, 0x75, 0x10, 0x99, 0x85, 0x86, 0x90, 0x55,
0x10, 0x4d, 0x41, 0x17, 0x82, 0x4b, 0xed, 0xa6, 0x60, 0x41, 0xb2, 0x74, 0x37, 0x26, 0x63, 0x1d,
0x6c, 0x26, 0x31, 0x99, 0x4a, 0x05, 0x1f, 0xc1, 0x85, 0x8f, 0xe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x03, 0xdd, 0xf2, 0x17, 0xfd, 0x9c, 0x9e, 0x7c, 0x49, 0x18, 0x69, 0xd9, 0xc8,
0xfd, 0xef, 0x2b, 0xed, 0xbc, 0x21, 0x30, 0xca, 0x2a, 0xee, 0x40, 0x6d, 0x98, 0x64, 0x9a, 0x6e,
0x2e, 0x15, 0x44, 0xf6, 0xcc, 0x03, 0x56, 0xc2, 0x2d, 0x1c, 0x76, 0x61, 0x87, 0x66, 0x19, 0x93,
0x3d, 0x76, 0xcf, 0x05, 0x97, 0x39, 0x98, 0x82, 0xf2, 0x7a, 0x8c, 0x8f, 0x61, 0x97, 0x86, 0xa1,
0xd2, 0x74, 0xd4, 0xa3, 0x92, 0x5e, 0xf5, 0x7b, 0x0a, 0xbc, 0xe9, 0x6f, 0x0e, 0x9c, 0x57, 0x68,
0xeb, 0x7f, 0xdd, 0x17, 0x21, 0x9b, 0xac, 0xc2, 0x40, 0xeb, 0x30, 0xb6, 0xa1, 0xaf, 0xfe, 0x11,
0x7d, 0x6d, 0x13, 0xfd, 0xe5, 0xf9, 0xc7, 0xcc, 0x42, 0xd3, 0x99, 0x85, 0xbe, 0x67, 0x16, 0x7a,
0x9f, 0x5b, 0x95, 0xe9, 0xdc, 0xaa, 0x7c, 0xce, 0xad, 0xca, 0xed, 0xe1, 0x92, 0xf1, 0xc9, 0x30,
0xee, 0x4e, 0x16, 0x1b, 0x9c, 0x43, 0xcc, 0xee, 0x1a, 0x6a, 0x81, 0xcf, 0x7e, 0x02, 0x00, 0x00,
0xff, 0xff, 0xb9, 0x18, 0x24, 0xb2, 0xe6, 0x02, 0x00, 0x00,
}
func (m *Machine) Marshal() (dAtA []byte, err error) {
@ -325,6 +333,11 @@ func (m *Machine) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if m.Type != 0 {
i = encodeVarintMachine(dAtA, i, uint64(m.Type))
i--
dAtA[i] = 0x58
}
if m.Metadata != nil {
{
size, err := m.Metadata.MarshalToSizedBuffer(dAtA[:i])
@ -551,6 +564,9 @@ func (m *Machine) Size() (n int) {
l = m.Metadata.Size()
n += 1 + l + sovMachine(uint64(l))
}
if m.Type != 0 {
n += 1 + sovMachine(uint64(m.Type))
}
return n
}
@ -921,6 +937,25 @@ func (m *Machine) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 11:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType)
}
m.Type = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowMachine
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Type |= uint32(b&0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipMachine(dAtA[iNdEx:])