diff --git a/common/client-libs/validator-client/examples/offline_signing.rs b/common/client-libs/validator-client/examples/offline_signing.rs index baa2d10035..0e5bce5681 100644 --- a/common/client-libs/validator-client/examples/offline_signing.rs +++ b/common/client-libs/validator-client/examples/offline_signing.rs @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 use cosmrs::bank::MsgSend; -use cosmrs::rpc::HttpClient; use cosmrs::tx::Msg; use cosmrs::{tx, AccountId, Coin, Denom}; +use nym_validator_client::http_client; use nym_validator_client::nyxd::CosmWasmClient; use nym_validator_client::signing::direct_wallet::DirectSecp256k1HdWallet; use nym_validator_client::signing::tx_signer::TxSigner; @@ -27,7 +27,7 @@ async fn main() { // possibly remote client that doesn't do ANY signing // (only broadcasts + queries for sequence numbers) - let broadcaster = HttpClient::new(validator).unwrap(); + let broadcaster = http_client(validator).unwrap(); // get signer information let sequence_response = broadcaster.get_sequence(&signer_address).await.unwrap(); diff --git a/common/client-libs/validator-client/src/client.rs b/common/client-libs/validator-client/src/client.rs index e70cbdaf2f..22a986558a 100644 --- a/common/client-libs/validator-client/src/client.rs +++ b/common/client-libs/validator-client/src/client.rs @@ -26,6 +26,7 @@ pub use nym_mixnet_contract_common::{ // re-export the type to not break existing imports pub use crate::coconut::CoconutApiClient; +use crate::rpc::http_client; #[cfg(feature = "http-client")] use crate::{DirectSigningHttpRpcValidatorClient, HttpRpcClient, QueryHttpRpcValidatorClient}; @@ -95,7 +96,7 @@ impl Client { config: Config, mnemonic: bip39::Mnemonic, ) -> Result { - let rpc_client = HttpRpcClient::new(config.nyxd_url.as_str())?; + let rpc_client = http_client(config.nyxd_url.as_str())?; let prefix = &config.nyxd_config.chain_details.bech32_account_prefix; let wallet = DirectSecp256k1HdWallet::from_mnemonic(prefix, mnemonic); @@ -126,7 +127,7 @@ impl Client { #[cfg(feature = "http-client")] impl Client { pub fn new_query(config: Config) -> Result { - let rpc_client = HttpRpcClient::new(config.nyxd_url.as_str())?; + let rpc_client = http_client(config.nyxd_url.as_str())?; Ok(Self::new_with_rpc_client(config, rpc_client)) } diff --git a/common/client-libs/validator-client/src/lib.rs b/common/client-libs/validator-client/src/lib.rs index c6391673a0..b3dca0a473 100644 --- a/common/client-libs/validator-client/src/lib.rs +++ b/common/client-libs/validator-client/src/lib.rs @@ -20,6 +20,8 @@ pub use nym_api_requests::*; #[cfg(feature = "http-client")] pub use cosmrs::rpc::HttpClient as HttpRpcClient; +#[cfg(feature = "http-client")] +pub use rpc::http_client; // some type aliasing diff --git a/common/client-libs/validator-client/src/nyxd/cosmwasm_client/mod.rs b/common/client-libs/validator-client/src/nyxd/cosmwasm_client/mod.rs index 7ebff2ef16..44c917e25d 100644 --- a/common/client-libs/validator-client/src/nyxd/cosmwasm_client/mod.rs +++ b/common/client-libs/validator-client/src/nyxd/cosmwasm_client/mod.rs @@ -10,11 +10,14 @@ use crate::signing::{ AccountData, }; use async_trait::async_trait; +use cosmrs::tx::{Raw, SignDoc}; +use std::fmt::Debug; use tendermint_rpc::{Error as TendermintRpcError, SimpleRequest}; +#[cfg(feature = "http-client")] +use crate::http_client; #[cfg(feature = "http-client")] use cosmrs::rpc::{HttpClient, HttpClientUrl}; -use cosmrs::tx::{Raw, SignDoc}; pub mod client_traits; mod helpers; @@ -73,7 +76,7 @@ impl MaybeSigningClient { where U: TryInto, { - self.client = HttpClient::new(new_endpoint)?; + self.client = http_client(new_endpoint)?; Ok(()) } } diff --git a/common/client-libs/validator-client/src/nyxd/mod.rs b/common/client-libs/validator-client/src/nyxd/mod.rs index 16027a1970..550608ad9d 100644 --- a/common/client-libs/validator-client/src/nyxd/mod.rs +++ b/common/client-libs/validator-client/src/nyxd/mod.rs @@ -50,9 +50,12 @@ use crate::signing::direct_wallet::DirectSecp256k1HdWallet; #[cfg(feature = "http-client")] use crate::{DirectSigningHttpRpcNyxdClient, QueryHttpRpcNyxdClient}; use crate::{DirectSigningReqwestRpcNyxdClient, QueryReqwestRpcNyxdClient, ReqwestRpcClient}; +use url::Url; + +#[cfg(feature = "http-client")] +use crate::http_client; #[cfg(feature = "http-client")] use cosmrs::rpc::{HttpClient, HttpClientUrl}; -use url::Url; pub mod coin; pub mod contract_traits; @@ -97,7 +100,7 @@ impl NyxdClient { where U: TryInto, { - let client = HttpClient::new(endpoint)?; + let client = http_client(endpoint)?; Ok(NyxdClient { client: MaybeSigningClient::new(client, (&config).into()), @@ -140,7 +143,7 @@ impl NyxdClient { where U: TryInto, { - let client = HttpClient::new(endpoint)?; + let client = http_client(endpoint)?; let prefix = &config.chain_details.bech32_account_prefix; let wallet = DirectSecp256k1HdWallet::from_mnemonic(prefix, mnemonic); diff --git a/common/client-libs/validator-client/src/rpc/mod.rs b/common/client-libs/validator-client/src/rpc/mod.rs index f483f1067c..fd3f7991ba 100644 --- a/common/client-libs/validator-client/src/rpc/mod.rs +++ b/common/client-libs/validator-client/src/rpc/mod.rs @@ -11,8 +11,27 @@ use tendermint_rpc::{ Error, Order, Paging, SimpleRequest, }; +#[cfg(feature = "http-client")] +use crate::error::TendermintRpcError; +#[cfg(feature = "http-client")] +use crate::HttpRpcClient; +#[cfg(feature = "http-client")] +use tendermint_rpc::client::CompatMode; +#[cfg(feature = "http-client")] +use tendermint_rpc::HttpClientUrl; + pub mod reqwest; +#[cfg(feature = "http-client")] +pub fn http_client(url: U) -> Result +where + U: TryInto, +{ + HttpRpcClient::builder(url.try_into()?) + .compat_mode(CompatMode::V0_34) + .build() +} + // we have to create a sealed trait since `TendermintClient` needs T: Send (due to how async trait is created) // which we can't do in wasm #[cfg_attr(target_arch = "wasm32", async_trait(?Send))]