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:
Bastian Köcher
2021-08-13 08:46:07 +02:00
committed by GitHub
parent 199b2883af
commit c44aba89e6
65 changed files with 1422 additions and 1291 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ use sp_runtime::transaction_validity::InvalidTransaction;
pub type Result<T> = std::result::Result<T, Error>;
/// Author RPC future Result type.
pub type FutureResult<T> = Box<dyn rpc::futures::Future<Item = T, Error = Error> + Send>;
pub type FutureResult<T> = jsonrpc_core::BoxFuture<Result<T>>;
/// Author RPC errors.
#[derive(Debug, derive_more::Display, derive_more::From)]
+1 -1
View File
@@ -25,7 +25,7 @@ use jsonrpc_core as rpc;
pub type Result<T> = std::result::Result<T, Error>;
/// Chain RPC future Result type.
pub type FutureResult<T> = Box<dyn rpc::futures::Future<Item = T, Error = Error> + Send>;
pub type FutureResult<T> = jsonrpc_core::BoxFuture<Result<T>>;
/// Chain RPC errors.
#[derive(Debug, derive_more::Display, derive_more::From)]
+15 -7
View File
@@ -16,18 +16,26 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use futures::{channel::oneshot, compat::Compat};
use jsonrpc_core::futures::prelude::*;
use futures::{channel::oneshot, Future};
use std::pin::Pin;
/// Wraps around `oneshot::Receiver` and adjusts the error type to produce an internal error if the
/// sender gets dropped.
pub struct Receiver<T>(pub Compat<oneshot::Receiver<T>>);
pub struct Receiver<T>(pub oneshot::Receiver<T>);
impl<T> Future for Receiver<T> {
type Item = T;
type Error = jsonrpc_core::Error;
type Output = Result<T, jsonrpc_core::Error>;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
self.0.poll().map_err(|_| jsonrpc_core::Error::internal_error())
fn poll(
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
Future::poll(Pin::new(&mut self.0), cx).map_err(|_| jsonrpc_core::Error::internal_error())
}
}
impl<T: Send + 'static> jsonrpc_core::WrapFuture<T, jsonrpc_core::Error> for Receiver<T> {
fn into_future(self) -> jsonrpc_core::BoxFuture<Result<T, jsonrpc_core::Error>> {
Box::pin(async { self.await })
}
}
+6 -6
View File
@@ -19,7 +19,7 @@
//! RPC Metadata
use std::sync::Arc;
use jsonrpc_core::futures::sync::mpsc;
use futures::channel::mpsc;
use jsonrpc_pubsub::{PubSubMetadata, Session};
/// RPC Metadata.
@@ -41,20 +41,20 @@ impl PubSubMetadata for Metadata {
impl Metadata {
/// Create new `Metadata` with session (Pub/Sub) support.
pub fn new(transport: mpsc::Sender<String>) -> Self {
pub fn new(transport: mpsc::UnboundedSender<String>) -> Self {
Metadata { session: Some(Arc::new(Session::new(transport))) }
}
/// Create new `Metadata` for tests.
#[cfg(test)]
pub fn new_test() -> (mpsc::Receiver<String>, Self) {
let (tx, rx) = mpsc::channel(1);
pub fn new_test() -> (mpsc::UnboundedReceiver<String>, Self) {
let (tx, rx) = mpsc::unbounded();
(rx, Self::new(tx))
}
}
impl From<mpsc::Sender<String>> for Metadata {
fn from(sender: mpsc::Sender<String>) -> Self {
impl From<mpsc::UnboundedSender<String>> for Metadata {
fn from(sender: mpsc::UnboundedSender<String>) -> Self {
Self::new(sender)
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ use jsonrpc_core as rpc;
pub type Result<T> = std::result::Result<T, Error>;
/// State RPC future Result type.
pub type FutureResult<T> = Box<dyn rpc::futures::Future<Item = T, Error = Error> + Send>;
pub type FutureResult<T> = jsonrpc_core::BoxFuture<Result<T>>;
/// State RPC errors.
#[derive(Debug, derive_more::Display, derive_more::From)]
+5 -12
View File
@@ -22,7 +22,7 @@ pub mod error;
pub mod helpers;
use crate::helpers::Receiver;
use futures::{compat::Compat, future::BoxFuture};
use jsonrpc_core::BoxFuture;
use jsonrpc_derive::rpc;
use self::error::Result as SystemResult;
@@ -76,9 +76,7 @@ pub trait SystemApi<Hash, Number> {
/// Returns currently connected peers
#[rpc(name = "system_peers", returns = "Vec<PeerInfo<Hash, Number>>")]
fn system_peers(
&self,
) -> Compat<BoxFuture<'static, jsonrpc_core::Result<Vec<PeerInfo<Hash, Number>>>>>;
fn system_peers(&self) -> BoxFuture<jsonrpc_core::Result<Vec<PeerInfo<Hash, Number>>>>;
/// Returns current state of the network.
///
@@ -87,9 +85,7 @@ pub trait SystemApi<Hash, Number> {
// TODO: the future of this call is uncertain: https://github.com/paritytech/substrate/issues/1890
// https://github.com/paritytech/substrate/issues/5541
#[rpc(name = "system_unstable_networkState", returns = "jsonrpc_core::Value")]
fn system_network_state(
&self,
) -> Compat<BoxFuture<'static, jsonrpc_core::Result<jsonrpc_core::Value>>>;
fn system_network_state(&self) -> BoxFuture<jsonrpc_core::Result<jsonrpc_core::Value>>;
/// Adds a reserved peer. Returns the empty string or an error. The string
/// parameter should encode a `p2p` multiaddr.
@@ -97,10 +93,7 @@ pub trait SystemApi<Hash, Number> {
/// `/ip4/198.51.100.19/tcp/30333/p2p/QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV`
/// is an example of a valid, passing multiaddr with PeerId attached.
#[rpc(name = "system_addReservedPeer", returns = "()")]
fn system_add_reserved_peer(
&self,
peer: String,
) -> Compat<BoxFuture<'static, Result<(), jsonrpc_core::Error>>>;
fn system_add_reserved_peer(&self, peer: String) -> BoxFuture<Result<(), jsonrpc_core::Error>>;
/// Remove a reserved peer. Returns the empty string or an error. The string
/// should encode only the PeerId e.g. `QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV`.
@@ -108,7 +101,7 @@ pub trait SystemApi<Hash, Number> {
fn system_remove_reserved_peer(
&self,
peer_id: String,
) -> Compat<BoxFuture<'static, Result<(), jsonrpc_core::Error>>>;
) -> BoxFuture<Result<(), jsonrpc_core::Error>>;
/// Returns the list of reserved peers
#[rpc(name = "system_reservedPeers", returns = "Vec<String>")]