Skip to content

Commit

Permalink
Stop using string for solution_id
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Dec 10, 2024
1 parent 2bb146f commit f9cbf83
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 69 deletions.
1 change: 0 additions & 1 deletion crates/autopilot/src/infra/solvers/dto/reveal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use {
#[serde(rename_all = "camelCase")]
pub struct Request {
/// Unique ID of the solution (per driver competition), to reveal.
#[serde_as(as = "serde_with::DisplayFromStr")]
pub solution_id: u64,
/// Auction ID in which the specified solution ID is competing.
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
Expand Down
1 change: 0 additions & 1 deletion crates/autopilot/src/infra/solvers/dto/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use {
#[serde(rename_all = "camelCase")]
pub struct Request {
/// Unique ID of the solution (per driver competition), to settle.
#[serde_as(as = "serde_with::DisplayFromStr")]
pub solution_id: u64,
/// The last block number in which the solution TX can be included
pub submission_deadline_latest_block: u64,
Expand Down
32 changes: 0 additions & 32 deletions crates/autopilot/src/infra/solvers/dto/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ pub enum Side {
pub struct Solution {
/// Unique ID of the solution (per driver competition), used to identify
/// it in subsequent requests (reveal, settle).
#[serde(deserialize_with = "deserialize_solution_id")]
pub solution_id: u64,
#[serde_as(as = "HexOrDecimalU256")]
pub score: U256,
Expand All @@ -182,37 +181,6 @@ pub struct Solution {
pub gas: Option<u64>,
}

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)
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
Expand Down
31 changes: 0 additions & 31 deletions crates/driver/src/infra/api/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,3 @@ pub(super) use {
settle::settle,
solve::{solve, AuctionError},
};

pub(crate) 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)
}
3 changes: 1 addition & 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,10 @@
use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_with::serde_as};
use {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(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
3 changes: 1 addition & 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,10 @@
use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_with::serde_as};
use {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(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 f9cbf83

Please sign in to comment.