Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, anyhow::Error> {
let client = $crate::rpc::RpcClient::new_with_timeout(uri, timeout)?;
Ok($struct_name { id: 0.into(), client })
}

pub fn post<PARAM, RET>(&self, method:&str, params: PARAM)->Result<RET, $crate::rpc::RpcError>
where
PARAM:serde::ser::Serialize + Send + 'static,
Expand Down Expand Up @@ -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<Self, anyhow::Error> {
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<PARAM, RET>(&self, method:&str, params: PARAM)->impl std::future::Future<Output =Result<RET, $crate::rpc::RpcError>> + Send + 'static
where
Expand Down Expand Up @@ -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, anyhow::Error> {
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\"");
Expand Down
Loading