connect to substrate using ws (#417)

This commit is contained in:
Svyatoslav Nikolsky
2020-10-14 08:19:39 +03:00
committed by Bastian Köcher
parent ede0ff8656
commit 55d22a0d1e
6 changed files with 23 additions and 13 deletions
@@ -22,7 +22,7 @@ use crate::{ConnectionParams, Result};
use jsonrpsee::common::DeserializeOwned;
use jsonrpsee::raw::RawClient;
use jsonrpsee::transport::http::HttpTransportClient;
use jsonrpsee::transport::ws::WsTransportClient;
use jsonrpsee::Client as RpcClient;
use num_traits::Zero;
use sp_core::Bytes;
@@ -49,10 +49,10 @@ impl<C: Chain> std::fmt::Debug for Client<C> {
}
impl<C: Chain> Client<C> {
/// Returns client that is able to call RPCs on Substrate node.
/// Returns client that is able to call RPCs on Substrate node over websocket connection.
pub async fn new(params: ConnectionParams) -> Result<Self> {
let uri = format!("http://{}:{}", params.host, params.port);
let transport = HttpTransportClient::new(&uri);
let uri = format!("ws://{}:{}", params.host, params.port);
let transport = WsTransportClient::new(&uri).await?;
let raw_client = RawClient::new(transport);
let client: RpcClient = raw_client.into();