Skip to content

Commit

Permalink
crates(diri): try to handle all events of a block even in case of han…
Browse files Browse the repository at this point in the history
…dle failure
  • Loading branch information
ptisserand committed Dec 9, 2024
1 parent 1d5c4ea commit 143c852
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions crates/diri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,58 @@ impl<S: Storage, E: EventHandler> Diri<S, E> {
match orderbook_event {
Event::OrderPlaced(ev) => {
trace!("OrderPlaced found: {:?}", ev);
self.storage
match self
.storage
.register_placed(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderPlaced event handler failed: {e}"),
}
}
Event::OrderCancelled(ev) => {
trace!("OrderCancelled found: {:?}", ev);
self.storage
match self
.storage
.register_cancelled(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderCancelled event handler failed: {e}"),
}
}
Event::OrderFulfilled(ev) => {
trace!("OrderFulfilled found: {:?}", ev);
self.storage
match self
.storage
.register_fulfilled(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderFulfilled event handler failed: {e}"),
}
}
Event::OrderExecuted(ev) => {
trace!("OrderExecuted found: {:?}", ev);
self.storage
match self
.storage
.register_executed(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("OrderExecuted event handler failed: {e}"),
}
}
Event::RollbackStatus(ev) => {
trace!("RollbackStatus found: {:?}", ev);
self.storage
match self
.storage
.status_back_to_open(*block_number, block_timestamp, &ev.into())
.await?;
.await
{
Ok(_) => (),
Err(e) => error!("RollbackStatus event handler failed: {e}"),
}
}
_ => warn!("Orderbook event not handled: {:?}", orderbook_event),
};
Expand Down

0 comments on commit 143c852

Please sign in to comment.