diff --git a/go.mod b/go.mod index bac72df8b8..f304247cb7 100644 --- a/go.mod +++ b/go.mod @@ -94,6 +94,7 @@ require ( github.com/firefart/nonamedreturns v1.0.1 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/fzipp/gocyclo v0.5.1 // indirect + github.com/ghodss/yaml v1.0.0 // indirect github.com/go-critic/go-critic v0.6.3 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.0 // indirect @@ -140,6 +141,7 @@ require ( github.com/gostaticanalysis/nilerr v0.1.1 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.13.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect diff --git a/go.sum b/go.sum index 3b2aeca27a..e146557dac 100644 --- a/go.sum +++ b/go.sum @@ -406,6 +406,7 @@ github.com/fullstorydev/grpcurl v1.6.0/go.mod h1:ZQ+ayqbKMJNhzLmbpCiurTVlaK2M/3n github.com/fzipp/gocyclo v0.5.1 h1:L66amyuYogbxl0j2U+vGqJXusPF2IkduvXLnYD5TFgw= github.com/fzipp/gocyclo v0.5.1/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -676,6 +677,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.13.0 h1:fi9bGIUJOGzzrHBbP8NWbTfNC5fKO6X7kFw40TOqGB8= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.13.0/go.mod h1:uY3Aurq+SxwQCpdX91xZ9CgxIMT1EsYtcidljXufYIY= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= diff --git a/proto/dex/order_cache.proto b/proto/dex/order_cache.proto new file mode 100644 index 0000000000..f50ad6cffe --- /dev/null +++ b/proto/dex/order_cache.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package seiprotocol.seichain.dex; + +option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; +import "dex/order.proto"; +import "gogoproto/gogo.proto"; + +message BlockOrders { + repeated Order orders = 1 [ + (gogoproto.jsontag) = "orders" + ]; +} + +message BlockCancels { + repeated Cancellation cancels = 1 [ + (gogoproto.jsontag) = "cancels" + ]; +} diff --git a/x/dex/keeper/long_book_test.go b/x/dex/keeper/long_book_test.go deleted file mode 100644 index 22c42a20e9..0000000000 --- a/x/dex/keeper/long_book_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" - "github.com/sei-protocol/sei-chain/testutil/nullify" - "github.com/stretchr/testify/require" -) - -func TestLongBookGet(t *testing.T) { - keeper, ctx := keepertest.DexKeeper(t) - items := keepertest.CreateNLongBook(keeper, ctx, 10) - for i, item := range items { - got, found := keeper.GetLongBookByPrice(ctx, keepertest.TestContract, sdk.NewDec(int64(i)), keepertest.TestPriceDenom, keepertest.TestAssetDenom) - require.True(t, found) - require.Equal(t, - nullify.Fill(&item), - nullify.Fill(&got), - ) - } -} - -func TestLongBookRemove(t *testing.T) { - keeper, ctx := keepertest.DexKeeper(t) - items := keepertest.CreateNLongBook(keeper, ctx, 10) - for i := range items { - keeper.RemoveLongBookByPrice(ctx, keepertest.TestContract, sdk.NewDec(int64(i)), keepertest.TestPriceDenom, keepertest.TestAssetDenom) - _, found := keeper.GetLongBookByPrice(ctx, keepertest.TestContract, sdk.NewDec(int64(i)), keepertest.TestPriceDenom, keepertest.TestAssetDenom) - require.False(t, found) - } -} - -func TestLongBookGetAll(t *testing.T) { - keeper, ctx := keepertest.DexKeeper(t) - items := keepertest.CreateNLongBook(keeper, ctx, 10) - require.ElementsMatch(t, - nullify.Fill(items), - nullify.Fill(keeper.GetAllLongBook(ctx, keepertest.TestContract)), - ) -} diff --git a/x/dex/cache/order.go b/x/dex/keeper/order.go similarity index 82% rename from x/dex/cache/order.go rename to x/dex/keeper/order.go index 1b3deedde5..b835f04b51 100644 --- a/x/dex/cache/order.go +++ b/x/dex/keeper/order.go @@ -1,34 +1,46 @@ -package dex +package keeper import ( "sort" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sei-protocol/sei-chain/utils" "github.com/sei-protocol/sei-chain/x/dex/types" "github.com/sei-protocol/sei-chain/x/dex/types/wasm" ) -type BlockOrders struct { - memStateItems[*types.Order] -} +func (k Keeper) AddOrder(ctx sdk.Context, contractAddr string, order *types.Order) { + store := prefix.NewStore( + ctx.KVStore(k.storeKey), + types.LimitBookPrefix( + contractAddr, order.PriceDenom, order.AssetDenom, + ), + ) + key := GetKeyForPrice(order.Price) + val := types.BlockOrders{} + + if store.Has(key) { + b := store.Get(key) + k.Cdc.MustUnmarshal(b, &val) + } + val.Orders = append(val.Orders, order) -func NewOrders() *BlockOrders { - return &BlockOrders{memStateItems: NewItems(utils.PtrCopier[types.Order])} + b := k.Cdc.MustMarshal(&val) + store.Set(key, b) } -func (o *BlockOrders) Copy() *BlockOrders { - return &BlockOrders{memStateItems: *o.memStateItems.Copy()} +type BlockOrders struct { + blockOrder types.BlockOrders } func (o *BlockOrders) MarkFailedToPlace(failedOrders []wasm.UnsuccessfulOrder) { - o.mu.Lock() - defer o.mu.Unlock() failedOrdersMap := map[uint64]wasm.UnsuccessfulOrder{} for _, failedOrder := range failedOrders { failedOrdersMap[failedOrder.ID] = failedOrder } newOrders := []*types.Order{} - for _, order := range o.internal { + for _, order := range o.blockOrder.Orders { if failedOrder, ok := failedOrdersMap[order.Id]; ok { order.Status = types.OrderStatus_FAILED_TO_PLACE order.StatusDescription = failedOrder.Reason @@ -39,9 +51,6 @@ func (o *BlockOrders) MarkFailedToPlace(failedOrders []wasm.UnsuccessfulOrder) { } func (o *BlockOrders) GetSortedMarketOrders(direction types.PositionDirection, includeLiquidationOrders bool) []*types.Order { - o.mu.Lock() - defer o.mu.Unlock() - res := o.getOrdersByCriteria(types.OrderType_MARKET, direction) res = append(res, o.getOrdersByCriteria(types.OrderType_FOKMARKET, direction)...) if includeLiquidationOrders { @@ -68,14 +77,10 @@ func (o *BlockOrders) GetSortedMarketOrders(direction types.PositionDirection, i } func (o *BlockOrders) GetLimitOrders(direction types.PositionDirection) []*types.Order { - o.mu.Lock() - defer o.mu.Unlock() return o.getOrdersByCriteria(types.OrderType_LIMIT, direction) } func (o *BlockOrders) GetTriggeredOrders() []*types.Order { - o.mu.Lock() - defer o.mu.Unlock() return o.getOrdersByCriteriaMap( map[types.OrderType]bool{ types.OrderType_STOPLOSS: true, diff --git a/x/dex/types/keys.go b/x/dex/types/keys.go index ed1c5b5c00..182fb5af82 100644 --- a/x/dex/types/keys.go +++ b/x/dex/types/keys.go @@ -34,6 +34,33 @@ func PairPrefix(priceDenom string, assetDenom string) []byte { return append([]byte(priceDenom), append([]byte(PairSeparator), []byte(assetDenom)...)...) } +func LimitBookPrefix(contractAddr string, priceDenom string, assetDenom string) []byte { + prefix := KeyPrefix(LimitBookKey) + + return append( + append(prefix, KeyPrefix(contractAddr)...), + PairPrefix(priceDenom, assetDenom)..., + ) +} + +func MarketBookPrefix(contractAddr string, priceDenom string, assetDenom string) []byte { + prefix := KeyPrefix(MarketBookKey) + + return append( + append(prefix, KeyPrefix(contractAddr)...), + PairPrefix(priceDenom, assetDenom)..., + ) +} + +func CancelBookPrefix(contractAddr string, priceDenom string, assetDenom string) []byte { + prefix := KeyPrefix(CancelBookKey) + + return append( + append(prefix, KeyPrefix(contractAddr)...), + PairPrefix(priceDenom, assetDenom)..., + ) +} + func OrderBookPrefix(long bool, contractAddr string, priceDenom string, assetDenom string) []byte { var prefix []byte if long { @@ -89,10 +116,6 @@ func TickSizeKeyPrefix(contractAddr string) []byte { return append(KeyPrefix(TickSizeKey), KeyPrefix(contractAddr)...) } -func OrderPrefix(contractAddr string) []byte { - return append(KeyPrefix(OrderKey), KeyPrefix(contractAddr)...) -} - func Cancel(contractAddr string) []byte { return append(KeyPrefix(CancelKey), KeyPrefix(contractAddr)...) } @@ -147,7 +170,10 @@ const ( ShortBookKey = "ShortBook-value-" + LimitBookKey = "LimitBook-value-" + MarketBookKey = "MarketBook-value-" TriggerBookKey = "TriggerBook-value-" + CancelBookKey = "CancelBook-value-" OrderKey = "order" AccountActiveOrdersKey = "account-active-orders" diff --git a/x/dex/types/order_cache.pb.go b/x/dex/types/order_cache.pb.go new file mode 100644 index 0000000000..095b519a2f --- /dev/null +++ b/x/dex/types/order_cache.pb.go @@ -0,0 +1,513 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: dex/order_cache.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type BlockOrders struct { + Orders []*Order `protobuf:"bytes,1,rep,name=orders,proto3" json:"orders"` +} + +func (m *BlockOrders) Reset() { *m = BlockOrders{} } +func (m *BlockOrders) String() string { return proto.CompactTextString(m) } +func (*BlockOrders) ProtoMessage() {} +func (*BlockOrders) Descriptor() ([]byte, []int) { + return fileDescriptor_954be8bf4ab3871a, []int{0} +} +func (m *BlockOrders) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlockOrders) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlockOrders.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 *BlockOrders) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockOrders.Merge(m, src) +} +func (m *BlockOrders) XXX_Size() int { + return m.Size() +} +func (m *BlockOrders) XXX_DiscardUnknown() { + xxx_messageInfo_BlockOrders.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockOrders proto.InternalMessageInfo + +func (m *BlockOrders) GetOrders() []*Order { + if m != nil { + return m.Orders + } + return nil +} + +type BlockCancels struct { + Cancels []*Cancellation `protobuf:"bytes,1,rep,name=cancels,proto3" json:"cancels"` +} + +func (m *BlockCancels) Reset() { *m = BlockCancels{} } +func (m *BlockCancels) String() string { return proto.CompactTextString(m) } +func (*BlockCancels) ProtoMessage() {} +func (*BlockCancels) Descriptor() ([]byte, []int) { + return fileDescriptor_954be8bf4ab3871a, []int{1} +} +func (m *BlockCancels) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlockCancels) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlockCancels.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 *BlockCancels) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockCancels.Merge(m, src) +} +func (m *BlockCancels) XXX_Size() int { + return m.Size() +} +func (m *BlockCancels) XXX_DiscardUnknown() { + xxx_messageInfo_BlockCancels.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockCancels proto.InternalMessageInfo + +func (m *BlockCancels) GetCancels() []*Cancellation { + if m != nil { + return m.Cancels + } + return nil +} + +func init() { + proto.RegisterType((*BlockOrders)(nil), "seiprotocol.seichain.dex.BlockOrders") + proto.RegisterType((*BlockCancels)(nil), "seiprotocol.seichain.dex.BlockCancels") +} + +func init() { proto.RegisterFile("dex/order_cache.proto", fileDescriptor_954be8bf4ab3871a) } + +var fileDescriptor_954be8bf4ab3871a = []byte{ + // 242 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4d, 0x49, 0xad, 0xd0, + 0xcf, 0x2f, 0x4a, 0x49, 0x2d, 0x8a, 0x4f, 0x4e, 0x4c, 0xce, 0x48, 0xd5, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, + 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0x52, 0x2b, 0xa4, 0xf8, 0xe1, 0x1a, 0x20, 0x4a, 0xa5, 0x44, + 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x14, 0xc4, 0xc5, 0xed, 0x94, + 0x93, 0x9f, 0x9c, 0xed, 0x0f, 0x52, 0x59, 0x2c, 0xe4, 0xcc, 0xc5, 0x06, 0xd6, 0x53, 0x2c, 0xc1, + 0xa8, 0xc0, 0xac, 0xc1, 0x6d, 0x24, 0xaf, 0x87, 0xcb, 0x02, 0x3d, 0xb0, 0x0e, 0x27, 0xae, 0x57, + 0xf7, 0xe4, 0xa1, 0x5a, 0x82, 0xa0, 0xb4, 0x52, 0x2c, 0x17, 0x0f, 0xd8, 0x4c, 0xe7, 0xc4, 0xbc, + 0xe4, 0xd4, 0x9c, 0x62, 0x21, 0x5f, 0x2e, 0xf6, 0x64, 0x08, 0x13, 0x6a, 0xaa, 0x1a, 0x6e, 0x53, + 0x21, 0x7a, 0x72, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x9c, 0xb8, 0x5f, 0xdd, 0x93, 0x87, 0x69, 0x0d, + 0x82, 0x31, 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, + 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, + 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xbf, 0x38, 0x35, 0x53, 0x17, 0x66, + 0x05, 0x98, 0x03, 0xb6, 0x43, 0xbf, 0x42, 0x1f, 0x14, 0x2e, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, + 0x6c, 0x60, 0x79, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x27, 0x9b, 0x86, 0x5c, 0x01, + 0x00, 0x00, +} + +func (m *BlockOrders) 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 *BlockOrders) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlockOrders) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Orders) > 0 { + for iNdEx := len(m.Orders) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Orders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintOrderCache(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *BlockCancels) 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 *BlockCancels) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlockCancels) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Cancels) > 0 { + for iNdEx := len(m.Cancels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Cancels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintOrderCache(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintOrderCache(dAtA []byte, offset int, v uint64) int { + offset -= sovOrderCache(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *BlockOrders) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Orders) > 0 { + for _, e := range m.Orders { + l = e.Size() + n += 1 + l + sovOrderCache(uint64(l)) + } + } + return n +} + +func (m *BlockCancels) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Cancels) > 0 { + for _, e := range m.Cancels { + l = e.Size() + n += 1 + l + sovOrderCache(uint64(l)) + } + } + return n +} + +func sovOrderCache(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozOrderCache(x uint64) (n int) { + return sovOrderCache(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *BlockOrders) 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 ErrIntOverflowOrderCache + } + 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: BlockOrders: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlockOrders: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Orders", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOrderCache + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthOrderCache + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthOrderCache + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Orders = append(m.Orders, &Order{}) + if err := m.Orders[len(m.Orders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipOrderCache(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthOrderCache + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BlockCancels) 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 ErrIntOverflowOrderCache + } + 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: BlockCancels: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlockCancels: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Cancels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOrderCache + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthOrderCache + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthOrderCache + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Cancels = append(m.Cancels, &Cancellation{}) + if err := m.Cancels[len(m.Cancels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipOrderCache(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthOrderCache + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipOrderCache(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, ErrIntOverflowOrderCache + } + 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, ErrIntOverflowOrderCache + } + 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, ErrIntOverflowOrderCache + } + 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, ErrInvalidLengthOrderCache + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupOrderCache + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthOrderCache + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthOrderCache = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowOrderCache = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupOrderCache = fmt.Errorf("proto: unexpected end of group") +)