diff --git a/common/client-libs/validator-client/src/connection_tester.rs b/common/client-libs/validator-client/src/connection_tester.rs index fe7ded3e5b..570d94f986 100644 --- a/common/client-libs/validator-client/src/connection_tester.rs +++ b/common/client-libs/validator-client/src/connection_tester.rs @@ -117,7 +117,7 @@ async fn test_nyxd_connection( ); code == 18 } - Ok(Err(error @ NyxdError::NoContractAddressAvailable)) => { + Ok(Err(error @ NyxdError::NoContractAddressAvailable(_))) => { log::debug!("Checking: nyxd url: {url}: {}: {error}", "failed".red()); false } diff --git a/common/client-libs/validator-client/src/nyxd/error.rs b/common/client-libs/validator-client/src/nyxd/error.rs index 2a82773edb..df4d8f0a49 100644 --- a/common/client-libs/validator-client/src/nyxd/error.rs +++ b/common/client-libs/validator-client/src/nyxd/error.rs @@ -22,7 +22,7 @@ use std::{io, time::Duration}; #[derive(Debug, Error)] pub enum NyxdError { #[error("No contract address is available to perform the call")] - NoContractAddressAvailable, + NoContractAddressAvailable(String), #[error(transparent)] WalletError(#[from] DirectSecp256k1HdWalletError), diff --git a/common/client-libs/validator-client/src/nyxd/mod.rs b/common/client-libs/validator-client/src/nyxd/mod.rs index c683075162..f7629abbd2 100644 --- a/common/client-libs/validator-client/src/nyxd/mod.rs +++ b/common/client-libs/validator-client/src/nyxd/mod.rs @@ -316,11 +316,9 @@ impl NyxdClient { self.config.coconut_dkg_contract_address.as_ref().unwrap() } - pub fn service_provider_contract_address(&self) -> &AccountId { - self.config - .service_provider_contract_address - .as_ref() - .expect("no service provider contract address set") + // The service provider directory contract is optional, so we return an Option not a Result + pub fn service_provider_contract_address(&self) -> Option<&AccountId> { + self.config.service_provider_contract_address.as_ref() } pub fn set_simulated_gas_multiplier(&mut self, multiplier: f32) { diff --git a/common/client-libs/validator-client/src/nyxd/traits/sp_directory_query_client.rs b/common/client-libs/validator-client/src/nyxd/traits/sp_directory_query_client.rs index d5042acf8b..3a4fb057f5 100644 --- a/common/client-libs/validator-client/src/nyxd/traits/sp_directory_query_client.rs +++ b/common/client-libs/validator-client/src/nyxd/traits/sp_directory_query_client.rs @@ -94,7 +94,14 @@ where for<'a> T: Deserialize<'a>, { self.client - .query_contract_smart(self.service_provider_contract_address(), &query) + .query_contract_smart( + self.service_provider_contract_address().ok_or( + NyxdError::NoContractAddressAvailable( + "service provider directory contract".to_string(), + ), + )?, + &query, + ) .await } } diff --git a/common/client-libs/validator-client/src/nyxd/traits/sp_directory_signing_client.rs b/common/client-libs/validator-client/src/nyxd/traits/sp_directory_signing_client.rs index 4e76cf913e..722097a99b 100644 --- a/common/client-libs/validator-client/src/nyxd/traits/sp_directory_signing_client.rs +++ b/common/client-libs/validator-client/src/nyxd/traits/sp_directory_signing_client.rs @@ -96,7 +96,11 @@ where self.client .execute( self.address(), - self.service_provider_contract_address(), + self.service_provider_contract_address().ok_or( + NyxdError::NoContractAddressAvailable( + "service provider directory contract".to_string(), + ), + )?, &msg, fee, memo, diff --git a/common/network-defaults/src/lib.rs b/common/network-defaults/src/lib.rs index 02b10ae69c..b966d61ee7 100644 --- a/common/network-defaults/src/lib.rs +++ b/common/network-defaults/src/lib.rs @@ -3,7 +3,12 @@ use crate::var_names::{DEPRECATED_API_VALIDATOR, DEPRECATED_NYMD_VALIDATOR, NYM_API, NYXD}; use serde::{Deserialize, Serialize}; -use std::{env::var, ops::Not, path::PathBuf}; +use std::{ + env::{var, VarError}, + ffi::OsStr, + ops::Not, + path::PathBuf, +}; use url::Url; pub mod mainnet; @@ -69,6 +74,14 @@ impl NymNetworkDetails { } pub fn new_from_env() -> Self { + fn get_optional_env>(env: K) -> Option { + match var(env) { + Ok(var) => Some(var), + Err(VarError::NotPresent) => None, + err => panic!("Unable to set: {:?}", err), + } + } + NymNetworkDetails::new_empty() .with_bech32_account_prefix( var(var_names::BECH32_PREFIX).expect("bech32 prefix not set"), @@ -118,9 +131,8 @@ impl NymNetworkDetails { .with_coconut_dkg_contract(Some( var(var_names::COCONUT_DKG_CONTRACT_ADDRESS).expect("coconut dkg contract not set"), )) - .with_service_provider_directory_contract(Some( - var(var_names::SERVICE_PROVIDER_DIRECTORY_CONTRACT_ADDRESS) - .expect("service provider contract not set"), + .with_service_provider_directory_contract(get_optional_env( + var_names::SERVICE_PROVIDER_DIRECTORY_CONTRACT_ADDRESS, )) } diff --git a/nym-connect/desktop/Cargo.lock b/nym-connect/desktop/Cargo.lock index 102a760698..1d13cbd89a 100644 --- a/nym-connect/desktop/Cargo.lock +++ b/nym-connect/desktop/Cargo.lock @@ -3578,6 +3578,14 @@ dependencies = [ "pem", ] +[[package]] +name = "nym-service-provider-directory-common" +version = "0.1.0" +dependencies = [ + "cosmwasm-std", + "serde", +] + [[package]] name = "nym-service-providers-common" version = "0.1.0" @@ -3826,6 +3834,7 @@ dependencies = [ "nym-mixnet-contract-common", "nym-multisig-contract-common", "nym-network-defaults", + "nym-service-provider-directory-common", "nym-vesting-contract", "nym-vesting-contract-common", "prost",