mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
fetch-metadata: remove tokio
This commit is contained in:
+2
-3
@@ -13,7 +13,7 @@ description = "Generate an API for interacting with a substrate node from FRAME
|
||||
|
||||
[features]
|
||||
default = []
|
||||
fetch-metadata = ["dep:jsonrpsee", "dep:tokio", "dep:frame-metadata"]
|
||||
fetch-metadata = ["dep:jsonrpsee", "dep:frame-metadata"]
|
||||
web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js"]
|
||||
|
||||
[dependencies]
|
||||
@@ -25,9 +25,8 @@ quote = { workspace = true }
|
||||
syn = { workspace = true }
|
||||
scale-info = { workspace = true }
|
||||
subxt-metadata = { workspace = true }
|
||||
jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport-tls", "http-client"], optional = true }
|
||||
jsonrpsee = { workspace = true, features = ["ws-client", "http-client"], optional = true }
|
||||
hex = { workspace = true, features = ["std"] }
|
||||
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
|
||||
thiserror = { workspace = true }
|
||||
scale-typegen = { workspace = true }
|
||||
|
||||
|
||||
@@ -7,11 +7,7 @@
|
||||
use crate::error::FetchMetadataError;
|
||||
use codec::{Decode, Encode};
|
||||
use jsonrpsee::{
|
||||
async_client::ClientBuilder,
|
||||
client_transport::ws::WsTransportClientBuilder,
|
||||
core::client::{ClientT, Error},
|
||||
http_client::HttpClientBuilder,
|
||||
rpc_params,
|
||||
core::client::ClientT, http_client::HttpClientBuilder, rpc_params, ws_client::WsClientBuilder,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -60,23 +56,6 @@ pub fn fetch_metadata_from_file_blocking(
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
/// Returns the metadata bytes from the provided URL, blocking the current thread.
|
||||
pub fn fetch_metadata_from_url_blocking(
|
||||
url: Url,
|
||||
version: MetadataVersion,
|
||||
) -> Result<Vec<u8>, FetchMetadataError> {
|
||||
tokio_block_on(fetch_metadata_from_url(url, version))
|
||||
}
|
||||
|
||||
// Block on some tokio runtime for sync contexts
|
||||
fn tokio_block_on<T, Fut: std::future::Future<Output = T>>(fut: Fut) -> T {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(fut)
|
||||
}
|
||||
|
||||
/// Returns the metadata bytes from the provided URL.
|
||||
pub async fn fetch_metadata_from_url(
|
||||
url: Url,
|
||||
@@ -95,15 +74,11 @@ async fn fetch_metadata_ws(
|
||||
url: Url,
|
||||
version: MetadataVersion,
|
||||
) -> Result<Vec<u8>, FetchMetadataError> {
|
||||
let (sender, receiver) = WsTransportClientBuilder::default()
|
||||
.build(url)
|
||||
.await
|
||||
.map_err(|e| Error::Transport(e.into()))?;
|
||||
|
||||
let client = ClientBuilder::default()
|
||||
let client = WsClientBuilder::new()
|
||||
.request_timeout(Duration::from_secs(180))
|
||||
.max_buffer_capacity_per_subscription(4096)
|
||||
.build_with_tokio(sender, receiver);
|
||||
.build(url)
|
||||
.await?;
|
||||
|
||||
fetch_metadata(client, version).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user