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
+3 -3
View File
@@ -12,9 +12,9 @@ description = "Substrate RPC for FRAME's support"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = { version = "0.3.0", features = ["compat"] }
jsonrpc-client-transports = { version = "15.1.0", default-features = false, features = ["http"] }
jsonrpc-core = "15.1.0"
futures = "0.3.16"
jsonrpc-client-transports = { version = "18.0.0", features = ["http"] }
jsonrpc-core = "18.0.0"
codec = { package = "parity-scale-codec", version = "2.0.0" }
serde = "1"
frame-support = { version = "4.0.0-dev", path = "../../../../frame/support" }
+3 -5
View File
@@ -23,7 +23,6 @@
use codec::{DecodeAll, FullCodec, FullEncode};
use core::marker::PhantomData;
use frame_support::storage::generator::{StorageDoubleMap, StorageMap, StorageValue};
use futures::compat::Future01CompatExt;
use jsonrpc_client_transports::RpcError;
use sc_rpc_api::state::StateClient;
use serde::{de::DeserializeOwned, Serialize};
@@ -32,7 +31,6 @@ use sp_storage::{StorageData, StorageKey};
/// A typed query on chain state usable from an RPC client.
///
/// ```no_run
/// # use futures::compat::Future01CompatExt;
/// # use jsonrpc_client_transports::RpcError;
/// # use jsonrpc_client_transports::transports::http;
/// # use codec::Encode;
@@ -69,7 +67,7 @@ use sp_storage::{StorageData, StorageKey};
/// }
///
/// # async fn test() -> Result<(), RpcError> {
/// let conn = http::connect("http://[::1]:9933").compat().await?;
/// let conn = http::connect("http://[::1]:9933").await?;
/// let cl = StateClient::<Hash>::new(conn);
///
/// let q = StorageQuery::value::<LastActionId>();
@@ -127,9 +125,9 @@ impl<V: FullCodec> StorageQuery<V> {
state_client: &StateClient<Hash>,
block_index: Option<Hash>,
) -> Result<Option<V>, RpcError> {
let opt: Option<StorageData> = state_client.storage(self.key, block_index).compat().await?;
let opt: Option<StorageData> = state_client.storage(self.key, block_index).await?;
opt.map(|encoded| V::decode_all(&encoded.0))
.transpose()
.map_err(|decode_err| RpcError::Other(decode_err.into()))
.map_err(|decode_err| RpcError::Other(Box::new(decode_err)))
}
}
+4 -4
View File
@@ -15,10 +15,10 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
sc-client-api = { version = "4.0.0-dev", path = "../../../../client/api" }
codec = { package = "parity-scale-codec", version = "2.0.0" }
futures = { version = "0.3.4", features = ["compat"] }
jsonrpc-core = "15.1.0"
jsonrpc-core-client = "15.1.0"
jsonrpc-derive = "15.1.0"
futures = "0.3.16"
jsonrpc-core = "18.0.0"
jsonrpc-core-client = "18.0.0"
jsonrpc-derive = "18.0.0"
log = "0.4.8"
serde = { version = "1.0.126", features = ["derive"] }
sp-runtime = { version = "4.0.0-dev", path = "../../../../primitives/runtime" }
+35 -34
View File
@@ -19,12 +19,9 @@
use std::sync::Arc;
use codec::{self, Codec, Decode, Encode};
use futures::future::{ready, TryFutureExt};
use jsonrpc_core::{
futures::future::{self as rpc_future, result, Future},
Error as RpcError, ErrorCode,
};
use codec::{Codec, Decode, Encode};
use futures::{future::ready, FutureExt, TryFutureExt};
use jsonrpc_core::{Error as RpcError, ErrorCode};
use jsonrpc_derive::rpc;
use sc_client_api::light::{future_header, Fetcher, RemoteBlockchain, RemoteCallRequest};
use sc_rpc_api::DenyUnsafe;
@@ -38,7 +35,7 @@ pub use self::gen_client::Client as SystemClient;
pub use frame_system_rpc_runtime_api::AccountNonceApi;
/// Future that resolves to account nonce.
pub type FutureResult<T> = Box<dyn Future<Item = T, Error = RpcError> + Send>;
type FutureResult<T> = jsonrpc_core::BoxFuture<Result<T, RpcError>>;
/// System RPC methods.
#[rpc]
@@ -116,7 +113,8 @@ where
Ok(adjust_nonce(&*self.pool, account, nonce))
};
Box::new(result(get_nonce()))
let res = get_nonce();
async move { res }.boxed()
}
fn dry_run(
@@ -125,7 +123,7 @@ where
at: Option<<Block as traits::Block>::Hash>,
) -> FutureResult<Bytes> {
if let Err(err) = self.deny_unsafe.check_if_safe() {
return Box::new(rpc_future::err(err.into()))
return async move { Err(err.into()) }.boxed()
}
let dry_run = || {
@@ -150,7 +148,9 @@ where
Ok(Encode::encode(&result).into())
};
Box::new(result(dry_run()))
let res = dry_run();
async move { res }.boxed()
}
}
@@ -197,19 +197,19 @@ where
.ok_or_else(|| ClientError::UnknownBlock(format!("{}", best_hash))),
)
});
let future_nonce = future_best_header
.and_then(move |best_header| {
fetcher.remote_call(RemoteCallRequest {
block: best_hash,
header: best_header,
method: "AccountNonceApi_account_nonce".into(),
call_data,
retry_count: None,
})
let future_nonce = future_best_header.and_then(move |best_header| {
fetcher.remote_call(RemoteCallRequest {
block: best_hash,
header: best_header,
method: "AccountNonceApi_account_nonce".into(),
call_data,
retry_count: None,
})
.compat();
let future_nonce = future_nonce.and_then(|nonce| {
Decode::decode(&mut &nonce[..])
});
let future_nonce = future_nonce.and_then(|nonce| async move {
Index::decode(&mut &nonce[..])
.map_err(|e| ClientError::CallResultDecode("Cannot decode account nonce", e))
});
let future_nonce = future_nonce.map_err(|e| RpcError {
@@ -219,9 +219,7 @@ where
});
let pool = self.pool.clone();
let future_nonce = future_nonce.map(move |nonce| adjust_nonce(&*pool, account, nonce));
Box::new(future_nonce)
future_nonce.map_ok(move |nonce| adjust_nonce(&*pool, account, nonce)).boxed()
}
fn dry_run(
@@ -229,11 +227,14 @@ where
_extrinsic: Bytes,
_at: Option<<Block as traits::Block>::Hash>,
) -> FutureResult<Bytes> {
Box::new(result(Err(RpcError {
code: ErrorCode::MethodNotFound,
message: "Unable to dry run extrinsic.".into(),
data: None,
})))
async {
Err(RpcError {
code: ErrorCode::MethodNotFound,
message: "Unable to dry run extrinsic.".into(),
data: None,
})
}
.boxed()
}
}
@@ -317,7 +318,7 @@ mod tests {
let nonce = accounts.nonce(AccountKeyring::Alice.into());
// then
assert_eq!(nonce.wait().unwrap(), 2);
assert_eq!(block_on(nonce).unwrap(), 2);
}
#[test]
@@ -336,7 +337,7 @@ mod tests {
let res = accounts.dry_run(vec![].into(), None);
// then
assert_eq!(res.wait(), Err(RpcError::method_not_found()));
assert_eq!(block_on(res), Err(RpcError::method_not_found()));
}
#[test]
@@ -363,7 +364,7 @@ mod tests {
let res = accounts.dry_run(tx.encode().into(), None);
// then
let bytes = res.wait().unwrap().0;
let bytes = block_on(res).unwrap().0;
let apply_res: ApplyExtrinsicResult = Decode::decode(&mut bytes.as_slice()).unwrap();
assert_eq!(apply_res, Ok(Ok(())));
}
@@ -392,7 +393,7 @@ mod tests {
let res = accounts.dry_run(tx.encode().into(), None);
// then
let bytes = res.wait().unwrap().0;
let bytes = block_on(res).unwrap().0;
let apply_res: ApplyExtrinsicResult = Decode::decode(&mut bytes.as_slice()).unwrap();
assert_eq!(apply_res, Err(TransactionValidityError::Invalid(InvalidTransaction::Stale)));
}