Skip to content

Commit

Permalink
Provide unique reasons when cancelling an order
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu-maeda committed Apr 19, 2024
1 parent 729bbb6 commit ec9c5cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/comms/comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,14 @@ impl CommsAccess {
pub(crate) async fn delete_maker_order_note(
&self,
event_id: EventIdString,
reason: impl Into<String>,
) -> Result<(), N3xbError> {
let (rsp_tx, rsp_rx) = oneshot::channel::<Result<(), N3xbError>>();
let request = CommsRequest::DeletMakerOrderNote { event_id, rsp_tx };
let request = CommsRequest::DeletMakerOrderNote {
event_id,
reason: reason.into(),
rsp_tx,
};
self.tx.send(request).await.unwrap();
rsp_rx.await.unwrap()
}
Expand Down Expand Up @@ -371,6 +376,7 @@ pub(super) enum CommsRequest {
},
DeletMakerOrderNote {
event_id: EventIdString,
reason: String,
rsp_tx: oneshot::Sender<Result<(), N3xbError>>,
},
Shutdown {
Expand Down Expand Up @@ -582,8 +588,12 @@ impl CommsActor {
.await;
}
// Delete an Maker Order Note
CommsRequest::DeletMakerOrderNote { event_id, rsp_tx } => {
self.delete_maker_order_note(event_id, rsp_tx).await;
CommsRequest::DeletMakerOrderNote {
event_id,
reason,
rsp_tx,
} => {
self.delete_maker_order_note(event_id, reason, rsp_tx).await;
}

// Shutdown
Expand Down Expand Up @@ -1367,14 +1377,12 @@ impl CommsActor {
async fn delete_maker_order_note(
&self,
event_id: EventIdString,
reason: String,
rsp_tx: oneshot::Sender<Result<(), N3xbError>>,
) {
let result = self
.client
.delete_event(
EventId::from_str(&event_id).unwrap(),
Some("n3xB: Order cancelled by Maker before Trade commenced"),
)
.delete_event(EventId::from_str(&event_id).unwrap(), Some(reason))
.await;
match result {
Ok(_) => rsp_tx.send(Ok(())).unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions src/maker/maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl MakerActor {
// Delete Order Note
let result = self
.comms_accessor
.delete_maker_order_note(maker_order_note_id.clone())
.delete_maker_order_note(maker_order_note_id.clone(), "Trade Started on Offer Accept")
.await;

// Send response back to user
Expand Down Expand Up @@ -576,7 +576,7 @@ impl MakerActor {
// Delete Order Note
let result = self
.comms_accessor
.delete_maker_order_note(maker_order_note_id.clone())
.delete_maker_order_note(maker_order_note_id.clone(), "Trade Cancelled")
.await;

// Send response back to user
Expand Down

0 comments on commit ec9c5cf

Please sign in to comment.