From f625e8ffac2eac0c3321ed5d9173dcb765d76d05 Mon Sep 17 00:00:00 2001 From: Olimdzhon Date: Thu, 1 Aug 2024 02:32:29 +0500 Subject: [PATCH] play your games in order; --- api/checkers/checkers/stored_game.pulsar.go | 210 +++++++++++++++--- api/checkers/checkers/system_info.pulsar.go | 185 +++++++++++++-- docs/static/openapi.yml | 2 +- proto/checkers/checkers/stored_game.proto | 2 + proto/checkers/checkers/system_info.proto | 3 +- x/checkers/keeper/msg_server_create_game.go | 3 + .../msg_server_create_game_fifo_test.go | 179 +++++++++++++++ x/checkers/keeper/msg_server_play_move.go | 10 + x/checkers/keeper/stored_game_in_fifo.go | 68 ++++++ x/checkers/types/genesis.go | 2 + x/checkers/types/genesis_test.go | 6 +- x/checkers/types/keys.go | 6 +- x/checkers/types/stored_game.pb.go | 154 ++++++++++--- x/checkers/types/system_info.pb.go | 125 ++++++++++- 14 files changed, 867 insertions(+), 88 deletions(-) create mode 100644 x/checkers/keeper/msg_server_create_game_fifo_test.go create mode 100644 x/checkers/keeper/stored_game_in_fifo.go diff --git a/api/checkers/checkers/stored_game.pulsar.go b/api/checkers/checkers/stored_game.pulsar.go index db5590d..30c07bc 100644 --- a/api/checkers/checkers/stored_game.pulsar.go +++ b/api/checkers/checkers/stored_game.pulsar.go @@ -13,15 +13,17 @@ import ( ) var ( - md_StoredGame protoreflect.MessageDescriptor - fd_StoredGame_index protoreflect.FieldDescriptor - fd_StoredGame_board protoreflect.FieldDescriptor - fd_StoredGame_turn protoreflect.FieldDescriptor - fd_StoredGame_black protoreflect.FieldDescriptor - fd_StoredGame_red protoreflect.FieldDescriptor - fd_StoredGame_winner protoreflect.FieldDescriptor - fd_StoredGame_deadline protoreflect.FieldDescriptor - fd_StoredGame_moveCount protoreflect.FieldDescriptor + md_StoredGame protoreflect.MessageDescriptor + fd_StoredGame_index protoreflect.FieldDescriptor + fd_StoredGame_board protoreflect.FieldDescriptor + fd_StoredGame_turn protoreflect.FieldDescriptor + fd_StoredGame_black protoreflect.FieldDescriptor + fd_StoredGame_red protoreflect.FieldDescriptor + fd_StoredGame_winner protoreflect.FieldDescriptor + fd_StoredGame_deadline protoreflect.FieldDescriptor + fd_StoredGame_moveCount protoreflect.FieldDescriptor + fd_StoredGame_beforeIndex protoreflect.FieldDescriptor + fd_StoredGame_afterIndex protoreflect.FieldDescriptor ) func init() { @@ -35,6 +37,8 @@ func init() { fd_StoredGame_winner = md_StoredGame.Fields().ByName("winner") fd_StoredGame_deadline = md_StoredGame.Fields().ByName("deadline") fd_StoredGame_moveCount = md_StoredGame.Fields().ByName("moveCount") + fd_StoredGame_beforeIndex = md_StoredGame.Fields().ByName("beforeIndex") + fd_StoredGame_afterIndex = md_StoredGame.Fields().ByName("afterIndex") } var _ protoreflect.Message = (*fastReflection_StoredGame)(nil) @@ -150,6 +154,18 @@ func (x *fastReflection_StoredGame) Range(f func(protoreflect.FieldDescriptor, p return } } + if x.BeforeIndex != "" { + value := protoreflect.ValueOfString(x.BeforeIndex) + if !f(fd_StoredGame_beforeIndex, value) { + return + } + } + if x.AfterIndex != "" { + value := protoreflect.ValueOfString(x.AfterIndex) + if !f(fd_StoredGame_afterIndex, value) { + return + } + } } // Has reports whether a field is populated. @@ -181,6 +197,10 @@ func (x *fastReflection_StoredGame) Has(fd protoreflect.FieldDescriptor) bool { return x.Deadline != "" case "checkers.checkers.StoredGame.moveCount": return x.MoveCount != uint64(0) + case "checkers.checkers.StoredGame.beforeIndex": + return x.BeforeIndex != "" + case "checkers.checkers.StoredGame.afterIndex": + return x.AfterIndex != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.StoredGame")) @@ -213,6 +233,10 @@ func (x *fastReflection_StoredGame) Clear(fd protoreflect.FieldDescriptor) { x.Deadline = "" case "checkers.checkers.StoredGame.moveCount": x.MoveCount = uint64(0) + case "checkers.checkers.StoredGame.beforeIndex": + x.BeforeIndex = "" + case "checkers.checkers.StoredGame.afterIndex": + x.AfterIndex = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.StoredGame")) @@ -253,6 +277,12 @@ func (x *fastReflection_StoredGame) Get(descriptor protoreflect.FieldDescriptor) case "checkers.checkers.StoredGame.moveCount": value := x.MoveCount return protoreflect.ValueOfUint64(value) + case "checkers.checkers.StoredGame.beforeIndex": + value := x.BeforeIndex + return protoreflect.ValueOfString(value) + case "checkers.checkers.StoredGame.afterIndex": + value := x.AfterIndex + return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.StoredGame")) @@ -289,6 +319,10 @@ func (x *fastReflection_StoredGame) Set(fd protoreflect.FieldDescriptor, value p x.Deadline = value.Interface().(string) case "checkers.checkers.StoredGame.moveCount": x.MoveCount = value.Uint() + case "checkers.checkers.StoredGame.beforeIndex": + x.BeforeIndex = value.Interface().(string) + case "checkers.checkers.StoredGame.afterIndex": + x.AfterIndex = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.StoredGame")) @@ -325,6 +359,10 @@ func (x *fastReflection_StoredGame) Mutable(fd protoreflect.FieldDescriptor) pro panic(fmt.Errorf("field deadline of message checkers.checkers.StoredGame is not mutable")) case "checkers.checkers.StoredGame.moveCount": panic(fmt.Errorf("field moveCount of message checkers.checkers.StoredGame is not mutable")) + case "checkers.checkers.StoredGame.beforeIndex": + panic(fmt.Errorf("field beforeIndex of message checkers.checkers.StoredGame is not mutable")) + case "checkers.checkers.StoredGame.afterIndex": + panic(fmt.Errorf("field afterIndex of message checkers.checkers.StoredGame is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.StoredGame")) @@ -354,6 +392,10 @@ func (x *fastReflection_StoredGame) NewField(fd protoreflect.FieldDescriptor) pr return protoreflect.ValueOfString("") case "checkers.checkers.StoredGame.moveCount": return protoreflect.ValueOfUint64(uint64(0)) + case "checkers.checkers.StoredGame.beforeIndex": + return protoreflect.ValueOfString("") + case "checkers.checkers.StoredGame.afterIndex": + return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.StoredGame")) @@ -454,6 +496,14 @@ func (x *fastReflection_StoredGame) ProtoMethods() *protoiface.Methods { if x.MoveCount != 0 { n += 1 + runtime.Sov(uint64(x.MoveCount)) } + l = len(x.BeforeIndex) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.AfterIndex) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -483,6 +533,20 @@ func (x *fastReflection_StoredGame) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.AfterIndex) > 0 { + i -= len(x.AfterIndex) + copy(dAtA[i:], x.AfterIndex) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AfterIndex))) + i-- + dAtA[i] = 0x52 + } + if len(x.BeforeIndex) > 0 { + i -= len(x.BeforeIndex) + copy(dAtA[i:], x.BeforeIndex) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.BeforeIndex))) + i-- + dAtA[i] = 0x4a + } if x.MoveCount != 0 { i = runtime.EncodeVarint(dAtA, i, uint64(x.MoveCount)) i-- @@ -829,6 +893,70 @@ func (x *fastReflection_StoredGame) ProtoMethods() *protoiface.Methods { break } } + case 9: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field BeforeIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.BeforeIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AfterIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.AfterIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -882,14 +1010,16 @@ type StoredGame struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Index string `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"` - Board string `protobuf:"bytes,2,opt,name=board,proto3" json:"board,omitempty"` - Turn string `protobuf:"bytes,3,opt,name=turn,proto3" json:"turn,omitempty"` - Black string `protobuf:"bytes,4,opt,name=black,proto3" json:"black,omitempty"` - Red string `protobuf:"bytes,5,opt,name=red,proto3" json:"red,omitempty"` - Winner string `protobuf:"bytes,6,opt,name=winner,proto3" json:"winner,omitempty"` - Deadline string `protobuf:"bytes,7,opt,name=deadline,proto3" json:"deadline,omitempty"` - MoveCount uint64 `protobuf:"varint,8,opt,name=moveCount,proto3" json:"moveCount,omitempty"` + Index string `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"` + Board string `protobuf:"bytes,2,opt,name=board,proto3" json:"board,omitempty"` + Turn string `protobuf:"bytes,3,opt,name=turn,proto3" json:"turn,omitempty"` + Black string `protobuf:"bytes,4,opt,name=black,proto3" json:"black,omitempty"` + Red string `protobuf:"bytes,5,opt,name=red,proto3" json:"red,omitempty"` + Winner string `protobuf:"bytes,6,opt,name=winner,proto3" json:"winner,omitempty"` + Deadline string `protobuf:"bytes,7,opt,name=deadline,proto3" json:"deadline,omitempty"` + MoveCount uint64 `protobuf:"varint,8,opt,name=moveCount,proto3" json:"moveCount,omitempty"` + BeforeIndex string `protobuf:"bytes,9,opt,name=beforeIndex,proto3" json:"beforeIndex,omitempty"` // Pertains to the FIFO. Toward head. + AfterIndex string `protobuf:"bytes,10,opt,name=afterIndex,proto3" json:"afterIndex,omitempty"` // Pertains to the FIFO. Toward tail. } func (x *StoredGame) Reset() { @@ -968,13 +1098,27 @@ func (x *StoredGame) GetMoveCount() uint64 { return 0 } +func (x *StoredGame) GetBeforeIndex() string { + if x != nil { + return x.BeforeIndex + } + return "" +} + +func (x *StoredGame) GetAfterIndex() string { + if x != nil { + return x.AfterIndex + } + return "" +} + var File_checkers_checkers_stored_game_proto protoreflect.FileDescriptor var file_checkers_checkers_stored_game_proto_rawDesc = []byte{ 0x0a, 0x23, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x5f, 0x67, 0x61, 0x6d, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x11, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2e, - 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x22, 0xc6, 0x01, 0x0a, 0x0a, 0x53, 0x74, 0x6f, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x22, 0x88, 0x02, 0x0a, 0x0a, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x64, 0x47, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x62, 0x6f, @@ -987,19 +1131,23 @@ var file_checkers_checkers_stored_game_proto_rawDesc = []byte{ 0x69, 0x6e, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6d, 0x6f, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x6d, 0x6f, 0x76, 0x65, 0x43, 0x6f, 0x75, 0x6e, - 0x74, 0x42, 0xc2, 0x01, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, - 0x72, 0x73, 0x2e, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x42, 0x0f, 0x53, 0x74, 0x6f, - 0x72, 0x65, 0x64, 0x47, 0x61, 0x6d, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x6c, 0x69, 0x6d, 0x64, - 0x7a, 0x68, 0x6f, 0x6e, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x61, 0x70, - 0x69, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, - 0x65, 0x72, 0x73, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x11, 0x43, 0x68, 0x65, 0x63, - 0x6b, 0x65, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0xca, 0x02, 0x11, - 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, - 0x73, 0xe2, 0x02, 0x1d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x43, 0x68, 0x65, - 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0xea, 0x02, 0x12, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x3a, 0x3a, 0x43, 0x68, - 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x49, 0x6e, 0x64, 0x65, 0x78, + 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x49, 0x6e, + 0x64, 0x65, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x66, 0x74, 0x65, 0x72, 0x49, 0x6e, 0x64, 0x65, + 0x78, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x66, 0x74, 0x65, 0x72, 0x49, 0x6e, + 0x64, 0x65, 0x78, 0x42, 0xc2, 0x01, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x65, 0x72, 0x73, 0x2e, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x42, 0x0f, 0x53, + 0x74, 0x6f, 0x72, 0x65, 0x64, 0x47, 0x61, 0x6d, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, + 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x6c, 0x69, + 0x6d, 0x64, 0x7a, 0x68, 0x6f, 0x6e, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x65, 0x72, 0x73, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x11, 0x43, 0x68, + 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0xca, + 0x02, 0x11, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x43, 0x68, 0x65, 0x63, 0x6b, + 0x65, 0x72, 0x73, 0xe2, 0x02, 0x1d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x43, + 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0xea, 0x02, 0x12, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x3a, 0x3a, + 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/checkers/checkers/system_info.pulsar.go b/api/checkers/checkers/system_info.pulsar.go index 4ea584a..2a9408f 100644 --- a/api/checkers/checkers/system_info.pulsar.go +++ b/api/checkers/checkers/system_info.pulsar.go @@ -13,14 +13,18 @@ import ( ) var ( - md_SystemInfo protoreflect.MessageDescriptor - fd_SystemInfo_nextId protoreflect.FieldDescriptor + md_SystemInfo protoreflect.MessageDescriptor + fd_SystemInfo_nextId protoreflect.FieldDescriptor + fd_SystemInfo_fifoHeadIndex protoreflect.FieldDescriptor + fd_SystemInfo_fifoTailIndex protoreflect.FieldDescriptor ) func init() { file_checkers_checkers_system_info_proto_init() md_SystemInfo = File_checkers_checkers_system_info_proto.Messages().ByName("SystemInfo") fd_SystemInfo_nextId = md_SystemInfo.Fields().ByName("nextId") + fd_SystemInfo_fifoHeadIndex = md_SystemInfo.Fields().ByName("fifoHeadIndex") + fd_SystemInfo_fifoTailIndex = md_SystemInfo.Fields().ByName("fifoTailIndex") } var _ protoreflect.Message = (*fastReflection_SystemInfo)(nil) @@ -94,6 +98,18 @@ func (x *fastReflection_SystemInfo) Range(f func(protoreflect.FieldDescriptor, p return } } + if x.FifoHeadIndex != "" { + value := protoreflect.ValueOfString(x.FifoHeadIndex) + if !f(fd_SystemInfo_fifoHeadIndex, value) { + return + } + } + if x.FifoTailIndex != "" { + value := protoreflect.ValueOfString(x.FifoTailIndex) + if !f(fd_SystemInfo_fifoTailIndex, value) { + return + } + } } // Has reports whether a field is populated. @@ -111,6 +127,10 @@ func (x *fastReflection_SystemInfo) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { case "checkers.checkers.SystemInfo.nextId": return x.NextId != uint64(0) + case "checkers.checkers.SystemInfo.fifoHeadIndex": + return x.FifoHeadIndex != "" + case "checkers.checkers.SystemInfo.fifoTailIndex": + return x.FifoTailIndex != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.SystemInfo")) @@ -129,6 +149,10 @@ func (x *fastReflection_SystemInfo) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { case "checkers.checkers.SystemInfo.nextId": x.NextId = uint64(0) + case "checkers.checkers.SystemInfo.fifoHeadIndex": + x.FifoHeadIndex = "" + case "checkers.checkers.SystemInfo.fifoTailIndex": + x.FifoTailIndex = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.SystemInfo")) @@ -148,6 +172,12 @@ func (x *fastReflection_SystemInfo) Get(descriptor protoreflect.FieldDescriptor) case "checkers.checkers.SystemInfo.nextId": value := x.NextId return protoreflect.ValueOfUint64(value) + case "checkers.checkers.SystemInfo.fifoHeadIndex": + value := x.FifoHeadIndex + return protoreflect.ValueOfString(value) + case "checkers.checkers.SystemInfo.fifoTailIndex": + value := x.FifoTailIndex + return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.SystemInfo")) @@ -170,6 +200,10 @@ func (x *fastReflection_SystemInfo) Set(fd protoreflect.FieldDescriptor, value p switch fd.FullName() { case "checkers.checkers.SystemInfo.nextId": x.NextId = value.Uint() + case "checkers.checkers.SystemInfo.fifoHeadIndex": + x.FifoHeadIndex = value.Interface().(string) + case "checkers.checkers.SystemInfo.fifoTailIndex": + x.FifoTailIndex = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.SystemInfo")) @@ -192,6 +226,10 @@ func (x *fastReflection_SystemInfo) Mutable(fd protoreflect.FieldDescriptor) pro switch fd.FullName() { case "checkers.checkers.SystemInfo.nextId": panic(fmt.Errorf("field nextId of message checkers.checkers.SystemInfo is not mutable")) + case "checkers.checkers.SystemInfo.fifoHeadIndex": + panic(fmt.Errorf("field fifoHeadIndex of message checkers.checkers.SystemInfo is not mutable")) + case "checkers.checkers.SystemInfo.fifoTailIndex": + panic(fmt.Errorf("field fifoTailIndex of message checkers.checkers.SystemInfo is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.SystemInfo")) @@ -207,6 +245,10 @@ func (x *fastReflection_SystemInfo) NewField(fd protoreflect.FieldDescriptor) pr switch fd.FullName() { case "checkers.checkers.SystemInfo.nextId": return protoreflect.ValueOfUint64(uint64(0)) + case "checkers.checkers.SystemInfo.fifoHeadIndex": + return protoreflect.ValueOfString("") + case "checkers.checkers.SystemInfo.fifoTailIndex": + return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: checkers.checkers.SystemInfo")) @@ -279,6 +321,14 @@ func (x *fastReflection_SystemInfo) ProtoMethods() *protoiface.Methods { if x.NextId != 0 { n += 1 + runtime.Sov(uint64(x.NextId)) } + l = len(x.FifoHeadIndex) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.FifoTailIndex) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -308,6 +358,20 @@ func (x *fastReflection_SystemInfo) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.FifoTailIndex) > 0 { + i -= len(x.FifoTailIndex) + copy(dAtA[i:], x.FifoTailIndex) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.FifoTailIndex))) + i-- + dAtA[i] = 0x1a + } + if len(x.FifoHeadIndex) > 0 { + i -= len(x.FifoHeadIndex) + copy(dAtA[i:], x.FifoHeadIndex) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.FifoHeadIndex))) + i-- + dAtA[i] = 0x12 + } if x.NextId != 0 { i = runtime.EncodeVarint(dAtA, i, uint64(x.NextId)) i-- @@ -381,6 +445,70 @@ func (x *fastReflection_SystemInfo) ProtoMethods() *protoiface.Methods { break } } + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FifoHeadIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.FifoHeadIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FifoTailIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.FifoTailIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -434,7 +562,9 @@ type SystemInfo struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - NextId uint64 `protobuf:"varint,1,opt,name=nextId,proto3" json:"nextId,omitempty"` + NextId uint64 `protobuf:"varint,1,opt,name=nextId,proto3" json:"nextId,omitempty"` + FifoHeadIndex string `protobuf:"bytes,2,opt,name=fifoHeadIndex,proto3" json:"fifoHeadIndex,omitempty"` + FifoTailIndex string `protobuf:"bytes,3,opt,name=fifoTailIndex,proto3" json:"fifoTailIndex,omitempty"` } func (x *SystemInfo) Reset() { @@ -464,28 +594,47 @@ func (x *SystemInfo) GetNextId() uint64 { return 0 } +func (x *SystemInfo) GetFifoHeadIndex() string { + if x != nil { + return x.FifoHeadIndex + } + return "" +} + +func (x *SystemInfo) GetFifoTailIndex() string { + if x != nil { + return x.FifoTailIndex + } + return "" +} + var File_checkers_checkers_system_info_proto protoreflect.FileDescriptor var file_checkers_checkers_system_info_proto_rawDesc = []byte{ 0x0a, 0x23, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x11, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2e, - 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x22, 0x24, 0x0a, 0x0a, 0x53, 0x79, 0x73, 0x74, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x22, 0x70, 0x0a, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x65, 0x78, 0x74, 0x49, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x65, 0x78, 0x74, 0x49, 0x64, 0x42, 0xc2, - 0x01, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2e, - 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x42, 0x0f, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, - 0x49, 0x6e, 0x66, 0x6f, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x6c, 0x69, 0x6d, 0x64, 0x7a, 0x68, 0x6f, - 0x6e, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, - 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, - 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x11, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, - 0x73, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0xca, 0x02, 0x11, 0x43, 0x68, 0x65, - 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0xe2, 0x02, - 0x1d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, - 0x72, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, - 0x12, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x3a, 0x3a, 0x43, 0x68, 0x65, 0x63, 0x6b, - 0x65, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x65, 0x78, 0x74, 0x49, 0x64, 0x12, 0x24, + 0x0a, 0x0d, 0x66, 0x69, 0x66, 0x6f, 0x48, 0x65, 0x61, 0x64, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x66, 0x69, 0x66, 0x6f, 0x48, 0x65, 0x61, 0x64, 0x49, + 0x6e, 0x64, 0x65, 0x78, 0x12, 0x24, 0x0a, 0x0d, 0x66, 0x69, 0x66, 0x6f, 0x54, 0x61, 0x69, 0x6c, + 0x49, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x66, 0x69, 0x66, + 0x6f, 0x54, 0x61, 0x69, 0x6c, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x42, 0xc2, 0x01, 0x0a, 0x15, 0x63, + 0x6f, 0x6d, 0x2e, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2e, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x65, 0x72, 0x73, 0x42, 0x0f, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, + 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x6c, 0x69, 0x6d, 0x64, 0x7a, 0x68, 0x6f, 0x6e, 0x2f, 0x63, 0x68, + 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, + 0x65, 0x72, 0x73, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0xa2, 0x02, 0x03, 0x43, + 0x43, 0x58, 0xaa, 0x02, 0x11, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x2e, 0x43, 0x68, + 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0xca, 0x02, 0x11, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, + 0x73, 0x5c, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0xe2, 0x02, 0x1d, 0x43, 0x68, 0x65, + 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x12, 0x43, 0x68, 0x65, + 0x63, 0x6b, 0x65, 0x72, 0x73, 0x3a, 0x3a, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x65, 0x72, 0x73, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 8c24085..5ed8ab4 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -1 +1 @@ -{"id":"github.com/olimdzhon/checkers","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/olimdzhon/checkers REST API","title":"HTTP API Console","contact":{"name":"github.com/olimdzhon/checkers"},"version":"version not set"},"paths":{"/checkers.checkers.Msg/CreateGame":{"post":{"tags":["Msg"],"operationId":"GithubComolimdzhoncheckersMsg_CreateGame","parameters":[{"name":"body","in":"body","required":true,"schema":{"$ref":"#/definitions/checkers.checkers.MsgCreateGame"}}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.MsgCreateGameResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/checkers.checkers.Msg/PlayMove":{"post":{"tags":["Msg"],"operationId":"GithubComolimdzhoncheckersMsg_PlayMove","parameters":[{"name":"body","in":"body","required":true,"schema":{"$ref":"#/definitions/checkers.checkers.MsgPlayMove"}}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.MsgPlayMoveResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/checkers.checkers.Msg/UpdateParams":{"post":{"tags":["Msg"],"summary":"UpdateParams defines a (governance) operation for updating the module\nparameters. The authority defaults to the x/gov module account.","operationId":"GithubComolimdzhoncheckersMsg_UpdateParams","parameters":[{"description":"MsgUpdateParams is the Msg/UpdateParams request type.","name":"body","in":"body","required":true,"schema":{"$ref":"#/definitions/checkers.checkers.MsgUpdateParams"}}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.MsgUpdateParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComolimdzhoncheckersQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/stored_game":{"get":{"tags":["Query"],"operationId":"GithubComolimdzhoncheckersQuery_StoredGameAll","parameters":[{"type":"string","format":"byte","description":"key is a value returned in PageResponse.next_key to begin\nquerying the next page most efficiently. Only one of offset or key\nshould be set.","name":"pagination.key","in":"query"},{"type":"string","format":"uint64","description":"offset is a numeric offset that can be used when key is unavailable.\nIt is less efficient than using key. Only one of offset or key should\nbe set.","name":"pagination.offset","in":"query"},{"type":"string","format":"uint64","description":"limit is the total number of results to be returned in the result page.\nIf left empty it will default to a value to be set by each app.","name":"pagination.limit","in":"query"},{"type":"boolean","description":"count_total is set to true to indicate that the result set should include\na count of the total number of items available for pagination in UIs.\ncount_total is only respected when offset is used. It is ignored when key\nis set.","name":"pagination.count_total","in":"query"},{"type":"boolean","description":"reverse is set to true if results are to be returned in the descending order.\n\nSince: cosmos-sdk 0.43","name":"pagination.reverse","in":"query"}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryAllStoredGameResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/stored_game/{index}":{"get":{"tags":["Query"],"summary":"Queries a list of StoredGame items.","operationId":"GithubComolimdzhoncheckersQuery_StoredGame","parameters":[{"type":"string","name":"index","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryGetStoredGameResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/system_info":{"get":{"tags":["Query"],"summary":"Queries a SystemInfo by index.","operationId":"GithubComolimdzhoncheckersQuery_SystemInfo","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryGetSystemInfoResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"checkers.checkers.MsgCreateGame":{"type":"object","properties":{"black":{"type":"string"},"creator":{"type":"string"},"red":{"type":"string"}}},"checkers.checkers.MsgCreateGameResponse":{"type":"object","properties":{"gameIndex":{"type":"string"}}},"checkers.checkers.MsgPlayMove":{"type":"object","properties":{"creator":{"type":"string"},"fromX":{"type":"string","format":"uint64"},"fromY":{"type":"string","format":"uint64"},"gameIndex":{"type":"string"},"toX":{"type":"string","format":"uint64"},"toY":{"type":"string","format":"uint64"}}},"checkers.checkers.MsgPlayMoveResponse":{"type":"object","properties":{"capturedX":{"type":"integer","format":"int32"},"capturedY":{"type":"integer","format":"int32"},"winner":{"type":"string"}}},"checkers.checkers.MsgUpdateParams":{"description":"MsgUpdateParams is the Msg/UpdateParams request type.","type":"object","properties":{"authority":{"description":"authority is the address that controls the module (defaults to x/gov unless overwritten).","type":"string"},"params":{"description":"NOTE: All parameters must be supplied.","$ref":"#/definitions/checkers.checkers.Params"}}},"checkers.checkers.MsgUpdateParamsResponse":{"description":"MsgUpdateParamsResponse defines the response structure for executing a\nMsgUpdateParams message.","type":"object"},"checkers.checkers.Params":{"description":"Params defines the parameters for the module.","type":"object"},"checkers.checkers.QueryAllStoredGameResponse":{"type":"object","properties":{"pagination":{"$ref":"#/definitions/cosmos.base.query.v1beta1.PageResponse"},"storedGame":{"type":"array","items":{"type":"object","$ref":"#/definitions/checkers.checkers.StoredGame"}}}},"checkers.checkers.QueryGetStoredGameResponse":{"type":"object","properties":{"storedGame":{"$ref":"#/definitions/checkers.checkers.StoredGame"}}},"checkers.checkers.QueryGetSystemInfoResponse":{"type":"object","properties":{"SystemInfo":{"$ref":"#/definitions/checkers.checkers.SystemInfo"}}},"checkers.checkers.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/checkers.checkers.Params"}}},"checkers.checkers.StoredGame":{"type":"object","properties":{"black":{"type":"string"},"board":{"type":"string"},"deadline":{"type":"string"},"index":{"type":"string"},"moveCount":{"type":"string","format":"uint64"},"red":{"type":"string"},"turn":{"type":"string"},"winner":{"type":"string"}}},"checkers.checkers.SystemInfo":{"type":"object","properties":{"nextId":{"type":"string","format":"uint64"}}},"cosmos.base.query.v1beta1.PageRequest":{"description":"message SomeRequest {\n Foo some_parameter = 1;\n PageRequest pagination = 2;\n }","type":"object","title":"PageRequest is to be embedded in gRPC request messages for efficient\npagination. Ex:","properties":{"count_total":{"description":"count_total is set to true to indicate that the result set should include\na count of the total number of items available for pagination in UIs.\ncount_total is only respected when offset is used. It is ignored when key\nis set.","type":"boolean"},"key":{"description":"key is a value returned in PageResponse.next_key to begin\nquerying the next page most efficiently. Only one of offset or key\nshould be set.","type":"string","format":"byte"},"limit":{"description":"limit is the total number of results to be returned in the result page.\nIf left empty it will default to a value to be set by each app.","type":"string","format":"uint64"},"offset":{"description":"offset is a numeric offset that can be used when key is unavailable.\nIt is less efficient than using key. Only one of offset or key should\nbe set.","type":"string","format":"uint64"},"reverse":{"description":"reverse is set to true if results are to be returned in the descending order.\n\nSince: cosmos-sdk 0.43","type":"boolean"}}},"cosmos.base.query.v1beta1.PageResponse":{"description":"PageResponse is to be embedded in gRPC response messages where the\ncorresponding request message has used PageRequest.\n\n message SomeResponse {\n repeated Bar results = 1;\n PageResponse page = 2;\n }","type":"object","properties":{"next_key":{"description":"next_key is the key to be passed to PageRequest.key to\nquery the next page most efficiently. It will be empty if\nthere are no more results.","type":"string","format":"byte"},"total":{"type":"string","format":"uint64","title":"total is total number of results available if PageRequest.count_total\nwas set, its value is undefined otherwise"}}},"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file +{"id":"github.com/olimdzhon/checkers","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/olimdzhon/checkers REST API","title":"HTTP API Console","contact":{"name":"github.com/olimdzhon/checkers"},"version":"version not set"},"paths":{"/checkers.checkers.Msg/CreateGame":{"post":{"tags":["Msg"],"operationId":"GithubComolimdzhoncheckersMsg_CreateGame","parameters":[{"name":"body","in":"body","required":true,"schema":{"$ref":"#/definitions/checkers.checkers.MsgCreateGame"}}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.MsgCreateGameResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/checkers.checkers.Msg/PlayMove":{"post":{"tags":["Msg"],"operationId":"GithubComolimdzhoncheckersMsg_PlayMove","parameters":[{"name":"body","in":"body","required":true,"schema":{"$ref":"#/definitions/checkers.checkers.MsgPlayMove"}}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.MsgPlayMoveResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/checkers.checkers.Msg/UpdateParams":{"post":{"tags":["Msg"],"summary":"UpdateParams defines a (governance) operation for updating the module\nparameters. The authority defaults to the x/gov module account.","operationId":"GithubComolimdzhoncheckersMsg_UpdateParams","parameters":[{"description":"MsgUpdateParams is the Msg/UpdateParams request type.","name":"body","in":"body","required":true,"schema":{"$ref":"#/definitions/checkers.checkers.MsgUpdateParams"}}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.MsgUpdateParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComolimdzhoncheckersQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/stored_game":{"get":{"tags":["Query"],"operationId":"GithubComolimdzhoncheckersQuery_StoredGameAll","parameters":[{"type":"string","format":"byte","description":"key is a value returned in PageResponse.next_key to begin\nquerying the next page most efficiently. Only one of offset or key\nshould be set.","name":"pagination.key","in":"query"},{"type":"string","format":"uint64","description":"offset is a numeric offset that can be used when key is unavailable.\nIt is less efficient than using key. Only one of offset or key should\nbe set.","name":"pagination.offset","in":"query"},{"type":"string","format":"uint64","description":"limit is the total number of results to be returned in the result page.\nIf left empty it will default to a value to be set by each app.","name":"pagination.limit","in":"query"},{"type":"boolean","description":"count_total is set to true to indicate that the result set should include\na count of the total number of items available for pagination in UIs.\ncount_total is only respected when offset is used. It is ignored when key\nis set.","name":"pagination.count_total","in":"query"},{"type":"boolean","description":"reverse is set to true if results are to be returned in the descending order.\n\nSince: cosmos-sdk 0.43","name":"pagination.reverse","in":"query"}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryAllStoredGameResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/stored_game/{index}":{"get":{"tags":["Query"],"summary":"Queries a list of StoredGame items.","operationId":"GithubComolimdzhoncheckersQuery_StoredGame","parameters":[{"type":"string","name":"index","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryGetStoredGameResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/olimdzhon/checkers/checkers/system_info":{"get":{"tags":["Query"],"summary":"Queries a SystemInfo by index.","operationId":"GithubComolimdzhoncheckersQuery_SystemInfo","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/checkers.checkers.QueryGetSystemInfoResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"checkers.checkers.MsgCreateGame":{"type":"object","properties":{"black":{"type":"string"},"creator":{"type":"string"},"red":{"type":"string"}}},"checkers.checkers.MsgCreateGameResponse":{"type":"object","properties":{"gameIndex":{"type":"string"}}},"checkers.checkers.MsgPlayMove":{"type":"object","properties":{"creator":{"type":"string"},"fromX":{"type":"string","format":"uint64"},"fromY":{"type":"string","format":"uint64"},"gameIndex":{"type":"string"},"toX":{"type":"string","format":"uint64"},"toY":{"type":"string","format":"uint64"}}},"checkers.checkers.MsgPlayMoveResponse":{"type":"object","properties":{"capturedX":{"type":"integer","format":"int32"},"capturedY":{"type":"integer","format":"int32"},"winner":{"type":"string"}}},"checkers.checkers.MsgUpdateParams":{"description":"MsgUpdateParams is the Msg/UpdateParams request type.","type":"object","properties":{"authority":{"description":"authority is the address that controls the module (defaults to x/gov unless overwritten).","type":"string"},"params":{"description":"NOTE: All parameters must be supplied.","$ref":"#/definitions/checkers.checkers.Params"}}},"checkers.checkers.MsgUpdateParamsResponse":{"description":"MsgUpdateParamsResponse defines the response structure for executing a\nMsgUpdateParams message.","type":"object"},"checkers.checkers.Params":{"description":"Params defines the parameters for the module.","type":"object"},"checkers.checkers.QueryAllStoredGameResponse":{"type":"object","properties":{"pagination":{"$ref":"#/definitions/cosmos.base.query.v1beta1.PageResponse"},"storedGame":{"type":"array","items":{"type":"object","$ref":"#/definitions/checkers.checkers.StoredGame"}}}},"checkers.checkers.QueryGetStoredGameResponse":{"type":"object","properties":{"storedGame":{"$ref":"#/definitions/checkers.checkers.StoredGame"}}},"checkers.checkers.QueryGetSystemInfoResponse":{"type":"object","properties":{"SystemInfo":{"$ref":"#/definitions/checkers.checkers.SystemInfo"}}},"checkers.checkers.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/checkers.checkers.Params"}}},"checkers.checkers.StoredGame":{"type":"object","properties":{"afterIndex":{"description":"Pertains to the FIFO. Toward tail.","type":"string"},"beforeIndex":{"description":"Pertains to the FIFO. Toward head.","type":"string"},"black":{"type":"string"},"board":{"type":"string"},"deadline":{"type":"string"},"index":{"type":"string"},"moveCount":{"type":"string","format":"uint64"},"red":{"type":"string"},"turn":{"type":"string"},"winner":{"type":"string"}}},"checkers.checkers.SystemInfo":{"type":"object","properties":{"fifoHeadIndex":{"type":"string"},"fifoTailIndex":{"type":"string"},"nextId":{"type":"string","format":"uint64"}}},"cosmos.base.query.v1beta1.PageRequest":{"description":"message SomeRequest {\n Foo some_parameter = 1;\n PageRequest pagination = 2;\n }","type":"object","title":"PageRequest is to be embedded in gRPC request messages for efficient\npagination. Ex:","properties":{"count_total":{"description":"count_total is set to true to indicate that the result set should include\na count of the total number of items available for pagination in UIs.\ncount_total is only respected when offset is used. It is ignored when key\nis set.","type":"boolean"},"key":{"description":"key is a value returned in PageResponse.next_key to begin\nquerying the next page most efficiently. Only one of offset or key\nshould be set.","type":"string","format":"byte"},"limit":{"description":"limit is the total number of results to be returned in the result page.\nIf left empty it will default to a value to be set by each app.","type":"string","format":"uint64"},"offset":{"description":"offset is a numeric offset that can be used when key is unavailable.\nIt is less efficient than using key. Only one of offset or key should\nbe set.","type":"string","format":"uint64"},"reverse":{"description":"reverse is set to true if results are to be returned in the descending order.\n\nSince: cosmos-sdk 0.43","type":"boolean"}}},"cosmos.base.query.v1beta1.PageResponse":{"description":"PageResponse is to be embedded in gRPC response messages where the\ncorresponding request message has used PageRequest.\n\n message SomeResponse {\n repeated Bar results = 1;\n PageResponse page = 2;\n }","type":"object","properties":{"next_key":{"description":"next_key is the key to be passed to PageRequest.key to\nquery the next page most efficiently. It will be empty if\nthere are no more results.","type":"string","format":"byte"},"total":{"type":"string","format":"uint64","title":"total is total number of results available if PageRequest.count_total\nwas set, its value is undefined otherwise"}}},"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file diff --git a/proto/checkers/checkers/stored_game.proto b/proto/checkers/checkers/stored_game.proto index 1ab362e..6331b40 100644 --- a/proto/checkers/checkers/stored_game.proto +++ b/proto/checkers/checkers/stored_game.proto @@ -12,5 +12,7 @@ message StoredGame { string winner = 6; string deadline = 7; uint64 moveCount = 8; + string beforeIndex = 9; // Pertains to the FIFO. Toward head. + string afterIndex = 10; // Pertains to the FIFO. Toward tail. } diff --git a/proto/checkers/checkers/system_info.proto b/proto/checkers/checkers/system_info.proto index f77af26..5b1bd30 100644 --- a/proto/checkers/checkers/system_info.proto +++ b/proto/checkers/checkers/system_info.proto @@ -5,5 +5,6 @@ option go_package = "github.com/olimdzhon/checkers/x/checkers/types"; message SystemInfo { uint64 nextId = 1; - + string fifoHeadIndex = 2; + string fifoTailIndex = 3; } diff --git a/x/checkers/keeper/msg_server_create_game.go b/x/checkers/keeper/msg_server_create_game.go index ba6cf2d..660c308 100644 --- a/x/checkers/keeper/msg_server_create_game.go +++ b/x/checkers/keeper/msg_server_create_game.go @@ -28,6 +28,8 @@ func (k msgServer) CreateGame(goCtx context.Context, msg *types.MsgCreateGame) ( Winner: rules.PieceStrings[rules.NO_PLAYER], Deadline: types.FormatDeadline(types.GetNextDeadline(ctx)), MoveCount: 0, + BeforeIndex: types.NoFifoIndex, + AfterIndex: types.NoFifoIndex, } err := storedGame.Validate() @@ -35,6 +37,7 @@ func (k msgServer) CreateGame(goCtx context.Context, msg *types.MsgCreateGame) ( return nil, err } + k.Keeper.SendToFifoTail(ctx, &storedGame, &systemInfo) k.Keeper.SetStoredGame(ctx, storedGame) systemInfo.NextId++ k.Keeper.SetSystemInfo(ctx, systemInfo) diff --git a/x/checkers/keeper/msg_server_create_game_fifo_test.go b/x/checkers/keeper/msg_server_create_game_fifo_test.go new file mode 100644 index 0000000..ff14631 --- /dev/null +++ b/x/checkers/keeper/msg_server_create_game_fifo_test.go @@ -0,0 +1,179 @@ +package keeper_test + +import ( + "testing" + + "github.com/olimdzhon/checkers/x/checkers/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +func TestCreate3GamesHasSavedFifo(t *testing.T) { + msgSrvr, keeper, context := setupMsgServerCreateGame(t) + ctx := sdk.UnwrapSDKContext(context) + msgSrvr.CreateGame(context, &types.MsgCreateGame{ + Creator: alice, + Black: bob, + Red: carol, + }) + + // Second game + msgSrvr.CreateGame(context, &types.MsgCreateGame{ + Creator: bob, + Black: carol, + Red: alice, + }) + systemInfo2, found := keeper.GetSystemInfo(ctx) + require.True(t, found) + require.EqualValues(t, types.SystemInfo{ + NextId: 3, + FifoHeadIndex: "1", + FifoTailIndex: "2", + }, systemInfo2) + game1, found := keeper.GetStoredGame(ctx, "1") + require.True(t, found) + require.EqualValues(t, types.StoredGame{ + Index: "1", + Board: "*b*b*b*b|b*b*b*b*|*b*b*b*b|********|********|r*r*r*r*|*r*r*r*r|r*r*r*r*", + Turn: "b", + Black: bob, + Red: carol, + Winner: "*", + Deadline: types.FormatDeadline(ctx.BlockTime().Add(types.MaxTurnDuration)), + MoveCount: uint64(0), + BeforeIndex: "-1", + AfterIndex: "2", + }, game1) + game2, found := keeper.GetStoredGame(ctx, "2") + require.True(t, found) + require.EqualValues(t, types.StoredGame{ + Index: "2", + Board: "*b*b*b*b|b*b*b*b*|*b*b*b*b|********|********|r*r*r*r*|*r*r*r*r|r*r*r*r*", + Turn: "b", + Black: carol, + Red: alice, + Winner: "*", + Deadline: types.FormatDeadline(ctx.BlockTime().Add(types.MaxTurnDuration)), + MoveCount: uint64(0), + BeforeIndex: "1", + AfterIndex: "-1", + }, game2) + + // Third game + msgSrvr.CreateGame(context, &types.MsgCreateGame{ + Creator: carol, + Black: alice, + Red: bob, + }) + systemInfo3, found := keeper.GetSystemInfo(ctx) + require.True(t, found) + require.EqualValues(t, types.SystemInfo{ + NextId: 4, + FifoHeadIndex: "1", + FifoTailIndex: "3", + }, systemInfo3) + game1, found = keeper.GetStoredGame(ctx, "1") + require.True(t, found) + require.EqualValues(t, types.StoredGame{ + Index: "1", + Board: "*b*b*b*b|b*b*b*b*|*b*b*b*b|********|********|r*r*r*r*|*r*r*r*r|r*r*r*r*", + Turn: "b", + Black: bob, + Red: carol, + Winner: "*", + Deadline: types.FormatDeadline(ctx.BlockTime().Add(types.MaxTurnDuration)), + MoveCount: uint64(0), + BeforeIndex: "-1", + AfterIndex: "2", + }, game1) + game2, found = keeper.GetStoredGame(ctx, "2") + require.True(t, found) + require.EqualValues(t, types.StoredGame{ + Index: "2", + Board: "*b*b*b*b|b*b*b*b*|*b*b*b*b|********|********|r*r*r*r*|*r*r*r*r|r*r*r*r*", + Turn: "b", + Black: carol, + Red: alice, + Winner: "*", + Deadline: types.FormatDeadline(ctx.BlockTime().Add(types.MaxTurnDuration)), + MoveCount: uint64(0), + BeforeIndex: "1", + AfterIndex: "3", + }, game2) + game3, found := keeper.GetStoredGame(ctx, "3") + require.True(t, found) + require.EqualValues(t, types.StoredGame{ + Index: "3", + Board: "*b*b*b*b|b*b*b*b*|*b*b*b*b|********|********|r*r*r*r*|*r*r*r*r|r*r*r*r*", + Turn: "b", + Black: alice, + Red: bob, + Winner: "*", + Deadline: types.FormatDeadline(ctx.BlockTime().Add(types.MaxTurnDuration)), + MoveCount: uint64(0), + BeforeIndex: "2", + AfterIndex: "-1", + }, game3) +} + +func TestPlayMove2Games2MovesHasSavedFifo(t *testing.T) { + msgServer, keeper, context := setupMsgServerWithOneGameForPlayMove(t) + ctx := sdk.UnwrapSDKContext(context) + msgServer.CreateGame(context, &types.MsgCreateGame{ + Creator: bob, + Black: carol, + Red: alice, + }) + msgServer.PlayMove(context, &types.MsgPlayMove{ + Creator: bob, + GameIndex: "1", + FromX: 1, + FromY: 2, + ToX: 2, + ToY: 3, + }) + + msgServer.PlayMove(context, &types.MsgPlayMove{ + Creator: carol, + GameIndex: "2", + FromX: 1, + FromY: 2, + ToX: 2, + ToY: 3, + }) + systemInfo1, found := keeper.GetSystemInfo(ctx) + require.True(t, found) + require.EqualValues(t, types.SystemInfo{ + NextId: 3, + FifoHeadIndex: "1", + FifoTailIndex: "2", + }, systemInfo1) + game1, found := keeper.GetStoredGame(ctx, "1") + require.True(t, found) + require.EqualValues(t, types.StoredGame{ + Index: "1", + Board: "*b*b*b*b|b*b*b*b*|***b*b*b|**b*****|********|r*r*r*r*|*r*r*r*r|r*r*r*r*", + Turn: "r", + Black: bob, + Red: carol, + Winner: "*", + Deadline: types.FormatDeadline(ctx.BlockTime().Add(types.MaxTurnDuration)), + MoveCount: uint64(1), + BeforeIndex: "-1", + AfterIndex: "2", + }, game1) + game2, found := keeper.GetStoredGame(ctx, "2") + require.True(t, found) + require.EqualValues(t, types.StoredGame{ + Index: "2", + Board: "*b*b*b*b|b*b*b*b*|***b*b*b|**b*****|********|r*r*r*r*|*r*r*r*r|r*r*r*r*", + Turn: "r", + Black: carol, + Red: alice, + Winner: "*", + Deadline: types.FormatDeadline(ctx.BlockTime().Add(types.MaxTurnDuration)), + MoveCount: uint64(1), + BeforeIndex: "1", + AfterIndex: "-1", + }, game2) +} \ No newline at end of file diff --git a/x/checkers/keeper/msg_server_play_move.go b/x/checkers/keeper/msg_server_play_move.go index c4ad7d2..61bd03c 100644 --- a/x/checkers/keeper/msg_server_play_move.go +++ b/x/checkers/keeper/msg_server_play_move.go @@ -61,16 +61,26 @@ func (k msgServer) PlayMove(goCtx context.Context, msg *types.MsgPlayMove) (*typ storedGame.Winner = rules.PieceStrings[game.Winner()] lastBoard := game.String() + + systemInfo, found := k.Keeper.GetSystemInfo(ctx) + if !found { + panic("SystemInfo not found") + } + if storedGame.Winner == rules.PieceStrings[rules.NO_PLAYER] { storedGame.Board = lastBoard + k.Keeper.SendToFifoTail(ctx, &storedGame, &systemInfo) } else { storedGame.Board = "" + k.Keeper.RemoveFromFifo(ctx, &storedGame, &systemInfo) } storedGame.Deadline = types.FormatDeadline(types.GetNextDeadline(ctx)) storedGame.MoveCount++ storedGame.Turn = rules.PieceStrings[game.Turn] k.Keeper.SetStoredGame(ctx, storedGame) + k.Keeper.SetSystemInfo(ctx, systemInfo) + ctx.EventManager().EmitEvent( sdk.NewEvent(types.MovePlayedEventType, diff --git a/x/checkers/keeper/stored_game_in_fifo.go b/x/checkers/keeper/stored_game_in_fifo.go new file mode 100644 index 0000000..9425de0 --- /dev/null +++ b/x/checkers/keeper/stored_game_in_fifo.go @@ -0,0 +1,68 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/olimdzhon/checkers/x/checkers/types" +) + +func (k Keeper) RemoveFromFifo(ctx sdk.Context, game *types.StoredGame, info *types.SystemInfo) { + // Does it have a predecessor? + if game.BeforeIndex != types.NoFifoIndex { + beforeElement, found := k.GetStoredGame(ctx, game.BeforeIndex) + if !found { + panic("Element before in Fifo was not found") + } + beforeElement.AfterIndex = game.AfterIndex + k.SetStoredGame(ctx, beforeElement) + if game.AfterIndex == types.NoFifoIndex { + info.FifoTailIndex = beforeElement.Index + } + // Is it at the FIFO head? + } else if info.FifoHeadIndex == game.Index { + info.FifoHeadIndex = game.AfterIndex + } + // Does it have a successor? + if game.AfterIndex != types.NoFifoIndex { + afterElement, found := k.GetStoredGame(ctx, game.AfterIndex) + if !found { + panic("Element after in Fifo was not found") + } + afterElement.BeforeIndex = game.BeforeIndex + k.SetStoredGame(ctx, afterElement) + if game.BeforeIndex == types.NoFifoIndex { + info.FifoHeadIndex = afterElement.Index + } + // Is it at the FIFO tail? + } else if info.FifoTailIndex == game.Index { + info.FifoTailIndex = game.BeforeIndex + } + game.BeforeIndex = types.NoFifoIndex + game.AfterIndex = types.NoFifoIndex +} + +func (k Keeper) SendToFifoTail(ctx sdk.Context, game *types.StoredGame, info *types.SystemInfo) { + if info.FifoHeadIndex == types.NoFifoIndex && info.FifoTailIndex == types.NoFifoIndex { + game.BeforeIndex = types.NoFifoIndex + game.AfterIndex = types.NoFifoIndex + info.FifoHeadIndex = game.Index + info.FifoTailIndex = game.Index + } else if info.FifoHeadIndex == types.NoFifoIndex || info.FifoTailIndex == types.NoFifoIndex { + panic("Fifo should have both head and tail or none") + } else if info.FifoTailIndex == game.Index { + // Nothing to do, already at tail + } else { + // Snip game out + k.RemoveFromFifo(ctx, game, info) + + // Now add to tail + currentTail, found := k.GetStoredGame(ctx, info.FifoTailIndex) + if !found { + panic("Current Fifo tail was not found") + } + currentTail.AfterIndex = game.Index + k.SetStoredGame(ctx, currentTail) + + game.BeforeIndex = currentTail.Index + info.FifoTailIndex = game.Index + } +} \ No newline at end of file diff --git a/x/checkers/types/genesis.go b/x/checkers/types/genesis.go index a517cee..75ec031 100644 --- a/x/checkers/types/genesis.go +++ b/x/checkers/types/genesis.go @@ -12,6 +12,8 @@ func DefaultGenesis() *GenesisState { return &GenesisState{ SystemInfo: SystemInfo{ NextId: uint64(DefaultIndex), + FifoHeadIndex: NoFifoIndex, + FifoTailIndex: NoFifoIndex, }, StoredGameList: []StoredGame{}, // this line is used by starport scaffolding # genesis/types/default diff --git a/x/checkers/types/genesis_test.go b/x/checkers/types/genesis_test.go index 606de26..701095a 100644 --- a/x/checkers/types/genesis_test.go +++ b/x/checkers/types/genesis_test.go @@ -69,7 +69,11 @@ func TestDefaultGenesisState_ExpectedInitialNextId(t *testing.T) { require.EqualValues(t, &types.GenesisState{ StoredGameList: []types.StoredGame{}, - SystemInfo: types.SystemInfo{uint64(1)}, + SystemInfo: types.SystemInfo{ + NextId: uint64(1), + FifoHeadIndex: "-1", + FifoTailIndex: "-1", + }, }, types.DefaultGenesis()) } diff --git a/x/checkers/types/keys.go b/x/checkers/types/keys.go index be1053a..ae2f4cd 100644 --- a/x/checkers/types/keys.go +++ b/x/checkers/types/keys.go @@ -46,4 +46,8 @@ const ( const ( MaxTurnDuration = time.Duration(24 * 3_600 * 1000_000_000) // 1 day DeadlineLayout = "2006-01-02 15:04:05.999999999 +0000 UTC" -) \ No newline at end of file +) + +const ( + NoFifoIndex = "-1" +) diff --git a/x/checkers/types/stored_game.pb.go b/x/checkers/types/stored_game.pb.go index cd010c8..e972c2b 100644 --- a/x/checkers/types/stored_game.pb.go +++ b/x/checkers/types/stored_game.pb.go @@ -23,14 +23,16 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type StoredGame struct { - Index string `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"` - Board string `protobuf:"bytes,2,opt,name=board,proto3" json:"board,omitempty"` - Turn string `protobuf:"bytes,3,opt,name=turn,proto3" json:"turn,omitempty"` - Black string `protobuf:"bytes,4,opt,name=black,proto3" json:"black,omitempty"` - Red string `protobuf:"bytes,5,opt,name=red,proto3" json:"red,omitempty"` - Winner string `protobuf:"bytes,6,opt,name=winner,proto3" json:"winner,omitempty"` - Deadline string `protobuf:"bytes,7,opt,name=deadline,proto3" json:"deadline,omitempty"` - MoveCount uint64 `protobuf:"varint,8,opt,name=moveCount,proto3" json:"moveCount,omitempty"` + Index string `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"` + Board string `protobuf:"bytes,2,opt,name=board,proto3" json:"board,omitempty"` + Turn string `protobuf:"bytes,3,opt,name=turn,proto3" json:"turn,omitempty"` + Black string `protobuf:"bytes,4,opt,name=black,proto3" json:"black,omitempty"` + Red string `protobuf:"bytes,5,opt,name=red,proto3" json:"red,omitempty"` + Winner string `protobuf:"bytes,6,opt,name=winner,proto3" json:"winner,omitempty"` + Deadline string `protobuf:"bytes,7,opt,name=deadline,proto3" json:"deadline,omitempty"` + MoveCount uint64 `protobuf:"varint,8,opt,name=moveCount,proto3" json:"moveCount,omitempty"` + BeforeIndex string `protobuf:"bytes,9,opt,name=beforeIndex,proto3" json:"beforeIndex,omitempty"` + AfterIndex string `protobuf:"bytes,10,opt,name=afterIndex,proto3" json:"afterIndex,omitempty"` } func (m *StoredGame) Reset() { *m = StoredGame{} } @@ -122,6 +124,20 @@ func (m *StoredGame) GetMoveCount() uint64 { return 0 } +func (m *StoredGame) GetBeforeIndex() string { + if m != nil { + return m.BeforeIndex + } + return "" +} + +func (m *StoredGame) GetAfterIndex() string { + if m != nil { + return m.AfterIndex + } + return "" +} + func init() { proto.RegisterType((*StoredGame)(nil), "checkers.checkers.StoredGame") } @@ -131,23 +147,25 @@ func init() { } var fileDescriptor_6a777ebb9b26769b = []byte{ - // 253 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x90, 0x31, 0x4e, 0xc3, 0x30, - 0x14, 0x86, 0x63, 0x9a, 0x86, 0xd6, 0x13, 0x58, 0x08, 0x59, 0x08, 0x59, 0x15, 0x2c, 0x9d, 0xd2, - 0x81, 0x1b, 0xc0, 0x00, 0x73, 0xd9, 0x58, 0x90, 0x13, 0x3f, 0x35, 0x56, 0x63, 0xbb, 0x72, 0x1c, - 0x28, 0x9c, 0x82, 0x53, 0x21, 0xc6, 0x8e, 0x8c, 0x28, 0xb9, 0x08, 0xca, 0x6b, 0x9b, 0x6c, 0xdf, - 0xf7, 0xbd, 0x7f, 0x7a, 0xf4, 0x36, 0x2f, 0x20, 0x5f, 0x83, 0xaf, 0x16, 0x3d, 0x54, 0xc1, 0x79, - 0x50, 0xaf, 0x2b, 0x69, 0x20, 0xdd, 0x78, 0x17, 0x1c, 0x3b, 0x3f, 0xde, 0xd2, 0x23, 0xdc, 0x7c, - 0x13, 0x4a, 0x9f, 0x71, 0xf8, 0x28, 0x0d, 0xb0, 0x0b, 0x3a, 0xd6, 0x56, 0xc1, 0x96, 0x93, 0x19, - 0x99, 0x4f, 0x97, 0x7b, 0xe9, 0x6a, 0xe6, 0xa4, 0x57, 0xfc, 0x64, 0x5f, 0x51, 0x18, 0xa3, 0x71, - 0xa8, 0xbd, 0xe5, 0x23, 0x8c, 0xc8, 0xb8, 0x2c, 0x65, 0xbe, 0xe6, 0xf1, 0x61, 0xd9, 0x09, 0x3b, - 0xa3, 0x23, 0x0f, 0x8a, 0x8f, 0xb1, 0x75, 0xc8, 0x2e, 0x69, 0xf2, 0xae, 0xad, 0x05, 0xcf, 0x13, - 0x8c, 0x07, 0x63, 0x57, 0x74, 0xa2, 0x40, 0xaa, 0x52, 0x5b, 0xe0, 0xa7, 0x78, 0xe9, 0x9d, 0x5d, - 0xd3, 0xa9, 0x71, 0x6f, 0xf0, 0xe0, 0x6a, 0x1b, 0xf8, 0x64, 0x46, 0xe6, 0xf1, 0x72, 0x08, 0xf7, - 0x4f, 0x3f, 0x8d, 0x20, 0xbb, 0x46, 0x90, 0xbf, 0x46, 0x90, 0xaf, 0x56, 0x44, 0xbb, 0x56, 0x44, - 0xbf, 0xad, 0x88, 0x5e, 0xd2, 0x95, 0x0e, 0x45, 0x9d, 0xa5, 0xb9, 0x33, 0x0b, 0x57, 0x6a, 0xa3, - 0x3e, 0x0b, 0x67, 0x87, 0x37, 0x6d, 0x07, 0x0c, 0x1f, 0x1b, 0xa8, 0xb2, 0x04, 0x9f, 0x75, 0xf7, - 0x1f, 0x00, 0x00, 0xff, 0xff, 0x05, 0x44, 0x46, 0xfe, 0x53, 0x01, 0x00, 0x00, + // 284 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xbf, 0x4e, 0xf3, 0x30, + 0x14, 0xc5, 0xeb, 0xfe, 0xfb, 0xda, 0xfb, 0x2d, 0x60, 0x21, 0x64, 0x21, 0x64, 0x55, 0xb0, 0x74, + 0x4a, 0x07, 0xde, 0x00, 0x06, 0x60, 0x2d, 0x1b, 0x0b, 0x72, 0xe2, 0xdb, 0x26, 0x6a, 0x62, 0x57, + 0x8e, 0x03, 0x85, 0x27, 0x60, 0xe4, 0xb1, 0x18, 0x3b, 0x32, 0xa2, 0xe4, 0x45, 0x50, 0x6e, 0xda, + 0xa6, 0xdb, 0x39, 0xbf, 0xfb, 0xb3, 0x64, 0x1d, 0xb8, 0x8e, 0x62, 0x8c, 0x56, 0xe8, 0xf2, 0xd9, + 0x21, 0xe4, 0xde, 0x3a, 0xd4, 0x2f, 0x4b, 0x95, 0x61, 0xb0, 0x76, 0xd6, 0x5b, 0x7e, 0xba, 0xbf, + 0x05, 0xfb, 0x70, 0xf5, 0xd9, 0x05, 0x78, 0x22, 0xf1, 0x5e, 0x65, 0xc8, 0xcf, 0x60, 0x90, 0x18, + 0x8d, 0x1b, 0xc1, 0x26, 0x6c, 0x3a, 0x9e, 0x37, 0xa5, 0xa6, 0xa1, 0x55, 0x4e, 0x8b, 0x6e, 0x43, + 0xa9, 0x70, 0x0e, 0x7d, 0x5f, 0x38, 0x23, 0x7a, 0x04, 0x29, 0x93, 0x99, 0xaa, 0x68, 0x25, 0xfa, + 0x3b, 0xb3, 0x2e, 0xfc, 0x04, 0x7a, 0x0e, 0xb5, 0x18, 0x10, 0xab, 0x23, 0x3f, 0x87, 0xe1, 0x5b, + 0x62, 0x0c, 0x3a, 0x31, 0x24, 0xb8, 0x6b, 0xfc, 0x02, 0x46, 0x1a, 0x95, 0x4e, 0x13, 0x83, 0xe2, + 0x1f, 0x5d, 0x0e, 0x9d, 0x5f, 0xc2, 0x38, 0xb3, 0xaf, 0x78, 0x67, 0x0b, 0xe3, 0xc5, 0x68, 0xc2, + 0xa6, 0xfd, 0x79, 0x0b, 0xf8, 0x04, 0xfe, 0x87, 0xb8, 0xb0, 0x0e, 0x1f, 0xe9, 0xff, 0x63, 0x7a, + 0x7c, 0x8c, 0xb8, 0x04, 0x50, 0x0b, 0x8f, 0xae, 0x11, 0x80, 0x84, 0x23, 0x72, 0xfb, 0xf0, 0x5d, + 0x4a, 0xb6, 0x2d, 0x25, 0xfb, 0x2d, 0x25, 0xfb, 0xaa, 0x64, 0x67, 0x5b, 0xc9, 0xce, 0x4f, 0x25, + 0x3b, 0xcf, 0xc1, 0x32, 0xf1, 0x71, 0x11, 0x06, 0x91, 0xcd, 0x66, 0x36, 0x4d, 0x32, 0xfd, 0x11, + 0x5b, 0xd3, 0x0e, 0xbd, 0x69, 0xa3, 0x7f, 0x5f, 0x63, 0x1e, 0x0e, 0x69, 0xee, 0x9b, 0xbf, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x0e, 0xd0, 0x68, 0x4d, 0x95, 0x01, 0x00, 0x00, } func (m *StoredGame) Marshal() (dAtA []byte, err error) { @@ -170,6 +188,20 @@ func (m *StoredGame) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.AfterIndex) > 0 { + i -= len(m.AfterIndex) + copy(dAtA[i:], m.AfterIndex) + i = encodeVarintStoredGame(dAtA, i, uint64(len(m.AfterIndex))) + i-- + dAtA[i] = 0x52 + } + if len(m.BeforeIndex) > 0 { + i -= len(m.BeforeIndex) + copy(dAtA[i:], m.BeforeIndex) + i = encodeVarintStoredGame(dAtA, i, uint64(len(m.BeforeIndex))) + i-- + dAtA[i] = 0x4a + } if m.MoveCount != 0 { i = encodeVarintStoredGame(dAtA, i, uint64(m.MoveCount)) i-- @@ -275,6 +307,14 @@ func (m *StoredGame) Size() (n int) { if m.MoveCount != 0 { n += 1 + sovStoredGame(uint64(m.MoveCount)) } + l = len(m.BeforeIndex) + if l > 0 { + n += 1 + l + sovStoredGame(uint64(l)) + } + l = len(m.AfterIndex) + if l > 0 { + n += 1 + l + sovStoredGame(uint64(l)) + } return n } @@ -556,6 +596,70 @@ func (m *StoredGame) Unmarshal(dAtA []byte) error { break } } + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BeforeIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStoredGame + } + 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 ErrInvalidLengthStoredGame + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStoredGame + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BeforeIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AfterIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStoredGame + } + 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 ErrInvalidLengthStoredGame + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthStoredGame + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AfterIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipStoredGame(dAtA[iNdEx:]) diff --git a/x/checkers/types/system_info.pb.go b/x/checkers/types/system_info.pb.go index f917794..45899ed 100644 --- a/x/checkers/types/system_info.pb.go +++ b/x/checkers/types/system_info.pb.go @@ -23,7 +23,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type SystemInfo struct { - NextId uint64 `protobuf:"varint,1,opt,name=nextId,proto3" json:"nextId,omitempty"` + NextId uint64 `protobuf:"varint,1,opt,name=nextId,proto3" json:"nextId,omitempty"` + FifoHeadIndex string `protobuf:"bytes,2,opt,name=fifoHeadIndex,proto3" json:"fifoHeadIndex,omitempty"` + FifoTailIndex string `protobuf:"bytes,3,opt,name=fifoTailIndex,proto3" json:"fifoTailIndex,omitempty"` } func (m *SystemInfo) Reset() { *m = SystemInfo{} } @@ -66,6 +68,20 @@ func (m *SystemInfo) GetNextId() uint64 { return 0 } +func (m *SystemInfo) GetFifoHeadIndex() string { + if m != nil { + return m.FifoHeadIndex + } + return "" +} + +func (m *SystemInfo) GetFifoTailIndex() string { + if m != nil { + return m.FifoTailIndex + } + return "" +} + func init() { proto.RegisterType((*SystemInfo)(nil), "checkers.checkers.SystemInfo") } @@ -75,17 +91,20 @@ func init() { } var fileDescriptor_4fddf76acd3e854e = []byte{ - // 155 bytes of a gzipped FileDescriptorProto + // 194 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xce, 0x48, 0x4d, 0xce, 0x4e, 0x2d, 0x2a, 0xd6, 0x87, 0x33, 0x8a, 0x2b, 0x8b, 0x4b, 0x52, 0x73, 0xe3, 0x33, 0xf3, - 0xd2, 0xf2, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x04, 0x61, 0x72, 0x7a, 0x30, 0x86, 0x92, - 0x0a, 0x17, 0x57, 0x30, 0x58, 0x9d, 0x67, 0x5e, 0x5a, 0xbe, 0x90, 0x18, 0x17, 0x5b, 0x5e, 0x6a, - 0x45, 0x89, 0x67, 0x8a, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4b, 0x10, 0x94, 0xe7, 0xe4, 0x71, 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, 0x7a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, - 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xf9, 0x39, 0x99, 0xb9, 0x29, 0x55, 0x19, 0xf9, 0x79, 0x08, 0x37, - 0x54, 0x20, 0x98, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x97, 0x18, 0x03, 0x02, 0x00, - 0x00, 0xff, 0xff, 0x30, 0x39, 0x51, 0x5a, 0xb0, 0x00, 0x00, 0x00, + 0xd2, 0xf2, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x04, 0x61, 0x72, 0x7a, 0x30, 0x86, 0x52, + 0x01, 0x17, 0x57, 0x30, 0x58, 0x9d, 0x67, 0x5e, 0x5a, 0xbe, 0x90, 0x18, 0x17, 0x5b, 0x5e, 0x6a, + 0x45, 0x89, 0x67, 0x8a, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4b, 0x10, 0x94, 0x27, 0xa4, 0xc2, 0xc5, + 0x9b, 0x96, 0x99, 0x96, 0xef, 0x91, 0x9a, 0x98, 0xe2, 0x99, 0x97, 0x92, 0x5a, 0x21, 0xc1, 0xa4, + 0xc0, 0xa8, 0xc1, 0x19, 0x84, 0x2a, 0x08, 0x53, 0x15, 0x92, 0x98, 0x99, 0x03, 0x51, 0xc5, 0x8c, + 0x50, 0x05, 0x17, 0x74, 0xf2, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, + 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, + 0xbd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xfc, 0x9c, 0xcc, 0xdc, + 0x94, 0xaa, 0x8c, 0xfc, 0x3c, 0x84, 0x7f, 0x2a, 0x10, 0xcc, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, + 0x36, 0xb0, 0xaf, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x33, 0x33, 0x72, 0x9c, 0xfc, 0x00, + 0x00, 0x00, } func (m *SystemInfo) Marshal() (dAtA []byte, err error) { @@ -108,6 +127,20 @@ func (m *SystemInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.FifoTailIndex) > 0 { + i -= len(m.FifoTailIndex) + copy(dAtA[i:], m.FifoTailIndex) + i = encodeVarintSystemInfo(dAtA, i, uint64(len(m.FifoTailIndex))) + i-- + dAtA[i] = 0x1a + } + if len(m.FifoHeadIndex) > 0 { + i -= len(m.FifoHeadIndex) + copy(dAtA[i:], m.FifoHeadIndex) + i = encodeVarintSystemInfo(dAtA, i, uint64(len(m.FifoHeadIndex))) + i-- + dAtA[i] = 0x12 + } if m.NextId != 0 { i = encodeVarintSystemInfo(dAtA, i, uint64(m.NextId)) i-- @@ -136,6 +169,14 @@ func (m *SystemInfo) Size() (n int) { if m.NextId != 0 { n += 1 + sovSystemInfo(uint64(m.NextId)) } + l = len(m.FifoHeadIndex) + if l > 0 { + n += 1 + l + sovSystemInfo(uint64(l)) + } + l = len(m.FifoTailIndex) + if l > 0 { + n += 1 + l + sovSystemInfo(uint64(l)) + } return n } @@ -193,6 +234,70 @@ func (m *SystemInfo) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FifoHeadIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSystemInfo + } + 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 ErrInvalidLengthSystemInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSystemInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FifoHeadIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FifoTailIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSystemInfo + } + 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 ErrInvalidLengthSystemInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSystemInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FifoTailIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSystemInfo(dAtA[iNdEx:])