Skip to content

Commit

Permalink
fix: not use manual parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
iajoiner committed Oct 29, 2024
1 parent 0d1dec6 commit b183ec7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
1 change: 0 additions & 1 deletion ethereum-core-counts.json

This file was deleted.

33 changes: 28 additions & 5 deletions sdk/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{parse_postprocessing_level, PostprocessingLevel, SxTClient};
use clap::Parser;
use crate::{PostprocessingLevel, SxTClient};
use clap::{Parser, ValueEnum};

/// Struct to define and parse command-line arguments for Proof of SQL Client.
///
Expand Down Expand Up @@ -85,10 +85,33 @@ pub struct SdkArgs {
long,
value_name = "POSTPROCESSING_LEVEL",
default_value = "cheap",
value_parser = parse_postprocessing_level,
value_enum,
help = "Level of postprocessing allowed, default is `Cheap`"
)]
pub postprocessing_level: PostprocessingLevel,
pub postprocessing_level: PostprocessingLevelArg,
}

/// Level of postprocessing allowed.
///
/// We have it as a separate enum from `PostprocessingLevel` so that the core of the lib won't depend on `clap`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum PostprocessingLevelArg {
/// No postprocessing allowed
None,
/// Only cheap postprocessing allowed
Cheap,
/// All postprocessing allowed
All,
}

impl From<PostprocessingLevelArg> for PostprocessingLevel {
fn from(arg: PostprocessingLevelArg) -> Self {
match arg {
PostprocessingLevelArg::None => PostprocessingLevel::None,
PostprocessingLevelArg::Cheap => PostprocessingLevel::Cheap,
PostprocessingLevelArg::All => PostprocessingLevel::All,
}
}
}

impl From<&SdkArgs> for SxTClient {
Expand All @@ -100,6 +123,6 @@ impl From<&SdkArgs> for SxTClient {
args.sxt_api_key.clone(),
args.verifier_setup.clone(),
)
.with_postprocessing(args.postprocessing_level)
.with_postprocessing(args.postprocessing_level.into())
}
}
29 changes: 1 addition & 28 deletions sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use proof_of_sql::{
};
use prover::{ProverContextRange, ProverQuery, ProverResponse};
use reqwest::Client;
use std::{collections::HashMap, path::Path, str::FromStr};
use std::{collections::HashMap, path::Path};

mod prover {
tonic::include_proto!("sxt.core");
Expand All @@ -31,33 +31,6 @@ pub enum PostprocessingLevel {
All,
}

impl FromStr for PostprocessingLevel {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"none" => Ok(PostprocessingLevel::None),
"cheap" => Ok(PostprocessingLevel::Cheap),
"all" => Ok(PostprocessingLevel::All),
_ => Err(format!("Invalid value for PostprocessingLevel: {}", s)),
}
}
}

impl std::fmt::Display for PostprocessingLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PostprocessingLevel::None => write!(f, "none"),
PostprocessingLevel::Cheap => write!(f, "cheap"),
PostprocessingLevel::All => write!(f, "expensive"),
}
}
}

pub(crate) fn parse_postprocessing_level(s: &str) -> Result<PostprocessingLevel, String> {
s.parse()
}

/// Space and Time (SxT) client
#[derive(Debug, Clone)]
pub struct SxTClient {
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
mod args;
pub use args::SdkArgs;
pub use args::{PostprocessingLevelArg, SdkArgs};
mod auth;
pub use auth::get_access_token;
mod client;
pub(crate) use client::parse_postprocessing_level;
pub use client::{PostprocessingLevel, SxTClient};
mod substrate;
pub use substrate::query_commitments;
Expand Down

0 comments on commit b183ec7

Please sign in to comment.