mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Global unique subscription ids. (#848)
* Global unique subscription ids. * Fix tests.
This commit is contained in:
@@ -36,7 +36,6 @@ use primitives::{Bytes, Blake2Hasher};
|
||||
use rpc::futures::{Sink, Stream, Future};
|
||||
use runtime_primitives::{generic, traits};
|
||||
use subscriptions::Subscriptions;
|
||||
use tokio::runtime::TaskExecutor;
|
||||
|
||||
pub mod error;
|
||||
|
||||
@@ -60,7 +59,7 @@ build_rpc_trait! {
|
||||
/// Returns all pending extrinsics, potentially grouped by sender.
|
||||
#[rpc(name = "author_pendingExtrinsics")]
|
||||
fn pending_extrinsics(&self) -> Result<PendingExtrinsics>;
|
||||
|
||||
|
||||
#[pubsub(name = "author_extrinsicUpdate")] {
|
||||
/// Submit an extrinsic to watch.
|
||||
#[rpc(name = "author_submitAndWatchExtrinsic")]
|
||||
@@ -90,11 +89,15 @@ impl<B, E, P> Author<B, E, P> where
|
||||
P: PoolChainApi + Sync + Send + 'static,
|
||||
{
|
||||
/// Create new instance of Authoring API.
|
||||
pub fn new(client: Arc<Client<B, E, <P as PoolChainApi>::Block>>, pool: Arc<Pool<P>>, executor: TaskExecutor) -> Self {
|
||||
pub fn new(
|
||||
client: Arc<Client<B, E, <P as PoolChainApi>::Block>>,
|
||||
pool: Arc<Pool<P>>,
|
||||
subscriptions: Subscriptions,
|
||||
) -> Self {
|
||||
Author {
|
||||
client,
|
||||
pool,
|
||||
subscriptions: Subscriptions::new(executor),
|
||||
subscriptions,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ use runtime_primitives::generic::BlockId;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Verified
|
||||
{
|
||||
sender: u64,
|
||||
sender: u64,
|
||||
hash: u64,
|
||||
}
|
||||
|
||||
@@ -57,13 +57,13 @@ impl ChainApi for TestApi {
|
||||
Ok(Verified {
|
||||
sender: uxt.transfer.from[31] as u64,
|
||||
hash: uxt.transfer.nonce,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn is_ready(&self, _at: &BlockId<Block>, _c: &mut Self::Ready, _xt: &VerifiedFor<Self>) -> Readiness {
|
||||
Readiness::Ready
|
||||
}
|
||||
|
||||
|
||||
fn ready(&self) -> Self::Ready { }
|
||||
|
||||
fn compare(old: &VerifiedFor<Self>, other: &VerifiedFor<Self>) -> ::std::cmp::Ordering {
|
||||
@@ -151,12 +151,12 @@ fn should_watch_extrinsic() {
|
||||
p.watch_extrinsic(Default::default(), subscriber, uxt(5, 5).encode().into());
|
||||
|
||||
// then
|
||||
assert_eq!(runtime.block_on(id_rx), Ok(Ok(0.into())));
|
||||
assert_eq!(runtime.block_on(id_rx), Ok(Ok(1.into())));
|
||||
// check notifications
|
||||
AuthorApi::submit_rich_extrinsic(&p, uxt(5, 1)).unwrap();
|
||||
assert_eq!(
|
||||
runtime.block_on(data.into_future()).unwrap().0,
|
||||
Some(r#"{"jsonrpc":"2.0","method":"test","params":{"result":{"usurped":1},"subscription":0}}"#.into())
|
||||
Some(r#"{"jsonrpc":"2.0","method":"test","params":{"result":{"usurped":1},"subscription":1}}"#.into())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user