mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 00:17:56 +00:00
Upgrade jsonrpc to 0.18.0 (#9547)
* Upgrade jsonrpc to 0.18.0
I think this says all :P
* 🤦
* Fmt etc
* Fix tests
* Fix tests again...
* Better impl
* Revert "Tell dependabot to ignore jsonrpc-* updates (#9518)"
This reverts commit 6e0cd5587d.
This commit is contained in:
@@ -18,28 +18,27 @@
|
||||
|
||||
//! Substrate system API.
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use futures::{channel::oneshot, compat::Compat, future::BoxFuture, FutureExt, TryFutureExt};
|
||||
use self::error::Result;
|
||||
use futures::{channel::oneshot, FutureExt};
|
||||
use sc_rpc_api::{DenyUnsafe, Receiver};
|
||||
use sc_tracing::logging;
|
||||
use sp_runtime::traits::{self, Header as HeaderT};
|
||||
use sp_utils::mpsc::TracingUnboundedSender;
|
||||
|
||||
use self::error::Result;
|
||||
|
||||
pub use self::{
|
||||
gen_client::Client as SystemClient,
|
||||
helpers::{Health, NodeRole, PeerInfo, SyncState, SystemInfo},
|
||||
};
|
||||
pub use sc_rpc_api::system::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// Early exit for RPCs that require `--rpc-methods=Unsafe` to be enabled
|
||||
macro_rules! bail_if_unsafe {
|
||||
($value: expr) => {
|
||||
if let Err(err) = $value.check_if_safe() {
|
||||
return async move { Err(err.into()) }.boxed().compat()
|
||||
return async move { Err(err.into()) }.boxed()
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -114,51 +113,42 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
||||
fn system_health(&self) -> Receiver<Health> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::Health(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
Receiver(rx)
|
||||
}
|
||||
|
||||
fn system_local_peer_id(&self) -> Receiver<String> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::LocalPeerId(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
Receiver(rx)
|
||||
}
|
||||
|
||||
fn system_local_listen_addresses(&self) -> Receiver<Vec<String>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::LocalListenAddresses(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
Receiver(rx)
|
||||
}
|
||||
|
||||
fn system_peers(
|
||||
&self,
|
||||
) -> Compat<
|
||||
BoxFuture<'static, rpc::Result<Vec<PeerInfo<B::Hash, <B::Header as HeaderT>::Number>>>>,
|
||||
> {
|
||||
) -> rpc::BoxFuture<rpc::Result<Vec<PeerInfo<B::Hash, <B::Header as HeaderT>::Number>>>> {
|
||||
bail_if_unsafe!(self.deny_unsafe);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::Peers(tx));
|
||||
|
||||
async move { rx.await.map_err(|_| rpc::Error::internal_error()) }
|
||||
.boxed()
|
||||
.compat()
|
||||
async move { rx.await.map_err(|_| rpc::Error::internal_error()) }.boxed()
|
||||
}
|
||||
|
||||
fn system_network_state(&self) -> Compat<BoxFuture<'static, rpc::Result<rpc::Value>>> {
|
||||
fn system_network_state(&self) -> rpc::BoxFuture<rpc::Result<rpc::Value>> {
|
||||
bail_if_unsafe!(self.deny_unsafe);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::NetworkState(tx));
|
||||
|
||||
async move { rx.await.map_err(|_| rpc::Error::internal_error()) }
|
||||
.boxed()
|
||||
.compat()
|
||||
async move { rx.await.map_err(|_| rpc::Error::internal_error()) }.boxed()
|
||||
}
|
||||
|
||||
fn system_add_reserved_peer(
|
||||
&self,
|
||||
peer: String,
|
||||
) -> Compat<BoxFuture<'static, std::result::Result<(), rpc::Error>>> {
|
||||
fn system_add_reserved_peer(&self, peer: String) -> rpc::BoxFuture<rpc::Result<()>> {
|
||||
bail_if_unsafe!(self.deny_unsafe);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
@@ -171,13 +161,9 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
||||
}
|
||||
}
|
||||
.boxed()
|
||||
.compat()
|
||||
}
|
||||
|
||||
fn system_remove_reserved_peer(
|
||||
&self,
|
||||
peer: String,
|
||||
) -> Compat<BoxFuture<'static, std::result::Result<(), rpc::Error>>> {
|
||||
fn system_remove_reserved_peer(&self, peer: String) -> rpc::BoxFuture<rpc::Result<()>> {
|
||||
bail_if_unsafe!(self.deny_unsafe);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
@@ -190,34 +176,33 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
||||
}
|
||||
}
|
||||
.boxed()
|
||||
.compat()
|
||||
}
|
||||
|
||||
fn system_reserved_peers(&self) -> Receiver<Vec<String>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::NetworkReservedPeers(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
Receiver(rx)
|
||||
}
|
||||
|
||||
fn system_node_roles(&self) -> Receiver<Vec<NodeRole>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::NodeRoles(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
Receiver(rx)
|
||||
}
|
||||
|
||||
fn system_sync_state(&self) -> Receiver<SyncState<<B::Header as HeaderT>::Number>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::SyncState(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
Receiver(rx)
|
||||
}
|
||||
|
||||
fn system_add_log_filter(&self, directives: String) -> std::result::Result<(), rpc::Error> {
|
||||
fn system_add_log_filter(&self, directives: String) -> rpc::Result<()> {
|
||||
self.deny_unsafe.check_if_safe()?;
|
||||
logging::add_directives(&directives);
|
||||
logging::reload_filter().map_err(|_e| rpc::Error::internal_error())
|
||||
}
|
||||
|
||||
fn system_reset_log_filter(&self) -> std::result::Result<(), rpc::Error> {
|
||||
fn system_reset_log_filter(&self) -> rpc::Result<()> {
|
||||
self.deny_unsafe.check_if_safe()?;
|
||||
logging::reset_log_filter().map_err(|_e| rpc::Error::internal_error())
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use super::*;
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use futures::prelude::*;
|
||||
use futures::{executor, prelude::*};
|
||||
use sc_network::{self, config::Role, PeerId};
|
||||
use sp_utils::mpsc::tracing_unbounded;
|
||||
use std::{
|
||||
@@ -139,8 +139,7 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> {
|
||||
}
|
||||
|
||||
fn wait_receiver<T>(rx: Receiver<T>) -> T {
|
||||
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
runtime.block_on(rx).unwrap()
|
||||
futures::executor::block_on(rx).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -223,12 +222,10 @@ fn system_local_listen_addresses_works() {
|
||||
|
||||
#[test]
|
||||
fn system_peers() {
|
||||
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
|
||||
let peer_id = PeerId::random();
|
||||
let req = api(Status { peer_id: peer_id.clone(), peers: 1, is_syncing: false, is_dev: true })
|
||||
.system_peers();
|
||||
let res = runtime.block_on(req).unwrap();
|
||||
let res = executor::block_on(req).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
res,
|
||||
@@ -243,9 +240,8 @@ fn system_peers() {
|
||||
|
||||
#[test]
|
||||
fn system_network_state() {
|
||||
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
let req = api(None).system_network_state();
|
||||
let res = runtime.block_on(req).unwrap();
|
||||
let res = executor::block_on(req).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
serde_json::from_value::<sc_network::network_state::NetworkState>(res).unwrap(),
|
||||
@@ -278,12 +274,11 @@ fn system_network_add_reserved() {
|
||||
let good_peer_id =
|
||||
"/ip4/198.51.100.19/tcp/30333/p2p/QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV";
|
||||
let bad_peer_id = "/ip4/198.51.100.19/tcp/30333";
|
||||
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
|
||||
let good_fut = api(None).system_add_reserved_peer(good_peer_id.into());
|
||||
let bad_fut = api(None).system_add_reserved_peer(bad_peer_id.into());
|
||||
assert_eq!(runtime.block_on(good_fut), Ok(()));
|
||||
assert!(runtime.block_on(bad_fut).is_err());
|
||||
assert_eq!(executor::block_on(good_fut), Ok(()));
|
||||
assert!(executor::block_on(bad_fut).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -291,12 +286,11 @@ fn system_network_remove_reserved() {
|
||||
let good_peer_id = "QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV";
|
||||
let bad_peer_id =
|
||||
"/ip4/198.51.100.19/tcp/30333/p2p/QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV";
|
||||
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
|
||||
let good_fut = api(None).system_remove_reserved_peer(good_peer_id.into());
|
||||
let bad_fut = api(None).system_remove_reserved_peer(bad_peer_id.into());
|
||||
assert_eq!(runtime.block_on(good_fut), Ok(()));
|
||||
assert!(runtime.block_on(bad_fut).is_err());
|
||||
assert_eq!(executor::block_on(good_fut), Ok(()));
|
||||
assert!(executor::block_on(bad_fut).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user