Skip to content

Commit

Permalink
Readability improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug committed Feb 19, 2025
1 parent 77bdeec commit 81c3029
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
54 changes: 46 additions & 8 deletions crates/database/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,17 @@ pub struct FullOrder {
pub full_app_data: Option<Vec<u8>>,
}

impl FullOrder {
pub fn valid_to(&self) -> i64 {
if let Some((_, valid_to)) = self.ethflow_data {
// For ethflow orders, we always return the user valid_to,
// as the Eip1271 valid to is u32::max
return valid_to;
}
self.valid_to
}
}

#[derive(Debug, sqlx::FromRow)]
pub struct FullOrderWithQuote {
#[sqlx(flatten)]
Expand All @@ -508,14 +519,41 @@ pub struct FullOrderWithQuote {
pub solver: Option<Address>,
}

impl FullOrder {
pub fn valid_to(&self) -> i64 {
if let Some((_, valid_to)) = self.ethflow_data {
// For ethflow orders, we always return the user valid_to,
// as the Eip1271 valid to is u32::max
return valid_to;
}
self.valid_to
impl FullOrderWithQuote {
pub fn into_order_and_quote(self) -> (FullOrder, Option<Quote>) {
let quote = match (
self.quote_buy_amount,
self.quote_sell_amount,
self.quote_gas_amount,
self.quote_gas_price,
self.quote_sell_token_price,
self.quote_verified,
self.quote_metadata,
self.solver,
) {
(
Some(buy_amount),
Some(sell_amount),
Some(gas_amount),
Some(gas_price),
Some(sell_token_price),
Some(verified),
Some(metadata),
Some(solver),
) => Some(Quote {
order_uid: self.full_order.uid,
gas_amount,
gas_price,
sell_token_price,
sell_amount,
buy_amount,
solver,
verified,
metadata,
}),
_ => None,
};
(self.full_order, quote)
}
}

Expand Down
36 changes: 2 additions & 34 deletions crates/orderbook/src/database/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,41 +319,9 @@ impl OrderStoring for Postgres {

match orders::single_full_order_with_quote(&mut ex, &ByteArray(uid.0)).await? {
Some(order_with_quote) => {
let quote = match (
order_with_quote.quote_buy_amount,
order_with_quote.quote_sell_amount,
order_with_quote.quote_gas_amount,
order_with_quote.quote_gas_price,
order_with_quote.quote_sell_token_price,
order_with_quote.quote_verified,
order_with_quote.quote_metadata,
order_with_quote.solver,
) {
(
Some(buy_amount),
Some(sell_amount),
Some(gas_amount),
Some(gas_price),
Some(sell_token_price),
Some(verified),
Some(metadata),
Some(solver),
) => Some(orders::Quote {
order_uid: order_with_quote.full_order.uid,
gas_amount,
gas_price,
sell_token_price,
sell_amount,
buy_amount,
solver,
verified,
metadata,
}),
_ => None,
};

let (order, quote) = order_with_quote.into_order_and_quote();
Some(full_order_with_quote_into_model_order(
order_with_quote.full_order,
order,
quote.as_ref(),
))
}
Expand Down

0 comments on commit 81c3029

Please sign in to comment.