From 8ef956084362a7aa9102dfececbdda7fed4cb611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 1 Aug 2023 16:58:58 +0100 Subject: [PATCH] all binaries compiling --- clients/native/src/client/mod.rs | 5 ++--- .../client/base_client/non_wasm_helpers.rs | 15 +++------------ nym-api/src/support/nyxd/mod.rs | 11 +++++++++++ sdk/rust/nym-sdk/src/bandwidth/client.rs | 19 ++++++++++++------- sdk/rust/nym-sdk/src/error.rs | 3 ++- sdk/rust/nym-sdk/src/mixnet/client.rs | 13 +++++++------ 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/clients/native/src/client/mod.rs b/clients/native/src/client/mod.rs index 8457268d79..6f3982038f 100644 --- a/clients/native/src/client/mod.rs +++ b/clients/native/src/client/mod.rs @@ -19,8 +19,7 @@ use nym_sphinx::anonymous_replies::requests::AnonymousSenderTag; use nym_sphinx::params::PacketType; use nym_task::connections::TransmissionLane; use nym_task::TaskManager; -use nym_validator_client::nyxd::QueryNyxdClient; -use nym_validator_client::Client; +use nym_validator_client::QueryHttpRpcNyxdClient; use std::error::Error; use tokio::sync::watch::error::SendError; @@ -29,7 +28,7 @@ pub use nym_sphinx::receiver::ReconstructedMessage; pub mod config; -type NativeClientBuilder<'a> = BaseClientBuilder<'a, Client, OnDiskPersistent>; +type NativeClientBuilder<'a> = BaseClientBuilder<'a, QueryHttpRpcNyxdClient, OnDiskPersistent>; pub struct SocketClient { /// Client configuration options, including, among other things, packet sending rates, diff --git a/common/client-core/src/client/base_client/non_wasm_helpers.rs b/common/client-core/src/client/base_client/non_wasm_helpers.rs index e060d3e8fe..d0d2d5a058 100644 --- a/common/client-core/src/client/base_client/non_wasm_helpers.rs +++ b/common/client-core/src/client/base_client/non_wasm_helpers.rs @@ -109,20 +109,15 @@ pub fn create_bandwidth_controller( .get_validator_endpoints() .pop() .expect("No nyxd validator endpoint provided"); - let api_url = config - .get_nym_api_endpoints() - .pop() - .expect("No validator api endpoint provided"); - create_bandwidth_controller_with_urls(nyxd_url, api_url, storage) + create_bandwidth_controller_with_urls(nyxd_url, storage) } pub fn create_bandwidth_controller_with_urls( nyxd_url: Url, - nym_api_url: Url, storage: St, ) -> BandwidthController { - let client = default_query_dkg_client(nyxd_url, nym_api_url); + let client = default_query_dkg_client(nyxd_url); BandwidthController::new(storage, client) } @@ -132,12 +127,8 @@ pub fn default_query_dkg_client_from_config(config: &Config) -> QueryHttpRpcNyxd .get_validator_endpoints() .pop() .expect("No nyxd validator endpoint provided"); - let api_url = config - .get_nym_api_endpoints() - .pop() - .expect("No validator api endpoint provided"); - default_query_dkg_client(nyxd_url, api_url) + default_query_dkg_client(nyxd_url) } pub fn default_query_dkg_client(nyxd_url: Url) -> QueryHttpRpcNyxdClient { diff --git a/nym-api/src/support/nyxd/mod.rs b/nym-api/src/support/nyxd/mod.rs index 5e252a1b95..ec0359c31b 100644 --- a/nym-api/src/support/nyxd/mod.rs +++ b/nym-api/src/support/nyxd/mod.rs @@ -9,6 +9,7 @@ use async_trait::async_trait; use cw3::ProposalResponse; use cw4::MemberResponse; use nym_coconut_bandwidth_contract_common::spend_credential::SpendCredentialResponse; +use nym_coconut_dkg_common::msg::QueryMsg as DkgQueryMsg; use nym_coconut_dkg_common::types::InitialReplacementData; use nym_coconut_dkg_common::{ dealer::{ContractDealing, DealerDetails, DealerDetailsResponse}, @@ -427,6 +428,16 @@ impl crate::coconut::client::Client for Client { } } +#[async_trait] +impl DkgQueryClient for Client { + async fn query_dkg_contract(&self, query: DkgQueryMsg) -> std::result::Result + where + for<'a> T: Deserialize<'a>, + { + self.0.read().await.query_dkg_contract(query).await + } +} + #[async_trait] impl SpDirectoryQueryClient for Client { async fn query_service_provider_contract( diff --git a/sdk/rust/nym-sdk/src/bandwidth/client.rs b/sdk/rust/nym-sdk/src/bandwidth/client.rs index 3be519bf49..7171282a71 100644 --- a/sdk/rust/nym-sdk/src/bandwidth/client.rs +++ b/sdk/rust/nym-sdk/src/bandwidth/client.rs @@ -6,9 +6,8 @@ use nym_bandwidth_controller::acquire::state::State; use nym_credential_storage::storage::Storage; use nym_credentials::coconut::bandwidth::BandwidthVoucher; use nym_network_defaults::NymNetworkDetails; -use nym_validator_client::nyxd::{Coin, SigningNyxdClient}; -use nym_validator_client::signing::direct_wallet::DirectSecp256k1HdWallet; -use nym_validator_client::{Client, Config}; +use nym_validator_client::nyxd::Coin; +use nym_validator_client::{nyxd, DirectSigningHttpRpcNyxdClient}; /// The serialized version of the yet untransformed bandwidth voucher. It can be used to complete /// the acquirement process of a bandwidth credential. @@ -22,7 +21,7 @@ pub type VoucherBlob = Vec; /// client. pub struct BandwidthAcquireClient<'a, St: Storage> { network_details: NymNetworkDetails, - client: Client>, + client: DirectSigningHttpRpcNyxdClient, storage: &'a St, } @@ -36,8 +35,14 @@ where mnemonic: String, storage: &'a St, ) -> Result { - let config = Config::try_from_nym_network_details(&network_details)?; - let client = nym_validator_client::Client::new_signing(config, mnemonic.parse()?)?; + let nyxd_url = network_details.endpoints[0].nyxd_url.as_str(); + let config = nyxd::Config::try_from_nym_network_details(&network_details)?; + + let client = DirectSigningHttpRpcNyxdClient::connect_with_mnemonic( + config, + nyxd_url, + mnemonic.parse()?, + )?; Ok(Self { network_details, client, @@ -51,7 +56,7 @@ where /// associated bandwidth credential, using [`Self::recover`]. pub async fn acquire(&self, amount: u128) -> Result<()> { let amount = Coin::new(amount, &self.network_details.chain_details.mix_denom.base); - let state = nym_bandwidth_controller::acquire::deposit(&self.client.nyxd, amount).await?; + let state = nym_bandwidth_controller::acquire::deposit(&self.client, amount).await?; nym_bandwidth_controller::acquire::get_credential(&state, &self.client, self.storage) .await .map_err(|reason| Error::UnconvertedDeposit { diff --git a/sdk/rust/nym-sdk/src/error.rs b/sdk/rust/nym-sdk/src/error.rs index 48469271e4..84283bc9a2 100644 --- a/sdk/rust/nym-sdk/src/error.rs +++ b/sdk/rust/nym-sdk/src/error.rs @@ -1,3 +1,4 @@ +use nym_validator_client::nyxd::error::NyxdError; use std::path::PathBuf; /// Top-level Error enum for the mixnet client and its relevant types. @@ -46,7 +47,7 @@ pub enum Error { DisabledCredentialsMode, #[error("bad validator details: {0}")] - BadValidatorDetails(#[from] nym_validator_client::ValidatorClientError), + BadValidatorDetails(#[from] NyxdError), #[error("socks5 configuration set: {}, but expected to be {}", set, !set)] Socks5Config { set: bool }, diff --git a/sdk/rust/nym-sdk/src/mixnet/client.rs b/sdk/rust/nym-sdk/src/mixnet/client.rs index 8f19074605..212c192f72 100644 --- a/sdk/rust/nym-sdk/src/mixnet/client.rs +++ b/sdk/rust/nym-sdk/src/mixnet/client.rs @@ -24,8 +24,7 @@ use nym_network_defaults::NymNetworkDetails; use nym_socks5_client_core::config::Socks5; use nym_task::manager::TaskStatus; use nym_topology::provider_trait::TopologyProvider; -use nym_validator_client::nyxd::QueryNyxdClient; -use nym_validator_client::Client; +use nym_validator_client::{nyxd, QueryHttpRpcNyxdClient}; use std::path::Path; use std::path::PathBuf; use url::Url; @@ -214,7 +213,7 @@ where /// In the case of enabled credentials, a client instance responsible for querying the state of the /// dkg and coconut contracts - dkg_query_client: Option>, + dkg_query_client: Option, /// Alternative provider of network topology used for constructing sphinx packets. custom_topology_provider: Option>, @@ -244,10 +243,12 @@ where ) -> Result> { // don't create dkg client for the bandwidth controller if credentials are disabled let dkg_query_client = if config.enabled_credentials_mode { - let client_config = nym_validator_client::Config::try_from_nym_network_details( - &config.network_details, + let client_config = + nyxd::Config::try_from_nym_network_details(&config.network_details)?; + let client = QueryHttpRpcNyxdClient::connect( + client_config, + config.network_details.endpoints[0].nyxd_url.as_str(), )?; - let client = nym_validator_client::Client::new_query(client_config)?; Some(client) } else { None