diff --git a/bitacross-worker/core-primitives/settings/src/lib.rs b/bitacross-worker/core-primitives/settings/src/lib.rs index fb3a84fd7a..74e9838a75 100644 --- a/bitacross-worker/core-primitives/settings/src/lib.rs +++ b/bitacross-worker/core-primitives/settings/src/lib.rs @@ -28,7 +28,7 @@ pub mod files { // used by enclave /// Path to the light-client db for the Integritee parentchain. - pub const LITENTRY_PARENTCHAIN_LIGHT_CLIENT_DB_PATH: &str = "integritee_lcdb"; + pub const LITENTRY_PARENTCHAIN_LIGHT_CLIENT_DB_PATH: &str = "litentry_lcdb"; /// Path to the light-client db for the Target A parentchain. pub const TARGET_A_PARENTCHAIN_LIGHT_CLIENT_DB_PATH: &str = "target_a_lcdb"; diff --git a/tee-worker/enclave-runtime/src/initialization/mod.rs b/tee-worker/enclave-runtime/src/initialization/mod.rs index 5f50cdb42d..a0edccab0b 100644 --- a/tee-worker/enclave-runtime/src/initialization/mod.rs +++ b/tee-worker/enclave-runtime/src/initialization/mod.rs @@ -216,8 +216,11 @@ pub(crate) fn init_enclave( Arc::new(IntelAttestationHandler::new(ocall_api, signing_key_repository)); GLOBAL_ATTESTATION_HANDLER_COMPONENT.initialize(attestation_handler); - let data_provider_config = DataProviderConfig::new(); - GLOBAL_DATA_PROVIDER_CONFIG.initialize(data_provider_config.into()); + if let Ok(data_provider_config) = DataProviderConfig::new() { + GLOBAL_DATA_PROVIDER_CONFIG.initialize(data_provider_config.into()); + } else { + return Err(Error::Other("data provider initialize error".into())) + } Ok(()) } diff --git a/tee-worker/litentry/core/assertion-build-v2/src/nft_holder/mod.rs b/tee-worker/litentry/core/assertion-build-v2/src/nft_holder/mod.rs index 677f8f1b82..bb4e1ed443 100644 --- a/tee-worker/litentry/core/assertion-build-v2/src/nft_holder/mod.rs +++ b/tee-worker/litentry/core/assertion-build-v2/src/nft_holder/mod.rs @@ -189,7 +189,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_config = DataProviderConfig::default(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".into()); data_provider_config.set_nodereal_api_chain_network_url(url.clone() + "/nodereal_jsonrpc/"); diff --git a/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs b/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs index 5ba68f7f9b..5c261f8f92 100644 --- a/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs +++ b/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs @@ -88,7 +88,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap() + "/karat_dao/"; - let mut config = DataProviderConfig::new(); + let mut config = DataProviderConfig::new().unwrap(); config.set_karat_dao_api_url(url); config } diff --git a/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs b/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs index a39660141b..50ca6477e1 100644 --- a/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs +++ b/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs @@ -287,7 +287,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_config = DataProviderConfig::default(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".into()); data_provider_config.set_nodereal_api_chain_network_url(url.clone() + "/nodereal_jsonrpc/"); diff --git a/tee-worker/litentry/core/assertion-build/src/a14.rs b/tee-worker/litentry/core/assertion-build/src/a14.rs index bde9bef807..91de2a1a3c 100644 --- a/tee-worker/litentry/core/assertion-build/src/a14.rs +++ b/tee-worker/litentry/core/assertion-build/src/a14.rs @@ -28,11 +28,11 @@ use http::header::{AUTHORIZATION, CONNECTION}; use http_req::response::Headers; use itc_rest_client::{ error::Error as RestClientError, - http_client::{DefaultSend, HttpClient}, + http_client::{HttpClient, SendWithCertificateVerification}, rest_client::RestClient, RestPath, RestPost, }; -use lc_data_providers::{build_client, DataProviderConfig}; +use lc_data_providers::{build_client_with_cert, DataProviderConfig}; use serde::{Deserialize, Serialize}; const VC_A14_SUBJECT_DESCRIPTION: &str = @@ -67,7 +67,7 @@ pub struct A14Response { // TODO: merge it to new achainable API client once the migration is done pub struct A14Client { - client: RestClient>, + client: RestClient>, } impl A14Client { @@ -79,7 +79,7 @@ impl A14Client { data_provider_config.achainable_auth_key.clone().as_str(), ); let client = - build_client("https://label-production.graph.tdf-labs.io/v1/run/labels/a719e99c-1f9b-432e-8f1d-cb3de0f14dde", headers); + build_client_with_cert("https://label-production.graph.tdf-labs.io/v1/run/labels/a719e99c-1f9b-432e-8f1d-cb3de0f14dde", headers); A14Client { client } } diff --git a/tee-worker/litentry/core/assertion-build/src/a2.rs b/tee-worker/litentry/core/assertion-build/src/a2.rs index 4307645078..b351f1aea1 100644 --- a/tee-worker/litentry/core/assertion-build/src/a2.rs +++ b/tee-worker/litentry/core/assertion-build/src/a2.rs @@ -94,7 +94,7 @@ mod tests { #[test] fn build_a2_works() { - let mut data_provider_config = DataProviderConfig::new(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config .set_litentry_discord_microservice_url("http://localhost:19527".to_string()); let guild_id_u: u64 = 919848390156767232; diff --git a/tee-worker/litentry/core/assertion-build/src/a20.rs b/tee-worker/litentry/core/assertion-build/src/a20.rs index 859f4358d9..822bcebabb 100644 --- a/tee-worker/litentry/core/assertion-build/src/a20.rs +++ b/tee-worker/litentry/core/assertion-build/src/a20.rs @@ -23,7 +23,7 @@ extern crate sgx_tstd as std; use http::header::CONNECTION; use http_req::response::Headers; use itc_rest_client::{error::Error as RestClientError, RestGet, RestPath}; -use lc_data_providers::{build_client, DataProviderConfig}; +use lc_data_providers::{build_client_with_cert, DataProviderConfig}; use serde::{Deserialize, Serialize}; #[cfg(all(not(feature = "std"), feature = "sgx"))] @@ -65,7 +65,7 @@ pub fn build( let mut headers = Headers::new(); headers.insert(CONNECTION.as_str(), "close"); - let mut client = build_client(&data_provider_config.litentry_archive_url, headers); + let mut client = build_client_with_cert(&data_provider_config.litentry_archive_url, headers); let query = vec![("account", who.as_str())]; let value = client .get_with::("".to_string(), query.as_slice()) diff --git a/tee-worker/litentry/core/assertion-build/src/a3.rs b/tee-worker/litentry/core/assertion-build/src/a3.rs index 0f2bad9a2f..c0dc6f5a5d 100644 --- a/tee-worker/litentry/core/assertion-build/src/a3.rs +++ b/tee-worker/litentry/core/assertion-build/src/a3.rs @@ -117,7 +117,7 @@ mod tests { #[test] fn build_a3_works() { - let mut data_provider_config = DataProviderConfig::new(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config .set_litentry_discord_microservice_url("http://localhost:19527".to_string()); let guild_id_u: u64 = 919848390156767232; diff --git a/tee-worker/litentry/core/assertion-build/src/generic_discord_role.rs b/tee-worker/litentry/core/assertion-build/src/generic_discord_role.rs index e460b7a324..9f82b9ba19 100644 --- a/tee-worker/litentry/core/assertion-build/src/generic_discord_role.rs +++ b/tee-worker/litentry/core/assertion-build/src/generic_discord_role.rs @@ -109,7 +109,7 @@ mod tests { fn init() -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_conifg = DataProviderConfig::new(); + let mut data_provider_conifg = DataProviderConfig::new().unwrap(); data_provider_conifg.set_litentry_discord_microservice_url(url); data_provider_conifg.set_contest_legend_discord_role_id("1034083718425493544".to_string()); diff --git a/tee-worker/litentry/core/assertion-build/src/holding_time.rs b/tee-worker/litentry/core/assertion-build/src/holding_time.rs index a6744d6eb0..c46fceafa4 100644 --- a/tee-worker/litentry/core/assertion-build/src/holding_time.rs +++ b/tee-worker/litentry/core/assertion-build/src/holding_time.rs @@ -345,7 +345,7 @@ mod tests { fn init() -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_config = DataProviderConfig::new(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_achainable_url(url); data_provider_config } diff --git a/tee-worker/litentry/core/assertion-build/src/lit_staking.rs b/tee-worker/litentry/core/assertion-build/src/lit_staking.rs index c24ef05256..2b1c1c5670 100644 --- a/tee-worker/litentry/core/assertion-build/src/lit_staking.rs +++ b/tee-worker/litentry/core/assertion-build/src/lit_staking.rs @@ -20,14 +20,14 @@ use frame_support::{StorageHasher, Twox64Concat}; use http::header::CONNECTION; use itc_rest_client::{ error::Error as RestClientError, - http_client::{DefaultSend, HttpClient}, + http_client::{HttpClient, SendWithCertificateVerification}, rest_client::{Headers, RestClient}, RestPath, RestPost, }; use itp_stf_primitives::types::AccountId; use itp_utils::hex_display::AsBytesRef; use lc_credentials::litentry_profile::lit_staking::UpdateLITStakingAmountCredential; -use lc_data_providers::build_client; +use lc_data_providers::build_client_with_cert; use litentry_primitives::ParentchainBalance; use pallet_parachain_staking::types::Delegator; use serde::{Deserialize, Serialize}; @@ -70,7 +70,7 @@ pub struct JsonRPCResponse { } pub struct LitentryStakingClient { - client: RestClient>, + client: RestClient>, } impl Default for LitentryStakingClient { @@ -83,7 +83,7 @@ impl LitentryStakingClient { pub fn new() -> Self { let mut headers = Headers::new(); headers.insert(CONNECTION.as_str(), "close"); - let client = build_client("https://litentry-rpc.dwellir.com:443", headers); + let client = build_client_with_cert("https://litentry-rpc.dwellir.com:443", headers); LitentryStakingClient { client } } diff --git a/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs b/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs index cebb4616b7..a547680733 100644 --- a/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs +++ b/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs @@ -169,7 +169,7 @@ mod tests { fn init() -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap() + "/nodereal_jsonrpc/"; - let mut data_provider_config = DataProviderConfig::default(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".into()); data_provider_config.set_nodereal_api_chain_network_url(url); diff --git a/tee-worker/litentry/core/assertion-build/src/nodereal/nft_holder/weirdo_ghost_gang_holder.rs b/tee-worker/litentry/core/assertion-build/src/nodereal/nft_holder/weirdo_ghost_gang_holder.rs index e768d5a420..df358ef0a6 100644 --- a/tee-worker/litentry/core/assertion-build/src/nodereal/nft_holder/weirdo_ghost_gang_holder.rs +++ b/tee-worker/litentry/core/assertion-build/src/nodereal/nft_holder/weirdo_ghost_gang_holder.rs @@ -120,7 +120,7 @@ mod tests { fn init() -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap() + "/nodereal_jsonrpc/"; - let mut config = DataProviderConfig::new(); + let mut config = DataProviderConfig::new().unwrap(); config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".to_string()); config.set_nodereal_api_chain_network_url(url); diff --git a/tee-worker/litentry/core/assertion-build/src/oneblock/mod.rs b/tee-worker/litentry/core/assertion-build/src/oneblock/mod.rs index 438f6fd183..24e514cb28 100644 --- a/tee-worker/litentry/core/assertion-build/src/oneblock/mod.rs +++ b/tee-worker/litentry/core/assertion-build/src/oneblock/mod.rs @@ -26,7 +26,7 @@ use crate::*; use http::header::{AUTHORIZATION, CONNECTION}; use http_req::response::Headers; use itc_rest_client::{error::Error as RestClientError, RestGet, RestPath}; -use lc_data_providers::{build_client, DataProviderConfig}; +use lc_data_providers::{build_client_with_cert, DataProviderConfig}; use serde::{Deserialize, Serialize}; use std::string::ToString; @@ -55,7 +55,7 @@ fn fetch_data_from_notion( headers.insert("Notion-Version", "2022-06-28"); headers.insert(AUTHORIZATION.as_str(), oneblock_notion_key.as_str()); - let mut client = build_client(oneblock_notion_url.as_str(), headers); + let mut client = build_client_with_cert(oneblock_notion_url.as_str(), headers); client.get::(String::default()).map_err(|e| { Error::RequestVCFailed( diff --git a/tee-worker/litentry/core/data-providers/src/achainable.rs b/tee-worker/litentry/core/data-providers/src/achainable.rs index 41668ecfd7..733b2261c7 100644 --- a/tee-worker/litentry/core/data-providers/src/achainable.rs +++ b/tee-worker/litentry/core/data-providers/src/achainable.rs @@ -1441,7 +1441,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_config = DataProviderConfig::new(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_achainable_url(url); AchainableClient::new(&data_provider_config) } diff --git a/tee-worker/litentry/core/data-providers/src/discord_litentry.rs b/tee-worker/litentry/core/data-providers/src/discord_litentry.rs index 302013aaa7..7ae93687de 100644 --- a/tee-worker/litentry/core/data-providers/src/discord_litentry.rs +++ b/tee-worker/litentry/core/data-providers/src/discord_litentry.rs @@ -161,7 +161,7 @@ mod tests { fn init() -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_config = DataProviderConfig::new(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_litentry_discord_microservice_url(url); data_provider_config } diff --git a/tee-worker/litentry/core/data-providers/src/discord_official.rs b/tee-worker/litentry/core/data-providers/src/discord_official.rs index 938b996133..7ee9d08617 100644 --- a/tee-worker/litentry/core/data-providers/src/discord_official.rs +++ b/tee-worker/litentry/core/data-providers/src/discord_official.rs @@ -125,7 +125,7 @@ mod tests { fn init() -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_config = DataProviderConfig::new(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_discord_official_url(url); data_provider_config } diff --git a/tee-worker/litentry/core/data-providers/src/karat_dao.rs b/tee-worker/litentry/core/data-providers/src/karat_dao.rs index 718fbfbd79..169ed48909 100644 --- a/tee-worker/litentry/core/data-providers/src/karat_dao.rs +++ b/tee-worker/litentry/core/data-providers/src/karat_dao.rs @@ -21,12 +21,13 @@ use crate::sgx_reexport_prelude::*; extern crate sgx_tstd as std; use crate::{ - build_client, DataProviderConfig, Error, HttpError, ReqPath, RetryOption, RetryableRestGet, + build_client_with_cert, DataProviderConfig, Error, HttpError, ReqPath, RetryOption, + RetryableRestGet, }; use http::header::CONNECTION; use http_req::response::Headers; use itc_rest_client::{ - http_client::{DefaultSend, HttpClient}, + http_client::{HttpClient, SendWithCertificateVerification}, rest_client::RestClient, RestPath, }; @@ -41,7 +42,7 @@ use std::{ pub struct KaratDaoClient { retry_option: RetryOption, - client: RestClient>, + client: RestClient>, } #[derive(Debug)] @@ -60,7 +61,7 @@ impl KaratDaoClient { let mut headers = Headers::new(); headers.insert(CONNECTION.as_str(), "close"); - let client = build_client(api_url.as_str(), headers); + let client = build_client_with_cert(api_url.as_str(), headers); KaratDaoClient { retry_option, client } } @@ -146,7 +147,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap() + "/karat_dao/"; - let mut config = DataProviderConfig::new(); + let mut config = DataProviderConfig::new().unwrap(); config.set_karat_dao_api_url(url); config } diff --git a/tee-worker/litentry/core/data-providers/src/lib.rs b/tee-worker/litentry/core/data-providers/src/lib.rs index 6d9cbebcb9..908019f57d 100644 --- a/tee-worker/litentry/core/data-providers/src/lib.rs +++ b/tee-worker/litentry/core/data-providers/src/lib.rs @@ -41,7 +41,7 @@ use core::time::Duration; use http_req::response::Headers; use itc_rest_client::{ error::Error as HttpError, - http_client::{DefaultSend, HttpClient, Send}, + http_client::{HttpClient, Send, SendWithCertificateVerification}, rest_client::RestClient, Query, RestGet, RestPath, RestPost, }; @@ -50,7 +50,6 @@ use log::debug; use serde::{Deserialize, Serialize}; use std::{thread, vec}; -use itc_rest_client::http_client::SendWithCertificateVerification; use litentry_primitives::{ AchainableParams, Assertion, ErrorDetail, ErrorString, IntoErrorDetail, ParameterString, VCMPError, @@ -201,14 +200,8 @@ pub struct DataProviderConfig { pub moralis_api_key: String, } -impl Default for DataProviderConfig { - fn default() -> Self { - Self::new() - } -} - impl DataProviderConfig { - pub fn new() -> Self { + pub fn new() -> Result { log::debug!("Initializing data providers config"); // default prod config @@ -252,22 +245,22 @@ impl DataProviderConfig { // we allow to override following config properties for non prod dev if_not_production!({ if let Ok(v) = env::var("TWITTER_OFFICIAL_URL") { - config.set_twitter_official_url(v); + config.set_twitter_official_url(v)?; } if let Ok(v) = env::var("DISCORD_OFFICIAL_URL") { - config.set_discord_official_url(v); + config.set_discord_official_url(v)?; } if let Ok(v) = env::var("LITENTRY_DISCORD_MICROSERVICE_URL") { - config.set_litentry_discord_microservice_url(v); + config.set_litentry_discord_microservice_url(v)?; } if let Ok(v) = env::var("ACHAINABLE_URL") { - config.set_achainable_url(v); + config.set_achainable_url(v)?; } if let Ok(v) = env::var("CREDENTIAL_ENDPOINT") { config.set_credential_endpoint(v); } if let Ok(v) = env::var("ONEBLOCK_NOTION_URL") { - config.set_oneblock_notion_url(v); + config.set_oneblock_notion_url(v)?; } if let Ok(v) = env::var("SORA_QUIZ_MASTER_ID") { config.set_sora_quiz_master_id(v); @@ -276,7 +269,7 @@ impl DataProviderConfig { config.set_sora_quiz_attendee_id(v); } if let Ok(v) = env::var("NODEREAL_API_URL") { - config.set_nodereal_api_url(v); + config.set_nodereal_api_url(v)?; } if let Ok(v) = env::var("NODEREAL_API_RETRY_DELAY") { config.set_nodereal_api_retry_delay(v.parse::().unwrap()); @@ -285,7 +278,7 @@ impl DataProviderConfig { config.set_nodereal_api_retry_times(v.parse::().unwrap()); } if let Ok(v) = env::var("NODEREAL_API_CHAIN_NETWORK_URL") { - config.set_nodereal_api_chain_network_url(v); + config.set_nodereal_api_chain_network_url(v)?; } if let Ok(v) = env::var("CONTEST_LEGEND_DISCORD_ROLE_ID") { config.set_contest_legend_discord_role_id(v); @@ -297,13 +290,13 @@ impl DataProviderConfig { config.set_contest_participant_discord_role_id(v); } if let Ok(v) = env::var("VIP3_URL") { - config.set_vip3_url(v); + config.set_vip3_url(v)?; } if let Ok(v) = env::var("GENIIDATA_URL") { - config.set_geniidata_url(v); + config.set_geniidata_url(v)?; } if let Ok(v) = env::var("LITENTRY_ARCHIVE_URL") { - config.set_litentry_archive_url(v); + config.set_litentry_archive_url(v)?; } if let Ok(v) = env::var("KARAT_DAO_API_RETRY_DELAY") { config.set_karat_dao_api_retry_delay(v.parse::().unwrap()); @@ -312,10 +305,10 @@ impl DataProviderConfig { config.set_karat_dao_api_retry_times(v.parse::().unwrap()); } if let Ok(v) = env::var("KARAT_DAO_API_URL") { - config.set_karat_dao_api_url(v); + config.set_karat_dao_api_url(v)?; } if let Ok(v) = env::var("MORALIS_API_URL") { - config.set_moralis_api_url(v); + config.set_moralis_api_url(v)?; } if let Ok(v) = env::var("MORALIS_API_RETRY_DELAY") { config.set_moralis_api_retry_delay(v.parse::().unwrap()); @@ -346,31 +339,39 @@ impl DataProviderConfig { if let Ok(v) = env::var("MORALIS_API_KEY") { config.set_moralis_api_key(v); } - config + Ok(config) } - pub fn set_twitter_official_url(&mut self, v: String) { + pub fn set_twitter_official_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_twitter_official_url: {:?}", v); self.twitter_official_url = v; + Ok(()) } pub fn set_twitter_auth_token_v2(&mut self, v: String) { debug!("set_twitter_auth_token_v2: {:?}", v); self.twitter_auth_token_v2 = v; } - pub fn set_discord_official_url(&mut self, v: String) { + pub fn set_discord_official_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_discord_official_url: {:?}", v); self.discord_official_url = v; + Ok(()) } - pub fn set_litentry_discord_microservice_url(&mut self, v: String) { + pub fn set_litentry_discord_microservice_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_litentry_discord_microservice_url: {:?}", v); self.litentry_discord_microservice_url = v; + Ok(()) } pub fn set_discord_auth_token(&mut self, v: String) { debug!("set_discord_auth_token: {:?}", v); self.discord_auth_token = v; } - pub fn set_achainable_url(&mut self, v: String) { + pub fn set_achainable_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_achainable_url: {:?}", v); self.achainable_url = v; + Ok(()) } pub fn set_achainable_auth_key(&mut self, v: String) { debug!("set_achainable_auth_key: {:?}", v); @@ -384,9 +385,11 @@ impl DataProviderConfig { debug!("set_oneblock_notion_key: {:?}", v); self.oneblock_notion_key = v; } - pub fn set_oneblock_notion_url(&mut self, v: String) { + pub fn set_oneblock_notion_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_oneblock_notion_url: {:?}", v); self.oneblock_notion_url = v; + Ok(()) } pub fn set_sora_quiz_master_id(&mut self, v: String) { debug!("set_sora_quiz_master_id: {:?}", v); @@ -408,13 +411,17 @@ impl DataProviderConfig { debug!("set_nodereal_api_retry_times: {:?}", v); self.nodereal_api_retry_times = v; } - pub fn set_nodereal_api_url(&mut self, v: String) { + pub fn set_nodereal_api_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_nodereal_api_url: {:?}", v); self.nodereal_api_url = v; + Ok(()) } - pub fn set_nodereal_api_chain_network_url(&mut self, v: String) { + pub fn set_nodereal_api_chain_network_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_nodereal_api_chain_network_url: {:?}", v); self.nodereal_api_chain_network_url = v; + Ok(()) } pub fn set_contest_legend_discord_role_id(&mut self, v: String) { debug!("set_contest_legend_discord_role_id: {:?}", v); @@ -428,21 +435,27 @@ impl DataProviderConfig { debug!("set_contest_participant_discord_role_id: {:?}", v); self.contest_participant_discord_role_id = v; } - pub fn set_vip3_url(&mut self, v: String) { + pub fn set_vip3_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_vip3_url: {:?}", v); self.vip3_url = v; + Ok(()) } - pub fn set_geniidata_url(&mut self, v: String) { + pub fn set_geniidata_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_geniidata_url: {:?}", v); self.geniidata_url = v; + Ok(()) } pub fn set_geniidata_api_key(&mut self, v: String) { debug!("set_geniidata_api_key: {:?}", v); self.geniidata_api_key = v; } - pub fn set_litentry_archive_url(&mut self, v: String) { + pub fn set_litentry_archive_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_litentry_archive_url: {:?}", v); self.litentry_archive_url = v; + Ok(()) } pub fn set_karat_dao_api_retry_delay(&mut self, v: u64) { debug!("set_karat_dao_api_retry_delay: {:?}", v); @@ -452,9 +465,11 @@ impl DataProviderConfig { debug!("set_karat_dao_api_retry_times: {:?}", v); self.karat_dao_api_retry_times = v; } - pub fn set_karat_dao_api_url(&mut self, v: String) { + pub fn set_karat_dao_api_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_karat_dao_api_url: {:?}", v); self.karat_dao_api_url = v; + Ok(()) } pub fn set_moralis_api_key(&mut self, v: String) { debug!("set_moralis_api_key: {:?}", v); @@ -468,9 +483,18 @@ impl DataProviderConfig { debug!("set_moralis_api_retry_times: {:?}", v); self.moralis_api_retry_times = v; } - pub fn set_moralis_api_url(&mut self, v: String) { + pub fn set_moralis_api_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; debug!("set_moralis_api_url: {:?}", v); self.moralis_api_url = v; + Ok(()) + } +} + +fn check_url(v: &String) -> Result<(), Error> { + match Url::parse(v) { + Ok(_) => Ok(()), + Err(err) => Err(Error::Utf8Error(format!("Input url: {:?}, parse error: {:?}", v, err))), } } @@ -516,13 +540,6 @@ pub fn vec_to_string(vec: Vec) -> Result { Ok(tmp.to_string()) } -pub fn build_client(base_url: &str, headers: Headers) -> RestClient> { - debug!("base_url: {}", base_url); - let base_url = Url::parse(base_url).unwrap(); - let http_client = HttpClient::new(DefaultSend {}, true, Some(TIMEOUT), Some(headers), None); - RestClient::new(http_client, base_url) -} - pub fn build_client_with_cert( base_url: &str, headers: Headers, diff --git a/tee-worker/litentry/core/data-providers/src/moralis.rs b/tee-worker/litentry/core/data-providers/src/moralis.rs index 4a606dcb44..8adefdad13 100644 --- a/tee-worker/litentry/core/data-providers/src/moralis.rs +++ b/tee-worker/litentry/core/data-providers/src/moralis.rs @@ -18,12 +18,13 @@ use crate::sgx_reexport_prelude::*; use crate::{ - build_client, DataProviderConfig, Error, HttpError, ReqPath, RetryOption, RetryableRestGet, + build_client_with_cert, DataProviderConfig, Error, HttpError, ReqPath, RetryOption, + RetryableRestGet, }; use http::header::CONNECTION; use http_req::response::Headers; use itc_rest_client::{ - http_client::{DefaultSend, HttpClient}, + http_client::{HttpClient, SendWithCertificateVerification}, rest_client::RestClient, RestPath, }; @@ -45,7 +46,7 @@ pub struct MoralisRequest { pub struct MoralisClient { retry_option: RetryOption, - client: RestClient>, + client: RestClient>, } impl MoralisClient { @@ -60,7 +61,7 @@ impl MoralisClient { let mut headers = Headers::new(); headers.insert(CONNECTION.as_str(), "close"); headers.insert("X-API-Key", api_key.as_str()); - let client = build_client(api_url.as_str(), headers); + let client = build_client_with_cert(api_url.as_str(), headers); MoralisClient { retry_option, client } } @@ -206,7 +207,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap() + "/moralis/"; - let mut config = DataProviderConfig::new(); + let mut config = DataProviderConfig::new().unwrap(); config.set_moralis_api_key("d416f55179dbd0e45b1a8ed030e3".to_string()); config.set_moralis_api_url(url); config diff --git a/tee-worker/litentry/core/data-providers/src/nodereal_jsonrpc.rs b/tee-worker/litentry/core/data-providers/src/nodereal_jsonrpc.rs index 905c473591..713535d2bc 100644 --- a/tee-worker/litentry/core/data-providers/src/nodereal_jsonrpc.rs +++ b/tee-worker/litentry/core/data-providers/src/nodereal_jsonrpc.rs @@ -18,13 +18,13 @@ use crate::sgx_reexport_prelude::*; use crate::{ - build_client, convert_balance_hex_json_value_to_u128, DataProviderConfig, Error, HttpError, - ReqPath, RetryOption, RetryableRestPost, + build_client_with_cert, convert_balance_hex_json_value_to_u128, DataProviderConfig, Error, + HttpError, ReqPath, RetryOption, RetryableRestPost, }; use http::header::CONNECTION; use http_req::response::Headers; use itc_rest_client::{ - http_client::{DefaultSend, HttpClient}, + http_client::{HttpClient, SendWithCertificateVerification}, rest_client::RestClient, RestPath, }; @@ -111,7 +111,7 @@ pub struct RpcResponse { pub struct NoderealJsonrpcClient { path: String, retry_option: RetryOption, - client: RestClient>, + client: RestClient>, } impl NoderealJsonrpcClient { @@ -127,7 +127,7 @@ impl NoderealJsonrpcClient { let mut headers = Headers::new(); headers.insert(CONNECTION.as_str(), "close"); - let client = build_client(base_url.as_str(), headers); + let client = build_client_with_cert(base_url.as_str(), headers); NoderealJsonrpcClient { path, retry_option, client } } @@ -529,7 +529,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap() + "/nodereal_jsonrpc/"; - let mut config = DataProviderConfig::new(); + let mut config = DataProviderConfig::new().unwrap(); config.set_nodereal_api_key("d416f55179dbd0e45b1a8ed030e3".to_string()); config.set_nodereal_api_chain_network_url(url); config diff --git a/tee-worker/litentry/core/data-providers/src/twitter_official.rs b/tee-worker/litentry/core/data-providers/src/twitter_official.rs index 09404f862a..43d6b7d618 100644 --- a/tee-worker/litentry/core/data-providers/src/twitter_official.rs +++ b/tee-worker/litentry/core/data-providers/src/twitter_official.rs @@ -255,7 +255,7 @@ mod tests { fn init() -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); let url = run(0).unwrap(); - let mut data_provider_config = DataProviderConfig::new(); + let mut data_provider_config = DataProviderConfig::new().unwrap(); data_provider_config.set_twitter_official_url(url); data_provider_config } diff --git a/tee-worker/litentry/core/stf-task/receiver/src/test.rs b/tee-worker/litentry/core/stf-task/receiver/src/test.rs index 61a9048590..1e55e37c90 100644 --- a/tee-worker/litentry/core/stf-task/receiver/src/test.rs +++ b/tee-worker/litentry/core/stf-task/receiver/src/test.rs @@ -21,7 +21,7 @@ fn test_threadpool_behaviour() { let stf_enclave_signer_mock = StfEnclaveSignerMock::default(); let handle_state_mock = HandleStateMock::default(); let onchain_mock = OnchainMock::default(); - let data_provider_conifg = DataProviderConfig::new(); + let data_provider_conifg = DataProviderConfig::new().unwrap(); let context = StfTaskContext::new( Arc::new(shielding_key_repository_mock), author_mock.into(), diff --git a/tee-worker/sidechain/consensus/slots/src/lib.rs b/tee-worker/sidechain/consensus/slots/src/lib.rs index c27f9d2450..b2201cfb08 100644 --- a/tee-worker/sidechain/consensus/slots/src/lib.rs +++ b/tee-worker/sidechain/consensus/slots/src/lib.rs @@ -466,7 +466,7 @@ pub trait SimpleSlotWorker { }; if is_single_worker { - error!("Running as single worker, skipping timestamp within slot check") + warn!("Running as single worker, skipping timestamp within slot check") } else if !timestamp_within_slot(&slot_info, &proposing.block) { warn!( "⌛️ Discarding proposal for slot {}, block number {}; block production took too long",