mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Companion – Update jsonrpsee to 0.4.1 (#4256)
* Update staking-miner * fmt * lockfile * Point to substrate companion branch * Revert "Point to substrate companion branch" This reverts commit 3f8afc5d3137614776f54c7dac3c9077268c5fe5. * Revert 3f8afc5d3137614776f54c7dac3c9077268c5fe5 * Remove `params` macro in favour of `rpc_macro` from jsonrpsee * update Cargo.lock * remove unused import Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
Generated
+214
-242
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,7 @@ tokio = { version = "1.13", features = ["macros"] }
|
||||
log = "0.4.11"
|
||||
env_logger = "0.9.0"
|
||||
structopt = "0.3.25"
|
||||
jsonrpsee-ws-client = { version = "0.3.1", default-features = false, features = ["tokio1"] }
|
||||
jsonrpsee = { version = "0.4.1", default-features = false, features = ["ws-client"] }
|
||||
serde_json = "1.0"
|
||||
serde = "1.0.130"
|
||||
paste = "1.0.6"
|
||||
|
||||
@@ -17,10 +17,11 @@
|
||||
//! The dry-run command.
|
||||
|
||||
use crate::{
|
||||
params, prelude::*, rpc_helpers::*, signer::Signer, DryRunConfig, Error, SharedConfig, WsClient,
|
||||
prelude::*, rpc_helpers::*, signer::Signer, DryRunConfig, Error, SharedConfig, WsClient,
|
||||
};
|
||||
use codec::Encode;
|
||||
use frame_support::traits::Currency;
|
||||
use jsonrpsee::rpc_params;
|
||||
|
||||
/// Forcefully create the snapshot. This can be used to compute the election at anytime.
|
||||
fn force_create_snapshot<T: EPM::Config>(ext: &mut Ext) -> Result<(), Error<T>> {
|
||||
@@ -74,7 +75,7 @@ async fn print_info<T: EPM::Config>(
|
||||
let info = rpc::<pallet_transaction_payment::RuntimeDispatchInfo<Balance>>(
|
||||
client,
|
||||
"payment_queryInfo",
|
||||
params! { extrinsic },
|
||||
rpc_params! { extrinsic },
|
||||
)
|
||||
.await;
|
||||
log::info!(
|
||||
@@ -149,7 +150,7 @@ macro_rules! dry_run_cmd_for { ($runtime:ident) => { paste::paste! {
|
||||
});
|
||||
log::info!(target: LOG_TARGET, "dispatch result is {:?}", dispatch_result);
|
||||
|
||||
let outcome = rpc_decode::<sp_runtime::ApplyExtrinsicResult>(client, "system_dryRun", params!{ bytes })
|
||||
let outcome = rpc_decode::<sp_runtime::ApplyExtrinsicResult>(client, "system_dryRun", rpc_params!{ bytes })
|
||||
.await
|
||||
.map_err::<Error<Runtime>, _>(Into::into)?;
|
||||
log::info!(target: LOG_TARGET, "dry-run outcome is {:?}", outcome);
|
||||
|
||||
@@ -40,10 +40,10 @@ pub(crate) use signer::get_account_info;
|
||||
|
||||
use frame_election_provider_support::NposSolver;
|
||||
use frame_support::traits::Get;
|
||||
use jsonrpsee_ws_client::{WsClient, WsClientBuilder};
|
||||
use jsonrpsee::ws_client::{WsClient, WsClientBuilder};
|
||||
use remote_externalities::{Builder, Mode, OnlineConfig};
|
||||
use sp_npos_elections::ExtendedBalance;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
|
||||
use structopt::StructOpt;
|
||||
|
||||
pub(crate) enum AnyRuntime {
|
||||
@@ -225,7 +225,7 @@ macro_rules! any_runtime_unit {
|
||||
#[derive(frame_support::DebugNoBound, thiserror::Error)]
|
||||
enum Error<T: EPM::Config> {
|
||||
Io(#[from] std::io::Error),
|
||||
JsonRpsee(#[from] jsonrpsee_ws_client::types::Error),
|
||||
JsonRpsee(#[from] jsonrpsee::types::Error),
|
||||
RpcHelperError(#[from] rpc_helpers::RpcHelperError),
|
||||
Codec(#[from] codec::Error),
|
||||
Crypto(sp_core::crypto::SecretStringError),
|
||||
@@ -364,7 +364,7 @@ struct Opt {
|
||||
|
||||
/// Build the Ext at hash with all the data of `ElectionProviderMultiPhase` and any additional
|
||||
/// pallets.
|
||||
async fn create_election_ext<T: EPM::Config, B: BlockT>(
|
||||
async fn create_election_ext<T: EPM::Config, B: BlockT + DeserializeOwned>(
|
||||
uri: String,
|
||||
at: Option<B::Hash>,
|
||||
additional: Vec<String>,
|
||||
@@ -493,13 +493,10 @@ pub(crate) async fn check_versions<T: frame_system::Config + EPM::Config>(
|
||||
client: &WsClient,
|
||||
) -> Result<(), Error<T>> {
|
||||
let linked_version = T::Version::get();
|
||||
let on_chain_version = rpc_helpers::rpc::<sp_version::RuntimeVersion>(
|
||||
client,
|
||||
"state_getRuntimeVersion",
|
||||
params! {},
|
||||
)
|
||||
.await
|
||||
.expect("runtime version RPC should always work; qed");
|
||||
let on_chain_version =
|
||||
rpc_helpers::rpc::<sp_version::RuntimeVersion>(client, "state_getRuntimeVersion", None)
|
||||
.await
|
||||
.expect("runtime version RPC should always work; qed");
|
||||
|
||||
log::debug!(target: LOG_TARGET, "linked version {:?}", linked_version);
|
||||
log::debug!(target: LOG_TARGET, "on-chain version {:?}", on_chain_version);
|
||||
@@ -543,7 +540,7 @@ async fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
let chain = rpc_helpers::rpc::<String>(&client, "system_chain", params! {})
|
||||
let chain = rpc_helpers::rpc::<String>(&client, "system_chain", None)
|
||||
.await
|
||||
.expect("system_chain infallible; qed.");
|
||||
match chain.to_lowercase().as_str() {
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
//! The monitor command.
|
||||
|
||||
use crate::{
|
||||
params, prelude::*, rpc_helpers::*, signer::Signer, Error, MonitorConfig, SharedConfig,
|
||||
};
|
||||
use crate::{prelude::*, rpc_helpers::*, signer::Signer, Error, MonitorConfig, SharedConfig};
|
||||
use codec::Encode;
|
||||
use jsonrpsee_ws_client::{
|
||||
use jsonrpsee::{
|
||||
rpc_params,
|
||||
types::{traits::SubscriptionClient, Subscription},
|
||||
WsClient,
|
||||
ws_client::WsClient,
|
||||
};
|
||||
|
||||
use sc_transaction_pool_api::TransactionStatus;
|
||||
use sp_core::storage::StorageKey;
|
||||
|
||||
@@ -33,7 +33,7 @@ async fn ensure_signed_phase<T: EPM::Config, B: BlockT>(
|
||||
at: B::Hash,
|
||||
) -> Result<(), Error<T>> {
|
||||
let key = StorageKey(EPM::CurrentPhase::<T>::hashed_key().to_vec());
|
||||
let phase = get_storage::<EPM::Phase<BlockNumber>>(client, params! {key, at})
|
||||
let phase = get_storage::<EPM::Phase<BlockNumber>>(client, rpc_params! {key, at})
|
||||
.await
|
||||
.map_err::<Error<T>, _>(Into::into)?
|
||||
.unwrap_or_default();
|
||||
@@ -82,7 +82,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
|
||||
loop {
|
||||
log::info!(target: LOG_TARGET, "subscribing to {:?} / {:?}", sub, unsub);
|
||||
let mut subscription: Subscription<Header> = client
|
||||
.subscribe(&sub, params! {}, &unsub)
|
||||
.subscribe(&sub, None, &unsub)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -134,7 +134,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
|
||||
let mut tx_subscription: Subscription<
|
||||
TransactionStatus<<Block as BlockT>::Hash, <Block as BlockT>::Hash>
|
||||
> = match client
|
||||
.subscribe(&"author_submitAndWatchExtrinsic", params! { bytes }, "author_unwatchExtrinsic")
|
||||
.subscribe(&"author_submitAndWatchExtrinsic", rpc_params! { bytes }, "author_unwatchExtrinsic")
|
||||
.await
|
||||
{
|
||||
Ok(sub) => sub,
|
||||
@@ -159,7 +159,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
|
||||
log::info!(target: LOG_TARGET, "included at {:?}", hash);
|
||||
let key = StorageKey(frame_support::storage::storage_prefix(b"System",b"Events").to_vec());
|
||||
let events = get_storage::<Vec<frame_system::EventRecord<Event, <Block as BlockT>::Hash>>,
|
||||
>(client, params!{ key, hash }).await?.unwrap_or_default();
|
||||
>(client, rpc_params!{ key, hash }).await?.unwrap_or_default();
|
||||
log::info!(target: LOG_TARGET, "events at inclusion {:?}", events);
|
||||
}
|
||||
TransactionStatus::Retracted(hash) => {
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
//! Helper method for RPC.
|
||||
|
||||
use super::*;
|
||||
use jsonrpsee_ws_client::types::traits::Client;
|
||||
pub(crate) use jsonrpsee_ws_client::types::v2::params::JsonRpcParams;
|
||||
use jsonrpsee::types::traits::Client;
|
||||
pub(crate) use jsonrpsee::types::v2::ParamsSer;
|
||||
|
||||
#[derive(frame_support::DebugNoBound, thiserror::Error)]
|
||||
pub(crate) enum RpcHelperError {
|
||||
JsonRpsee(#[from] jsonrpsee_ws_client::types::Error),
|
||||
JsonRpsee(#[from] jsonrpsee::types::Error),
|
||||
Codec(#[from] codec::Error),
|
||||
}
|
||||
|
||||
@@ -32,27 +32,11 @@ impl std::fmt::Display for RpcHelperError {
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! params {
|
||||
($($param:expr),*) => {
|
||||
{
|
||||
let mut __params = vec![];
|
||||
$(
|
||||
__params.push(serde_json::to_value($param).expect("json serialization infallible; qed."));
|
||||
)*
|
||||
$crate::rpc_helpers::JsonRpcParams::Array(__params)
|
||||
}
|
||||
};
|
||||
() => {
|
||||
$crate::rpc::JsonRpcParams::NoParams,
|
||||
}
|
||||
}
|
||||
|
||||
/// Make the rpc request, returning `Ret`.
|
||||
pub(crate) async fn rpc<'a, Ret: serde::de::DeserializeOwned>(
|
||||
client: &WsClient,
|
||||
method: &'a str,
|
||||
params: JsonRpcParams<'a>,
|
||||
params: Option<ParamsSer<'a>>,
|
||||
) -> Result<Ret, RpcHelperError> {
|
||||
client
|
||||
.request::<Ret>(method, params)
|
||||
@@ -65,7 +49,7 @@ pub(crate) async fn rpc<'a, Ret: serde::de::DeserializeOwned>(
|
||||
pub(crate) async fn rpc_decode<'a, Dec: codec::Decode>(
|
||||
client: &WsClient,
|
||||
method: &'a str,
|
||||
params: JsonRpcParams<'a>,
|
||||
params: Option<ParamsSer<'a>>,
|
||||
) -> Result<Dec, RpcHelperError> {
|
||||
let bytes = rpc::<sp_core::Bytes>(client, method, params)
|
||||
.await
|
||||
@@ -76,7 +60,7 @@ pub(crate) async fn rpc_decode<'a, Dec: codec::Decode>(
|
||||
/// Get the storage item.
|
||||
pub(crate) async fn get_storage<'a, T: codec::Decode>(
|
||||
client: &WsClient,
|
||||
params: JsonRpcParams<'a>,
|
||||
params: Option<ParamsSer<'a>>,
|
||||
) -> Result<Option<T>, RpcHelperError> {
|
||||
let maybe_bytes = rpc::<Option<sp_core::Bytes>>(client, "state_getStorage", params)
|
||||
.await
|
||||
|
||||
@@ -41,7 +41,7 @@ pub(crate) async fn get_account_info<T: frame_system::Config + EPM::Config>(
|
||||
) -> Result<Option<frame_system::AccountInfo<Index, T::AccountData>>, Error<T>> {
|
||||
rpc_helpers::get_storage::<frame_system::AccountInfo<Index, T::AccountData>>(
|
||||
client,
|
||||
crate::params! {
|
||||
jsonrpsee::rpc_params! {
|
||||
sp_core::storage::StorageKey(<frame_system::Account<T>>::hashed_key_for(&who)),
|
||||
maybe_at
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user