Skip to content

Commit

Permalink
Simplify types to string
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMHasperhoven committed Feb 20, 2025
1 parent adcda80 commit 29bca0d
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions crates/bin/pindexer/src/dex_ex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,24 +676,14 @@ struct PairMetrics {
#[derive(Debug, Clone, Type, serde::Serialize)]
#[sqlx(type_name = "batch_swap_summary")]
struct BatchSwapSummary {
#[serde(serialize_with = "serialize_bytes")]
asset_start: Vec<u8>,
#[serde(serialize_with = "serialize_bytes")]
asset_end: Vec<u8>,
input: BigDecimal,
output: BigDecimal,
asset_start: String,
asset_end: String,
input: String,
output: String,
num_swaps: i32,
price_float: f64,
}

// Add this helper function to serialize byte vectors as hex strings
fn serialize_bytes<S>(bytes: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&hex::encode(bytes))
}

#[derive(Debug)]
struct Events {
time: Option<DateTime>,
Expand Down Expand Up @@ -1160,10 +1150,10 @@ impl Component {
let num_swaps = filtered_swaps.len() as i32;

batch_swap_summaries.push(BatchSwapSummary {
asset_start: asset_start.to_bytes().to_vec(),
asset_end: asset_end.to_bytes().to_vec(),
input: BigDecimal::from(input.value()),
output: BigDecimal::from(output.value()),
asset_start: hex::encode(asset_start.to_bytes()),
asset_end: hex::encode(asset_end.to_bytes()),
input: input.value().to_string(),
output: output.value().to_string(),
num_swaps,
price_float,
});
Expand All @@ -1185,10 +1175,10 @@ impl Component {
let num_swaps = filtered_swaps.len() as i32;

batch_swap_summaries.push(BatchSwapSummary {
asset_start: asset_start.to_bytes().to_vec(),
asset_end: asset_end.to_bytes().to_vec(),
input: BigDecimal::from(input.value()),
output: BigDecimal::from(output.value()),
asset_start: hex::encode(asset_start.to_bytes()),
asset_end: hex::encode(asset_end.to_bytes()),
input: input.value().to_string(),
output: output.value().to_string(),
num_swaps,
price_float,
});
Expand Down

0 comments on commit 29bca0d

Please sign in to comment.