From cb4bee5c03af2a41e2f1bc4bf18bb55a80ddb474 Mon Sep 17 00:00:00 2001 From: Greg Hill Date: Mon, 22 Mar 2021 10:55:14 +0000 Subject: [PATCH] return none if subscription returns early (#250) * return none if subscription returns early Signed-off-by: Gregory Hill * add comment on subscription close Signed-off-by: Gregory Hill * no need for jsonrpsee error enum Signed-off-by: Gregory Hill --- src/subscription.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/subscription.rs b/src/subscription.rs index 485c614340..8ade68a789 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with substrate-subxt. If not, see . -use jsonrpsee_types::error::Error as RpcError; use jsonrpsee_ws_client::WsSubscription as Subscription; use sp_core::{ storage::{ @@ -95,14 +94,8 @@ impl<'a, T: Runtime> EventSubscription<'a, T> { if self.finished { return None } - let change_set = match self.subscription.next().await { - Some(c) => c, - None => { - return Some(Err( - RpcError::Custom("RPC subscription dropped".into()).into() - )) - } - }; + // always return None if subscription has closed + let change_set = self.subscription.next().await?; if let Some(hash) = self.block.as_ref() { if &change_set.block == hash { self.finished = true; @@ -184,13 +177,12 @@ impl FinalizedEventStorageSubscription { return Some(storage_change) } let header: T::Header = self.subscription.next().await?; - if let Ok(storage_changes) = self - .rpc - .query_storage_at(&[self.storage_key.clone()], Some(header.hash())) - .await - { - self.storage_changes.extend(storage_changes); - } + self.storage_changes.extend( + self.rpc + .query_storage_at(&[self.storage_key.clone()], Some(header.hash())) + .await + .ok()?, + ); } } }