frame/utils: introduce substrate-rpc-client crate for RPC utils (#12212)

* hack together a PoC

* Update utils/frame/rpc-utils/Cargo.toml

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update utils/frame/rpc-utils/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* rpc_utils -> substrate_rpc_client

* try runtime: remove keep connection

* make CI happy

* cargo fmt

* fix ci

* update lock file

* fix

* fix

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
Niklas Adolfsson
2022-10-18 18:39:19 +02:00
committed by GitHub
parent 096553cb59
commit e3b269ab0f
19 changed files with 437 additions and 497 deletions
@@ -267,8 +267,7 @@
use parity_scale_codec::Decode;
use remote_externalities::{
rpc_api::RpcService, Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig,
TestExternalities,
Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, TestExternalities,
};
use sc_chain_spec::ChainSpec;
use sc_cli::{
@@ -297,6 +296,7 @@ use sp_runtime::{
use sp_state_machine::{OverlayedChanges, StateMachine, TrieBackendBuilder};
use sp_version::StateVersion;
use std::{fmt::Debug, path::PathBuf, str::FromStr};
use substrate_rpc_client::{ws_client, StateApi};
mod commands;
pub(crate) mod parse;
@@ -633,9 +633,8 @@ pub(crate) async fn ensure_matching_spec<Block: BlockT + DeserializeOwned>(
expected_spec_version: u32,
relaxed: bool,
) {
let rpc_service = RpcService::new(uri.clone(), false).await.unwrap();
match rpc_service
.get_runtime_version::<Block>(None)
let rpc = ws_client(&uri).await.unwrap();
match StateApi::<Block::Hash>::runtime_version(&rpc, None)
.await
.map(|version| (String::from(version.spec_name.clone()), version.spec_version))
.map(|(spec_name, spec_version)| (spec_name.to_lowercase(), spec_version))