Skip to content

Commit

Permalink
Review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lumos42 committed Sep 17, 2023
1 parent 5ba92b7 commit 2a179a3
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions plugin/evm/orderbook/memory_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (db *InMemoryDatabase) Add(order *Order) {
// Insert the order at the determined position
orders = append(orders, &Order{}) // Add an empty order to the end
copy(orders[position+1:], orders[position:]) // Shift orders to the right
orders[position] = order // Insert newOrder at the right position
orders[position] = order // Insert new Order at the right position

if order.PositionType == LONG {
db.LongOrders[market] = orders
Expand Down Expand Up @@ -506,23 +506,15 @@ func (db *InMemoryDatabase) deleteOrderWithoutLock(orderId common.Hash) {

market := order.Market
if order.PositionType == LONG {
marketOrders := db.LongOrders[market]
for i, _order := range marketOrders {
if _order.Id == orderId {
marketOrders = append(marketOrders[:i], marketOrders[i+1:]...)
db.LongOrders[market] = marketOrders
break
}
}
orders := db.LongOrders[market]
idx := getOrderIdx(orders, orderId)
orders = append(orders[:idx], orders[idx+1:]...)
db.LongOrders[market] = orders
} else {
marketOrders := db.ShortOrders[market]
for i, _order := range marketOrders {
if _order.Id == orderId {
marketOrders = append(marketOrders[:i], marketOrders[i+1:]...)
db.ShortOrders[market] = marketOrders
break
}
}
orders := db.ShortOrders[market]
idx := getOrderIdx(orders, orderId)
orders = append(orders[:idx], orders[idx+1:]...)
db.ShortOrders[market] = orders
}

delete(db.Orders, orderId)
Expand Down Expand Up @@ -1152,3 +1144,12 @@ func deepCopyTrader(order *Trader) *Trader {
Margin: margin,
}
}

func getOrderIdx(orders []*Order, orderId common.Hash) int {
for i, order := range orders {
if order.Id == orderId {
return i
}
}
return -1
}

0 comments on commit 2a179a3

Please sign in to comment.