diff --git a/common/client-core/src/client/topology_control/geo_aware_provider.rs b/common/client-core/src/client/topology_control/geo_aware_provider.rs index 268f6612e0..62085796c6 100644 --- a/common/client-core/src/client/topology_control/geo_aware_provider.rs +++ b/common/client-core/src/client/topology_control/geo_aware_provider.rs @@ -2,6 +2,7 @@ use std::{collections::HashMap, fmt}; use log::{debug, error, info}; use nym_explorer_api_requests::PrettyDetailedMixNodeBond; +use nym_network_defaults::var_names::EXPLORER_API; use nym_topology::{ nym_topology_from_detailed, provider_trait::{async_trait, TopologyProvider}, @@ -13,11 +14,23 @@ use serde::{Deserialize, Serialize}; use url::Url; const MIN_NODES_PER_LAYER: usize = 1; -const EXPLORER_API_MIXNODES_URL: &str = "https://explorer.nymtech.net/api/v1/mix-nodes"; // TODO: create a explorer-api-client async fn fetch_mixnodes_from_explorer_api() -> Option> { - reqwest::get(EXPLORER_API_MIXNODES_URL) + let explorer_api_url = std::env::var(EXPLORER_API).ok()?; + let explorer_api_url = Url::parse(&explorer_api_url) + .ok()? + .join("v1/mix-nodes") + .ok()?; + + debug!("Fetching: {}", explorer_api_url); + let client = reqwest::Client::builder() + .timeout(std::time::Duration::from_secs(5)) + .build() + .ok()?; + client + .get(explorer_api_url) + .send() .await .ok()? .json::>() diff --git a/common/network-defaults/src/lib.rs b/common/network-defaults/src/lib.rs index 8de0ed465c..1704608043 100644 --- a/common/network-defaults/src/lib.rs +++ b/common/network-defaults/src/lib.rs @@ -43,6 +43,7 @@ pub struct NymNetworkDetails { pub chain_details: ChainDetails, pub endpoints: Vec, pub contracts: NymContracts, + pub explorer_api: Option, } // by default we assume the same defaults as mainnet, i.e. same prefixes and denoms @@ -71,6 +72,7 @@ impl NymNetworkDetails { }, endpoints: Default::default(), contracts: Default::default(), + explorer_api: Default::default(), } } @@ -136,6 +138,7 @@ impl NymNetworkDetails { var_names::SERVICE_PROVIDER_DIRECTORY_CONTRACT_ADDRESS, )) .with_name_service_contract(get_optional_env(var_names::NAME_SERVICE_CONTRACT_ADDRESS)) + .with_explorer_api(get_optional_env(var_names::EXPLORER_API)) } pub fn new_mainnet() -> Self { @@ -167,6 +170,7 @@ impl NymNetworkDetails { service_provider_directory_contract_address: None, name_service_contract_address: None, }, + explorer_api: parse_optional_str(mainnet::EXPLORER_API), } } @@ -278,6 +282,12 @@ impl NymNetworkDetails { self.contracts.name_service_contract_address = contract.map(Into::into); self } + + #[must_use] + pub fn with_explorer_api>(mut self, endpoint: Option) -> Self { + self.explorer_api = endpoint.map(Into::into); + self + } } #[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq)] diff --git a/common/network-defaults/src/mainnet.rs b/common/network-defaults/src/mainnet.rs index fbc25c4b00..bfb3f42531 100644 --- a/common/network-defaults/src/mainnet.rs +++ b/common/network-defaults/src/mainnet.rs @@ -26,6 +26,8 @@ pub(crate) const REWARDING_VALIDATOR_ADDRESS: &str = "n10yyd98e2tuwu0f7ypz9dy3hh pub const STATISTICS_SERVICE_DOMAIN_ADDRESS: &str = "https://mainnet-stats.nymte.ch:8090/"; pub const NYXD_URL: &str = "https://rpc.nymtech.net"; pub const NYM_API: &str = "https://validator.nymtech.net/api/"; +pub const EXPLORER_API: &str = "https://explorer.nymtech.net/api/"; + pub(crate) fn validators() -> Vec { vec![ValidatorDetails::new(NYXD_URL, Some(NYM_API))] } @@ -99,6 +101,7 @@ pub fn export_to_env() { ); set_var_to_default(var_names::NYXD, NYXD_URL); set_var_to_default(var_names::NYM_API, NYM_API); + set_var_to_default(var_names::EXPLORER_API, EXPLORER_API); } pub fn export_to_env_if_not_set() { @@ -145,4 +148,5 @@ pub fn export_to_env_if_not_set() { ); set_var_conditionally_to_default(var_names::NYXD, NYXD_URL); set_var_conditionally_to_default(var_names::NYM_API, NYM_API); + set_var_conditionally_to_default(var_names::EXPLORER_API, EXPLORER_API); } diff --git a/common/network-defaults/src/var_names.rs b/common/network-defaults/src/var_names.rs index 26b65b7f95..d082045a03 100644 --- a/common/network-defaults/src/var_names.rs +++ b/common/network-defaults/src/var_names.rs @@ -26,6 +26,7 @@ pub const SERVICE_PROVIDER_DIRECTORY_CONTRACT_ADDRESS: &str = pub const NAME_SERVICE_CONTRACT_ADDRESS: &str = "NAME_SERVICE_CONTRACT_ADDRESS"; pub const NYXD: &str = "NYXD"; pub const NYM_API: &str = "NYM_API"; +pub const EXPLORER_API: &str = "EXPLORER_API"; pub const DKG_TIME_CONFIGURATION: &str = "DKG_TIME_CONFIGURATION"; diff --git a/envs/mainnet.env b/envs/mainnet.env index 4bf406bd64..9dc5b5272d 100644 --- a/envs/mainnet.env +++ b/envs/mainnet.env @@ -22,5 +22,6 @@ REWARDING_VALIDATOR_ADDRESS=n10yyd98e2tuwu0f7ypz9dy3hhjw7v772q6287gy STATISTICS_SERVICE_DOMAIN_ADDRESS="https://mainnet-stats.nymte.ch:8090" NYXD="https://rpc.nymtech.net" NYM_API="https://validator.nymtech.net/api/" +EXPLORER_API="https://explorer.nymtech.net/api/" DKG_TIME_CONFIGURATION="259200,300,300,60,60,1209600" diff --git a/envs/sandbox.env b/envs/sandbox.env index 95b0b4d49a..b4a66a70d1 100644 --- a/envs/sandbox.env +++ b/envs/sandbox.env @@ -23,4 +23,5 @@ EPHEMERA_CONTRACT_ADDRESS="nymt1gwk6muhmzeuxje7df7rjvqwl2vex0kj4t2hwuzmyx5k62kfu STATISTICS_SERVICE_DOMAIN_ADDRESS="http://0.0.0.0" NYXD="https://sandbox-validator1.nymtech.net" -NYM_API="https://sandbox-nym-api1.nymtech.net/api/" \ No newline at end of file +NYM_API="https://sandbox-nym-api1.nymtech.net/api/" +EXPLORER_API="https://sandbox-explorer.nymtech.net/api/"