diff --git a/subxt/src/rpc/rpc_client.rs b/subxt/src/rpc/rpc_client.rs index 56592c0363..00d801cf3c 100644 --- a/subxt/src/rpc/rpc_client.rs +++ b/subxt/src/rpc/rpc_client.rs @@ -5,6 +5,7 @@ use super::{ RpcClientT, RpcSubscription, + RpcSubscriptionId, }; use crate::error::Error; use futures::{ @@ -60,8 +61,8 @@ impl RpcClient { params: RpcParams, unsub: &str, ) -> Result, Error> { - let sub = self.0.subscribe_raw(sub, params.build(), unsub).await?; - Ok(Subscription::new(sub)) + let (sub, sub_id) = self.0.subscribe_raw(sub, params.build(), unsub).await?; + Ok(Subscription::new(sub, sub_id)) } } @@ -166,6 +167,7 @@ impl RpcParams { /// [`StreamExt`] extension trait. pub struct Subscription { inner: RpcSubscription, + sub_id: Option, _marker: std::marker::PhantomData, } @@ -179,12 +181,18 @@ impl std::fmt::Debug for Subscription { } impl Subscription { - fn new(inner: RpcSubscription) -> Self { + fn new(inner: RpcSubscription, sub_id: Option) -> Self { Self { inner, + sub_id, _marker: std::marker::PhantomData, } } + + /// Obtain the ID associated with this subscription. + pub fn subscription_id(&self) -> Option<&RpcSubscriptionId> { + self.sub_id.as_ref() + } } impl Subscription {