| 463 | |
| 464 | #[instrument(skip_all)] |
| 465 | pub async fn cancel_order( |
| 466 | ex: &mut PgConnection, |
| 467 | order_uid: &OrderUid, |
| 468 | timestamp: DateTime<Utc>, |
| 469 | ) -> Result<(), sqlx::Error> { |
| 470 | // We do not overwrite previously cancelled orders, |
| 471 | // but this query does allow the user to soft cancel |
| 472 | // an order that has already been invalidated on-chain. |
| 473 | const QUERY: &str = r#" |
| 474 | UPDATE orders |
| 475 | SET cancellation_timestamp = $1 |
| 476 | WHERE uid = $2 |
| 477 | AND cancellation_timestamp IS NULL |
| 478 | "#; |
| 479 | sqlx::query(QUERY) |
| 480 | .bind(timestamp) |
| 481 | .bind(order_uid.0.as_ref()) |
| 482 | .execute(ex) |
| 483 | .await |
| 484 | .map(|_| ()) |
| 485 | } |
| 486 | |
| 487 | /// Interactions are read as arrays of their fields: target, value, data. |
| 488 | /// This is done as sqlx does not support reading arrays of more complicated |