Upgrade jsonrpsee to v0.4.1 (#10022)

* Upgrade jsonrpsee to v0.4.1

* remove needless BlockT trait bound

* use default wss port in URL

* Fix try_runtime build

* Partially fix for "remote-tests" feature

* Review feedback

* fmt

* Sort out trait bounds for benches

* Fmt

* fmt again?

* fmt with nightly-2021-09-13

* Upgrade try-runtime as well

* fmt

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
David
2021-11-11 12:29:28 +01:00
committed by GitHub
parent bb6aecee7a
commit eeb80f9e0b
12 changed files with 130 additions and 176 deletions
@@ -18,9 +18,10 @@
//! WS RPC API for one off RPC calls to a substrate node.
// TODO: Consolidate one off RPC calls https://github.com/paritytech/substrate/issues/8988
use jsonrpsee_ws_client::{
types::{traits::Client, v2::params::JsonRpcParams},
WsClient, WsClientBuilder,
use jsonrpsee::{
rpc_params,
types::traits::Client,
ws_client::{WsClient, WsClientBuilder},
};
use sp_runtime::{
generic::SignedBlock,
@@ -34,11 +35,10 @@ where
Block::Header: serde::de::DeserializeOwned,
S: AsRef<str>,
{
let params = vec![hash_to_json::<Block>(at)?];
let client = build_client(from).await?;
client
.request::<Block::Header>("chain_getHeader", JsonRpcParams::Array(params))
.request::<Block::Header>("chain_getHeader", rpc_params!(at))
.await
.map_err(|e| format!("chain_getHeader request failed: {:?}", e))
}
@@ -52,7 +52,7 @@ where
let client = build_client(from).await?;
client
.request::<Block::Hash>("chain_getFinalizedHead", JsonRpcParams::NoParams)
.request::<Block::Hash>("chain_getFinalizedHead", None)
.await
.map_err(|e| format!("chain_getFinalizedHead request failed: {:?}", e))
}
@@ -64,22 +64,15 @@ where
Block: BlockT + serde::de::DeserializeOwned,
Block::Header: HeaderT,
{
let params = vec![hash_to_json::<Block>(at)?];
let client = build_client(from).await?;
let signed_block = client
.request::<SignedBlock<Block>>("chain_getBlock", JsonRpcParams::Array(params))
.request::<SignedBlock<Block>>("chain_getBlock", rpc_params!(at))
.await
.map_err(|e| format!("chain_getBlock request failed: {:?}", e))?;
Ok(signed_block.block)
}
/// Convert a block hash to a serde json value.
fn hash_to_json<Block: BlockT>(hash: Block::Hash) -> Result<serde_json::Value, String> {
serde_json::to_value(hash)
.map_err(|e| format!("Block hash could not be converted to JSON: {:?}", e))
}
/// Build a website client that connects to `from`.
async fn build_client<S: AsRef<str>>(from: S) -> Result<WsClient, String> {
WsClientBuilder::default()
@@ -99,13 +92,9 @@ where
Block: BlockT + serde::de::DeserializeOwned,
Block::Header: HeaderT,
{
let params = if let Some(at) = at { vec![hash_to_json::<Block>(at)?] } else { vec![] };
let client = build_client(from).await?;
client
.request::<sp_version::RuntimeVersion>(
"state_getRuntimeVersion",
JsonRpcParams::Array(params),
)
.request::<sp_version::RuntimeVersion>("state_getRuntimeVersion", rpc_params!(at))
.await
.map_err(|e| format!("state_getRuntimeVersion request failed: {:?}", e))
}