diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index baac5fa..2ba7403 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -107,6 +107,11 @@ macro_rules! jsonrpc { Ok($struct_name { id: 0.into(), client }) } + pub fn new_with_timeout(uri: &str, timeout: std::time::Duration) -> Result { + let client = $crate::rpc::RpcClient::new_with_timeout(uri, timeout)?; + Ok($struct_name { id: 0.into(), client }) + } + pub fn post(&self, method:&str, params: PARAM)->Result where PARAM:serde::ser::Serialize + Send + 'static, @@ -195,6 +200,12 @@ macro_rules! jsonrpc_async { Ok($struct_name { id: 0.into(), client }) } + #[cfg(not(target_arch="wasm32"))] + pub fn new_with_timeout(uri: &str, timeout: std::time::Duration) -> Result { + let client = $crate::rpc::RpcClient::new_with_timeout(uri, timeout)?; + Ok($struct_name { id: 0.into(), client }) + } + #[cfg(not(target_arch="wasm32"))] pub fn post(&self, method:&str, params: PARAM)->impl std::future::Future> + Send + 'static where @@ -288,6 +299,14 @@ impl RpcClient { Ok(Self { client, url }) } + #[cfg(not(target_arch = "wasm32"))] + pub fn new_with_timeout( + uri: &str, + timeout: std::time::Duration, + ) -> Result { + Self::with_builder(uri, |builder| builder.timeout(timeout)) + } + #[cfg(not(target_arch = "wasm32"))] pub fn new_with_cookie(uri: &str) -> Self { let url = reqwest::Url::parse(uri).expect("ckb uri, e.g. \"http://127.0.0.1:8114\"");