diff --git a/sdk/build.rs b/sdk/build.rs index 168f8964..c2777ba1 100644 --- a/sdk/build.rs +++ b/sdk/build.rs @@ -1,4 +1,4 @@ fn main() -> Result<(), Box> { tonic_build::compile_protos("src/proto/stage.proto")?; Ok(()) -} \ No newline at end of file +} diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index c5ed955f..8b837558 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -1,11 +1,10 @@ - -pub mod prover; pub mod local; pub mod network; +pub mod prover; -use std::env; -use prover::Prover; use network::prover::NetworkProver; +use prover::Prover; +use std::env; pub struct ProverClient { pub prover: Box, @@ -14,7 +13,11 @@ pub struct ProverClient { impl ProverClient { pub fn new() -> Self { #[allow(unreachable_code)] - match env::var("ZKM_PROVER").unwrap_or("network".to_string()).to_lowercase().as_str() { + match env::var("ZKM_PROVER") + .unwrap_or("network".to_string()) + .to_lowercase() + .as_str() + { // "local" => Self { // prover: Box::new(CpuProver::new()), // }, @@ -32,7 +35,9 @@ impl ProverClient { // } pub fn network() -> Self { - Self { prover: Box::new(NetworkProver::default()) } + Self { + prover: Box::new(NetworkProver::default()), + } } } @@ -40,4 +45,4 @@ impl Default for ProverClient { fn default() -> Self { Self::new() } -} \ No newline at end of file +} diff --git a/sdk/src/local/mod.rs b/sdk/src/local/mod.rs index e69de29b..8b137891 100644 --- a/sdk/src/local/mod.rs +++ b/sdk/src/local/mod.rs @@ -0,0 +1 @@ + diff --git a/sdk/src/network/mod.rs b/sdk/src/network/mod.rs index 4cd3d7d8..b8fcb1c3 100644 --- a/sdk/src/network/mod.rs +++ b/sdk/src/network/mod.rs @@ -1,2 +1 @@ - -pub mod prover; \ No newline at end of file +pub mod prover; diff --git a/sdk/src/network/prover.rs b/sdk/src/network/prover.rs index 7747c4ad..ee071948 100644 --- a/sdk/src/network/prover.rs +++ b/sdk/src/network/prover.rs @@ -3,13 +3,13 @@ use stage_service::stage_service_client::StageServiceClient; use stage_service::{GenerateProofRequest, GetStatusRequest}; use std::env; use std::time::Instant; -use tonic::transport::{Channel, ClientTlsConfig}; use tonic::transport::Endpoint; +use tonic::transport::{Channel, ClientTlsConfig}; -use ethers::signers::{LocalWallet, Signer}; use crate::prover::{Prover, ProverInput, ProverResult}; -use tokio::time::Duration; +use ethers::signers::{LocalWallet, Signer}; use tokio::time::sleep; +use tokio::time::Duration; use async_trait::async_trait; @@ -33,7 +33,8 @@ impl NetworkProver { let ca_cert_path = env::var("CA_CERT_PATH").unwrap_or("".to_string()); let cert_path = env::var("CERT_PATH").unwrap_or("".to_string()); let key_path = env::var("KEY_PATH").unwrap_or("".to_string()); - let domain_name = env::var("DOMAIN_NAME").unwrap_or(DEFALUT_PROVER_NETWORK_DOMAIN.to_string()); + let domain_name = + env::var("DOMAIN_NAME").unwrap_or(DEFALUT_PROVER_NETWORK_DOMAIN.to_string()); let private_key = env::var("PRIVATE_KEY").unwrap_or("".to_string()); let ssl_config = if ca_cert_path.is_empty() { @@ -41,7 +42,7 @@ impl NetworkProver { } else { Some(Config::new(ca_cert_path, cert_path, key_path).await?) }; - + let endpoint = match ssl_config { Some(config) => { let mut tls_config = ClientTlsConfig::new().domain_name(domain_name); @@ -57,7 +58,10 @@ impl NetworkProver { }; let stage_client = StageServiceClient::connect(endpoint).await?; let wallet = private_key.parse::().unwrap(); - Ok(NetworkProver { stage_client, wallet }) + Ok(NetworkProver { + stage_client, + wallet, + }) } pub async fn sign_ecdsa(&self, request: &mut GenerateProofRequest) { @@ -72,7 +76,7 @@ impl NetworkProver { impl Default for NetworkProver { fn default() -> Self { - let rt = tokio::runtime::Runtime::new().unwrap(); + let rt = tokio::runtime::Runtime::new().unwrap(); let result = rt.block_on(Self::new()); result.unwrap() } @@ -97,7 +101,11 @@ impl Prover for NetworkProver { Ok(response.proof_id) } - async fn wait_proof<'a>(&self, proof_id: &'a str, timeout: Option) -> anyhow::Result > { + async fn wait_proof<'a>( + &self, + proof_id: &'a str, + timeout: Option, + ) -> anyhow::Result> { let start_time = Instant::now(); let mut client = self.stage_client.clone(); loop { @@ -110,10 +118,7 @@ impl Prover for NetworkProver { let get_status_request = GetStatusRequest { proof_id: proof_id.to_string(), }; - let get_status_response = client - .get_status(get_status_request) - .await? - .into_inner(); + let get_status_response = client.get_status(get_status_request).await?.into_inner(); match Status::from_i32(get_status_response.status as i32) { Some(Status::Computing) => { @@ -138,8 +143,12 @@ impl Prover for NetworkProver { } } - async fn prover<'a>(&self, input: &'a ProverInput, timeout: Option) -> anyhow::Result > { + async fn prover<'a>( + &self, + input: &'a ProverInput, + timeout: Option, + ) -> anyhow::Result> { let proof_id = self.request_proof(input).await?; self.wait_proof(&proof_id, timeout).await } -} \ No newline at end of file +} diff --git a/sdk/src/prover.rs b/sdk/src/prover.rs index 60786b51..a28378fe 100644 --- a/sdk/src/prover.rs +++ b/sdk/src/prover.rs @@ -1,8 +1,7 @@ - -use tokio::time::Duration; use async_trait::async_trait; -use serde::Serialize; use serde::Deserialize; +use serde::Serialize; +use tokio::time::Duration; #[derive(Debug, Default, Deserialize, Serialize)] pub struct ProverInput { @@ -23,6 +22,14 @@ pub struct ProverResult { #[async_trait] pub trait Prover { async fn request_proof<'a>(&self, input: &'a ProverInput) -> anyhow::Result; - async fn wait_proof<'a>(&self, proof_id: &'a str, timeout: Option) -> anyhow::Result>; - async fn prover<'a>(&self, input: &'a ProverInput, timeout: Option) -> anyhow::Result>; -} \ No newline at end of file + async fn wait_proof<'a>( + &self, + proof_id: &'a str, + timeout: Option, + ) -> anyhow::Result>; + async fn prover<'a>( + &self, + input: &'a ProverInput, + timeout: Option, + ) -> anyhow::Result>; +}