Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send OrderExpired event for Signed orders #189

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions plugin/evm/orderbook/memory_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ func shouldRemove(acceptedBlockNumber, blockTimestamp uint64, order Order) Order
return KEEP
}

// do not remove expired signed order here. They should be removed from
// RemoveExpiredSignedOrders function only so that the appropriate Trader event is sent
if order.OrderType == Signed {
return KEEP
}

// remove if order is expired; valid for both IOC and Signed orders
expireAt := order.getExpireAt()
if expireAt.Sign() > 0 && expireAt.Int64() < int64(blockTimestamp) {
Expand All @@ -347,6 +353,24 @@ func (db *InMemoryDatabase) RemoveExpiredSignedOrders() {
for _, order := range db.Orders {
if order.OrderType == Signed && order.getExpireAt().Int64() <= now {
db.deleteOrderWithoutLock(order.Id)

// send TraderEvent for the expired order
go func(order_ *Order) {
traderEvent := TraderEvent{
Trader: order_.Trader,
Removed: false,
EventName: "OrderExpired",
BlockStatus: ConfirmationLevelHead,
OrderId: order_.Id,
OrderType: order_.OrderType.String(),
Timestamp: big.NewInt(now),
}

traderFeed.Send(traderEvent)
traderEvent.BlockStatus = ConfirmationLevelAccepted
traderFeed.Send(traderEvent)
}(order)

}
}
}
Expand Down
Loading