From 743108e059a6e4a1845f20b670ad3d23723d4eb5 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 7 May 2024 11:47:34 +0200 Subject: [PATCH] remove tmp files --- util/store/slice.go | 263 --------------------------------------- util/store/slice_test.go | 34 ----- 2 files changed, 297 deletions(-) delete mode 100644 util/store/slice.go delete mode 100644 util/store/slice_test.go diff --git a/util/store/slice.go b/util/store/slice.go deleted file mode 100644 index f8b7a7a6ce..0000000000 --- a/util/store/slice.go +++ /dev/null @@ -1,263 +0,0 @@ -package store - -import ( - "fmt" - "io" - math_bits "math/bits" - - "github.com/cosmos/cosmos-sdk/codec" - proto "github.com/cosmos/gogoproto/proto" -) - -var ( - ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") -) - -type ProtoMarshalable interface { - codec.ProtoMarshaler -} - -type PtrProtoMarshalable[T any] interface { - ProtoMarshalable - *T -} - -type Slice[TPtr PtrProtoMarshalable[T], T any] struct { - Content []TPtr -} - -func NewSlice[TPtr PtrProtoMarshalable[T], T any](ts ...TPtr) Slice[TPtr, T] { - return Slice[TPtr, T]{Content: ts} -} - -// Size implements ProtoMarshaler -func (s Slice[TPtr, T]) Size() (n int) { - var l int - for i := range s.Content { - l = s.Content[i].Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - -// Marshal implements ProtoMarshaler -func (s Slice[TPtr, T]) Marshal() (dAtA []byte, err error) { - size := s.Size() - dAtA = make([]byte, size) - n, err := s.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -// MarshalTo implements ProtoMarshaler -func (s Slice[TPtr, T]) MarshalTo(dAtA []byte) (int, error) { - return s.MarshalToSizedBuffer(dAtA[:s.Size()]) -} - -// MarshalToSizedBuffer implements ProtoMarshaler -func (s Slice[TPtr, T]) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - for iNdEx := len(s.Content) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := s.Content[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -// Unmarshal implements ProtoMarshaler -func (s Slice[TPtr, T]) 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: Slice: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Slice: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var t TPtr = new(T) - if err := t.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - s.Content = append(s.Content, t) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} - -func skipQuery(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthQuery - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupQuery - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthQuery - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -func (s Slice[TPtr, T]) Reset() { /* *s = Slice{} */ } -func (s Slice[TPtr, T]) String() string { return proto.CompactTextString(s) } -func (s Slice[TPtr, T]) ProtoMessage() {} - -func sovQuery(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} - -func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { - offset -= sovQuery(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} diff --git a/util/store/slice_test.go b/util/store/slice_test.go deleted file mode 100644 index f8b9bafd92..0000000000 --- a/util/store/slice_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package store - -import ( - "testing" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "gotest.tools/v3/assert" -) - -var _ codec.ProtoMarshaler = Slice[*sdk.Coin, sdk.Coin]{} - -func TestCoinMarshal(t *testing.T) { - c1 := sdk.NewInt64Coin("aa12", 5566) - bz, err := c1.Marshal() - assert.NilError(t, err) - - var c2 sdk.Coin - err = c2.Unmarshal(bz) - assert.NilError(t, err) - - assert.DeepEqual(t, c1, c2) - - c2 = sdk.NewInt64Coin("xrr", 8157) - s := NewSlice(&c1, &c2, &c2) - bz, err = s.Marshal() - assert.NilError(t, err) - - var s2 = Slice[*sdk.Coin, sdk.Coin]{Content: []*sdk.Coin{}} - err = s2.Unmarshal(bz) - assert.NilError(t, err) - - assert.DeepEqual(t, s, s2) -}