Skip to content

Commit

Permalink
Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug committed Jan 8, 2025
1 parent 672b30f commit 1ccbf34
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
10 changes: 10 additions & 0 deletions crates/model/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

#[derive(Eq, PartialEq, Clone, Copy, Debug, Deserialize, Serialize, Hash, Default)]
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions crates/orderbook/src/database/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -670,6 +672,7 @@ fn full_order_into_model_order(order: FullOrder) -> Result<Order> {
pre: pre_interactions,
post: post_interactions,
},
quote_metadata: None,
})
}

Expand Down
6 changes: 5 additions & 1 deletion crates/orderbook/src/orderbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,11 @@ impl Orderbook {
}

pub async fn get_order(&self, uid: &OrderUid) -> Result<Option<Order>> {
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<Vec<Order>> {
Expand Down
1 change: 1 addition & 0 deletions crates/shared/src/db_order_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/shared/src/order_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ impl OrderValidating for OrderValidator {
signature: order.signature.clone(),
data,
interactions: app_data.interactions,
quote_metadata: None,
};

Ok((order, quote))
Expand Down

0 comments on commit 1ccbf34

Please sign in to comment.