Skip to content

Commit

Permalink
Added support for versioning into QuoteMetadata type
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug committed Dec 9, 2024
1 parent 17d25e6 commit e252f0e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
7 changes: 4 additions & 3 deletions crates/orderbook/src/database/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ mod tests {
signature::{Signature, SigningScheme},
},
primitive_types::U256,
shared::order_quoting::{QuoteData, QuoteMetadata},
shared::order_quoting::{QuoteData, QuoteMetadataV1},
std::sync::atomic::{AtomicI64, Ordering},
};

Expand Down Expand Up @@ -1221,7 +1221,7 @@ mod tests {
buy_amount: U256::from(2),
data: QuoteData {
verified: true,
metadata: QuoteMetadata {
metadata: QuoteMetadataV1 {
interactions: vec![
InteractionData {
target: H160([1; 20]),
Expand All @@ -1234,7 +1234,8 @@ mod tests {
call_data: vec![2, 20],
},
],
},
}
.into(),
..Default::default()
},
..Default::default()
Expand Down
30 changes: 24 additions & 6 deletions crates/shared/src/order_quoting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,10 @@ impl OrderQuoter {
quote_kind,
solver: trade_estimate.solver,
verified: trade_estimate.verified,
metadata: QuoteMetadata {
metadata: QuoteMetadataV1 {
interactions: trade_estimate.interactions,
},
}
.into(),
};

Ok(quote)
Expand Down Expand Up @@ -636,10 +637,9 @@ pub fn quote_kind_from_signing_scheme(scheme: &QuoteSigningScheme) -> QuoteKind
}

/// Used to store in database any quote metadata.
#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct QuoteMetadata {
/// Data provided by the solver in response to /quote request.
pub interactions: Vec<InteractionData>,
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum QuoteMetadata {
V1(QuoteMetadataV1),
}

impl TryInto<serde_json::Value> for QuoteMetadata {
Expand All @@ -658,6 +658,24 @@ impl TryFrom<serde_json::Value> for QuoteMetadata {
}
}

impl Default for QuoteMetadata {
fn default() -> Self {
Self::V1(Default::default())
}
}

impl From<QuoteMetadataV1> for QuoteMetadata {
fn from(val: QuoteMetadataV1) -> Self {
QuoteMetadata::V1(val)
}
}

#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct QuoteMetadataV1 {
/// Data provided by the solver in response to /quote request.
pub interactions: Vec<InteractionData>,
}

#[cfg(test)]
mod tests {
use {
Expand Down

0 comments on commit e252f0e

Please sign in to comment.