mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 23:47:56 +00:00
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:
@@ -20,11 +20,11 @@ use crate::{
|
||||
state_machine_call_with_proof, SharedParams, State, LOG_TARGET,
|
||||
};
|
||||
use parity_scale_codec::Encode;
|
||||
use remote_externalities::rpc_api;
|
||||
use sc_service::{Configuration, NativeExecutionDispatch};
|
||||
use sp_core::storage::well_known_keys;
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use std::{fmt::Debug, str::FromStr};
|
||||
use substrate_rpc_client::{ws_client, ChainApi};
|
||||
|
||||
/// Configurations of the [`Command::ExecuteBlock`].
|
||||
///
|
||||
@@ -84,10 +84,11 @@ pub struct ExecuteBlockCmd {
|
||||
impl ExecuteBlockCmd {
|
||||
async fn block_at<Block: BlockT>(&self, ws_uri: String) -> sc_cli::Result<Block::Hash>
|
||||
where
|
||||
Block::Hash: FromStr,
|
||||
Block::Hash: FromStr + serde::de::DeserializeOwned,
|
||||
<Block::Hash as FromStr>::Err: Debug,
|
||||
Block::Header: serde::de::DeserializeOwned,
|
||||
{
|
||||
let rpc_service = rpc_api::RpcService::new(ws_uri, false).await?;
|
||||
let rpc = ws_client(&ws_uri).await?;
|
||||
|
||||
match (&self.block_at, &self.state) {
|
||||
(Some(block_at), State::Snap { .. }) => hash_of::<Block>(block_at),
|
||||
@@ -100,7 +101,9 @@ impl ExecuteBlockCmd {
|
||||
target: LOG_TARGET,
|
||||
"No --block-at or --at provided, using the latest finalized block instead"
|
||||
);
|
||||
rpc_service.get_finalized_head::<Block>().await.map_err(Into::into)
|
||||
ChainApi::<(), Block::Hash, Block::Header, ()>::finalized_head(&rpc)
|
||||
.await
|
||||
.map_err(|e| e.to_string().into())
|
||||
},
|
||||
(None, State::Live { at: Some(at), .. }) => hash_of::<Block>(at),
|
||||
_ => {
|
||||
@@ -137,6 +140,8 @@ where
|
||||
Block: BlockT + serde::de::DeserializeOwned,
|
||||
Block::Hash: FromStr,
|
||||
<Block::Hash as FromStr>::Err: Debug,
|
||||
Block::Hash: serde::de::DeserializeOwned,
|
||||
Block::Header: serde::de::DeserializeOwned,
|
||||
NumberFor<Block>: FromStr,
|
||||
<NumberFor<Block> as FromStr>::Err: Debug,
|
||||
ExecDispatch: NativeExecutionDispatch + 'static,
|
||||
@@ -146,8 +151,11 @@ where
|
||||
|
||||
let block_ws_uri = command.block_ws_uri::<Block>();
|
||||
let block_at = command.block_at::<Block>(block_ws_uri.clone()).await?;
|
||||
let rpc_service = rpc_api::RpcService::new(block_ws_uri.clone(), false).await?;
|
||||
let block: Block = rpc_service.get_block::<Block>(block_at).await?;
|
||||
let rpc = ws_client(&block_ws_uri).await?;
|
||||
let block: Block = ChainApi::<(), Block::Hash, Block::Header, _>::block(&rpc, Some(block_at))
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let parent_hash = block.header().parent_hash();
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
|
||||
Reference in New Issue
Block a user