Commit 4de59b3a authored by David's avatar David
Browse files

Update staking-miner

parent f26e523a
......@@ -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,8 +17,9 @@
//! 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 jsonrpsee::rpc_params;
use codec::Encode;
use frame_support::traits::Currency;
......@@ -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::{DeserializeOwned, traits::Block as BlockT};
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>,
......@@ -496,7 +496,7 @@ pub(crate) async fn check_versions<T: frame_system::Config + EPM::Config>(
let on_chain_version = rpc_helpers::rpc::<sp_version::RuntimeVersion>(
client,
"state_getRuntimeVersion",
params! {},
None,
)
.await
.expect("runtime version RPC should always work; qed");
......@@ -543,7 +543,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() {
......
......@@ -17,13 +17,13 @@
//! The monitor command.
use crate::{
params, prelude::*, rpc_helpers::*, signer::Signer, Error, MonitorConfig, SharedConfig,
prelude::*, rpc_helpers::*, signer::Signer, Error, MonitorConfig, SharedConfig,
};
use codec::Encode;
use jsonrpsee_ws_client::{
types::{traits::SubscriptionClient, Subscription},
WsClient,
};
use jsonrpsee::types::{traits::SubscriptionClient, Subscription};
use jsonrpsee::ws_client::WsClient;
use jsonrpsee::rpc_params;
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,13 @@
//! 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 use jsonrpsee::rpc_params; // TODO: needed actually?
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 +33,27 @@ 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,
}
}
// #[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::ParamsSer::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 +66,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 +77,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
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment