diff --git a/crates/model/src/order.rs b/crates/model/src/order.rs index 6aa3e4b78b..bf323d7dfb 100644 --- a/crates/model/src/order.rs +++ b/crates/model/src/order.rs @@ -53,6 +53,10 @@ pub struct Order { pub signature: Signature, #[serde(default)] pub interactions: Interactions, + /// If this order was crated from quote, then this field contains that quote + /// metadata + #[serde(default, skip_serializing_if = "Option::is_none")] + pub quote_metadata: Option, } #[derive(Eq, PartialEq, Clone, Copy, Debug, Deserialize, Serialize, Hash, Default)] @@ -184,6 +188,11 @@ impl OrderBuilder { self } + pub fn with_quote_metadata(mut self, metadata: &str) -> Self { + self.0.quote_metadata = Some(metadata.to_string()); + self + } + pub fn build(self) -> Order { self.0 } @@ -1098,6 +1107,7 @@ mod tests { } .to_signature(signing_scheme), interactions: Interactions::default(), + quote_metadata: None, }; let deserialized: Order = serde_json::from_value(value.clone()).unwrap(); assert_eq!(deserialized, expected); diff --git a/crates/orderbook/src/database/orders.rs b/crates/orderbook/src/database/orders.rs index 51bce8a8c6..a5be8f8f25 100644 --- a/crates/orderbook/src/database/orders.rs +++ b/crates/orderbook/src/database/orders.rs @@ -402,10 +402,12 @@ impl OrderStoring for Postgres { _ => None, }; - Ok(OrderWithQuote { - order: full_order_into_model_order(order_with_quote.full_order)?, - quote, - }) + let mut order = full_order_into_model_order(order_with_quote.full_order)?; + if let Some(quote) = quote.as_ref() { + order.quote_metadata = Some(quote.metadata.to_string()); + } + + Ok(OrderWithQuote { order, quote }) }) .transpose() } @@ -670,6 +672,7 @@ fn full_order_into_model_order(order: FullOrder) -> Result { pre: pre_interactions, post: post_interactions, }, + quote_metadata: None, }) } diff --git a/crates/orderbook/src/orderbook.rs b/crates/orderbook/src/orderbook.rs index eabf66518c..e3673dada8 100644 --- a/crates/orderbook/src/orderbook.rs +++ b/crates/orderbook/src/orderbook.rs @@ -428,7 +428,11 @@ impl Orderbook { } pub async fn get_order(&self, uid: &OrderUid) -> Result> { - self.database.single_order(uid).await + Ok(self + .database + .single_order_with_quote(uid) + .await? + .map(|order_with_qoute| order_with_qoute.order)) } pub async fn get_orders_for_tx(&self, hash: &H256) -> Result> { diff --git a/crates/shared/src/db_order_conversions.rs b/crates/shared/src/db_order_conversions.rs index 44e2ae3320..3dfb737d6c 100644 --- a/crates/shared/src/db_order_conversions.rs +++ b/crates/shared/src/db_order_conversions.rs @@ -135,6 +135,7 @@ pub fn full_order_into_model_order(order: database::orders::FullOrder) -> Result pre: pre_interactions, post: post_interactions, }, + quote_metadata: None, }) } diff --git a/crates/shared/src/order_validation.rs b/crates/shared/src/order_validation.rs index 05b2368238..a91de22ac3 100644 --- a/crates/shared/src/order_validation.rs +++ b/crates/shared/src/order_validation.rs @@ -725,6 +725,7 @@ impl OrderValidating for OrderValidator { signature: order.signature.clone(), data, interactions: app_data.interactions, + quote_metadata: None, }; Ok((order, quote))