Skip to content

Commit

Permalink
update: SharpClient shifted to new_with_settings from new (madara-all…
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv authored Sep 28, 2024
1 parent 05e8acb commit ab66b83
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 8 additions & 11 deletions crates/prover-services/sharp-service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,15 +27,17 @@ impl SharpClient {
/// and then copy it and paste it into .env file :
///
/// `cat <file_name> | 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 {
Expand Down Expand Up @@ -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())
}
}
5 changes: 3 additions & 2 deletions crates/prover-services/sharp-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ 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)
}

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

0 comments on commit ab66b83

Please sign in to comment.