Skip to content

Commit

Permalink
Reveal and settle to receive integer solution id
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Dec 9, 2024
1 parent c47c80c commit 441681f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
31 changes: 31 additions & 0 deletions crates/driver/src/infra/api/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,34 @@ pub(super) use {
settle::settle,
solve::{solve, AuctionError},
};

pub fn deserialize_solution_id<'de, D>(deserializer: D) -> Result<u64, D::Error>
where
D: serde::Deserializer<'de>,
{
struct SolutionIdVisitor;

impl serde::de::Visitor<'_> for SolutionIdVisitor {
type Value = u64;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a string or integer representing a solution ID")
}

fn visit_u64<E>(self, value: u64) -> Result<u64, E>
where
E: serde::de::Error,
{
Ok(value)
}

fn visit_str<E>(self, value: &str) -> Result<u64, E>
where
E: serde::de::Error,
{
value.parse::<u64>().map_err(serde::de::Error::custom)
}
}

deserializer.deserialize_any(SolutionIdVisitor)
}
4 changes: 2 additions & 2 deletions crates/driver/src/infra/api/routes/reveal/dto/solution.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use {serde::Deserialize, serde_with::serde_as};
use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_with::serde_as};

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Solution {
/// Unique ID of the solution (per driver competition), to reveal.
#[serde_as(as = "serde_with::DisplayFromStr")]
#[serde(deserialize_with = "deserialize_solution_id")]
pub solution_id: u64,
/// Auction ID in which the specified solution ID is competing.
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/infra/api/routes/settle/dto/solution.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use {serde::Deserialize, serde_with::serde_as};
use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_with::serde_as};

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Solution {
/// Unique ID of the solution (per driver competition), to settle.
#[serde_as(as = "serde_with::DisplayFromStr")]
#[serde(deserialize_with = "deserialize_solution_id")]
pub solution_id: u64,
/// The last block number in which the solution TX can be included
pub submission_deadline_latest_block: u64,
Expand Down

0 comments on commit 441681f

Please sign in to comment.