zombienet_orchestrator/tx_helper/
client.rs1use subxt::{backend::rpc::RpcClient, OnlineClient};
2
3#[async_trait::async_trait]
4pub trait ClientFromUrl: Sized {
5 async fn from_secure_url(url: &str) -> Result<Self, subxt::Error>;
6 async fn from_insecure_url(url: &str) -> Result<Self, subxt::Error>;
7}
8
9#[async_trait::async_trait]
10impl<Config: subxt::Config + Send + Sync> ClientFromUrl for OnlineClient<Config> {
11 async fn from_secure_url(url: &str) -> Result<Self, subxt::Error> {
12 Self::from_url(url).await
13 }
14
15 async fn from_insecure_url(url: &str) -> Result<Self, subxt::Error> {
16 Self::from_insecure_url(url).await
17 }
18}
19
20#[async_trait::async_trait]
21impl ClientFromUrl for RpcClient {
22 async fn from_secure_url(url: &str) -> Result<Self, subxt::Error> {
23 Self::from_url(url).await.map_err(subxt::Error::from)
24 }
25
26 async fn from_insecure_url(url: &str) -> Result<Self, subxt::Error> {
27 Self::from_insecure_url(url)
28 .await
29 .map_err(subxt::Error::from)
30 }
31}
32
33pub async fn get_client_from_url<T: ClientFromUrl + Send>(url: &str) -> Result<T, subxt::Error> {
34 if subxt::utils::url_is_secure(url)? {
35 T::from_secure_url(url).await
36 } else {
37 T::from_insecure_url(url).await
38 }
39}