rpc: Expose the subscription ID for RpcClientT (#733)

* rpc: Extend `RpcClientT` to return the subscription ID

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Return `RpcSubscriptionId` for jsonrpsee clients

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Expose subscription ID via subxt subscription

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* examples: Adjust example to return subscription ID

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Add structure for subscription stream and subscription id

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-11-25 17:07:26 +02:00
committed by GitHub
parent f0ce26db7b
commit 463e2aa93f
5 changed files with 48 additions and 15 deletions
+7 -1
View File
@@ -5,6 +5,7 @@
use super::{
RpcClientT,
RpcSubscription,
RpcSubscriptionId,
};
use crate::error::Error;
use futures::{
@@ -185,6 +186,11 @@ impl<Res> Subscription<Res> {
_marker: std::marker::PhantomData,
}
}
/// Obtain the ID associated with this subscription.
pub fn subscription_id(&self) -> Option<&RpcSubscriptionId> {
self.inner.id.as_ref()
}
}
impl<Res: DeserializeOwned> Subscription<Res> {
@@ -203,7 +209,7 @@ impl<Res: DeserializeOwned> Stream for Subscription<Res> {
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> Poll<Option<Self::Item>> {
let res = futures::ready!(self.inner.poll_next_unpin(cx));
let res = futures::ready!(self.inner.stream.poll_next_unpin(cx));
// Decode the inner RawValue to the type we're expecting and map
// any errors to the right shape: