mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +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"
|
log = "0.4.11"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
structopt = "0.3.25"
|
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_json = "1.0"
|
||||||
serde = "1.0.130"
|
serde = "1.0.130"
|
||||||
paste = "1.0.6"
|
paste = "1.0.6"
|
||||||
|
|||||||
@@ -17,10 +17,11 @@
|
|||||||
//! The dry-run command.
|
//! The dry-run command.
|
||||||
|
|
||||||
use crate::{
|
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 codec::Encode;
|
||||||
use frame_support::traits::Currency;
|
use frame_support::traits::Currency;
|
||||||
|
use jsonrpsee::rpc_params;
|
||||||
|
|
||||||
/// Forcefully create the snapshot. This can be used to compute the election at anytime.
|
/// 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>> {
|
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>>(
|
let info = rpc::<pallet_transaction_payment::RuntimeDispatchInfo<Balance>>(
|
||||||
client,
|
client,
|
||||||
"payment_queryInfo",
|
"payment_queryInfo",
|
||||||
params! { extrinsic },
|
rpc_params! { extrinsic },
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
log::info!(
|
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);
|
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
|
.await
|
||||||
.map_err::<Error<Runtime>, _>(Into::into)?;
|
.map_err::<Error<Runtime>, _>(Into::into)?;
|
||||||
log::info!(target: LOG_TARGET, "dry-run outcome is {:?}", outcome);
|
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_election_provider_support::NposSolver;
|
||||||
use frame_support::traits::Get;
|
use frame_support::traits::Get;
|
||||||
use jsonrpsee_ws_client::{WsClient, WsClientBuilder};
|
use jsonrpsee::ws_client::{WsClient, WsClientBuilder};
|
||||||
use remote_externalities::{Builder, Mode, OnlineConfig};
|
use remote_externalities::{Builder, Mode, OnlineConfig};
|
||||||
use sp_npos_elections::ExtendedBalance;
|
use sp_npos_elections::ExtendedBalance;
|
||||||
use sp_runtime::traits::Block as BlockT;
|
use sp_runtime::{traits::Block as BlockT, DeserializeOwned};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
pub(crate) enum AnyRuntime {
|
pub(crate) enum AnyRuntime {
|
||||||
@@ -225,7 +225,7 @@ macro_rules! any_runtime_unit {
|
|||||||
#[derive(frame_support::DebugNoBound, thiserror::Error)]
|
#[derive(frame_support::DebugNoBound, thiserror::Error)]
|
||||||
enum Error<T: EPM::Config> {
|
enum Error<T: EPM::Config> {
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
JsonRpsee(#[from] jsonrpsee_ws_client::types::Error),
|
JsonRpsee(#[from] jsonrpsee::types::Error),
|
||||||
RpcHelperError(#[from] rpc_helpers::RpcHelperError),
|
RpcHelperError(#[from] rpc_helpers::RpcHelperError),
|
||||||
Codec(#[from] codec::Error),
|
Codec(#[from] codec::Error),
|
||||||
Crypto(sp_core::crypto::SecretStringError),
|
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
|
/// Build the Ext at hash with all the data of `ElectionProviderMultiPhase` and any additional
|
||||||
/// pallets.
|
/// pallets.
|
||||||
async fn create_election_ext<T: EPM::Config, B: BlockT>(
|
async fn create_election_ext<T: EPM::Config, B: BlockT + DeserializeOwned>(
|
||||||
uri: String,
|
uri: String,
|
||||||
at: Option<B::Hash>,
|
at: Option<B::Hash>,
|
||||||
additional: Vec<String>,
|
additional: Vec<String>,
|
||||||
@@ -493,11 +493,8 @@ pub(crate) async fn check_versions<T: frame_system::Config + EPM::Config>(
|
|||||||
client: &WsClient,
|
client: &WsClient,
|
||||||
) -> Result<(), Error<T>> {
|
) -> Result<(), Error<T>> {
|
||||||
let linked_version = T::Version::get();
|
let linked_version = T::Version::get();
|
||||||
let on_chain_version = rpc_helpers::rpc::<sp_version::RuntimeVersion>(
|
let on_chain_version =
|
||||||
client,
|
rpc_helpers::rpc::<sp_version::RuntimeVersion>(client, "state_getRuntimeVersion", None)
|
||||||
"state_getRuntimeVersion",
|
|
||||||
params! {},
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.expect("runtime version RPC should always work; qed");
|
.expect("runtime version RPC should always work; qed");
|
||||||
|
|
||||||
@@ -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
|
.await
|
||||||
.expect("system_chain infallible; qed.");
|
.expect("system_chain infallible; qed.");
|
||||||
match chain.to_lowercase().as_str() {
|
match chain.to_lowercase().as_str() {
|
||||||
|
|||||||
@@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
//! The monitor command.
|
//! The monitor command.
|
||||||
|
|
||||||
use crate::{
|
use crate::{prelude::*, rpc_helpers::*, signer::Signer, Error, MonitorConfig, SharedConfig};
|
||||||
params, prelude::*, rpc_helpers::*, signer::Signer, Error, MonitorConfig, SharedConfig,
|
|
||||||
};
|
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use jsonrpsee_ws_client::{
|
use jsonrpsee::{
|
||||||
|
rpc_params,
|
||||||
types::{traits::SubscriptionClient, Subscription},
|
types::{traits::SubscriptionClient, Subscription},
|
||||||
WsClient,
|
ws_client::WsClient,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sc_transaction_pool_api::TransactionStatus;
|
use sc_transaction_pool_api::TransactionStatus;
|
||||||
use sp_core::storage::StorageKey;
|
use sp_core::storage::StorageKey;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ async fn ensure_signed_phase<T: EPM::Config, B: BlockT>(
|
|||||||
at: B::Hash,
|
at: B::Hash,
|
||||||
) -> Result<(), Error<T>> {
|
) -> Result<(), Error<T>> {
|
||||||
let key = StorageKey(EPM::CurrentPhase::<T>::hashed_key().to_vec());
|
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
|
.await
|
||||||
.map_err::<Error<T>, _>(Into::into)?
|
.map_err::<Error<T>, _>(Into::into)?
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
@@ -82,7 +82,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
|
|||||||
loop {
|
loop {
|
||||||
log::info!(target: LOG_TARGET, "subscribing to {:?} / {:?}", sub, unsub);
|
log::info!(target: LOG_TARGET, "subscribing to {:?} / {:?}", sub, unsub);
|
||||||
let mut subscription: Subscription<Header> = client
|
let mut subscription: Subscription<Header> = client
|
||||||
.subscribe(&sub, params! {}, &unsub)
|
.subscribe(&sub, None, &unsub)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
|
|||||||
let mut tx_subscription: Subscription<
|
let mut tx_subscription: Subscription<
|
||||||
TransactionStatus<<Block as BlockT>::Hash, <Block as BlockT>::Hash>
|
TransactionStatus<<Block as BlockT>::Hash, <Block as BlockT>::Hash>
|
||||||
> = match client
|
> = match client
|
||||||
.subscribe(&"author_submitAndWatchExtrinsic", params! { bytes }, "author_unwatchExtrinsic")
|
.subscribe(&"author_submitAndWatchExtrinsic", rpc_params! { bytes }, "author_unwatchExtrinsic")
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(sub) => sub,
|
Ok(sub) => sub,
|
||||||
@@ -159,7 +159,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
|
|||||||
log::info!(target: LOG_TARGET, "included at {:?}", hash);
|
log::info!(target: LOG_TARGET, "included at {:?}", hash);
|
||||||
let key = StorageKey(frame_support::storage::storage_prefix(b"System",b"Events").to_vec());
|
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>>,
|
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);
|
log::info!(target: LOG_TARGET, "events at inclusion {:?}", events);
|
||||||
}
|
}
|
||||||
TransactionStatus::Retracted(hash) => {
|
TransactionStatus::Retracted(hash) => {
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
//! Helper method for RPC.
|
//! Helper method for RPC.
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use jsonrpsee_ws_client::types::traits::Client;
|
use jsonrpsee::types::traits::Client;
|
||||||
pub(crate) use jsonrpsee_ws_client::types::v2::params::JsonRpcParams;
|
pub(crate) use jsonrpsee::types::v2::ParamsSer;
|
||||||
|
|
||||||
#[derive(frame_support::DebugNoBound, thiserror::Error)]
|
#[derive(frame_support::DebugNoBound, thiserror::Error)]
|
||||||
pub(crate) enum RpcHelperError {
|
pub(crate) enum RpcHelperError {
|
||||||
JsonRpsee(#[from] jsonrpsee_ws_client::types::Error),
|
JsonRpsee(#[from] jsonrpsee::types::Error),
|
||||||
Codec(#[from] codec::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`.
|
/// Make the rpc request, returning `Ret`.
|
||||||
pub(crate) async fn rpc<'a, Ret: serde::de::DeserializeOwned>(
|
pub(crate) async fn rpc<'a, Ret: serde::de::DeserializeOwned>(
|
||||||
client: &WsClient,
|
client: &WsClient,
|
||||||
method: &'a str,
|
method: &'a str,
|
||||||
params: JsonRpcParams<'a>,
|
params: Option<ParamsSer<'a>>,
|
||||||
) -> Result<Ret, RpcHelperError> {
|
) -> Result<Ret, RpcHelperError> {
|
||||||
client
|
client
|
||||||
.request::<Ret>(method, params)
|
.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>(
|
pub(crate) async fn rpc_decode<'a, Dec: codec::Decode>(
|
||||||
client: &WsClient,
|
client: &WsClient,
|
||||||
method: &'a str,
|
method: &'a str,
|
||||||
params: JsonRpcParams<'a>,
|
params: Option<ParamsSer<'a>>,
|
||||||
) -> Result<Dec, RpcHelperError> {
|
) -> Result<Dec, RpcHelperError> {
|
||||||
let bytes = rpc::<sp_core::Bytes>(client, method, params)
|
let bytes = rpc::<sp_core::Bytes>(client, method, params)
|
||||||
.await
|
.await
|
||||||
@@ -76,7 +60,7 @@ pub(crate) async fn rpc_decode<'a, Dec: codec::Decode>(
|
|||||||
/// Get the storage item.
|
/// Get the storage item.
|
||||||
pub(crate) async fn get_storage<'a, T: codec::Decode>(
|
pub(crate) async fn get_storage<'a, T: codec::Decode>(
|
||||||
client: &WsClient,
|
client: &WsClient,
|
||||||
params: JsonRpcParams<'a>,
|
params: Option<ParamsSer<'a>>,
|
||||||
) -> Result<Option<T>, RpcHelperError> {
|
) -> Result<Option<T>, RpcHelperError> {
|
||||||
let maybe_bytes = rpc::<Option<sp_core::Bytes>>(client, "state_getStorage", params)
|
let maybe_bytes = rpc::<Option<sp_core::Bytes>>(client, "state_getStorage", params)
|
||||||
.await
|
.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>> {
|
) -> Result<Option<frame_system::AccountInfo<Index, T::AccountData>>, Error<T>> {
|
||||||
rpc_helpers::get_storage::<frame_system::AccountInfo<Index, T::AccountData>>(
|
rpc_helpers::get_storage::<frame_system::AccountInfo<Index, T::AccountData>>(
|
||||||
client,
|
client,
|
||||||
crate::params! {
|
jsonrpsee::rpc_params! {
|
||||||
sp_core::storage::StorageKey(<frame_system::Account<T>>::hashed_key_for(&who)),
|
sp_core::storage::StorageKey(<frame_system::Account<T>>::hashed_key_for(&who)),
|
||||||
maybe_at
|
maybe_at
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user