mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 01:07:57 +00:00
Use Subscription Manager from jsonrpc-pubsub (#6208)
* Bump jsonrpc pubsub, core, http, and ws Right now these are the packages which _need_ to be updated so I can just the latest `jsonrpc-pubsub` code. Once a release it cut upstream the rest of the dependencies should be updated as well. * Use jsonrpc-pubsub's SubscriptionManager This places sc-rpc-api::Subscriptions * Bump jsonrpc-core outside of sc-rpc-* * Update client/rpc tests Right now one of the `author` tests is failing, I need to think a bit about how best to fix it. * Remove Subscriptions manager There's no need for this implementation since we're using the one from `jsonrpc-pubsub` now * Fix author RPC test This test used to check for a numerial subscription ID, whereas now it uses a string based ID which is the default provided by `jsonrpc-pubsub`'s subscription manager. * Remove unused NumericIdProvider * Add missing bracket Removed one too many with that last one, lol * Bump `jsonrpc` to v14.2 There's an exception though. `jsonrpc-derive` cannot be bumped past v14.0.5 just yet since it has a dependency on `quote` pinned to v1.0.1. This means that at the moment it won't build on Substrate since it's using v1.0.3. * Track `jsonrpc-derive` master branch * Bump `quote` version to v1.0.6 * Bump `jsonrpc-derive` to v14.2.1 This includes support for `quote` v1.0.6
This commit is contained in:
@@ -32,8 +32,8 @@ use rpc::futures::{
|
||||
};
|
||||
use futures::{StreamExt as _, compat::Compat};
|
||||
use futures::future::{ready, FutureExt, TryFutureExt};
|
||||
use sc_rpc_api::{DenyUnsafe, Subscriptions};
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
use sc_rpc_api::DenyUnsafe;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, manager::SubscriptionManager};
|
||||
use codec::{Encode, Decode};
|
||||
use sp_core::{Bytes, traits::BareCryptoStorePtr};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
@@ -55,7 +55,7 @@ pub struct Author<P, Client> {
|
||||
/// Transactions pool
|
||||
pool: Arc<P>,
|
||||
/// Subscriptions manager
|
||||
subscriptions: Subscriptions,
|
||||
subscriptions: SubscriptionManager,
|
||||
/// The key store.
|
||||
keystore: BareCryptoStorePtr,
|
||||
/// Whether to deny unsafe calls
|
||||
@@ -67,7 +67,7 @@ impl<P, Client> Author<P, Client> {
|
||||
pub fn new(
|
||||
client: Arc<Client>,
|
||||
pool: Arc<P>,
|
||||
subscriptions: Subscriptions,
|
||||
subscriptions: SubscriptionManager,
|
||||
keystore: BareCryptoStorePtr,
|
||||
deny_unsafe: DenyUnsafe,
|
||||
) -> Self {
|
||||
@@ -81,7 +81,6 @@ impl<P, Client> Author<P, Client> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Currently we treat all RPC transactions as externals.
|
||||
///
|
||||
/// Possibly in the future we could allow opt-in for special treatment
|
||||
|
||||
@@ -81,7 +81,7 @@ impl TestSetup {
|
||||
Author {
|
||||
client: self.client.clone(),
|
||||
pool: self.pool.clone(),
|
||||
subscriptions: Subscriptions::new(Arc::new(crate::testing::TaskExecutor)),
|
||||
subscriptions: SubscriptionManager::new(Arc::new(crate::testing::TaskExecutor)),
|
||||
keystore: self.keystore.clone(),
|
||||
deny_unsafe: DenyUnsafe::No,
|
||||
}
|
||||
@@ -133,8 +133,14 @@ fn should_watch_extrinsic() {
|
||||
uxt(AccountKeyring::Alice, 0).encode().into(),
|
||||
);
|
||||
|
||||
// then
|
||||
assert_eq!(executor::block_on(id_rx.compat()), Ok(Ok(1.into())));
|
||||
let id = executor::block_on(id_rx.compat()).unwrap().unwrap();
|
||||
assert_matches!(id, SubscriptionId::String(_));
|
||||
|
||||
let id = match id {
|
||||
SubscriptionId::String(id) => id,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
// check notifications
|
||||
let replacement = {
|
||||
let tx = Transfer {
|
||||
@@ -147,15 +153,22 @@ fn should_watch_extrinsic() {
|
||||
};
|
||||
AuthorApi::submit_extrinsic(&p, replacement.encode().into()).wait().unwrap();
|
||||
let (res, data) = executor::block_on(data.into_future().compat()).unwrap();
|
||||
assert_eq!(
|
||||
res,
|
||||
Some(r#"{"jsonrpc":"2.0","method":"test","params":{"result":"ready","subscription":1}}"#.into())
|
||||
);
|
||||
|
||||
let expected = Some(format!(
|
||||
r#"{{"jsonrpc":"2.0","method":"test","params":{{"result":"ready","subscription":"{}"}}}}"#,
|
||||
id,
|
||||
));
|
||||
assert_eq!(res, expected);
|
||||
|
||||
let h = blake2_256(&replacement.encode());
|
||||
assert_eq!(
|
||||
executor::block_on(data.into_future().compat()).unwrap().0,
|
||||
Some(format!(r#"{{"jsonrpc":"2.0","method":"test","params":{{"result":{{"usurped":"0x{}"}},"subscription":1}}}}"#, HexDisplay::from(&h)))
|
||||
);
|
||||
let expected = Some(format!(
|
||||
r#"{{"jsonrpc":"2.0","method":"test","params":{{"result":{{"usurped":"0x{}"}},"subscription":"{}"}}}}"#,
|
||||
HexDisplay::from(&h),
|
||||
id,
|
||||
));
|
||||
|
||||
let res = executor::block_on(data.into_future().compat()).unwrap().0;
|
||||
assert_eq!(res, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user