mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 05:17:58 +00:00
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:
Generated
+51
-79
@@ -144,9 +144,9 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.0"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a2f58b0bb10c380af2b26e57212856b8c9a59e0925b4c20f4a174a49734eaf7"
|
||||
checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd"
|
||||
|
||||
[[package]]
|
||||
name = "asn1_der"
|
||||
@@ -419,19 +419,6 @@ dependencies = [
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bae"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec107f431ee3d8a8e45e6dd117adab769556ef463959e77bf6a4888d5fd500cf"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error 0.4.12",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base-x"
|
||||
version = "0.2.8"
|
||||
@@ -477,9 +464,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "beef"
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6736e2428df2ca2848d846c43e88745121a6654696e349ce0054a420815a7409"
|
||||
checksum = "bed554bd50246729a1ec158d08aa3235d1b69d94ad120ebe187e28894787e736"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1634,7 +1621,7 @@ dependencies = [
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"lazy_static",
|
||||
"proc-macro-error 1.0.4",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
@@ -3141,13 +3128,24 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jsonrpsee-proc-macros"
|
||||
version = "0.3.1"
|
||||
name = "jsonrpsee"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8edb341d35279b59c79d7fe9e060a51aec29d45af99cc7c72ea7caa350fa71a4"
|
||||
checksum = "6373a33d987866ccfe1af4bc11b089dce941764313f9fd8b7cf13fcb51b72dc5"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"bae",
|
||||
"jsonrpsee-proc-macros",
|
||||
"jsonrpsee-types",
|
||||
"jsonrpsee-utils",
|
||||
"jsonrpsee-ws-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jsonrpsee-proc-macros"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d802063f7a3c867456955f9d2f15eb3ee0edb5ec9ec2b5526324756759221c0f"
|
||||
dependencies = [
|
||||
"log 0.4.14",
|
||||
"proc-macro-crate 1.0.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3156,10 +3154,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonrpsee-types"
|
||||
version = "0.3.1"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4cc738fd55b676ada3271ef7c383a14a0867a2a88b0fa941311bf5fc0a29d498"
|
||||
checksum = "62f778cf245158fbd8f5d50823a2e9e4c708a40be164766bd35e9fb1d86715b2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"beef",
|
||||
"futures-channel",
|
||||
@@ -3168,32 +3167,43 @@ dependencies = [
|
||||
"log 0.4.14",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"soketto 0.6.0",
|
||||
"soketto 0.7.0",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jsonrpsee-ws-client"
|
||||
version = "0.3.1"
|
||||
name = "jsonrpsee-utils"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9841352dbecf4c2ed5dc71698df9f1660262ae4e0b610e968602529bdbcf7b30"
|
||||
checksum = "0109c4f972058f3b1925b73a17210aff7b63b65967264d0045d15ee88fe84f0c"
|
||||
dependencies = [
|
||||
"arrayvec 0.7.1",
|
||||
"beef",
|
||||
"jsonrpsee-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jsonrpsee-ws-client"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "559aa56fc402af206c00fc913dc2be1d9d788dcde045d14df141a535245d35ef"
|
||||
dependencies = [
|
||||
"arrayvec 0.7.1",
|
||||
"async-trait",
|
||||
"fnv",
|
||||
"futures 0.3.16",
|
||||
"http",
|
||||
"jsonrpsee-types",
|
||||
"log 0.4.14",
|
||||
"pin-project 1.0.8",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"soketto 0.6.0",
|
||||
"soketto 0.7.0",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-util",
|
||||
"url 2.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4353,7 +4363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "424f6e86263cd5294cbd7f1e95746b95aca0e0d66bff31e5a40d6baa87b4aa99"
|
||||
dependencies = [
|
||||
"proc-macro-crate 1.0.0",
|
||||
"proc-macro-error 1.0.4",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
@@ -6249,7 +6259,7 @@ version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909"
|
||||
dependencies = [
|
||||
"arrayvec 0.7.0",
|
||||
"arrayvec 0.7.1",
|
||||
"bitvec 0.20.2",
|
||||
"byte-slice-cast",
|
||||
"impl-trait-for-tuples",
|
||||
@@ -6742,45 +6752,19 @@ dependencies = [
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr 0.4.12",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr 1.0.4",
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn-mid",
|
||||
"version_check 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
@@ -7365,8 +7349,7 @@ version = "0.10.0-dev"
|
||||
dependencies = [
|
||||
"env_logger 0.9.0",
|
||||
"frame-support",
|
||||
"jsonrpsee-proc-macros",
|
||||
"jsonrpsee-ws-client",
|
||||
"jsonrpsee",
|
||||
"log 0.4.14",
|
||||
"pallet-elections-phragmen",
|
||||
"parity-scale-codec",
|
||||
@@ -9157,9 +9140,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "soketto"
|
||||
version = "0.6.0"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a74e48087dbeed4833785c2f3352b59140095dc192dce966a3bfc155020a439f"
|
||||
checksum = "083624472e8817d44d02c0e55df043737ff11f279af924abdf93845717c2b75c"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"bytes 1.0.1",
|
||||
@@ -10062,7 +10045,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error 1.0.4",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
@@ -10355,17 +10338,6 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn-mid"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baa8e7560a164edb1621a55d18a0c59abf49d360f47aa7b821061dd7eea7fac9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.12.4"
|
||||
@@ -10974,7 +10946,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
|
||||
name = "try-runtime-cli"
|
||||
version = "0.10.0-dev"
|
||||
dependencies = [
|
||||
"jsonrpsee-ws-client",
|
||||
"jsonrpsee",
|
||||
"log 0.4.14",
|
||||
"parity-scale-codec",
|
||||
"remote-externalities",
|
||||
@@ -11447,7 +11419,7 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8b86dcd2c3efdb8390728a2b56f762db07789aaa5aa872a9dc776ba3a7912ed"
|
||||
dependencies = [
|
||||
"proc-macro-error 1.0.4",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
|
||||
@@ -130,7 +130,7 @@ async-std = { version = "1.10.0", features = ["attributes"] }
|
||||
soketto = "0.4.2"
|
||||
criterion = { version = "0.3.5", features = [ "async_tokio" ] }
|
||||
tokio = { version = "1.10", features = ["macros", "time"] }
|
||||
jsonrpsee-ws-client = { version = "0.3.1", default-features = false, features = ["tokio1"] }
|
||||
jsonrpsee-ws-client = "0.4.1"
|
||||
wait-timeout = "0.2"
|
||||
remote-externalities = { path = "../../../utils/frame/remote-externalities" }
|
||||
pallet-timestamp = { version = "4.0.0-dev", path = "../../../frame/timestamp" }
|
||||
|
||||
@@ -21,11 +21,11 @@ use frame_election_provider_support::SortedListProvider;
|
||||
use frame_support::traits::PalletInfoAccess;
|
||||
use pallet_staking::Nominators;
|
||||
use remote_externalities::{Builder, Mode, OnlineConfig};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
|
||||
|
||||
/// Test voter bags migration. `currency_unit` is the number of planks per the the runtimes `UNITS`
|
||||
/// (i.e. number of decimal places per DOT, KSM etc)
|
||||
pub async fn execute<Runtime: RuntimeT, Block: BlockT>(
|
||||
pub async fn execute<Runtime: RuntimeT, Block: BlockT + DeserializeOwned>(
|
||||
currency_unit: u64,
|
||||
currency_name: &'static str,
|
||||
ws_url: String,
|
||||
|
||||
@@ -22,11 +22,11 @@ use frame_support::{
|
||||
traits::{Get, PalletInfoAccess},
|
||||
};
|
||||
use remote_externalities::{Builder, Mode, OnlineConfig};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Execute the sanity check of the bags-list.
|
||||
pub async fn execute<Runtime: crate::RuntimeT, Block: BlockT>(
|
||||
pub async fn execute<Runtime: crate::RuntimeT, Block: BlockT + DeserializeOwned>(
|
||||
currency_unit: u64,
|
||||
currency_name: &'static str,
|
||||
ws_url: String,
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
|
||||
use frame_support::traits::PalletInfoAccess;
|
||||
use remote_externalities::{Builder, Mode, OnlineConfig};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
|
||||
|
||||
/// Execute create a snapshot from pallet-staking.
|
||||
pub async fn execute<Runtime: crate::RuntimeT, Block: BlockT>(
|
||||
pub async fn execute<Runtime: crate::RuntimeT, Block: BlockT + DeserializeOwned>(
|
||||
voter_limit: Option<usize>,
|
||||
currency_unit: u64,
|
||||
ws_url: String,
|
||||
|
||||
@@ -225,7 +225,7 @@ impl Parse for PalletDeclaration {
|
||||
{
|
||||
return Err(input.error(
|
||||
"Unexpected tokens, expected one of `::$ident` `::{`, `exclude_parts`, `use_parts`, `=`, `,`",
|
||||
))
|
||||
));
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@@ -13,10 +13,7 @@ readme = "README.md"
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
jsonrpsee-ws-client = { version = "0.3.1", default-features = false, features = [
|
||||
"tokio1",
|
||||
]}
|
||||
jsonrpsee-proc-macros = "0.3.1"
|
||||
jsonrpsee = { version = "0.4.1", features = ["ws-client", "macros"] }
|
||||
|
||||
env_logger = "0.9"
|
||||
log = "0.4.11"
|
||||
|
||||
@@ -21,7 +21,16 @@
|
||||
//! based chain, or a local state snapshot file.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use jsonrpsee_ws_client::{types::v2::params::JsonRpcParams, WsClient, WsClientBuilder};
|
||||
|
||||
use jsonrpsee::{
|
||||
proc_macros::rpc,
|
||||
rpc_params,
|
||||
types::{traits::Client, Error as RpcError},
|
||||
ws_client::{WsClient, WsClientBuilder},
|
||||
};
|
||||
|
||||
use log::*;
|
||||
use serde::de::DeserializeOwned;
|
||||
use sp_core::{
|
||||
hashing::twox_128,
|
||||
hexdisplay::HexDisplay,
|
||||
@@ -39,23 +48,25 @@ pub mod rpc_api;
|
||||
type KeyPair = (StorageKey, StorageData);
|
||||
|
||||
const LOG_TARGET: &str = "remote-ext";
|
||||
const DEFAULT_TARGET: &str = "wss://rpc.polkadot.io";
|
||||
const DEFAULT_TARGET: &str = "wss://rpc.polkadot.io:443";
|
||||
const BATCH_SIZE: usize = 1000;
|
||||
|
||||
jsonrpsee_proc_macros::rpc_client_api! {
|
||||
RpcApi<B: BlockT> {
|
||||
#[rpc(method = "state_getStorage", positional_params)]
|
||||
fn get_storage(prefix: StorageKey, hash: Option<B::Hash>) -> StorageData;
|
||||
#[rpc(method = "state_getKeysPaged", positional_params)]
|
||||
fn get_keys_paged(
|
||||
prefix: Option<StorageKey>,
|
||||
count: u32,
|
||||
start_key: Option<StorageKey>,
|
||||
hash: Option<B::Hash>,
|
||||
) -> Vec<StorageKey>;
|
||||
#[rpc(method = "chain_getFinalizedHead", positional_params)]
|
||||
fn finalized_head() -> B::Hash;
|
||||
}
|
||||
#[rpc(client)]
|
||||
pub trait RpcApi<Hash> {
|
||||
#[method(name = "state_getStorage")]
|
||||
fn get_storage(&self, prefix: StorageKey, hash: Option<Hash>) -> Result<StorageData, RpcError>;
|
||||
|
||||
#[method(name = "state_getKeysPaged")]
|
||||
fn get_keys_paged(
|
||||
&self,
|
||||
prefix: Option<StorageKey>,
|
||||
count: u32,
|
||||
start_key: Option<StorageKey>,
|
||||
hash: Option<Hash>,
|
||||
) -> Result<Vec<StorageKey>, RpcError>;
|
||||
|
||||
#[method(name = "chain_getFinalizedHead")]
|
||||
fn finalized_head(&self) -> Result<Hash, RpcError>;
|
||||
}
|
||||
|
||||
/// The execution mode.
|
||||
@@ -183,7 +194,7 @@ pub struct Builder<B: BlockT> {
|
||||
|
||||
// NOTE: ideally we would use `DefaultNoBound` here, but not worth bringing in frame-support for
|
||||
// that.
|
||||
impl<B: BlockT> Default for Builder<B> {
|
||||
impl<B: BlockT + DeserializeOwned> Default for Builder<B> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mode: Default::default(),
|
||||
@@ -196,7 +207,7 @@ impl<B: BlockT> Default for Builder<B> {
|
||||
}
|
||||
|
||||
// Mode methods
|
||||
impl<B: BlockT> Builder<B> {
|
||||
impl<B: BlockT + DeserializeOwned> Builder<B> {
|
||||
fn as_online(&self) -> &OnlineConfig<B> {
|
||||
match &self.mode {
|
||||
Mode::Online(config) => &config,
|
||||
@@ -215,25 +226,23 @@ impl<B: BlockT> Builder<B> {
|
||||
}
|
||||
|
||||
// RPC methods
|
||||
impl<B: BlockT> Builder<B> {
|
||||
impl<B: BlockT + DeserializeOwned> Builder<B> {
|
||||
async fn rpc_get_storage(
|
||||
&self,
|
||||
key: StorageKey,
|
||||
maybe_at: Option<B::Hash>,
|
||||
) -> Result<StorageData, &'static str> {
|
||||
log::trace!(target: LOG_TARGET, "rpc: get_storage");
|
||||
RpcApi::<B>::get_storage(self.as_online().rpc_client(), key, maybe_at)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
log::error!(target: LOG_TARGET, "Error = {:?}", e);
|
||||
"rpc get_storage failed."
|
||||
})
|
||||
trace!(target: LOG_TARGET, "rpc: get_storage");
|
||||
self.as_online().rpc_client().get_storage(key, maybe_at).await.map_err(|e| {
|
||||
error!("Error = {:?}", e);
|
||||
"rpc get_storage failed."
|
||||
})
|
||||
}
|
||||
/// Get the latest finalized head.
|
||||
async fn rpc_get_head(&self) -> Result<B::Hash, &'static str> {
|
||||
log::trace!(target: LOG_TARGET, "rpc: finalized_head");
|
||||
RpcApi::<B>::finalized_head(self.as_online().rpc_client()).await.map_err(|e| {
|
||||
log::error!(target: LOG_TARGET, "Error = {:?}", e);
|
||||
trace!(target: LOG_TARGET, "rpc: finalized_head");
|
||||
self.as_online().rpc_client().finalized_head().await.map_err(|e| {
|
||||
error!("Error = {:?}", e);
|
||||
"rpc finalized_head failed."
|
||||
})
|
||||
}
|
||||
@@ -248,18 +257,15 @@ impl<B: BlockT> Builder<B> {
|
||||
let mut last_key: Option<StorageKey> = None;
|
||||
let mut all_keys: Vec<StorageKey> = vec![];
|
||||
let keys = loop {
|
||||
let page = RpcApi::<B>::get_keys_paged(
|
||||
self.as_online().rpc_client(),
|
||||
Some(prefix.clone()),
|
||||
PAGE,
|
||||
last_key.clone(),
|
||||
Some(at),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
log::error!(target: LOG_TARGET, "Error = {:?}", e);
|
||||
"rpc get_keys failed"
|
||||
})?;
|
||||
let page = self
|
||||
.as_online()
|
||||
.rpc_client()
|
||||
.get_keys_paged(Some(prefix.clone()), PAGE, last_key.clone(), Some(at))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!(target: LOG_TARGET, "Error = {:?}", e);
|
||||
"rpc get_keys failed"
|
||||
})?;
|
||||
let page_len = page.len();
|
||||
all_keys.extend(page);
|
||||
|
||||
@@ -291,8 +297,6 @@ impl<B: BlockT> Builder<B> {
|
||||
prefix: StorageKey,
|
||||
at: B::Hash,
|
||||
) -> Result<Vec<KeyPair>, &'static str> {
|
||||
use jsonrpsee_ws_client::types::traits::Client;
|
||||
use serde_json::to_value;
|
||||
let keys = self.get_keys_paged(prefix, at).await?;
|
||||
let keys_count = keys.len();
|
||||
log::debug!(target: LOG_TARGET, "Querying a total of {} keys", keys.len());
|
||||
@@ -303,15 +307,7 @@ impl<B: BlockT> Builder<B> {
|
||||
let batch = chunk_keys
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|key| {
|
||||
(
|
||||
"state_getStorage",
|
||||
JsonRpcParams::Array(vec![
|
||||
to_value(key).expect("json serialization will work; qed."),
|
||||
to_value(at).expect("json serialization will work; qed."),
|
||||
]),
|
||||
)
|
||||
})
|
||||
.map(|key| ("state_getStorage", rpc_params![key, at]))
|
||||
.collect::<Vec<_>>();
|
||||
let values = client.batch_request::<Option<StorageData>>(batch).await.map_err(|e| {
|
||||
log::error!(
|
||||
@@ -348,7 +344,7 @@ impl<B: BlockT> Builder<B> {
|
||||
}
|
||||
|
||||
// Internal methods
|
||||
impl<B: BlockT> Builder<B> {
|
||||
impl<B: BlockT + DeserializeOwned> Builder<B> {
|
||||
/// Save the given data as state snapshot.
|
||||
fn save_state_snapshot(&self, data: &[KeyPair], path: &Path) -> Result<(), &'static str> {
|
||||
log::debug!(target: LOG_TARGET, "writing to state snapshot file {:?}", path);
|
||||
@@ -489,7 +485,7 @@ impl<B: BlockT> Builder<B> {
|
||||
}
|
||||
|
||||
// Public methods
|
||||
impl<B: BlockT> Builder<B> {
|
||||
impl<B: BlockT + DeserializeOwned> Builder<B> {
|
||||
/// Create a new builder.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
@@ -625,7 +621,7 @@ mod tests {
|
||||
#[cfg(all(test, feature = "remote-test"))]
|
||||
mod remote_tests {
|
||||
use super::test_prelude::*;
|
||||
|
||||
use pallet_elections_phragmen::Members;
|
||||
const REMOTE_INACCESSIBLE: &'static str = "Can't reach the remote node. Is it running?";
|
||||
|
||||
#[tokio::test]
|
||||
@@ -697,7 +693,6 @@ mod remote_tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn sanity_check_decoding() {
|
||||
use pallet_elections_phragmen::SeatHolder;
|
||||
use sp_core::crypto::Ss58Codec;
|
||||
|
||||
type AccountId = sp_runtime::AccountId32;
|
||||
@@ -722,7 +717,7 @@ mod remote_tests {
|
||||
let gav_polkadot =
|
||||
AccountId::from_ss58check("13RDY9nrJpyTDBSUdBw12dGwhk19sGwsrVZ2bxkzYHBSagP2")
|
||||
.unwrap();
|
||||
let members = Members::get().unwrap();
|
||||
let members = Members::get();
|
||||
assert!(members
|
||||
.iter()
|
||||
.map(|s| s.who.clone())
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -31,6 +31,4 @@ sp-externalities = { version = "0.10.0-dev", path = "../../../../primitives/exte
|
||||
sp-version = { version = "4.0.0-dev", path = "../../../../primitives/version" }
|
||||
|
||||
remote-externalities = { version = "0.10.0-dev", path = "../../remote-externalities" }
|
||||
jsonrpsee-ws-client = { version = "0.3.1", default-features = false, features = [
|
||||
"tokio1",
|
||||
]}
|
||||
jsonrpsee = { version = "0.4.1", default-features = false, features = ["ws-client"]}
|
||||
|
||||
@@ -19,9 +19,9 @@ use crate::{
|
||||
build_executor, ensure_matching_spec, extract_code, full_extensions, local_spec, parse,
|
||||
state_machine_call, SharedParams, LOG_TARGET,
|
||||
};
|
||||
use jsonrpsee_ws_client::{
|
||||
types::{traits::SubscriptionClient, v2::params::JsonRpcParams, Subscription},
|
||||
WsClientBuilder,
|
||||
use jsonrpsee::{
|
||||
types::{traits::SubscriptionClient, Subscription},
|
||||
ws_client::WsClientBuilder,
|
||||
};
|
||||
use parity_scale_codec::Decode;
|
||||
use remote_externalities::{rpc_api, Builder, Mode, OnlineConfig};
|
||||
@@ -72,7 +72,7 @@ where
|
||||
|
||||
log::info!(target: LOG_TARGET, "subscribing to {:?} / {:?}", SUB, UN_SUB);
|
||||
let mut subscription: Subscription<Block::Header> =
|
||||
client.subscribe(&SUB, JsonRpcParams::NoParams, &UN_SUB).await.unwrap();
|
||||
client.subscribe(&SUB, None, &UN_SUB).await.unwrap();
|
||||
|
||||
let (code_key, code) = extract_code(&config.chain_spec)?;
|
||||
let executor = build_executor::<ExecDispatch>(&shared, &config);
|
||||
|
||||
@@ -281,7 +281,10 @@ use sp_core::{
|
||||
};
|
||||
use sp_externalities::Extensions;
|
||||
use sp_keystore::{testing::KeyStore, KeystoreExt};
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, NumberFor},
|
||||
DeserializeOwned,
|
||||
};
|
||||
use sp_state_machine::{OverlayedChanges, StateMachine};
|
||||
use std::{fmt::Debug, path::PathBuf, str::FromStr};
|
||||
|
||||
@@ -464,7 +467,7 @@ pub enum State {
|
||||
|
||||
impl State {
|
||||
/// Create the [`remote_externalities::Builder`] from self.
|
||||
pub(crate) fn builder<Block: BlockT>(&self) -> sc_cli::Result<Builder<Block>>
|
||||
pub(crate) fn builder<Block: BlockT + DeserializeOwned>(&self) -> sc_cli::Result<Builder<Block>>
|
||||
where
|
||||
Block::Hash: FromStr,
|
||||
<Block::Hash as FromStr>::Err: Debug,
|
||||
|
||||
Reference in New Issue
Block a user