diff --git a/CHANGELOG.md b/CHANGELOG.md index 308df458..cc2a0ce0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Fixed +- Added new_with_settings to SharpClient. - Calculate root hash logic and added a simple test for it. - Cargo.toml dependency reorg. - Get Fact Info logic. diff --git a/crates/prover-services/sharp-service/src/client.rs b/crates/prover-services/sharp-service/src/client.rs index 437f592b..4894961c 100644 --- a/crates/prover-services/sharp-service/src/client.rs +++ b/crates/prover-services/sharp-service/src/client.rs @@ -4,6 +4,7 @@ use reqwest::{Certificate, ClientBuilder, Identity}; use std::clone::Clone; use url::Url; use utils::env_utils::get_env_var_or_panic; +use utils::settings::Settings; use uuid::Uuid; use crate::error::SharpError; @@ -26,15 +27,17 @@ impl SharpClient { /// and then copy it and paste it into .env file : /// /// `cat | base64` - pub fn new(url: Url) -> Self { + pub fn new_with_settings(url: Url, settings: &impl Settings) -> Self { // Getting the cert files from the .env and then decoding it from base64 - let cert = general_purpose::STANDARD.decode(get_env_var_or_panic("SHARP_USER_CRT")).unwrap(); - let key = general_purpose::STANDARD.decode(get_env_var_or_panic("SHARP_USER_KEY")).unwrap(); - let server_cert = general_purpose::STANDARD.decode(get_env_var_or_panic("SHARP_SERVER_CRT")).unwrap(); + + let cert = general_purpose::STANDARD.decode(settings.get_settings_or_panic("SHARP_USER_CRT")).unwrap(); + let key = general_purpose::STANDARD.decode(settings.get_settings_or_panic("SHARP_USER_KEY")).unwrap(); + let server_cert = general_purpose::STANDARD.decode(settings.get_settings_or_panic("SHARP_SERVER_CRT")).unwrap(); // Adding Customer ID to the url + let mut url_mut = url.clone(); - let customer_id = get_env_var_or_panic("SHARP_CUSTOMER_ID"); + let customer_id = settings.get_settings_or_panic("SHARP_CUSTOMER_ID"); url_mut.query_pairs_mut().append_pair("customer_id", customer_id.as_str()); Self { @@ -109,9 +112,3 @@ fn add_params_to_url(url: &mut Url, params: Vec<(&str, &str)>) { pairs.append_pair(key, value); } } - -impl Default for SharpClient { - fn default() -> Self { - Self::new(get_env_var_or_panic("SHARP_URL").parse().unwrap()) - } -} diff --git a/crates/prover-services/sharp-service/src/lib.rs b/crates/prover-services/sharp-service/src/lib.rs index 808fde75..88e6cf9b 100644 --- a/crates/prover-services/sharp-service/src/lib.rs +++ b/crates/prover-services/sharp-service/src/lib.rs @@ -75,7 +75,7 @@ impl SharpProverService { pub fn new_with_settings(settings: &impl Settings) -> Self { let sharp_config = SharpConfig::new_with_settings(settings) .expect("Not able to create SharpProverService from given settings."); - let sharp_client = SharpClient::new(sharp_config.service_url); + let sharp_client = SharpClient::new_with_settings(sharp_config.service_url, settings); let fact_checker = FactChecker::new(sharp_config.rpc_node_url, sharp_config.verifier_address); Self::new(sharp_client, fact_checker) } @@ -83,7 +83,8 @@ impl SharpProverService { pub fn with_test_settings(settings: &impl Settings, port: u16) -> Self { let sharp_config = SharpConfig::new_with_settings(settings) .expect("Not able to create SharpProverService from given settings."); - let sharp_client = SharpClient::new(format!("http://127.0.0.1:{}", port).parse().unwrap()); + let sharp_client = + SharpClient::new_with_settings(format!("http://127.0.0.1:{}", port).parse().unwrap(), settings); let fact_checker = FactChecker::new(sharp_config.rpc_node_url, sharp_config.verifier_address); Self::new(sharp_client, fact_checker) }